]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliSteppingAction.cxx
Initial version
[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
9bcb6317 101#include "AliMC.h"
102
676fb573 103// public methods
104
9bcb6317 105void AliSteppingAction::SteppingAction(const G4Step* step)
676fb573 106{
107// After processing the given number of steps (kCheckNofSteps)
108// the particle position is compared with the previus one
c63f260d 109// - in case the distance is less than fgkTolerance value
676fb573 110// the verbose mode is switched on, particle is let
111// to process a small number of steps (kMaxNofLoopSteps)
112// and then stopped and killed.
113// ---
114
115 G4Track* track = step->GetTrack();
116
117 // reset parameters at beginning of tracking
118 G4int stepNumber = track->GetCurrentStepNumber();
119 if (stepNumber == 0) {
120 fKeptStepPoint = G4ThreeVector();
121 fLoopStepCounter = 0;
122 fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
123 return;
124 }
125
126 if (fLoopStepCounter) {
127 // count steps after detecting looping track
128 fLoopStepCounter++;
129 if (fLoopStepCounter == kMaxNofLoopSteps) {
130
131 // stop the looping track
132 track->SetTrackStatus(fStopAndKill);
133
134 // reset back parameters
135 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
136 fKeptStepPoint = G4ThreeVector();
137 fLoopStepCounter = 0;
138 }
139 }
140
141 if (stepNumber % kCheckNofSteps == 0) {
142 // detect looping track
143 G4ThreeVector newStepPoint = step->GetPreStepPoint()->GetPosition();
144 G4double trajectory = (newStepPoint-fKeptStepPoint).mag();
b7af6ca0 145 G4bool kill = false;
c63f260d 146 if (trajectory < fgkTolerance) {
676fb573 147
148 // print looping info
149 if (fLoopVerboseLevel > 0) {
5f1d09c5 150 G4cout << "*** Particle is looping. ***" << G4endl;
676fb573 151 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
152 }
b7af6ca0 153 kill = true;
154 }
155
156 if (stepNumber> kMaxNofSteps) {
157
158 // print looping info
159 if (fLoopVerboseLevel > 0) {
160 G4cout << "*** Particle reached max step number ("
161 << kMaxNofSteps << "). ***" << G4endl;
162 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
163 }
164 kill = true;
165 }
166
167 if (kill) {
168
676fb573 169 // set loop verbose level
170 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
171
172 fLoopStepCounter++;
173 }
174 fKeptStepPoint = newStepPoint;
175 }
176}