ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ITTrackingInteractivity.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ITTrackingInteractivity.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // and papers
31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // -------------------------------------------------------------------
36 // November 2016
37 // -------------------------------------------------------------------
38 //
39 //
42 
43 #include "ITTrackingInteractivity.hh"
44 #include "G4TrackingInformation.hh"
45 #include "G4VTrajectory.hh"
46 #include "G4Trajectory.hh"
47 #include "G4SmoothTrajectory.hh"
48 #include "G4RichTrajectory.hh"
49 #include "G4UserTrackingAction.hh"
50 #include "G4UserSteppingAction.hh"
51 #include "G4IT.hh"
52 #include "G4EventManager.hh"
53 #include "G4Event.hh"
54 #include "G4VSteppingVerbose.hh"
55 #include "G4VisManager.hh"
56 
58 {
59  friend class ITTrackingInteractivity;
60 
62  {;}
63 
65  {;}
66 
68 };
69 
71 {
72  fStoreTrajectory = 0;
73  fVerboseLevel = 0;
74 
77 
79  // In case you want to use same tracking/stepping action
80  // for normal and IT stepping
81  /*
82  fpUserTrackingAction =
83  trackingManager->GetUserTrackingAction();
84  fpUserSteppingAction =
85  G4EventManager::GetEventManager()->GetUserSteppingAction();
86  */
88 }
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
91 
93 {
94  G4EventManager* eventManager =
96 
97  if (eventManager)
98  {
99  G4UserTrackingAction* std_trackAct =
100  eventManager->GetUserTrackingAction();
101  if(fpUserTrackingAction != std_trackAct && fpUserTrackingAction)
102  delete fpUserTrackingAction;
103 
104  G4UserSteppingAction* std_stepAct =
105  eventManager->GetUserSteppingAction();
106  if(fpUserSteppingAction != std_stepAct && fpUserSteppingAction)
107  delete fpUserSteppingAction;
108  }
109  else
110  {
112  {
113  delete fpUserSteppingAction;
114  }
115 
117  {
118  delete fpUserTrackingAction;
119  }
120  }
121 }
122 
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
124 
126 {
127  G4TrackingManager* trackingManager =
129  fStoreTrajectory = trackingManager->GetStoreTrajectory();
130  fVerboseLevel = trackingManager->GetVerboseLevel();
131 }
132 
133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
134 
136 {
137 #ifdef G4VERBOSE
138  if(fVerboseLevel)
139  {
140  TrackBanner(track, "G4ITTrackingManager::StartTracking : ");
141  }
142 #endif
143 
145  TrackBanner(track);
146 
147  // Pre tracking user intervention process.
148  if( fpUserTrackingAction != 0 ) {
150  }
151 //#ifdef G4_STORE_TRAJECTORY
152  G4TrackingInformation* trackingInfo = GetIT(track)->GetTrackingInfo();
153  G4Trajectory_Lock* trajectory_lock =
154  trackingInfo->GetTrajectory_Lock();
155 
156  // Construct a trajectory if it is requested
157  if(fStoreTrajectory&&(!trajectory_lock))
158  {
159  trajectory_lock = new G4Trajectory_Lock();
160  trackingInfo->SetTrajectory_Lock(trajectory_lock);
161  G4VTrajectory* trajectory = 0;
162  // default trajectory concrete class object
163  switch (fStoreTrajectory) {
164  default:
165  case 1: trajectory = new G4Trajectory(track); break;
166  case 2: trajectory = new G4SmoothTrajectory(track); break;
167  case 3: trajectory = new G4RichTrajectory(track); break;
168  }
169  trajectory_lock->fpTrajectory = trajectory;
170  }
171 //#endif
172 }
173 
174 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
175 
176 void
178 {
180  // If you want to use sensitive detector
181  /*
182  G4VPhysicalVolume* currentVolume =
183  step->GetPreStepPoint()->GetPhysicalVolume();
184  G4SteppingControl stepControlFlag = step->GetControlFlag();
185 
186  if( currentVolume != 0 && stepControlFlag != AvoidHitInvocation)
187  {
188  G4VSensitiveDetector* sensitive = step->GetPreStepPoint()->
189  GetSensitiveDetector();
190  if( sensitive != 0 )
191  {
192  sensitive->Hit(fpStep);
193  }
194  }
195  */
197 
200 
202  // If you want to use regional stepping action
203  /*
204  G4UserSteppingAction* regionalAction
205  = fpStep->GetPreStepPoint()->GetPhysicalVolume()->
206  GetLogicalVolume()->GetRegion()->
207  GetRegionalSteppingAction();
208  if( regionalAction ) regionalAction->UserSteppingAction(fpStep);
209  */
211 
212  if(fStoreTrajectory)
213  {
214  G4TrackingInformation* trackingInfo =
215  GetIT(track)->GetTrackingInfo();
216  G4Trajectory_Lock* trajectory_lock =
217  trackingInfo->GetTrajectory_Lock();
218  trajectory_lock->fpTrajectory->AppendStep(step);
219  }
220 }
221 
222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
223 
225 {
226 #ifdef G4VERBOSE
227  if(fVerboseLevel)
228  {
229  TrackBanner(track, "G4ITTrackingManager::EndTracking : ");
230  }
231 #endif
232  // Post tracking user intervention process.
233  if( fpUserTrackingAction != 0 ) {
235  }
236 
237 //#ifdef G4_STORE_TRAJECTORY
238  G4TrackingInformation* trackingInfo =
239  GetIT(track)->GetTrackingInfo();
240  G4Trajectory_Lock* trajectory_lock =
241  trackingInfo->GetTrajectory_Lock();
242 
243  if(trajectory_lock)
244  {
245  G4VTrajectory*& trajectory = trajectory_lock->fpTrajectory;
246 
247  if(fStoreTrajectory && trajectory)
248  {
249 
250 #ifdef G4VERBOSE
251  if(fVerboseLevel>10) trajectory->ShowTrajectory();
252 #endif
253  G4TrackStatus istop = track->GetTrackStatus();
254 
255  if (trajectory && (istop != fStopButAlive) && (istop != fSuspend))
256  {
257  G4Event* currentEvent = G4EventManager::GetEventManager()
259 
260  if (currentEvent)
261  {
262  G4TrajectoryContainer* trajectoryContainer = currentEvent
264 
265  if (!trajectoryContainer)
266  {
267  trajectoryContainer = new G4TrajectoryContainer;
268  currentEvent->SetTrajectoryContainer(trajectoryContainer);
269  }
270  trajectoryContainer->insert(trajectory);
271  }
272  else
273  {
274  fTrajectories.push_back(trajectory);
275  }
276  }
277  }
278  // Destruct the trajectory if it was created
279  else if( (!fStoreTrajectory)&&trajectory ) {
280  delete trajectory;
281  trajectory = 0;
282  }
283  delete trajectory_lock;
284  trackingInfo->SetTrajectory_Lock(0);
285  }
286 //#endif
287 }
288 
290 {
291  for (std::vector<G4VTrajectory*>::iterator it = fTrajectories.begin();
292  it != fTrajectories.end(); it++)
293  {
295  }
296 }