Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /// \file exoticphysics/monopole/src/G4Monopol << 26 // $Id: G4MonopoleFieldSetup.cc,v 1.2 2010/11/29 15:14:17 vnivanch Exp $ 27 /// \brief Implementation of the G4MonopoleFie << 27 // GEANT4 tag $Name: geant4-09-04 $ 28 // << 29 // 28 // 30 //....oooOO0OOooo........oooOO0OOooo........oo 29 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 // 31 // 33 // 32 // 34 // G4MonopoleFieldSetup is responsible for set 33 // G4MonopoleFieldSetup is responsible for setting up a magnetic field 35 // and the ability to use it with two differen << 34 // and the ability to use it with two different equation of motions, 36 // one for monopoles and another for the rest << 35 // one for monopoles and another for the rest of the particles. 37 // << 36 // 38 // << 37 // 39 38 40 // =========================================== 39 // ======================================================================= 41 // Created: 13 May 2010, B. Bozsogi 40 // Created: 13 May 2010, B. Bozsogi 42 // =========================================== 41 // ======================================================================= 43 42 44 #include "G4MonopoleFieldSetup.hh" 43 #include "G4MonopoleFieldSetup.hh" >> 44 #include "G4MonopoleFieldMessenger.hh" 45 45 46 #include "G4ChordFinder.hh" << 46 #include "G4MagneticField.hh" >> 47 #include "G4UniformMagField.hh" 47 #include "G4FieldManager.hh" 48 #include "G4FieldManager.hh" 48 #include "G4MagIntegratorStepper.hh" << 49 #include "G4TransportationManager.hh" 49 #include "G4Mag_UsualEqRhs.hh" 50 #include "G4Mag_UsualEqRhs.hh" 50 #include "G4MagneticField.hh" << 51 #include "G4MonopoleEquation.hh" 51 #include "G4MonopoleEquation.hh" 52 #include "G4MonopoleFieldMessenger.hh" << 52 #include "G4MagIntegratorStepper.hh" 53 #include "G4TransportationManager.hh" << 53 #include "G4ChordFinder.hh" 54 #include "G4UniformMagField.hh" << 55 54 56 // #include "G4ExplicitEuler.hh" 55 // #include "G4ExplicitEuler.hh" 57 // #include "G4ImplicitEuler.hh" 56 // #include "G4ImplicitEuler.hh" 58 // #include "G4SimpleRunge.hh" 57 // #include "G4SimpleRunge.hh" 59 // #include "G4SimpleHeum.hh" 58 // #include "G4SimpleHeum.hh" 60 #include "G4ClassicalRK4.hh" 59 #include "G4ClassicalRK4.hh" 61 // #include "G4HelixExplicitEuler.hh" 60 // #include "G4HelixExplicitEuler.hh" 62 // #include "G4HelixImplicitEuler.hh" 61 // #include "G4HelixImplicitEuler.hh" 63 // #include "G4HelixSimpleRunge.hh" 62 // #include "G4HelixSimpleRunge.hh" 64 // #include "G4CashKarpRKF45.hh" 63 // #include "G4CashKarpRKF45.hh" 65 // #include "G4RKG3_Stepper.hh" 64 // #include "G4RKG3_Stepper.hh" 66 65 67 #include "G4SystemOfUnits.hh" << 66 // #include "G4SIunits.hh" 68 << 69 // G4MonopoleFieldSetup* G4MonopoleFieldSetup: << 70 67 71 //....oooOO0OOooo........oooOO0OOooo........oo << 68 G4MonopoleFieldSetup* G4MonopoleFieldSetup::fMonopoleFieldSetup=0; 72 69 >> 70 ////////////////////////////////////////////////////////////////////////// >> 71 // >> 72 // Constructor 73 G4MonopoleFieldSetup::G4MonopoleFieldSetup() 73 G4MonopoleFieldSetup::G4MonopoleFieldSetup() 74 : fFieldManager(0), << 75 fChordFinder(0), << 76 fUsualChordFinder(0), << 77 fMonopoleChordFinder(0), << 78 fEquation(0), << 79 fMonopoleEquation(0), << 80 fMagneticField(0), << 81 fStepper(0), << 82 fMonopoleStepper(0), << 83 fMinStep(0.0), << 84 fZmagFieldValue(0.2 * tesla), << 85 fMonopoleFieldMessenger(0) << 86 { 74 { 87 fMonopoleFieldMessenger = new G4MonopoleFiel << 75 if (!fMonopoleFieldSetup) 88 fFieldManager = GetGlobalFieldManager(); << 76 { >> 77 fChordFinder = 0; >> 78 fStepper = 0; >> 79 fMagneticField = 0; >> 80 >> 81 fMonopoleFieldMessenger = new G4MonopoleFieldMessenger(this); >> 82 } >> 83 else >> 84 { >> 85 G4cerr << "Only ONE instance of G4MonopoleFieldSetup is allowed!" >> 86 << G4endl; >> 87 G4Exception("G4MonopoleFieldSetup::G4MonopoleFieldSetup()", >> 88 "InvalidSetup", FatalException, >> 89 "Only ONE instance of MagneticFieldSetup is allowed!"); >> 90 } 89 } 91 } 90 92 91 //....oooOO0OOooo........oooOO0OOooo........oo << 93 ////////////////////////////////////////////////////////////////////////// 92 << 94 // Retrieve the static instance of the singleton 93 // G4MonopoleFieldSetup* G4MonopoleFieldSetup: << 95 // 94 // { << 96 G4MonopoleFieldSetup* G4MonopoleFieldSetup::GetMonopoleFieldSetup() 95 // if (0 == fMonopoleFieldSetup) << 96 // { << 97 // static G4ThreadLocal G4MonopoleFieldSe << 98 // fMonopoleFieldSetup = &theInstance; << 99 // } << 100 << 101 // return fMonopoleFieldSetup; << 102 // } << 103 << 104 //....oooOO0OOooo........oooOO0OOooo........oo << 105 << 106 G4MonopoleFieldSetup::~G4MonopoleFieldSetup() << 107 { 97 { 108 delete fMonopoleFieldMessenger; << 98 static G4MonopoleFieldSetup theInstance; 109 if (fMagneticField) delete fMagneticField; << 99 if (!fMonopoleFieldSetup) 110 // if(fChordFinder) delete fChordFinder; << 100 { 111 if (fUsualChordFinder) delete fUsualChordFin << 101 fMonopoleFieldSetup = &theInstance; 112 if (fMonopoleChordFinder) delete fMonopoleCh << 102 } 113 if (fStepper) delete fStepper; << 103 114 if (fMonopoleStepper) delete fMonopoleSteppe << 104 return fMonopoleFieldSetup; 115 } 105 } 116 106 117 //....oooOO0OOooo........oooOO0OOooo........oo << 107 //////////////////////////////////////////////////////////////////////////////// 118 108 119 void G4MonopoleFieldSetup::SetZMagFieldValue(G << 109 G4MonopoleFieldSetup::~G4MonopoleFieldSetup() 120 { 110 { 121 // set new magnetic field value and rebuild << 111 delete fMonopoleFieldMessenger; 122 fZmagFieldValue = val; << 112 if(fMagneticField) delete fMagneticField; 123 << 113 if(fChordFinder) delete fChordFinder; 124 ConstructMagField(); << 114 if(fStepper) delete fStepper; >> 115 if(fMonopoleStepper) delete fMonopoleStepper; 125 } 116 } 126 117 127 //....oooOO0OOooo........oooOO0OOooo........oo << 118 //////////////////////////////////////////////////////////////////////////////// 128 119 129 void G4MonopoleFieldSetup::ConstructMagField() << 120 void G4MonopoleFieldSetup::SetMagField(G4double fieldValue) 130 { 121 { 131 // apply a global uniform magnetic field alo << 122 //apply a global uniform magnetic field along Z axis 132 if (fMagneticField) { << 123 if (fMagneticField) { delete fMagneticField; } //delete the existing magn field 133 delete fMagneticField; << 134 } // delete the existing magn field << 135 << 136 if (fZmagFieldValue != 0.) // create a new << 137 { << 138 // G4cout << "Go to create new field ..." << 139 fMagneticField = new G4UniformMagField(G4T << 140 InitialiseAll(); << 141 } << 142 else { << 143 // G4cout << "Set field = 0 ..." << G4endl << 144 fMagneticField = 0; << 145 } << 146 124 147 fFieldManager->SetDetectorField(fMagneticFie << 125 if (fieldValue != 0.) // create a new one if non nul >> 126 { >> 127 fMagneticField = new G4UniformMagField(G4ThreeVector(0., 0., fieldValue)); >> 128 InitialiseAll(); >> 129 } >> 130 else >> 131 { >> 132 fMagneticField = 0; >> 133 fFieldManager->SetDetectorField(fMagneticField); >> 134 } 148 } 135 } 149 136 150 //....oooOO0OOooo........oooOO0OOooo........oo << 137 //////////////////////////////////////////////////////////////////////////////// 151 138 152 void G4MonopoleFieldSetup::InitialiseAll() << 139 void >> 140 G4MonopoleFieldSetup::InitialiseAll() 153 { 141 { 154 fEquation = new G4Mag_UsualEqRhs(fMagneticFi << 142 fFieldManager = G4TransportationManager::GetTransportationManager() >> 143 ->GetFieldManager(); >> 144 >> 145 fEquation = new G4Mag_UsualEqRhs(fMagneticField); 155 fMonopoleEquation = new G4MonopoleEquation(f 146 fMonopoleEquation = new G4MonopoleEquation(fMagneticField); 156 << 147 157 fMinStep = 0.01 * mm; // minimal step of 1 << 148 fMinStep = 0.01*mm ; // minimal step of 1 mm is default 158 << 149 159 fMonopoleStepper = new G4ClassicalRK4(fMonop << 150 fMonopoleStepper = new G4ClassicalRK4( fMonopoleEquation, 8 ); // for time information.. 160 fStepper = new G4ClassicalRK4(fEquation); << 151 fStepper = new G4ClassicalRK4( fEquation ); 161 << 152 162 fUsualChordFinder = new G4ChordFinder(fMagne << 163 fMonopoleChordFinder = new G4ChordFinder(fMa << 164 << 165 SetStepperAndChordFinder(0); 153 SetStepperAndChordFinder(0); 166 } 154 } 167 155 168 //....oooOO0OOooo........oooOO0OOooo........oo << 156 ///////////////////////////////////////////////////////////////////////////// 169 << 157 // >> 158 // Update field >> 159 // 170 void G4MonopoleFieldSetup::SetStepperAndChordF 160 void G4MonopoleFieldSetup::SetStepperAndChordFinder(G4int val) 171 { 161 { 172 if (fMagneticField) { << 162 if (fMagneticField) 173 fFieldManager->SetDetectorField(fMagneticF << 163 { 174 // if(fChordFinder) delete fChordFinder << 164 fFieldManager->SetDetectorField(fMagneticField ); 175 << 165 176 switch (val) { << 166 if(fChordFinder) delete fChordFinder; 177 // case 0: << 167 178 // fChordFinder = new G4ChordF << 168 switch (val) 179 // break; << 169 { 180 // case 1: << 181 // fChordFinder = new G4ChordF << 182 // << 183 // break; << 184 case 0: 170 case 0: 185 fChordFinder = fUsualChordFinder; << 171 fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fStepper); 186 break; 172 break; 187 case 1: << 173 case 1: 188 fChordFinder = fMonopoleChordFinder; << 174 fChordFinder = new G4ChordFinder( fMagneticField, fMinStep, fMonopoleStepper); 189 break; 175 break; 190 } << 176 } 191 << 177 192 fFieldManager->SetChordFinder(fChordFinder << 178 fFieldManager->SetChordFinder( fChordFinder ); 193 } 179 } 194 } 180 } 195 181 196 //....oooOO0OOooo........oooOO0OOooo........oo << 182 //////////////////////////////////////////////////////////////////////////////// 197 << 183 // 198 G4FieldManager* G4MonopoleFieldSetup::GetGloba << 184 // Utility method >> 185 G4FieldManager* G4MonopoleFieldSetup::GetGlobalFieldManager() 199 { 186 { 200 return G4TransportationManager::GetTransport << 187 return G4TransportationManager::GetTransportationManager() >> 188 ->GetFieldManager(); 201 } 189 } 202 << 203 //....oooOO0OOooo........oooOO0OOooo........oo << 204 190