4 // Author: I.Hrivnacova
6 // Class TG4SteppingAction
7 // -----------------------
8 // See the class description in the header file.
10 #include "TG4SteppingAction.h"
11 #include "TG4VSensitiveDetector.h"
12 #include "TG4SDServices.h"
13 #include "TG4Globals.h"
16 #include <G4SteppingManager.hh>
18 //_____________________________________________________________________________
19 TG4SteppingAction::TG4SteppingAction()
20 : fMaxNofSteps(kMaxNofSteps),
21 fStandardVerboseLevel(0),
28 //_____________________________________________________________________________
29 TG4SteppingAction::TG4SteppingAction(const TG4SteppingAction& right) {
31 TG4Globals::Exception("TG4SteppingAction is protected from copying.");
34 //_____________________________________________________________________________
35 TG4SteppingAction::~TG4SteppingAction() {
41 //_____________________________________________________________________________
43 TG4SteppingAction::operator=(const TG4SteppingAction &right)
45 // check assignement to self
46 if (this == &right) return *this;
48 TG4Globals::Exception("TG4SteppingAction is protected from assigning.");
55 //_____________________________________________________________________________
56 void TG4SteppingAction::PrintTrackInfo(const G4Track* track) const
58 // Prints the track info
59 // - taken from private G4TrackingManager::Verbose()
60 // and the standard header for verbose tracking
61 // - taken from G4SteppingVerbose::TrackingStarted().
66 G4cout << "*******************************************************"
67 << "**************************************************"
69 G4cout << "* G4Track Information: "
70 << " Particle = " << track->GetDefinition()->GetParticleName()
72 << " Track ID = " << track->GetTrackID()
74 << " Parent ID = " << track->GetParentID()
76 G4cout << "*******************************************************"
77 << "**************************************************"
82 #ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
83 G4cout << G4std::setw( 5) << "Step#" << " "
84 << G4std::setw( 8) << "X" << " "
85 << G4std::setw( 8) << "Y" << " "
86 << G4std::setw( 8) << "Z" << " "
87 << G4std::setw( 9) << "KineE" << " "
88 << G4std::setw( 8) << "dE" << " "
89 << G4std::setw(12) << "StepLeng" << " "
90 << G4std::setw(12) << "TrackLeng" << " "
91 << G4std::setw(12) << "NextVolume" << " "
92 << G4std::setw( 8) << "ProcName" << G4endl;
94 G4cout << G4std::setw( 5) << "Step#" << " "
95 << G4std::setw( 8) << "X(mm)" << " "
96 << G4std::setw( 8) << "Y(mm)" << " "
97 << G4std::setw( 8) << "Z(mm)" << " "
98 << G4std::setw( 9) << "KinE(MeV)" << " "
99 << G4std::setw( 8) << "dE(MeV)" << " "
100 << G4std::setw( 8) << "StepLeng" << " "
101 << G4std::setw( 9) << "TrackLeng" << " "
102 << G4std::setw(11) << "NextVolume" << " "
103 << G4std::setw( 8) << "ProcName" << G4endl;
109 //_____________________________________________________________________________
110 void TG4SteppingAction::UserSteppingAction(const G4Step* step)
112 // Called by G4 kernel at the end of each step.
115 G4Track* track = step->GetTrack();
117 // reset parameters at beginning of tracking
118 G4int stepNumber = track->GetCurrentStepNumber();
119 if (stepNumber == 1) {
120 fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
121 fLoopStepCounter = 0;
123 else if (fLoopStepCounter) {
124 // count steps after detecting looping track
126 if (fLoopStepCounter == kMaxNofLoopSteps) {
128 // stop the looping track
129 track->SetTrackStatus(fStopAndKill);
131 // reset back parameters
132 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
133 fLoopStepCounter = 0;
136 else if (stepNumber> fMaxNofSteps) {
138 // print looping info
139 if (fLoopVerboseLevel > 0) {
140 G4cout << "*** Particle reached max step number ("
141 << fMaxNofSteps << "). ***" << G4endl;
142 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
145 // set loop verbose level
146 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
148 // start looping counter
152 // call stepping action of derived class
153 SteppingAction(step);
155 // let sensitive detector process boundary step
156 // if crossing geometry border
157 // (this ensures compatibility with G3 that
158 // makes boundary step of zero length)
160 if (step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary &&
161 step->GetTrack()->GetTrackStatus() == fAlive &&
162 step->GetTrack()->GetNextVolume() != 0) {
165 TG4VSensitiveDetector* tsd
166 = TG4SDServices::Instance()
167 ->GetSensitiveDetector(
168 step->GetPostStepPoint()->GetPhysicalVolume()
169 ->GetLogicalVolume()->GetSensitiveDetector());
171 if (tsd) = tsd->ProcessHitsOnBoundary((G4Step*)step);
173 TG4VSensitiveDetector* tsd
174 = (TG4VSensitiveDetector*) step->GetPostStepPoint()->GetPhysicalVolume()
175 ->GetLogicalVolume()->GetSensitiveDetector();
177 if (tsd) tsd->ProcessHitsOnBoundary((G4Step*)step);