Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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: [email protected])
31// Takashi Sasaki (e-mail: [email protected])
32// --------------------------------------------------------------------
33
34#include "G4TrackingManager.hh"
35
36#include "G4Profiler.hh"
37#include "G4RichTrajectory.hh"
38#include "G4SmoothTrajectory.hh"
39#include "G4TiMemory.hh"
40#include "G4Trajectory.hh"
41#include "G4ios.hh"
42
43//////////////////////////////////////
45//////////////////////////////////////
46{
47 messenger = new G4TrackingMessenger(this);
48 fpSteppingManager = new G4SteppingManager();
49}
50
51///////////////////////////////////////
53///////////////////////////////////////
54{
55 delete messenger;
56 delete fpSteppingManager;
57 delete fpUserTrackingAction;
58}
59
60////////////////////////////////////////////////////////////////
62////////////////////////////////////////////////////////////////
63{
64 // Receiving a G4Track from the EventManager, this funciton has the
65 // responsibility to trace the track till it stops
66
67 fpTrack = apValueG4Track;
68 EventIsAborted = false;
69
70 // Clear secondary particle vector
71 //
72 for (auto& itr : *GimmeSecondaries()) {
73 delete 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 fpUserTrackingAction->PreUserTrackingAction(fpTrack);
88 }
89
90 // we need this to scope the G4Track::ProfilerConfig b/t
91 // the PreUserTrackingAction and PostUserTrackingAction
92 {
93#if defined(GEANT4_USE_TIMEMORY)
94 ProfilerConfig profiler{fpTrack};
95#endif
96
97#ifdef G4_STORE_TRAJECTORY
98 // Construct a trajectory if it is requested
99 //
100 if ((StoreTrajectory != 0) && (fpTrajectory == nullptr)) {
101 // default trajectory concrete class object
102 switch (StoreTrajectory) {
103 default:
104 case 1:
105 fpTrajectory = new G4Trajectory(fpTrack);
106 break;
107 case 2:
108 fpTrajectory = new G4SmoothTrajectory(fpTrack);
109 break;
110 case 3:
111 fpTrajectory = new G4RichTrajectory(fpTrack);
112 break;
113 case 4:
114 fpTrajectory = new G4RichTrajectory(fpTrack);
115 break;
116 }
117 }
118#endif
119
120 // Give SteppingManger the maxmimum number of processes
121 fpSteppingManager->GetProcessNumber();
122
123 // Give track the pointer to the Step
124 fpTrack->SetStep(fpSteppingManager->GetStep());
125
126 // Inform beginning of tracking to physics processes
127 fpTrack->GetDefinition()->GetProcessManager()->StartTracking(fpTrack);
128
129 // Track the particle Step-by-Step while it is alive
130 //
131 while ((fpTrack->GetTrackStatus() == fAlive) || (fpTrack->GetTrackStatus() == fStopButAlive)) {
133 fpSteppingManager->Stepping();
134#ifdef G4_STORE_TRAJECTORY
135 if (StoreTrajectory != 0) {
136 fpTrajectory->AppendStep(fpSteppingManager->GetStep());
137 }
138#endif
139 if (EventIsAborted) {
141 }
142 }
143 // Inform end of tracking to physics processes
145 }
146
147 // Post tracking user intervention process.
148 if (fpUserTrackingAction != nullptr) {
149 fpUserTrackingAction->PostUserTrackingAction(fpTrack);
150 }
151
152 // Destruct the trajectory if it was created
153#ifdef G4VERBOSE
154 if ((StoreTrajectory != 0) && verboseLevel > 10) {
155 fpTrajectory->ShowTrajectory();
156 }
157#endif
158 if ((StoreTrajectory == 0) && (fpTrajectory != nullptr)) {
159 delete fpTrajectory;
160 fpTrajectory = nullptr;
161 }
162}
163
164//////////////////////////////////////
166//////////////////////////////////////
167{
168#ifndef G4_STORE_TRAJECTORY
169 G4Exception("G4TrackingManager::SetTrajectory()", "Tracking0015", FatalException,
170 "Invoked without G4_STORE_TRAJECTORY option set!");
171#endif
172 fpTrajectory = aTrajectory;
173}
174
175//////////////////////////////////////
177//////////////////////////////////////
178{
180 EventIsAborted = true;
181}
182
183//////////////////////////////////////
184void G4TrackingManager::TrackBanner()
185//////////////////////////////////////
186{
187 G4cout << G4endl;
188 G4cout << "*******************************************************"
189 << "**************************************************" << G4endl;
190 G4cout << "* G4Track Information: "
191 << " Particle = " << fpTrack->GetDefinition()->GetParticleName() << ","
192 << " Track ID = " << fpTrack->GetTrackID() << ","
193 << " Parent ID = " << fpTrack->GetParentID() << G4endl;
194 G4cout << "*******************************************************"
195 << "**************************************************" << G4endl;
196 G4cout << G4endl;
197}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
@ fKillTrackAndSecondaries
@ fAlive
@ fStopButAlive
#define G4endl
Definition G4ios.hh:67
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 *)
virtual void ShowTrajectory(std::ostream &os=G4cout) const
virtual void AppendStep(const G4Step *aStep)=0