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 // 26 // 27 /// \file field/field04/src/F04GlobalField.cc 27 /// \file field/field04/src/F04GlobalField.cc 28 /// \brief Implementation of the F04GlobalFiel 28 /// \brief Implementation of the F04GlobalField class 29 // 29 // 30 30 31 #include "F04GlobalField.hh" << 31 #include <time.h> 32 32 33 #include "F04FocusSolenoid.hh" << 33 #include "Randomize.hh" 34 #include "F04SimpleSolenoid.hh" << 34 #include "G4TransportationManager.hh" 35 35 36 #include "G4CashKarpRKF45.hh" << 37 #include "G4ClassicalRK4.hh" << 38 #include "G4ExplicitEuler.hh" 36 #include "G4ExplicitEuler.hh" 39 #include "G4ImplicitEuler.hh" 37 #include "G4ImplicitEuler.hh" 40 #include "G4SimpleHeum.hh" << 41 #include "G4SimpleRunge.hh" 38 #include "G4SimpleRunge.hh" >> 39 #include "G4SimpleHeum.hh" >> 40 #include "G4ClassicalRK4.hh" >> 41 #include "G4CashKarpRKF45.hh" 42 #include "G4SystemOfUnits.hh" 42 #include "G4SystemOfUnits.hh" 43 #include "G4TransportationManager.hh" << 44 #include "Randomize.hh" << 45 43 46 #include <ctime> << 44 #include "F04GlobalField.hh" >> 45 #include "F04SimpleSolenoid.hh" >> 46 #include "F04FocusSolenoid.hh" 47 47 48 //....oooOO0OOooo........oooOO0OOooo........oo 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 49 50 G4ThreadLocal F04GlobalField* F04GlobalField:: << 50 G4ThreadLocal F04GlobalField* F04GlobalField::fObject = 0; 51 51 52 //....oooOO0OOooo........oooOO0OOooo........oo 52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 53 54 F04GlobalField::F04GlobalField(F04DetectorCons << 54 F04GlobalField::F04GlobalField(F04DetectorConstruction* det) >> 55 : G4ElectroMagneticField(), // old : G4MagneticField(), >> 56 fMinStep(0.01*mm), fDeltaChord(3.0*mm), >> 57 fDeltaOneStep(0.01*mm), fDeltaIntersection(0.1*mm), >> 58 // fEpsMin(2.5e-7), fEpsMax(0.001), // These are pure numbers -- relative values >> 59 // fEquation(0), fFieldManager(0), >> 60 // fFieldPropagator(0), fStepper(0), fChordFinder(0), >> 61 fDetectorConstruction(det) 55 { 62 { 56 fFieldMessenger = new F04FieldMessenger(this << 63 fFieldMessenger = new F04FieldMessenger(this,det); 57 64 58 fFields = new FieldList(); 65 fFields = new FieldList(); 59 66 >> 67 fStepperType = 4 ; // ClassicalRK4 is default stepper >> 68 60 // set object 69 // set object >> 70 61 fObject = this; 71 fObject = this; >> 72 fFirst = true; >> 73 >> 74 fNfp = 0; >> 75 fFp = NULL; 62 76 63 ConstructField(); 77 ConstructField(); 64 } 78 } 65 79 66 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 81 68 F04GlobalField::~F04GlobalField() 82 F04GlobalField::~F04GlobalField() 69 { 83 { 70 Clear(); 84 Clear(); 71 85 72 delete fFields; 86 delete fFields; 73 87 74 delete fFieldMessenger; 88 delete fFieldMessenger; 75 89 76 delete fEquation; << 90 if (fEquation) delete fEquation; 77 delete fStepper; << 91 if (fStepper) delete fStepper; 78 delete fChordFinder; << 92 if (fChordFinder) delete fChordFinder; 79 } 93 } 80 94 81 //....oooOO0OOooo........oooOO0OOooo........oo 95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 82 96 83 void F04GlobalField::ConstructField() 97 void F04GlobalField::ConstructField() 84 { 98 { 85 Clear(); 99 Clear(); 86 100 87 // Construct equ. of motion of particles th 101 // Construct equ. of motion of particles through B fields 88 // fEquation = new G4Mag_EqRhs(this); << 102 // fEquation = new G4Mag_EqRhs(this); 89 // Construct equ. of motion of particles th 103 // Construct equ. of motion of particles through e.m. fields 90 // fEquation = new G4EqMagElectricField(thi << 104 // fEquation = new G4EqMagElectricField(this); 91 // Construct equ. of motion of particles in 105 // Construct equ. of motion of particles including spin through B fields 92 // fEquation = new G4Mag_SpinEqRhs(this); << 106 // fEquation = new G4Mag_SpinEqRhs(this); 93 // Construct equ. of motion of particles in 107 // Construct equ. of motion of particles including spin through e.m. fields 94 fEquation = new G4EqEMFieldWithSpin(this); 108 fEquation = new G4EqEMFieldWithSpin(this); 95 109 96 // Get transportation, field, and propagato 110 // Get transportation, field, and propagator managers 97 G4TransportationManager* transportManager = << 111 G4TransportationManager* transportManager = >> 112 G4TransportationManager::GetTransportationManager(); 98 113 99 fFieldManager = GetGlobalFieldManager(); 114 fFieldManager = GetGlobalFieldManager(); 100 115 101 fFieldPropagator = transportManager->GetProp 116 fFieldPropagator = transportManager->GetPropagatorInField(); 102 117 103 // Need to SetFieldChangesEnergy to account 118 // Need to SetFieldChangesEnergy to account for a time varying electric 104 // field (r.f. fields) 119 // field (r.f. fields) 105 fFieldManager->SetFieldChangesEnergy(true); 120 fFieldManager->SetFieldChangesEnergy(true); 106 121 107 // Set the field 122 // Set the field 108 fFieldManager->SetDetectorField(this); 123 fFieldManager->SetDetectorField(this); 109 124 110 // Choose a stepper for integration of the 125 // Choose a stepper for integration of the equation of motion 111 SetStepper(); 126 SetStepper(); 112 127 113 // Create a cord finder providing the (glob 128 // Create a cord finder providing the (global field, min step length, 114 // a pointer to the stepper) 129 // a pointer to the stepper) 115 fChordFinder = new G4ChordFinder((G4Magnetic << 130 fChordFinder = new G4ChordFinder((G4MagneticField*)this,fMinStep,fStepper); 116 131 117 // Set accuracy parameters 132 // Set accuracy parameters 118 fChordFinder->SetDeltaChord(fDeltaChord); << 133 fChordFinder->SetDeltaChord( fDeltaChord ); 119 134 120 fFieldManager->SetAccuraciesWithDeltaOneStep 135 fFieldManager->SetAccuraciesWithDeltaOneStep(fDeltaOneStep); 121 136 122 fFieldManager->SetDeltaIntersection(fDeltaIn 137 fFieldManager->SetDeltaIntersection(fDeltaIntersection); 123 138 124 fFieldPropagator->SetMinimumEpsilonStep(fEps 139 fFieldPropagator->SetMinimumEpsilonStep(fEpsMin); 125 fFieldPropagator->SetMaximumEpsilonStep(fEps 140 fFieldPropagator->SetMaximumEpsilonStep(fEpsMax); 126 141 127 G4cout << "Accuracy Parameters:" << 142 G4cout << "Accuracy Parameters:" << 128 << " MinStep=" << fMinStep << " Delta << 143 " MinStep=" << fMinStep << 129 << " DeltaOneStep=" << fDeltaOneStep << 144 " DeltaChord=" << fDeltaChord << 130 G4cout << " " << 145 " DeltaOneStep=" << fDeltaOneStep << G4endl; 131 << " DeltaIntersection=" << fDeltaInt << 146 G4cout << " " << 132 << " EpsMax=" << fEpsMax << G4endl; << 147 " DeltaIntersection=" << fDeltaIntersection << >> 148 " EpsMin=" << fEpsMin << >> 149 " EpsMax=" << fEpsMax << G4endl; 133 150 134 fFieldManager->SetChordFinder(fChordFinder); 151 fFieldManager->SetChordFinder(fChordFinder); 135 152 136 G4double l = 0.0; 153 G4double l = 0.0; 137 G4double B1 = fDetectorConstruction->GetCapt 154 G4double B1 = fDetectorConstruction->GetCaptureMgntB1(); 138 G4double B2 = fDetectorConstruction->GetCapt 155 G4double B2 = fDetectorConstruction->GetCaptureMgntB2(); 139 156 140 G4LogicalVolume* logicCaptureMgnt = fDetecto 157 G4LogicalVolume* logicCaptureMgnt = fDetectorConstruction->GetCaptureMgnt(); 141 G4ThreeVector captureMgntCenter = fDetectorC << 158 G4ThreeVector captureMgntCenter = >> 159 fDetectorConstruction->GetCaptureMgntCenter(); 142 160 143 auto focusSolenoid = new F04FocusSolenoid(B1 << 161 F04FocusSolenoid* focusSolenoid = 144 focusSolenoid->SetHalf(true); << 162 new F04FocusSolenoid(B1, B2, l, logicCaptureMgnt,captureMgntCenter); >> 163 focusSolenoid -> SetHalf(true); 145 164 146 G4double B = fDetectorConstruction->GetTrans 165 G4double B = fDetectorConstruction->GetTransferMgntB(); 147 166 148 G4LogicalVolume* logicTransferMgnt = fDetect << 167 G4LogicalVolume* logicTransferMgnt = 149 G4ThreeVector transferMgntCenter = fDetector << 168 fDetectorConstruction->GetTransferMgnt(); >> 169 G4ThreeVector transferMgntCenter = >> 170 fDetectorConstruction->GetTransferMgntCenter(); 150 171 151 auto simpleSolenoid = new F04SimpleSolenoid( << 172 F04SimpleSolenoid* simpleSolenoid = >> 173 new F04SimpleSolenoid(B, l, logicTransferMgnt,transferMgntCenter); 152 174 153 simpleSolenoid->SetColor("1,0,1"); 175 simpleSolenoid->SetColor("1,0,1"); 154 simpleSolenoid->SetColor("0,1,1"); 176 simpleSolenoid->SetColor("0,1,1"); 155 simpleSolenoid->SetMaxStep(1.5 * mm); << 177 simpleSolenoid->SetMaxStep(1.5*mm); 156 simpleSolenoid->SetMaxStep(2.5 * mm); << 178 simpleSolenoid->SetMaxStep(2.5*mm); 157 179 158 if (fFields) { 180 if (fFields) { 159 if (fFields->size() > 0) { << 181 if (fFields->size()>0) { 160 FieldList::iterator i; << 182 FieldList::iterator i; 161 for (i = fFields->begin(); i != fFields- << 183 for (i=fFields->begin(); i!=fFields->end(); ++i){ 162 (*i)->Construct(); << 184 (*i)->Construct(); 163 } << 185 } 164 } << 186 } 165 } 187 } 166 } 188 } 167 189 168 //....oooOO0OOooo........oooOO0OOooo........oo 190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 169 191 170 F04GlobalField* F04GlobalField::GetObject(F04D 192 F04GlobalField* F04GlobalField::GetObject(F04DetectorConstruction* det) 171 { 193 { 172 if (!fObject) new F04GlobalField(det); 194 if (!fObject) new F04GlobalField(det); 173 return fObject; 195 return fObject; 174 } 196 } 175 197 176 //....oooOO0OOooo........oooOO0OOooo........oo 198 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 177 199 178 F04GlobalField* F04GlobalField::GetObject() 200 F04GlobalField* F04GlobalField::GetObject() 179 { 201 { 180 if (fObject) return fObject; 202 if (fObject) return fObject; 181 return nullptr; << 203 return NULL; 182 } 204 } 183 205 184 //....oooOO0OOooo........oooOO0OOooo........oo 206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 185 207 186 void F04GlobalField::SetStepper() 208 void F04GlobalField::SetStepper() 187 { 209 { 188 delete fStepper; << 210 if(fStepper) delete fStepper; 189 211 190 switch (fStepperType) { << 212 switch ( fStepperType ) >> 213 { 191 case 0: 214 case 0: 192 // fStepper = new G4ExplicitEuler( << 215 // fStepper = new G4ExplicitEuler( fEquation, 8 ); // no spin tracking 193 fStepper = new G4ExplicitEuler(fEquation << 216 fStepper = new G4ExplicitEuler( fEquation, 12 ); // with spin tracking 194 G4cout << "G4ExplicitEuler is called" << 217 G4cout << "G4ExplicitEuler is called" << G4endl; 195 break; 218 break; 196 case 1: 219 case 1: 197 // fStepper = new G4ImplicitEuler( << 220 // fStepper = new G4ImplicitEuler( fEquation, 8 ); // no spin tracking 198 fStepper = new G4ImplicitEuler(fEquation << 221 fStepper = new G4ImplicitEuler( fEquation, 12 ); // with spin tracking 199 G4cout << "G4ImplicitEuler is called" << 222 G4cout << "G4ImplicitEuler is called" << G4endl; 200 break; 223 break; 201 case 2: 224 case 2: 202 // fStepper = new G4SimpleRunge( fE << 225 // fStepper = new G4SimpleRunge( fEquation, 8 ); // no spin tracking 203 fStepper = new G4SimpleRunge(fEquation, << 226 fStepper = new G4SimpleRunge( fEquation, 12 ); // with spin tracking 204 G4cout << "G4SimpleRunge is called" << G 227 G4cout << "G4SimpleRunge is called" << G4endl; 205 break; 228 break; 206 case 3: 229 case 3: 207 // fStepper = new G4SimpleHeum( fEq << 230 // fStepper = new G4SimpleHeum( fEquation, 8 ); // no spin tracking 208 fStepper = new G4SimpleHeum(fEquation, 1 << 231 fStepper = new G4SimpleHeum( fEquation, 12 ); // with spin tracking 209 G4cout << "G4SimpleHeum is called" << G4 232 G4cout << "G4SimpleHeum is called" << G4endl; 210 break; 233 break; 211 case 4: 234 case 4: 212 // fStepper = new G4ClassicalRK4( f << 235 // fStepper = new G4ClassicalRK4( fEquation, 8 ); // no spin tracking 213 fStepper = new G4ClassicalRK4(fEquation, << 236 fStepper = new G4ClassicalRK4( fEquation, 12 ); // with spin tracking 214 G4cout << "G4ClassicalRK4 (default) is c 237 G4cout << "G4ClassicalRK4 (default) is called" << G4endl; 215 break; 238 break; 216 case 5: 239 case 5: 217 // fStepper = new G4CashKarpRKF45( << 240 // fStepper = new G4CashKarpRKF45( fEquation, 8 ); // no spin tracking 218 fStepper = new G4CashKarpRKF45(fEquation << 241 fStepper = new G4CashKarpRKF45( fEquation, 12 ); // with spin tracking 219 G4cout << "G4CashKarpRKF45 is called" << 242 G4cout << "G4CashKarpRKF45 is called" << G4endl; 220 break; 243 break; 221 default: << 244 default: fStepper = 0; 222 fStepper = nullptr; << 223 } 245 } 224 } 246 } 225 247 226 //....oooOO0OOooo........oooOO0OOooo........oo 248 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 227 249 228 G4FieldManager* F04GlobalField::GetGlobalField 250 G4FieldManager* F04GlobalField::GetGlobalFieldManager() 229 { 251 { 230 return G4TransportationManager::GetTransport << 252 return G4TransportationManager::GetTransportationManager() >> 253 ->GetFieldManager(); 231 } 254 } 232 255 233 //....oooOO0OOooo........oooOO0OOooo........oo 256 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 234 257 235 void F04GlobalField::GetFieldValue(const G4dou 258 void F04GlobalField::GetFieldValue(const G4double* point, G4double* field) const 236 { 259 { 237 // NOTE: this routine dominates the CPU time 260 // NOTE: this routine dominates the CPU time for tracking. 238 // Using the simple array fFp[] instead of f << 261 // Using the simple array fFp[] instead of fields[] 239 // directly sped it up 262 // directly sped it up 240 263 241 field[0] = field[1] = field[2] = field[3] = 264 field[0] = field[1] = field[2] = field[3] = field[4] = field[5] = 0.0; 242 265 243 // protect against Geant4 bug that calls us 266 // protect against Geant4 bug that calls us with point[] NaN. 244 if (point[0] != point[0]) return; << 267 if(point[0] != point[0]) return; 245 268 246 // (can't use fNfp or fFp, as they may chang 269 // (can't use fNfp or fFp, as they may change) 247 if (fFirst) ((F04GlobalField*)this)->SetupAr << 270 if (fFirst) ((F04GlobalField*)this)->SetupArray(); // (cast away const) 248 271 249 for (int i = 0; i < fNfp; ++i) { << 272 for (int i=0; i<fNfp; ++i) { 250 const F04ElementField* p = fFp[i]; << 273 const F04ElementField* p = fFp[i]; 251 if (p->IsInBoundingBox(point)) { << 274 if (p->IsInBoundingBox(point)) { 252 p->AddFieldValue(point, field); << 275 p->AddFieldValue(point,field); 253 } << 276 } 254 } 277 } >> 278 255 } 279 } 256 280 257 //....oooOO0OOooo........oooOO0OOooo........oo 281 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 258 282 259 void F04GlobalField::Clear() 283 void F04GlobalField::Clear() 260 { 284 { 261 if (fFields) { 285 if (fFields) { 262 if (fFields->size() > 0) { << 286 if (fFields->size()>0) { 263 FieldList::iterator i; << 287 FieldList::iterator i; 264 for (i = fFields->begin(); i != fFields- << 288 for (i=fFields->begin(); i!=fFields->end(); ++i) delete *i; 265 delete *i; << 289 fFields->clear(); 266 fFields->clear(); << 290 } 267 } << 268 } 291 } 269 292 270 delete[] fFp; << 293 if (fFp) { delete [] fFp; } 271 fFirst = true; 294 fFirst = true; 272 fNfp = 0; 295 fNfp = 0; 273 fFp = nullptr; << 296 fFp = NULL; 274 } 297 } 275 298 276 //....oooOO0OOooo........oooOO0OOooo........oo 299 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 277 300 278 void F04GlobalField::SetupArray() 301 void F04GlobalField::SetupArray() 279 { 302 { 280 fFirst = false; 303 fFirst = false; 281 fNfp = fFields->size(); 304 fNfp = fFields->size(); 282 fFp = new const F04ElementField*[fNfp + 1]; << 305 fFp = new const F04ElementField* [fNfp+1]; // add 1 so it's never 0 283 for (int i = 0; i < fNfp; ++i) << 306 for (int i=0; i<fNfp; ++i) fFp[i] = (*fFields)[i]; 284 fFp[i] = (*fFields)[i]; << 285 } 307 } 286 308