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 TG4SteppingAction::TG4SteppingAction()
14 : fMaxNofSteps(kMaxNofSteps),
15 fStandardVerboseLevel(0),
22 TG4SteppingAction::TG4SteppingAction(const TG4SteppingAction& right) {
24 TG4Globals::Exception("TG4SteppingAction is protected from copying.");
27 TG4SteppingAction::~TG4SteppingAction() {
34 TG4SteppingAction::operator=(const TG4SteppingAction &right)
36 // check assignement to self
37 if (this == &right) return *this;
39 TG4Globals::Exception("TG4SteppingAction is protected from assigning.");
46 void TG4SteppingAction::PrintTrackInfo(const G4Track* track) const
48 // Prints the track info
49 // - taken from private G4TrackingManager::Verbose()
50 // and the standard header for verbose tracking
51 // - taken from G4SteppingVerbose::TrackingStarted().
56 G4cout << "*******************************************************"
57 << "**************************************************"
59 G4cout << "* G4Track Information: "
60 << " Particle = " << track->GetDefinition()->GetParticleName()
62 << " Track ID = " << track->GetTrackID()
64 << " Parent ID = " << track->GetParentID()
66 G4cout << "*******************************************************"
67 << "**************************************************"
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;
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;
99 void TG4SteppingAction::UserSteppingAction(const G4Step* step)
101 // Called by G4 kernel at the end of each step.
104 G4Track* track = step->GetTrack();
106 // reset parameters at beginning of tracking
107 G4int stepNumber = track->GetCurrentStepNumber();
108 if (stepNumber == 1) {
109 fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
110 fLoopStepCounter = 0;
112 else if (fLoopStepCounter) {
113 // count steps after detecting looping track
115 if (fLoopStepCounter == kMaxNofLoopSteps) {
117 // stop the looping track
118 track->SetTrackStatus(fStopAndKill);
120 // reset back parameters
121 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
122 fLoopStepCounter = 0;
125 else if (stepNumber> fMaxNofSteps) {
127 // print looping info
128 if (fLoopVerboseLevel > 0) {
129 G4cout << "*** Particle reached max step number ("
130 << fMaxNofSteps << "). ***" << G4endl;
131 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
134 // set loop verbose level
135 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
137 // start looping counter
141 // call stepping action of derived class
142 SteppingAction(step);
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)
149 if (step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary &&
150 step->GetTrack()->GetTrackStatus() == fAlive &&
151 step->GetTrack()->GetNextVolume() != 0) {
153 G4VSensitiveDetector* sd
154 = step->GetPostStepPoint()->GetPhysicalVolume()
155 ->GetLogicalVolume()->GetSensitiveDetector();
158 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
160 tsd->ProcessHitsOnBoundary((G4Step*)step);
162 G4String text = "TG4SteppingAction:::UserSteppingAction: \n";
163 text = text + " Unknown sensitive detector type";
164 TG4Globals::Exception(text);