check for max number of steps moved from AliSteppingAction here
[u/mrichter/AliRoot.git] / TGeant4 / TG4SteppingAction.cxx
CommitLineData
6fc5df41 1// $Id$
2// Category: event
3//
4// See the class description in the header file.
5
6#include "TG4SteppingAction.h"
6fc5df41 7#include "TG4VSensitiveDetector.h"
8#include "TG4Globals.h"
9
4148f156 10#include <G4Track.hh>
11#include <G4SteppingManager.hh>
12
13TG4SteppingAction::TG4SteppingAction()
14 : fMaxNofSteps(kMaxNofSteps),
15 fStandardVerboseLevel(0),
16 fLoopVerboseLevel(1),
17 fLoopStepCounter(0)
18 {
6fc5df41 19//
20}
21
22TG4SteppingAction::TG4SteppingAction(const TG4SteppingAction& right) {
23//
24 TG4Globals::Exception("TG4SteppingAction is protected from copying.");
25}
26
27TG4SteppingAction::~TG4SteppingAction() {
28//
29}
30
31// operators
32
33TG4SteppingAction&
34TG4SteppingAction::operator=(const TG4SteppingAction &right)
35{
36 // check assignement to self
37 if (this == &right) return *this;
38
39 TG4Globals::Exception("TG4SteppingAction is protected from assigning.");
40
41 return *this;
42}
43
4148f156 44// protected methods
45
46void TG4SteppingAction::PrintTrackInfo(const G4Track* track) const
47{
48// Prints the track info
49// - taken from private G4TrackingManager::Verbose()
50// and the standard header for verbose tracking
51// - taken from G4SteppingVerbose::TrackingStarted().
52// ---
53
54 // print track info
55 G4cout << G4endl;
56 G4cout << "*******************************************************"
57 << "**************************************************"
58 << G4endl;
59 G4cout << "* G4Track Information: "
60 << " Particle = " << track->GetDefinition()->GetParticleName()
61 << ","
62 << " Track ID = " << track->GetTrackID()
63 << ","
64 << " Parent ID = " << track->GetParentID()
65 << G4endl;
66 G4cout << "*******************************************************"
67 << "**************************************************"
68 << G4endl;
69 G4cout << G4endl;
70
71 // print header
72#ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
73 G4cout << G4std::setw( 5) << "Step#" << " "
74 << G4std::setw( 8) << "X" << " "
75 << G4std::setw( 8) << "Y" << " "
76 << G4std::setw( 8) << "Z" << " "
77 << G4std::setw( 9) << "KineE" << " "
78 << G4std::setw( 8) << "dE" << " "
79 << G4std::setw(12) << "StepLeng" << " "
80 << G4std::setw(12) << "TrackLeng" << " "
81 << G4std::setw(12) << "NextVolume" << " "
82 << G4std::setw( 8) << "ProcName" << G4endl;
83#else
84 G4cout << G4std::setw( 5) << "Step#" << " "
85 << G4std::setw( 8) << "X(mm)" << " "
86 << G4std::setw( 8) << "Y(mm)" << " "
87 << G4std::setw( 8) << "Z(mm)" << " "
88 << G4std::setw( 9) << "KinE(MeV)" << " "
89 << G4std::setw( 8) << "dE(MeV)" << " "
90 << G4std::setw( 8) << "StepLeng" << " "
91 << G4std::setw( 9) << "TrackLeng" << " "
92 << G4std::setw(11) << "NextVolume" << " "
93 << G4std::setw( 8) << "ProcName" << G4endl;
94#endif
95}
96
6fc5df41 97// public methods
98
99void TG4SteppingAction::UserSteppingAction(const G4Step* step)
100{
101// Called by G4 kernel at the end of each step.
102// ---
103
4148f156 104 G4Track* track = step->GetTrack();
105
106 // reset parameters at beginning of tracking
107 G4int stepNumber = track->GetCurrentStepNumber();
108 if (stepNumber == 1) {
109 fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
110 fLoopStepCounter = 0;
111 }
112 else if (fLoopStepCounter) {
113 // count steps after detecting looping track
114 fLoopStepCounter++;
115 if (fLoopStepCounter == kMaxNofLoopSteps) {
116
117 // stop the looping track
118 track->SetTrackStatus(fStopAndKill);
119
120 // reset back parameters
121 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
122 fLoopStepCounter = 0;
123 }
124 }
125 else if (stepNumber> fMaxNofSteps) {
126
127 // print looping info
128 if (fLoopVerboseLevel > 0) {
129 G4cout << "*** Particle reached max step number ("
130 << fMaxNofSteps << "). ***" << G4endl;
131 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
132 }
133
134 // set loop verbose level
135 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
136
137 // start looping counter
138 fLoopStepCounter++;
139 }
140
6fc5df41 141 // call stepping action of derived class
142 SteppingAction(step);
143
144 // let sensitive detector process boundary step
145 // if crossing geometry border
146 // (this ensures compatibility with G3 that
147 // makes boundary step of zero length)
148
149 if (step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary &&
c2c02aa6 150 step->GetTrack()->GetTrackStatus() == fAlive &&
6fc5df41 151 step->GetTrack()->GetNextVolume() != 0) {
152
153 G4VSensitiveDetector* sd
154 = step->GetPostStepPoint()->GetPhysicalVolume()
155 ->GetLogicalVolume()->GetSensitiveDetector();
156
157 if (sd) {
158 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
159 if (tsd)
160 tsd->ProcessHitsOnBoundary((G4Step*)step);
161 else {
162 G4String text = "TG4SteppingAction:::UserSteppingAction: \n";
163 text = text + " Unknown sensitive detector type";
164 TG4Globals::Exception(text);
165 }
166 }
167 }
168}
169