4 // See the class description in the header file.
6 #include "TG4SteppingAction.h"
7 #include "TG4VSensitiveDetector.h"
8 #include "TG4Globals.h"
11 #include <G4SteppingManager.hh>
13 //_____________________________________________________________________________
14 TG4SteppingAction::TG4SteppingAction()
15 : fMaxNofSteps(kMaxNofSteps),
16 fStandardVerboseLevel(0),
23 //_____________________________________________________________________________
24 TG4SteppingAction::TG4SteppingAction(const TG4SteppingAction& right) {
26 TG4Globals::Exception("TG4SteppingAction is protected from copying.");
29 //_____________________________________________________________________________
30 TG4SteppingAction::~TG4SteppingAction() {
36 //_____________________________________________________________________________
38 TG4SteppingAction::operator=(const TG4SteppingAction &right)
40 // check assignement to self
41 if (this == &right) return *this;
43 TG4Globals::Exception("TG4SteppingAction is protected from assigning.");
50 //_____________________________________________________________________________
51 void TG4SteppingAction::PrintTrackInfo(const G4Track* track) const
53 // Prints the track info
54 // - taken from private G4TrackingManager::Verbose()
55 // and the standard header for verbose tracking
56 // - taken from G4SteppingVerbose::TrackingStarted().
61 G4cout << "*******************************************************"
62 << "**************************************************"
64 G4cout << "* G4Track Information: "
65 << " Particle = " << track->GetDefinition()->GetParticleName()
67 << " Track ID = " << track->GetTrackID()
69 << " Parent ID = " << track->GetParentID()
71 G4cout << "*******************************************************"
72 << "**************************************************"
77 #ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
78 G4cout << G4std::setw( 5) << "Step#" << " "
79 << G4std::setw( 8) << "X" << " "
80 << G4std::setw( 8) << "Y" << " "
81 << G4std::setw( 8) << "Z" << " "
82 << G4std::setw( 9) << "KineE" << " "
83 << G4std::setw( 8) << "dE" << " "
84 << G4std::setw(12) << "StepLeng" << " "
85 << G4std::setw(12) << "TrackLeng" << " "
86 << G4std::setw(12) << "NextVolume" << " "
87 << G4std::setw( 8) << "ProcName" << G4endl;
89 G4cout << G4std::setw( 5) << "Step#" << " "
90 << G4std::setw( 8) << "X(mm)" << " "
91 << G4std::setw( 8) << "Y(mm)" << " "
92 << G4std::setw( 8) << "Z(mm)" << " "
93 << G4std::setw( 9) << "KinE(MeV)" << " "
94 << G4std::setw( 8) << "dE(MeV)" << " "
95 << G4std::setw( 8) << "StepLeng" << " "
96 << G4std::setw( 9) << "TrackLeng" << " "
97 << G4std::setw(11) << "NextVolume" << " "
98 << G4std::setw( 8) << "ProcName" << G4endl;
104 //_____________________________________________________________________________
105 void TG4SteppingAction::UserSteppingAction(const G4Step* step)
107 // Called by G4 kernel at the end of each step.
110 G4Track* track = step->GetTrack();
112 // reset parameters at beginning of tracking
113 G4int stepNumber = track->GetCurrentStepNumber();
114 if (stepNumber == 1) {
115 fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
116 fLoopStepCounter = 0;
118 else if (fLoopStepCounter) {
119 // count steps after detecting looping track
121 if (fLoopStepCounter == kMaxNofLoopSteps) {
123 // stop the looping track
124 track->SetTrackStatus(fStopAndKill);
126 // reset back parameters
127 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
128 fLoopStepCounter = 0;
131 else if (stepNumber> fMaxNofSteps) {
133 // print looping info
134 if (fLoopVerboseLevel > 0) {
135 G4cout << "*** Particle reached max step number ("
136 << fMaxNofSteps << "). ***" << G4endl;
137 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
140 // set loop verbose level
141 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
143 // start looping counter
147 // call stepping action of derived class
148 SteppingAction(step);
150 // let sensitive detector process boundary step
151 // if crossing geometry border
152 // (this ensures compatibility with G3 that
153 // makes boundary step of zero length)
155 if (step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary &&
156 step->GetTrack()->GetTrackStatus() == fAlive &&
157 step->GetTrack()->GetNextVolume() != 0) {
159 G4VSensitiveDetector* sd
160 = step->GetPostStepPoint()->GetPhysicalVolume()
161 ->GetLogicalVolume()->GetSensitiveDetector();
164 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
166 tsd->ProcessHitsOnBoundary((G4Step*)step);
168 G4String text = "TG4SteppingAction:::UserSteppingAction: \n";
169 text = text + " Unknown sensitive detector type";
170 TG4Globals::Exception(text);