]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliSteppingAction.cxx
major modification with taking into account new step status values {kVertex, kBoundar...
[u/mrichter/AliRoot.git] / AliGeant4 / AliSteppingAction.cxx
CommitLineData
676fb573 1// $Id$
2// Category: event
3//
4// See the class description in the header file.
5
6#include "AliSteppingAction.h"
7#include "AliSteppingActionMessenger.h"
8#include "AliGlobals.h"
9
10#include <G4Track.hh>
11#include <G4SteppingManager.hh>
12
c63f260d 13const G4double AliSteppingAction::fgkTolerance = 1e-6*mm;
676fb573 14
15AliSteppingAction::AliSteppingAction()
16 : fKeptStepPoint(G4ThreeVector()),
17 fLoopVerboseLevel(1),
18 fStandardVerboseLevel(0),
19 fLoopStepCounter(0)
20{
21//
22 fMessenger = new AliSteppingActionMessenger(this);
23}
24
25AliSteppingAction::AliSteppingAction(const AliSteppingAction& right) {
26//
27 AliGlobals::Exception("AliSteppingAction is protected from copying.");
28}
29
30AliSteppingAction::~AliSteppingAction() {
31//
32 delete fMessenger;
33}
34
35// operators
36
37AliSteppingAction&
38AliSteppingAction::operator=(const AliSteppingAction &right)
39{
40 // check assignement to self
41 if (this == &right) return *this;
42
43 AliGlobals::Exception("AliSteppingAction is protected from assigning.");
44
45 return *this;
46}
47
48// private methods
49
50void AliSteppingAction::PrintTrackInfo(const G4Track* track) const
51{
52// Prints the track info
53// - taken from private G4TrackingManager::Verbose()
54// and the standard header for verbose tracking
55// - taken from G4SteppingVerbose::TrackingStarted().
56// ---
57
58 // print track info
5f1d09c5 59 G4cout << G4endl;
676fb573 60 G4cout << "*******************************************************"
61 << "**************************************************"
5f1d09c5 62 << G4endl;
676fb573 63 G4cout << "* G4Track Information: "
64 << " Particle = " << track->GetDefinition()->GetParticleName()
65 << ","
66 << " Track ID = " << track->GetTrackID()
67 << ","
68 << " Parent ID = " << track->GetParentID()
5f1d09c5 69 << G4endl;
676fb573 70 G4cout << "*******************************************************"
71 << "**************************************************"
5f1d09c5 72 << G4endl;
73 G4cout << G4endl;
676fb573 74
75 // print header
76#ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
5f1d09c5 77 G4cout << G4std::setw( 5) << "Step#" << " "
78 << G4std::setw( 8) << "X" << " "
79 << G4std::setw( 8) << "Y" << " "
80 << G4std::setw( 8) << "Z" << " "
81 << G4std::setw( 9) << "KineE" << " "
82 << G4std::setw( 8) << "dE" << " "
83 << G4std::setw(12) << "StepLeng" << " "
84 << G4std::setw(12) << "TrackLeng" << " "
85 << G4std::setw(12) << "NextVolume" << " "
86 << G4std::setw( 8) << "ProcName" << G4endl;
676fb573 87#else
5f1d09c5 88 G4cout << G4std::setw( 5) << "Step#" << " "
89 << G4std::setw( 8) << "X(mm)" << " "
90 << G4std::setw( 8) << "Y(mm)" << " "
91 << G4std::setw( 8) << "Z(mm)" << " "
92 << G4std::setw( 9) << "KinE(MeV)" << " "
93 << G4std::setw( 8) << "dE(MeV)" << " "
94 << G4std::setw( 8) << "StepLeng" << " "
95 << G4std::setw( 9) << "TrackLeng" << " "
96 << G4std::setw(11) << "NextVolume" << " "
97 << G4std::setw( 8) << "ProcName" << G4endl;
676fb573 98#endif
99}
100
101// public methods
102
103void AliSteppingAction::UserSteppingAction(const G4Step* step)
104{
105// After processing the given number of steps (kCheckNofSteps)
106// the particle position is compared with the previus one
c63f260d 107// - in case the distance is less than fgkTolerance value
676fb573 108// the verbose mode is switched on, particle is let
109// to process a small number of steps (kMaxNofLoopSteps)
110// and then stopped and killed.
111// ---
112
113 G4Track* track = step->GetTrack();
114
115 // reset parameters at beginning of tracking
116 G4int stepNumber = track->GetCurrentStepNumber();
117 if (stepNumber == 0) {
118 fKeptStepPoint = G4ThreeVector();
119 fLoopStepCounter = 0;
120 fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
121 return;
122 }
123
124 if (fLoopStepCounter) {
125 // count steps after detecting looping track
126 fLoopStepCounter++;
127 if (fLoopStepCounter == kMaxNofLoopSteps) {
128
129 // stop the looping track
130 track->SetTrackStatus(fStopAndKill);
131
132 // reset back parameters
133 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
134 fKeptStepPoint = G4ThreeVector();
135 fLoopStepCounter = 0;
136 }
137 }
138
139 if (stepNumber % kCheckNofSteps == 0) {
140 // detect looping track
141 G4ThreeVector newStepPoint = step->GetPreStepPoint()->GetPosition();
142 G4double trajectory = (newStepPoint-fKeptStepPoint).mag();
b7af6ca0 143 G4bool kill = false;
c63f260d 144 if (trajectory < fgkTolerance) {
676fb573 145
146 // print looping info
147 if (fLoopVerboseLevel > 0) {
5f1d09c5 148 G4cout << "*** Particle is looping. ***" << G4endl;
676fb573 149 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
150 }
b7af6ca0 151 kill = true;
152 }
153
154 if (stepNumber> kMaxNofSteps) {
155
156 // print looping info
157 if (fLoopVerboseLevel > 0) {
158 G4cout << "*** Particle reached max step number ("
159 << kMaxNofSteps << "). ***" << G4endl;
160 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
161 }
162 kill = true;
163 }
164
165 if (kill) {
166
676fb573 167 // set loop verbose level
168 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
169
170 fLoopStepCounter++;
171 }
172 fKeptStepPoint = newStepPoint;
173 }
174}