Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /// \file field/BlineTracer/src/G4BlineTracer. 27 /// \brief Implementation of the G4BlineTracer 28 // 29 // 30 // 31 // 32 // ------------------------------------------- 33 // 34 // G4BlineTracer implementation 35 // 36 // ------------------------------------------- 37 // Author: Laurent Desorgher (desorgher@phim.u 38 // Created - 2003-10-06 39 // ------------------------------------------- 40 41 #include "G4BlineTracer.hh" 42 43 #include "G4BlineEquation.hh" 44 #include "G4BlineEventAction.hh" 45 #include "G4BlinePrimaryGeneratorAction.hh" 46 #include "G4BlineSteppingAction.hh" 47 #include "G4BlineTracerMessenger.hh" 48 #include "G4CashKarpRKF45.hh" 49 #include "G4ChordFinder.hh" 50 #include "G4FieldManager.hh" 51 #include "G4LogicalVolumeStore.hh" 52 #include "G4MagIntegratorDriver.hh" 53 #include "G4PropagatorInField.hh" 54 #include "G4RunManager.hh" 55 #include "G4SystemOfUnits.hh" 56 #include "G4TransportationManager.hh" 57 58 //....oooOO0OOooo........oooOO0OOooo........oo 59 60 G4BlineTracer::G4BlineTracer() 61 { 62 fMessenger = new G4BlineTracerMessenger(this 63 fSteppingAction = new G4BlineSteppingAction( 64 fEventAction = new G4BlineEventAction(this); 65 fPrimaryGeneratorAction = new G4BlinePrimary 66 } 67 68 //....oooOO0OOooo........oooOO0OOooo........oo 69 70 G4BlineTracer::~G4BlineTracer() 71 { 72 delete fMessenger; 73 delete fSteppingAction; 74 delete fEventAction; 75 delete fPrimaryGeneratorAction; 76 for (size_t i = 0; i < fVecEquationOfMotion. 77 if (fVecEquationOfMotion[i]) delete fVecEq 78 if (fVecChordFinders[i]) delete fVecChordF 79 } 80 } 81 82 //....oooOO0OOooo........oooOO0OOooo........oo 83 84 void G4BlineTracer::BeginOfRunAction(const G4R 85 86 //....oooOO0OOooo........oooOO0OOooo........oo 87 88 void G4BlineTracer::EndOfRunAction(const G4Run 89 90 //....oooOO0OOooo........oooOO0OOooo........oo 91 92 void G4BlineTracer::ComputeBlines(G4int n_of_l 93 { 94 // the first time ResetChordFinders should b 95 // 96 if (!fWas_ResetChordFinders_already_called) 97 ResetChordFinders(); 98 fWas_ResetChordFinders_already_called = tr 99 } 100 101 // Replace the user action by the ad-hoc act 102 103 G4RunManager* theRunManager = G4RunManager:: 104 auto user_run_action = (G4UserRunAction*)the 105 theRunManager->SetUserAction(this); 106 107 auto user_stepping_action = (G4UserSteppingA 108 theRunManager->SetUserAction(fSteppingAction 109 110 auto userPrimaryAction = 111 (G4VUserPrimaryGeneratorAction*)theRunMana 112 if (userPrimaryAction) fPrimaryGeneratorActi 113 theRunManager->SetUserAction(fPrimaryGenerat 114 115 auto user_event_action = (G4UserEventAction* 116 theRunManager->SetUserAction(fEventAction); 117 118 auto user_tracking_action = (G4UserTrackingA 119 G4UserTrackingAction* aNullTrackingAction = 120 theRunManager->SetUserAction(aNullTrackingAc 121 122 auto user_stacking_action = (G4UserStackingA 123 G4UserStackingAction* aNullStackingAction = 124 theRunManager->SetUserAction(aNullStackingAc 125 126 // replace the user defined chordfinder by t 127 128 std::vector<G4ChordFinder*> user_chord_finde 129 std::vector<G4double> user_largest_acceptabl 130 for (size_t i = 0; i < fVecChordFinders.size 131 user_largest_acceptable_step.push_back(-1. 132 if (fVecChordFinders[i]) { 133 user_chord_finders.push_back(fVecFieldMa 134 fVecChordFinders[i]->SetDeltaChord(user_ 135 fVecFieldManagers[i]->SetChordFinder(fVe 136 } 137 else 138 user_chord_finders.push_back(nullptr); 139 } 140 141 // I have tried to use the smooth line filte 142 // a smooth trajectory in the G4TrajectoryCo 143 // Another solution for obtaining a smooth t 144 // the LargestAcceptableStep in the G4Propag 145 // This is the solution I used. 146 147 // Old solution: 148 // G4TransportationManager::GetTransportatio 149 // ->GetPropagatorInField()->SetTrajecto 150 151 // New solution: 152 // set the largest_acceptable_step to max_st 153 154 G4TransportationManager* tmanager = G4Transp 155 G4double previous_largest_acceptable_step = 156 tmanager->GetPropagatorInField()->GetLarge 157 158 tmanager->GetPropagatorInField()->SetLargest 159 160 // Start the integration of n_of_lines diffe 161 162 for (G4int il = 0; il < n_of_lines; il++) { 163 // for each magnetic field line we integra 164 // forward from the same starting point 165 166 // backward integration 167 168 for (size_t i = 0; i < fVecEquationOfMotio 169 if (fVecEquationOfMotion[i]) fVecEquatio 170 } 171 theRunManager->BeamOn(1); 172 173 // forward integration 174 175 for (size_t i = 0; i < fVecEquationOfMotio 176 if (fVecEquationOfMotion[i]) 177 fVecEquationOfMotion[i]->SetBackwardDi 178 } 179 theRunManager->BeamOn(1); 180 } 181 182 // Remove trajectory filter to PropagatorInF 183 // It was for old solution when using smooth 184 185 // tmanager->GetPropagatorInField()->SetTraj 186 187 // back to User defined actions and other pa 188 // ----------------------------------------- 189 190 tmanager->GetPropagatorInField()->SetLargest 191 192 // return to User actions 193 194 theRunManager->SetUserAction(user_run_action 195 theRunManager->SetUserAction(user_event_acti 196 theRunManager->SetUserAction(userPrimaryActi 197 theRunManager->SetUserAction(user_stepping_a 198 theRunManager->SetUserAction(user_tracking_a 199 theRunManager->SetUserAction(user_stacking_a 200 201 // set user defined chord finders and larges 202 203 for (size_t i = 0; i < fVecFieldManagers.siz 204 if (user_chord_finders[i]) fVecFieldManage 205 } 206 } 207 208 //....oooOO0OOooo........oooOO0OOooo........oo 209 ////////////////////////////////////////////// 210 211 /* 212 G4bool G4BlineTracer::CheckMagneticFields() 213 { 214 // Check FieldManagers 215 216 G4TransportationManager* tmanager = 217 G4TransportationManager::GetTransportation 218 219 if (fVecFieldManagers[0] != tmanager->GetFie 220 return false; 221 if (fVecMagneticFields[0] != tmanager->GetFi 222 return false; 223 G4LogicalVolumeStore* theVolumeStore = G4Log 224 225 std::vector<G4FieldManagers*> LogicalVolumeF 226 size_t j=0; 227 for (size_t i=0; i<theVolumeStore.size();i++ 228 { 229 if (theVolumeStore[i]->GetFieldManager()) 230 { 231 j++; 232 if (j >= fVecFieldManagers.size()) retur 233 if (fVecFieldManagers[j] != theVolumeSto 234 return false; 235 if (fVecMagneticFields[j] != 236 theVolumeStore[i]->GetFieldManager() 237 return false; 238 } 239 } 240 if (j<fVecFieldManagers.size()) return false 241 242 return true; 243 } 244 */ 245 246 //....oooOO0OOooo........oooOO0OOooo........oo 247 248 void G4BlineTracer::ResetChordFinders() 249 { 250 for (size_t i = 0; i < fVecEquationOfMotion. 251 delete fVecEquationOfMotion[i]; 252 delete fVecChordFinders[i]; 253 } 254 255 fVecChordFinders.clear(); 256 fVecFieldManagers.clear(); 257 fVecMagneticFields.clear(); 258 fVecEquationOfMotion.clear(); 259 260 // global field 261 262 fVecChordFinders.push_back(nullptr); 263 fVecMagneticFields.push_back(nullptr); 264 fVecEquationOfMotion.push_back(nullptr); 265 fVecFieldManagers.push_back( 266 G4TransportationManager::GetTransportation 267 if (fVecFieldManagers[0]) { 268 fVecMagneticFields[0] = (G4MagneticField*) 269 if (fVecMagneticFields[0]) { 270 fVecEquationOfMotion[0] = new G4BlineEqu 271 auto pStepper = new G4CashKarpRKF45(fVec 272 auto pIntgrDriver = 273 new G4MagInt_Driver(0.01 * mm, pSteppe 274 fVecChordFinders[0] = new G4ChordFinder( 275 } 276 } 277 278 // local fields 279 280 G4LogicalVolumeStore* theVolumeStore = G4Log 281 282 size_t j = 0; 283 for (size_t i = 0; i < theVolumeStore->size( 284 if ((*theVolumeStore)[i]->GetFieldManager( 285 j++; 286 fVecFieldManagers.push_back(((*theVolume 287 fVecMagneticFields.push_back((G4Magnetic 288 fVecEquationOfMotion.push_back(nullptr); 289 fVecChordFinders.push_back(nullptr); 290 if (fVecMagneticFields[j]) { 291 fVecEquationOfMotion[j] = new G4BlineE 292 auto pStepper = new G4CashKarpRKF45(fV 293 auto pIntgrDriver = 294 new G4MagInt_Driver(.01 * mm, pStepp 295 fVecChordFinders[j] = new G4ChordFinde 296 } 297 } 298 } 299 } 300