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 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 28 //....oooOO0OOooo........oooOO0OOooo........oo 28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 29 29 30 #include "SpecializedTrackingManager.hh" 30 #include "SpecializedTrackingManager.hh" 31 31 32 #include "G4EventManager.hh" 32 #include "G4EventManager.hh" 33 #include "G4ProcessManager.hh" 33 #include "G4ProcessManager.hh" 34 #include "G4RegionStore.hh" 34 #include "G4RegionStore.hh" 35 #include "G4StackManager.hh" 35 #include "G4StackManager.hh" 36 #include "G4SystemOfUnits.hh" << 37 #include "G4TrackingManager.hh" 36 #include "G4TrackingManager.hh" 38 37 >> 38 #include "G4SystemOfUnits.hh" >> 39 39 //....oooOO0OOooo........oooOO0OOooo........oo 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 41 41 SpecializedTrackingManager::SpecializedTrackin 42 SpecializedTrackingManager::SpecializedTrackingManager() {} 42 43 43 //....oooOO0OOooo........oooOO0OOooo........oo 44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 45 45 SpecializedTrackingManager::~SpecializedTracki 46 SpecializedTrackingManager::~SpecializedTrackingManager() {} 46 47 47 //....oooOO0OOooo........oooOO0OOooo........oo 48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 48 49 49 void SpecializedTrackingManager::BuildPhysicsT << 50 void SpecializedTrackingManager::BuildPhysicsTable( >> 51 const G4ParticleDefinition& part) 50 { 52 { 51 if (fBackRegion == nullptr) { << 53 if(fBackRegion == nullptr) >> 54 { 52 fBackRegion = G4RegionStore::GetInstance() 55 fBackRegion = G4RegionStore::GetInstance()->GetRegion("Back", false); 53 } 56 } 54 57 55 G4ProcessManager* pManager = part.GetProcess << 58 G4ProcessManager* pManager = part.GetProcessManager(); 56 G4ProcessManager* pManagerShadow = part.GetM 59 G4ProcessManager* pManagerShadow = part.GetMasterProcessManager(); 57 60 58 G4ProcessVector* pVector = pManager->GetProc 61 G4ProcessVector* pVector = pManager->GetProcessList(); 59 for (std::size_t j = 0; j < pVector->size(); << 62 for(std::size_t j = 0; j < pVector->size(); ++j) 60 if (pManagerShadow == pManager) { << 63 { >> 64 if(pManagerShadow == pManager) >> 65 { 61 (*pVector)[j]->BuildPhysicsTable(part); 66 (*pVector)[j]->BuildPhysicsTable(part); 62 } 67 } 63 else { << 68 else >> 69 { 64 (*pVector)[j]->BuildWorkerPhysicsTable(p 70 (*pVector)[j]->BuildWorkerPhysicsTable(part); 65 } 71 } 66 } 72 } 67 } 73 } 68 74 69 //....oooOO0OOooo........oooOO0OOooo........oo 75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 76 71 void SpecializedTrackingManager::PreparePhysic << 77 void SpecializedTrackingManager::PreparePhysicsTable( >> 78 const G4ParticleDefinition& part) 72 { 79 { 73 G4ProcessManager* pManager = part.GetProcess << 80 G4ProcessManager* pManager = part.GetProcessManager(); 74 G4ProcessManager* pManagerShadow = part.GetM 81 G4ProcessManager* pManagerShadow = part.GetMasterProcessManager(); 75 82 76 G4ProcessVector* pVector = pManager->GetProc 83 G4ProcessVector* pVector = pManager->GetProcessList(); 77 for (std::size_t j = 0; j < pVector->size(); << 84 for(std::size_t j = 0; j < pVector->size(); ++j) 78 if (pManagerShadow == pManager) { << 85 { >> 86 if(pManagerShadow == pManager) >> 87 { 79 (*pVector)[j]->PreparePhysicsTable(part) 88 (*pVector)[j]->PreparePhysicsTable(part); 80 } 89 } 81 else { << 90 else >> 91 { 82 (*pVector)[j]->PrepareWorkerPhysicsTable 92 (*pVector)[j]->PrepareWorkerPhysicsTable(part); 83 } 93 } 84 } 94 } 85 } 95 } 86 96 87 //....oooOO0OOooo........oooOO0OOooo........oo 97 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 98 89 void SpecializedTrackingManager::HandOverOneTr 99 void SpecializedTrackingManager::HandOverOneTrack(G4Track* aTrack) 90 { 100 { 91 if (aTrack->GetKineticEnergy() < 100 * MeV) << 101 if(aTrack->GetKineticEnergy() < 100 * MeV) >> 102 { 92 // If the particle energy is lower than 10 103 // If the particle energy is lower than 100 MeV, track it immediately by 93 // passing to the generic G4TrackingManage 104 // passing to the generic G4TrackingManager. This avoids storing lower 94 // energy particles in the buffer and feed 105 // energy particles in the buffer and feeding it through the specialized 95 // tracking. 106 // tracking. 96 G4EventManager* eventManager = G4EventMana << 107 G4EventManager* eventManager = G4EventManager::GetEventManager(); 97 G4TrackingManager* trackManager = eventMan 108 G4TrackingManager* trackManager = eventManager->GetTrackingManager(); 98 109 99 trackManager->ProcessOneTrack(aTrack); 110 trackManager->ProcessOneTrack(aTrack); 100 if (aTrack->GetTrackStatus() != fStopAndKi << 111 if(aTrack->GetTrackStatus() != fStopAndKill) 101 G4Exception("SpecializedTrackingManager: << 112 { 102 "track was not stopped"); << 113 G4Exception("SpecializedTrackingManager::HandOverOneTrack", "NotStopped", >> 114 FatalException, "track was not stopped"); 103 } 115 } 104 116 105 G4TrackVector* secondaries = trackManager- 117 G4TrackVector* secondaries = trackManager->GimmeSecondaries(); 106 eventManager->StackTracks(secondaries); 118 eventManager->StackTracks(secondaries); 107 delete aTrack; 119 delete aTrack; 108 return; 120 return; 109 } 121 } 110 122 111 fBufferedTracks.push_back(aTrack); 123 fBufferedTracks.push_back(aTrack); 112 } 124 } 113 125 114 //....oooOO0OOooo........oooOO0OOooo........oo 126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 115 127 116 void SpecializedTrackingManager::FlushEvent() 128 void SpecializedTrackingManager::FlushEvent() 117 { 129 { 118 G4EventManager* eventManager = G4EventManage << 130 G4EventManager* eventManager = G4EventManager::GetEventManager(); 119 G4TrackingManager* trackManager = eventManag << 131 G4TrackingManager* trackManager = eventManager->GetTrackingManager(); 120 G4SteppingManager* steppingManager = trackMa 132 G4SteppingManager* steppingManager = trackManager->GetSteppingManager(); 121 G4TrackVector* secondaries = trackManager->G << 133 G4TrackVector* secondaries = trackManager->GimmeSecondaries(); 122 134 123 for (G4Track* aTrack : fBufferedTracks) { << 135 for(G4Track* aTrack : fBufferedTracks) >> 136 { 124 // Clear secondary particle vector 137 // Clear secondary particle vector 125 for (std::size_t itr = 0; itr < secondarie << 138 for(std::size_t itr = 0; itr < secondaries->size(); ++itr) 126 delete (*secondaries)[itr]; << 139 { >> 140 delete(*secondaries)[itr]; 127 } 141 } 128 secondaries->clear(); 142 secondaries->clear(); 129 143 130 steppingManager->SetInitialStep(aTrack); 144 steppingManager->SetInitialStep(aTrack); 131 145 132 G4UserTrackingAction* userTrackingAction = << 146 G4UserTrackingAction* userTrackingAction = 133 if (userTrackingAction != nullptr) { << 147 trackManager->GetUserTrackingAction(); >> 148 if(userTrackingAction != nullptr) >> 149 { 134 userTrackingAction->PreUserTrackingActio 150 userTrackingAction->PreUserTrackingAction(aTrack); 135 } 151 } 136 152 137 // Give SteppingManger the maxmimum number 153 // Give SteppingManger the maxmimum number of processes 138 steppingManager->GetProcessNumber(); 154 steppingManager->GetProcessNumber(); 139 155 140 // Give track the pointer to the Step 156 // Give track the pointer to the Step 141 aTrack->SetStep(steppingManager->GetStep() 157 aTrack->SetStep(steppingManager->GetStep()); 142 158 143 // Inform beginning of tracking to physics 159 // Inform beginning of tracking to physics processes 144 aTrack->GetDefinition()->GetProcessManager 160 aTrack->GetDefinition()->GetProcessManager()->StartTracking(aTrack); 145 161 146 // Track the particle Step-by-Step while i 162 // Track the particle Step-by-Step while it is alive 147 while ((aTrack->GetTrackStatus() == fAlive << 163 while((aTrack->GetTrackStatus() == fAlive) || >> 164 (aTrack->GetTrackStatus() == fStopButAlive)) >> 165 { 148 G4Region* region = aTrack->GetVolume()-> 166 G4Region* region = aTrack->GetVolume()->GetLogicalVolume()->GetRegion(); 149 if (region == fBackRegion) { << 167 if(region == fBackRegion) >> 168 { 150 StepInBackRegion(aTrack); 169 StepInBackRegion(aTrack); 151 } 170 } 152 else { << 171 else >> 172 { 153 StepOutside(aTrack); 173 StepOutside(aTrack); 154 } 174 } 155 } 175 } 156 176 157 aTrack->GetDefinition()->GetProcessManager 177 aTrack->GetDefinition()->GetProcessManager()->EndTracking(); 158 178 159 if (userTrackingAction != nullptr) { << 179 if(userTrackingAction != nullptr) >> 180 { 160 userTrackingAction->PostUserTrackingActi 181 userTrackingAction->PostUserTrackingAction(aTrack); 161 } 182 } 162 183 163 eventManager->StackTracks(secondaries); 184 eventManager->StackTracks(secondaries); 164 delete aTrack; 185 delete aTrack; 165 } 186 } 166 187 167 fBufferedTracks.clear(); 188 fBufferedTracks.clear(); 168 } 189 } 169 190 170 //....oooOO0OOooo........oooOO0OOooo........oo 191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 171 192 172 void SpecializedTrackingManager::StepInBackReg 193 void SpecializedTrackingManager::StepInBackRegion(G4Track* aTrack) 173 { 194 { 174 G4EventManager* eventManager = G4EventManage << 195 G4EventManager* eventManager = G4EventManager::GetEventManager(); 175 G4TrackingManager* trackManager = eventManag << 196 G4TrackingManager* trackManager = eventManager->GetTrackingManager(); 176 G4SteppingManager* steppingManager = trackMa 197 G4SteppingManager* steppingManager = trackManager->GetSteppingManager(); 177 198 178 // Track the particle Step-by-Step while it 199 // Track the particle Step-by-Step while it is alive and inside the "Back" 179 // region of the detector. Implement a low-e 200 // region of the detector. Implement a low-energy cut-off for particles 180 // below 100 MeV. More specialized handling 201 // below 100 MeV. More specialized handling would also be possible, such 181 // as only killing particles in non-sensitiv 202 // as only killing particles in non-sensitive materials / volumes. 182 while ((aTrack->GetTrackStatus() == fAlive) << 203 while((aTrack->GetTrackStatus() == fAlive) || >> 204 (aTrack->GetTrackStatus() == fStopButAlive)) >> 205 { 183 aTrack->IncrementCurrentStepNumber(); 206 aTrack->IncrementCurrentStepNumber(); 184 steppingManager->Stepping(); 207 steppingManager->Stepping(); 185 208 186 if (aTrack->GetTrackStatus() != fStopAndKi << 209 if(aTrack->GetTrackStatus() != fStopAndKill) >> 210 { 187 // Switch the touchable to update the vo 211 // Switch the touchable to update the volume, which is checked in the 188 // condition below and at the call site. 212 // condition below and at the call site. 189 aTrack->SetTouchableHandle(aTrack->GetNe 213 aTrack->SetTouchableHandle(aTrack->GetNextTouchableHandle()); 190 G4Region* region = aTrack->GetVolume()-> 214 G4Region* region = aTrack->GetVolume()->GetLogicalVolume()->GetRegion(); 191 if (region != fBackRegion) { << 215 if(region != fBackRegion) >> 216 { 192 return; 217 return; 193 } 218 } 194 219 195 if (aTrack->GetKineticEnergy() < 100 * M << 220 if(aTrack->GetKineticEnergy() < 100 * MeV) >> 221 { 196 // Kill the particle. 222 // Kill the particle. 197 aTrack->SetTrackStatus(fStopAndKill); 223 aTrack->SetTrackStatus(fStopAndKill); 198 } 224 } 199 } 225 } 200 } 226 } 201 } 227 } 202 228 203 //....oooOO0OOooo........oooOO0OOooo........oo 229 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 204 230 205 void SpecializedTrackingManager::StepOutside(G 231 void SpecializedTrackingManager::StepOutside(G4Track* aTrack) 206 { 232 { 207 G4EventManager* eventManager = G4EventManage << 233 G4EventManager* eventManager = G4EventManager::GetEventManager(); 208 G4TrackingManager* trackManager = eventManag << 234 G4TrackingManager* trackManager = eventManager->GetTrackingManager(); 209 G4SteppingManager* steppingManager = trackMa 235 G4SteppingManager* steppingManager = trackManager->GetSteppingManager(); 210 236 211 // Track the particle Step-by-Step while it 237 // Track the particle Step-by-Step while it is alive and still outside of 212 // the "Back" region. 238 // the "Back" region. 213 while ((aTrack->GetTrackStatus() == fAlive) << 239 while((aTrack->GetTrackStatus() == fAlive) || >> 240 (aTrack->GetTrackStatus() == fStopButAlive)) >> 241 { 214 aTrack->IncrementCurrentStepNumber(); 242 aTrack->IncrementCurrentStepNumber(); 215 steppingManager->Stepping(); 243 steppingManager->Stepping(); 216 244 217 if (aTrack->GetTrackStatus() != fStopAndKi << 245 if(aTrack->GetTrackStatus() != fStopAndKill) >> 246 { 218 // Switch the touchable to update the vo 247 // Switch the touchable to update the volume, which is checked in the 219 // condition below and at the call site. 248 // condition below and at the call site. 220 aTrack->SetTouchableHandle(aTrack->GetNe 249 aTrack->SetTouchableHandle(aTrack->GetNextTouchableHandle()); 221 G4Region* region = aTrack->GetVolume()-> 250 G4Region* region = aTrack->GetVolume()->GetLogicalVolume()->GetRegion(); 222 if (region == fBackRegion) { << 251 if(region == fBackRegion) >> 252 { 223 return; 253 return; 224 } 254 } 225 } 255 } 226 } 256 } 227 } 257 } 228 258