Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4TrackingManager.cc
Go to the documentation of this file.
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// G4TrackingManager class implementation
27//
28// Contact:
29// Questions and comments to this code should be sent to
30// Katsuya Amako (e-mail: Katsuya.Amako@kek.jp)
31// Takashi Sasaki (e-mail: Takashi.Sasaki@kek.jp)
32// --------------------------------------------------------------------
33
34#include "G4TrackingManager.hh"
35#include "G4Trajectory.hh"
36#include "G4SmoothTrajectory.hh"
37#include "G4RichTrajectory.hh"
38#include "G4ios.hh"
39#include "G4Profiler.hh"
40#include "G4TiMemory.hh"
41
42//////////////////////////////////////
44//////////////////////////////////////
45{
46 messenger = new G4TrackingMessenger(this);
47 fpSteppingManager = new G4SteppingManager();
48}
49
50///////////////////////////////////////
52///////////////////////////////////////
53{
54 delete messenger;
55 delete fpSteppingManager;
56 delete fpUserTrackingAction;
57}
58
59////////////////////////////////////////////////////////////////
61////////////////////////////////////////////////////////////////
62{
63 // Receiving a G4Track from the EventManager, this funciton has the
64 // responsibility to trace the track till it stops
65
66 fpTrack = apValueG4Track;
67 EventIsAborted = false;
68
69 // Clear secondary particle vector
70 //
71 for(std:: size_t itr=0; itr<GimmeSecondaries()->size(); ++itr)
72 {
73 delete (*GimmeSecondaries())[itr];
74 }
75 GimmeSecondaries()->clear();
76
77 if(verboseLevel>0 && (G4VSteppingVerbose::GetSilent()!=1) ) TrackBanner();
78
79 // Give SteppingManger the pointer to the track which will be tracked
80 //
81 fpSteppingManager->SetInitialStep(fpTrack);
82
83 // Pre tracking user intervention process
84
85 fpTrajectory = nullptr;
86 if( fpUserTrackingAction != nullptr )
87 {
88 fpUserTrackingAction->PreUserTrackingAction(fpTrack);
89 }
90
91 // we need this to scope the G4Track::ProfilerConfig b/t
92 // the PreUserTrackingAction and PostUserTrackingAction
93 {
94#if defined(GEANT4_USE_TIMEMORY)
95 ProfilerConfig profiler{ fpTrack };
96#endif
97
98#ifdef G4_STORE_TRAJECTORY
99 // Construct a trajectory if it is requested
100 //
101 if(StoreTrajectory && (fpTrajectory == nullptr))
102 {
103 // default trajectory concrete class object
104 switch(StoreTrajectory)
105 {
106 default:
107 case 1:
108 fpTrajectory = new G4Trajectory(fpTrack);
109 break;
110 case 2:
111 fpTrajectory = new G4SmoothTrajectory(fpTrack);
112 break;
113 case 3:
114 fpTrajectory = new G4RichTrajectory(fpTrack);
115 break;
116 case 4:
117 fpTrajectory = new G4RichTrajectory(fpTrack);
118 break;
119 }
120 }
121#endif
122
123 // Give SteppingManger the maxmimum number of processes
124 fpSteppingManager->GetProcessNumber();
125
126 // Give track the pointer to the Step
127 fpTrack->SetStep(fpSteppingManager->GetStep());
128
129 // Inform beginning of tracking to physics processes
130 fpTrack->GetDefinition()->GetProcessManager()->StartTracking(fpTrack);
131
132 // Track the particle Step-by-Step while it is alive
133 //
134 while((fpTrack->GetTrackStatus() == fAlive) ||
135 (fpTrack->GetTrackStatus() == fStopButAlive))
136 {
138 fpSteppingManager->Stepping();
139#ifdef G4_STORE_TRAJECTORY
140 if(StoreTrajectory)
141 {
142 fpTrajectory->AppendStep(fpSteppingManager->GetStep());
143 }
144#endif
145 if(EventIsAborted)
146 {
148 }
149 }
150 // Inform end of tracking to physics processes
152 }
153
154 // Post tracking user intervention process.
155 if( fpUserTrackingAction != nullptr )
156 {
157 fpUserTrackingAction->PostUserTrackingAction(fpTrack);
158 }
159
160 // Destruct the trajectory if it was created
161#ifdef G4VERBOSE
162 if(StoreTrajectory&&verboseLevel>10)
163 {
164 fpTrajectory->ShowTrajectory();
165 }
166#endif
167 if( (!StoreTrajectory) && (fpTrajectory != nullptr) )
168 {
169 delete fpTrajectory;
170 fpTrajectory = nullptr;
171 }
172}
173
174//////////////////////////////////////
176//////////////////////////////////////
177{
178#ifndef G4_STORE_TRAJECTORY
179 G4Exception("G4TrackingManager::SetTrajectory()",
180 "Tracking0015", FatalException,
181 "Invoked without G4_STORE_TRAJECTORY option set!");
182#endif
183 fpTrajectory = aTrajectory;
184}
185
186//////////////////////////////////////
188//////////////////////////////////////
189{
191 EventIsAborted = true;
192}
193
194//////////////////////////////////////
195void G4TrackingManager::TrackBanner()
196//////////////////////////////////////
197{
198 G4cout << G4endl;
199 G4cout << "*******************************************************"
200 << "**************************************************"
201 << G4endl;
202 G4cout << "* G4Track Information: "
203 << " Particle = " << fpTrack->GetDefinition()->GetParticleName()
204 << ","
205 << " Track ID = " << fpTrack->GetTrackID()
206 << ","
207 << " Parent ID = " << fpTrack->GetParentID()
208 << G4endl;
209 G4cout << "*******************************************************"
210 << "**************************************************"
211 << G4endl;
212 G4cout << G4endl;
213}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
@ fKillTrackAndSecondaries
@ fAlive
@ fStopButAlive
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
void StartTracking(G4Track *aTrack=nullptr)
G4StepStatus Stepping()
void SetInitialStep(G4Track *valueTrack)
G4Step * GetStep() const
G4TrackStatus GetTrackStatus() const
void SetTrackStatus(const G4TrackStatus aTrackStatus)
G4int GetTrackID() const
void SetStep(const G4Step *aValue)
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
void IncrementCurrentStepNumber()
G4TrackVector * GimmeSecondaries() const
void ProcessOneTrack(G4Track *apValueG4Track)
void SetTrajectory(G4VTrajectory *aTrajectory)
virtual void PostUserTrackingAction(const G4Track *)
virtual void PreUserTrackingAction(const G4Track *)
static G4int GetSilent()
virtual void ShowTrajectory(std::ostream &os=G4cout) const
virtual void AppendStep(const G4Step *aStep)=0