]>
Commit | Line | Data |
---|---|---|
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 | ||
72095f7c | 13 | //_____________________________________________________________________________ |
4148f156 | 14 | TG4SteppingAction::TG4SteppingAction() |
15 | : fMaxNofSteps(kMaxNofSteps), | |
16 | fStandardVerboseLevel(0), | |
17 | fLoopVerboseLevel(1), | |
18 | fLoopStepCounter(0) | |
19 | { | |
6fc5df41 | 20 | // |
21 | } | |
22 | ||
72095f7c | 23 | //_____________________________________________________________________________ |
6fc5df41 | 24 | TG4SteppingAction::TG4SteppingAction(const TG4SteppingAction& right) { |
25 | // | |
26 | TG4Globals::Exception("TG4SteppingAction is protected from copying."); | |
27 | } | |
28 | ||
72095f7c | 29 | //_____________________________________________________________________________ |
6fc5df41 | 30 | TG4SteppingAction::~TG4SteppingAction() { |
31 | // | |
32 | } | |
33 | ||
34 | // operators | |
35 | ||
72095f7c | 36 | //_____________________________________________________________________________ |
6fc5df41 | 37 | TG4SteppingAction& |
38 | TG4SteppingAction::operator=(const TG4SteppingAction &right) | |
39 | { | |
40 | // check assignement to self | |
41 | if (this == &right) return *this; | |
42 | ||
43 | TG4Globals::Exception("TG4SteppingAction is protected from assigning."); | |
44 | ||
45 | return *this; | |
46 | } | |
47 | ||
4148f156 | 48 | // protected methods |
49 | ||
72095f7c | 50 | //_____________________________________________________________________________ |
4148f156 | 51 | void TG4SteppingAction::PrintTrackInfo(const G4Track* track) const |
52 | { | |
53 | // Prints the track info | |
54 | // - taken from private G4TrackingManager::Verbose() | |
55 | // and the standard header for verbose tracking | |
56 | // - taken from G4SteppingVerbose::TrackingStarted(). | |
57 | // --- | |
58 | ||
59 | // print track info | |
60 | G4cout << G4endl; | |
61 | G4cout << "*******************************************************" | |
62 | << "**************************************************" | |
63 | << G4endl; | |
64 | G4cout << "* G4Track Information: " | |
65 | << " Particle = " << track->GetDefinition()->GetParticleName() | |
66 | << "," | |
67 | << " Track ID = " << track->GetTrackID() | |
68 | << "," | |
69 | << " Parent ID = " << track->GetParentID() | |
70 | << G4endl; | |
71 | G4cout << "*******************************************************" | |
72 | << "**************************************************" | |
73 | << G4endl; | |
74 | G4cout << G4endl; | |
75 | ||
76 | // print header | |
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; | |
88 | #else | |
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; | |
99 | #endif | |
100 | } | |
101 | ||
6fc5df41 | 102 | // public methods |
103 | ||
72095f7c | 104 | //_____________________________________________________________________________ |
6fc5df41 | 105 | void TG4SteppingAction::UserSteppingAction(const G4Step* step) |
106 | { | |
107 | // Called by G4 kernel at the end of each step. | |
108 | // --- | |
109 | ||
4148f156 | 110 | G4Track* track = step->GetTrack(); |
111 | ||
112 | // reset parameters at beginning of tracking | |
113 | G4int stepNumber = track->GetCurrentStepNumber(); | |
114 | if (stepNumber == 1) { | |
115 | fStandardVerboseLevel = fpSteppingManager->GetverboseLevel(); | |
116 | fLoopStepCounter = 0; | |
117 | } | |
118 | else if (fLoopStepCounter) { | |
119 | // count steps after detecting looping track | |
120 | fLoopStepCounter++; | |
121 | if (fLoopStepCounter == kMaxNofLoopSteps) { | |
122 | ||
123 | // stop the looping track | |
124 | track->SetTrackStatus(fStopAndKill); | |
125 | ||
126 | // reset back parameters | |
127 | fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel); | |
128 | fLoopStepCounter = 0; | |
129 | } | |
130 | } | |
131 | else if (stepNumber> fMaxNofSteps) { | |
132 | ||
133 | // print looping info | |
134 | if (fLoopVerboseLevel > 0) { | |
135 | G4cout << "*** Particle reached max step number (" | |
136 | << fMaxNofSteps << "). ***" << G4endl; | |
137 | if (fStandardVerboseLevel == 0) PrintTrackInfo(track); | |
138 | } | |
139 | ||
140 | // set loop verbose level | |
141 | fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel); | |
142 | ||
143 | // start looping counter | |
144 | fLoopStepCounter++; | |
145 | } | |
146 | ||
6fc5df41 | 147 | // call stepping action of derived class |
148 | SteppingAction(step); | |
149 | ||
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) | |
154 | ||
155 | if (step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary && | |
c2c02aa6 | 156 | step->GetTrack()->GetTrackStatus() == fAlive && |
6fc5df41 | 157 | step->GetTrack()->GetNextVolume() != 0) { |
158 | ||
159 | G4VSensitiveDetector* sd | |
160 | = step->GetPostStepPoint()->GetPhysicalVolume() | |
161 | ->GetLogicalVolume()->GetSensitiveDetector(); | |
162 | ||
163 | if (sd) { | |
164 | TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd); | |
165 | if (tsd) | |
166 | tsd->ProcessHitsOnBoundary((G4Step*)step); | |
167 | else { | |
168 | G4String text = "TG4SteppingAction:::UserSteppingAction: \n"; | |
169 | text = text + " Unknown sensitive detector type"; | |
170 | TG4Globals::Exception(text); | |
171 | } | |
172 | } | |
173 | } | |
174 | } | |
175 |