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