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 // This example is provided by the Geant4-DNA 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained us 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collabo 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 37 (2010) 4692-4708 29 // Med. Phys. 37 (2010) 4692-4708 30 // and papers 30 // and papers 31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507 32 // O. Belov et al. Physica Medica 32 (2016) 15 32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520 33 // The Geant4-DNA web site is available at htt 33 // The Geant4-DNA web site is available at http://geant4-dna.org 34 // << 34 // 35 // ------------------------------------------- 35 // ------------------------------------------------------------------- 36 // November 2016 36 // November 2016 37 // ------------------------------------------- 37 // ------------------------------------------------------------------- 38 // 38 // >> 39 // $Id$ 39 // 40 // 40 /// \file ITTrackingInteractivity.hh 41 /// \file ITTrackingInteractivity.hh 41 /// \brief Implementation of the ITTrackingInt 42 /// \brief Implementation of the ITTrackingInteractivity class 42 43 43 #include "ITTrackingInteractivity.hh" 44 #include "ITTrackingInteractivity.hh" 44 << 45 #include "G4Event.hh" << 46 #include "G4EventManager.hh" << 47 #include "G4IT.hh" << 48 #include "G4RichTrajectory.hh" << 49 #include "G4SmoothTrajectory.hh" << 50 #include "G4TrackingInformation.hh" 45 #include "G4TrackingInformation.hh" >> 46 #include "G4VTrajectory.hh" 51 #include "G4Trajectory.hh" 47 #include "G4Trajectory.hh" 52 #include "G4UserSteppingAction.hh" << 48 #include "G4SmoothTrajectory.hh" >> 49 #include "G4RichTrajectory.hh" 53 #include "G4UserTrackingAction.hh" 50 #include "G4UserTrackingAction.hh" >> 51 #include "G4UserSteppingAction.hh" >> 52 #include "G4IT.hh" >> 53 #include "G4EventManager.hh" >> 54 #include "G4Event.hh" 54 #include "G4VSteppingVerbose.hh" 55 #include "G4VSteppingVerbose.hh" 55 #include "G4VTrajectory.hh" << 56 #include "G4VisManager.hh" 56 #include "G4VisManager.hh" 57 57 58 class G4Trajectory_Lock 58 class G4Trajectory_Lock 59 { 59 { 60 friend class ITTrackingInteractivity; << 60 friend class ITTrackingInteractivity; 61 61 62 G4Trajectory_Lock() : fpTrajectory(0) { ; << 62 G4Trajectory_Lock(): fpTrajectory(0) >> 63 {;} 63 64 64 ~G4Trajectory_Lock() { ; } << 65 ~G4Trajectory_Lock() >> 66 {;} 65 67 66 G4VTrajectory* fpTrajectory; << 68 G4VTrajectory* fpTrajectory; 67 }; 69 }; 68 70 69 ITTrackingInteractivity::ITTrackingInteractivi 71 ITTrackingInteractivity::ITTrackingInteractivity() 70 { 72 { 71 fStoreTrajectory = 0; 73 fStoreTrajectory = 0; 72 fVerboseLevel = 0; 74 fVerboseLevel = 0; 73 75 74 fpUserTrackingAction = 0; << 76 fpUserTrackingAction = 0; 75 fpUserSteppingAction = 0; 77 fpUserSteppingAction = 0; 76 78 77 //////////////////////////// 79 //////////////////////////// 78 // In case you want to use same tracking/ste 80 // In case you want to use same tracking/stepping action 79 // for normal and IT stepping 81 // for normal and IT stepping 80 /* 82 /* 81 fpUserTrackingAction = 83 fpUserTrackingAction = 82 trackingManager->GetUserTrackingAction() 84 trackingManager->GetUserTrackingAction(); 83 fpUserSteppingAction = 85 fpUserSteppingAction = 84 G4EventManager::GetEventManager()->GetUs 86 G4EventManager::GetEventManager()->GetUserSteppingAction(); 85 */ 87 */ 86 //////////////////////////// 88 //////////////////////////// 87 } 89 } 88 90 89 //....oooOO0OOooo........oooOO0OOooo........oo 91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 90 92 91 ITTrackingInteractivity::~ITTrackingInteractiv 93 ITTrackingInteractivity::~ITTrackingInteractivity() 92 { 94 { 93 G4EventManager* eventManager = G4EventManage << 95 G4EventManager* eventManager = >> 96 G4EventManager::GetEventManager(); 94 97 95 if (eventManager) { << 98 if (eventManager) 96 G4UserTrackingAction* std_trackAct = event << 99 { 97 if (fpUserTrackingAction != std_trackAct & << 100 G4UserTrackingAction* std_trackAct = 98 << 101 eventManager->GetUserTrackingAction(); 99 G4UserSteppingAction* std_stepAct = eventM << 102 if(fpUserTrackingAction != std_trackAct && fpUserTrackingAction) 100 if (fpUserSteppingAction != std_stepAct && << 103 delete fpUserTrackingAction; >> 104 >> 105 G4UserSteppingAction* std_stepAct = >> 106 eventManager->GetUserSteppingAction(); >> 107 if(fpUserSteppingAction != std_stepAct && fpUserSteppingAction) >> 108 delete fpUserSteppingAction; 101 } 109 } 102 else { << 110 else 103 if (fpUserSteppingAction) { << 111 { >> 112 if(fpUserSteppingAction) >> 113 { 104 delete fpUserSteppingAction; 114 delete fpUserSteppingAction; 105 } 115 } 106 << 116 107 if (fpUserTrackingAction) { << 117 if(fpUserTrackingAction) >> 118 { 108 delete fpUserTrackingAction; 119 delete fpUserTrackingAction; 109 } 120 } 110 } 121 } 111 } 122 } 112 123 113 //....oooOO0OOooo........oooOO0OOooo........oo 124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 114 125 115 void ITTrackingInteractivity::Initialize() 126 void ITTrackingInteractivity::Initialize() 116 { 127 { 117 G4TrackingManager* trackingManager = G4Event << 128 G4TrackingManager* trackingManager = >> 129 G4EventManager::GetEventManager()->GetTrackingManager(); 118 fStoreTrajectory = trackingManager->GetStore 130 fStoreTrajectory = trackingManager->GetStoreTrajectory(); 119 fVerboseLevel = trackingManager->GetVerboseL 131 fVerboseLevel = trackingManager->GetVerboseLevel(); 120 } 132 } 121 133 122 //....oooOO0OOooo........oooOO0OOooo........oo 134 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 123 135 124 void ITTrackingInteractivity::StartTracking(G4 136 void ITTrackingInteractivity::StartTracking(G4Track* track) 125 { 137 { 126 #ifdef G4VERBOSE 138 #ifdef G4VERBOSE 127 if (fVerboseLevel) { << 139 if(fVerboseLevel) >> 140 { 128 TrackBanner(track, "G4ITTrackingManager::S 141 TrackBanner(track, "G4ITTrackingManager::StartTracking : "); 129 } 142 } 130 #endif 143 #endif 131 144 132 if (fVerboseLevel > 0 && (G4VSteppingVerbose << 145 if(fVerboseLevel>0 && (G4VSteppingVerbose::GetSilent()!=1) ) >> 146 TrackBanner(track); 133 147 134 // Pre tracking user intervention process. 148 // Pre tracking user intervention process. 135 if (fpUserTrackingAction != 0) { << 149 if( fpUserTrackingAction != 0 ) { 136 fpUserTrackingAction->PreUserTrackingActio 150 fpUserTrackingAction->PreUserTrackingAction(track); 137 } 151 } 138 // #ifdef G4_STORE_TRAJECTORY << 152 //#ifdef G4_STORE_TRAJECTORY 139 G4TrackingInformation* trackingInfo = GetIT( 153 G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo(); 140 G4Trajectory_Lock* trajectory_lock = trackin << 154 G4Trajectory_Lock* trajectory_lock = >> 155 trackingInfo->GetTrajectory_Lock(); 141 156 142 // Construct a trajectory if it is requested 157 // Construct a trajectory if it is requested 143 if (fStoreTrajectory && (!trajectory_lock)) << 158 if(fStoreTrajectory&&(!trajectory_lock)) >> 159 { 144 trajectory_lock = new G4Trajectory_Lock(); 160 trajectory_lock = new G4Trajectory_Lock(); 145 trackingInfo->SetTrajectory_Lock(trajector 161 trackingInfo->SetTrajectory_Lock(trajectory_lock); 146 G4VTrajectory* trajectory = 0; 162 G4VTrajectory* trajectory = 0; 147 // default trajectory concrete class objec 163 // default trajectory concrete class object 148 switch (fStoreTrajectory) { 164 switch (fStoreTrajectory) { 149 default: 165 default: 150 case 1: << 166 case 1: trajectory = new G4Trajectory(track); break; 151 trajectory = new G4Trajectory(track); << 167 case 2: trajectory = new G4SmoothTrajectory(track); break; 152 break; << 168 case 3: trajectory = new G4RichTrajectory(track); break; 153 case 2: << 154 trajectory = new G4SmoothTrajectory(tr << 155 break; << 156 case 3: << 157 trajectory = new G4RichTrajectory(trac << 158 break; << 159 } 169 } 160 trajectory_lock->fpTrajectory = trajectory 170 trajectory_lock->fpTrajectory = trajectory; 161 } 171 } 162 // #endif << 172 //#endif 163 } 173 } 164 174 165 //....oooOO0OOooo........oooOO0OOooo........oo 175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 166 176 167 void ITTrackingInteractivity::AppendStep(G4Tra << 177 void >> 178 ITTrackingInteractivity::AppendStep(G4Track* track, G4Step* step) 168 { 179 { 169 //////////////////////////// 180 //////////////////////////// 170 // If you want to use sensitive detector 181 // If you want to use sensitive detector 171 /* 182 /* 172 G4VPhysicalVolume* currentVolume = 183 G4VPhysicalVolume* currentVolume = 173 step->GetPreStepPoint()->GetPhysicalVolume 184 step->GetPreStepPoint()->GetPhysicalVolume(); 174 G4SteppingControl stepControlFlag = step- 185 G4SteppingControl stepControlFlag = step->GetControlFlag(); 175 186 176 if( currentVolume != 0 && stepControlFlag 187 if( currentVolume != 0 && stepControlFlag != AvoidHitInvocation) 177 { 188 { 178 G4VSensitiveDetector* sensitive = step 189 G4VSensitiveDetector* sensitive = step->GetPreStepPoint()-> 179 GetSensitiveDetector(); 190 GetSensitiveDetector(); 180 if( sensitive != 0 ) 191 if( sensitive != 0 ) 181 { 192 { 182 sensitive->Hit(fpStep); 193 sensitive->Hit(fpStep); 183 } 194 } 184 } 195 } 185 */ 196 */ 186 //////////////////////////// 197 //////////////////////////// 187 198 188 if (fpUserSteppingAction) fpUserSteppingActi << 199 if(fpUserSteppingAction) >> 200 fpUserSteppingAction->UserSteppingAction(step); 189 201 190 //////////////////////////// 202 //////////////////////////// 191 // If you want to use regional stepping acti 203 // If you want to use regional stepping action 192 /* 204 /* 193 G4UserSteppingAction* regionalAction 205 G4UserSteppingAction* regionalAction 194 = fpStep->GetPreStepPoint()->GetPh 206 = fpStep->GetPreStepPoint()->GetPhysicalVolume()-> 195 GetLogicalVolume()->GetRegio 207 GetLogicalVolume()->GetRegion()-> 196 GetRegionalSteppingAction(); 208 GetRegionalSteppingAction(); 197 if( regionalAction ) regionalAction->UserS 209 if( regionalAction ) regionalAction->UserSteppingAction(fpStep); 198 */ 210 */ 199 //////////////////////////// 211 //////////////////////////// 200 212 201 if (fStoreTrajectory) { << 213 if(fStoreTrajectory) 202 G4TrackingInformation* trackingInfo = GetI << 214 { 203 G4Trajectory_Lock* trajectory_lock = track << 215 G4TrackingInformation* trackingInfo = >> 216 GetIT(track)->GetTrackingInfo(); >> 217 G4Trajectory_Lock* trajectory_lock = >> 218 trackingInfo->GetTrajectory_Lock(); 204 trajectory_lock->fpTrajectory->AppendStep( 219 trajectory_lock->fpTrajectory->AppendStep(step); 205 } 220 } 206 } 221 } 207 222 208 //....oooOO0OOooo........oooOO0OOooo........oo 223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 209 224 210 void ITTrackingInteractivity::EndTracking(G4Tr 225 void ITTrackingInteractivity::EndTracking(G4Track* track) 211 { 226 { 212 #ifdef G4VERBOSE 227 #ifdef G4VERBOSE 213 if (fVerboseLevel) { << 228 if(fVerboseLevel) >> 229 { 214 TrackBanner(track, "G4ITTrackingManager::E 230 TrackBanner(track, "G4ITTrackingManager::EndTracking : "); 215 } 231 } 216 #endif 232 #endif 217 // Post tracking user intervention process. 233 // Post tracking user intervention process. 218 if (fpUserTrackingAction != 0) { << 234 if( fpUserTrackingAction != 0 ) { 219 fpUserTrackingAction->PostUserTrackingActi 235 fpUserTrackingAction->PostUserTrackingAction(track); 220 } 236 } 221 237 222 // #ifdef G4_STORE_TRAJECTORY << 238 //#ifdef G4_STORE_TRAJECTORY 223 G4TrackingInformation* trackingInfo = GetIT( << 239 G4TrackingInformation* trackingInfo = 224 G4Trajectory_Lock* trajectory_lock = trackin << 240 GetIT(track)->GetTrackingInfo(); >> 241 G4Trajectory_Lock* trajectory_lock = >> 242 trackingInfo->GetTrajectory_Lock(); 225 243 226 if (trajectory_lock) { << 244 if(trajectory_lock) >> 245 { 227 G4VTrajectory*& trajectory = trajectory_lo 246 G4VTrajectory*& trajectory = trajectory_lock->fpTrajectory; 228 247 229 if (fStoreTrajectory && trajectory) { << 248 if(fStoreTrajectory && trajectory) >> 249 { >> 250 230 #ifdef G4VERBOSE 251 #ifdef G4VERBOSE 231 if (fVerboseLevel > 10) trajectory->Show << 252 if(fVerboseLevel>10) trajectory->ShowTrajectory(); 232 #endif 253 #endif 233 G4TrackStatus istop = track->GetTrackSta 254 G4TrackStatus istop = track->GetTrackStatus(); 234 255 235 if (trajectory && (istop != fStopButAliv << 256 if (trajectory && (istop != fStopButAlive) && (istop != fSuspend)) 236 G4Event* currentEvent = G4EventManager << 257 { >> 258 G4Event* currentEvent = G4EventManager::GetEventManager() >> 259 ->GetNonconstCurrentEvent(); 237 260 238 if (currentEvent) { << 261 if (currentEvent) 239 G4TrajectoryContainer* trajectoryCon << 262 { >> 263 G4TrajectoryContainer* trajectoryContainer = currentEvent >> 264 ->GetTrajectoryContainer(); 240 265 241 if (!trajectoryContainer) { << 266 if (!trajectoryContainer) >> 267 { 242 trajectoryContainer = new G4Trajec 268 trajectoryContainer = new G4TrajectoryContainer; 243 currentEvent->SetTrajectoryContain 269 currentEvent->SetTrajectoryContainer(trajectoryContainer); 244 } 270 } 245 trajectoryContainer->insert(trajecto 271 trajectoryContainer->insert(trajectory); 246 } 272 } 247 else { << 273 else >> 274 { 248 fTrajectories.push_back(trajectory); 275 fTrajectories.push_back(trajectory); 249 } 276 } 250 } 277 } 251 } 278 } 252 // Destruct the trajectory if it was creat 279 // Destruct the trajectory if it was created 253 else if ((!fStoreTrajectory) && trajectory << 280 else if( (!fStoreTrajectory)&&trajectory ) { 254 delete trajectory; 281 delete trajectory; 255 trajectory = 0; 282 trajectory = 0; 256 } 283 } 257 delete trajectory_lock; 284 delete trajectory_lock; 258 trackingInfo->SetTrajectory_Lock(0); 285 trackingInfo->SetTrajectory_Lock(0); 259 } 286 } 260 // #endif << 287 //#endif 261 } 288 } 262 289 263 void ITTrackingInteractivity::Finalize() 290 void ITTrackingInteractivity::Finalize() 264 { 291 { 265 for (std::vector<G4VTrajectory*>::iterator i << 292 for (std::vector<G4VTrajectory*>::iterator it = fTrajectories.begin(); 266 it++) << 293 it != fTrajectories.end(); it++) 267 { 294 { 268 G4VisManager::GetConcreteInstance()->Draw( 295 G4VisManager::GetConcreteInstance()->Draw(**it); 269 } 296 } 270 } 297 } 271 298