4 // See the class description in the header file.
6 #include "AliSteppingAction.h"
7 #include "AliSteppingActionMessenger.h"
8 #include "AliGlobals.h"
11 #include <G4SteppingManager.hh>
13 const G4double AliSteppingAction::fgkTolerance = 1e-6*mm;
15 AliSteppingAction::AliSteppingAction()
16 : fKeptStepPoint(G4ThreeVector()),
18 fStandardVerboseLevel(0),
22 fMessenger = new AliSteppingActionMessenger(this);
25 AliSteppingAction::AliSteppingAction(const AliSteppingAction& right) {
27 AliGlobals::Exception("AliSteppingAction is protected from copying.");
30 AliSteppingAction::~AliSteppingAction() {
38 AliSteppingAction::operator=(const AliSteppingAction &right)
40 // check assignement to self
41 if (this == &right) return *this;
43 AliGlobals::Exception("AliSteppingAction is protected from assigning.");
50 void AliSteppingAction::PrintTrackInfo(const G4Track* track) const
52 // Prints the track info
53 // - taken from private G4TrackingManager::Verbose()
54 // and the standard header for verbose tracking
55 // - taken from G4SteppingVerbose::TrackingStarted().
60 G4cout << "*******************************************************"
61 << "**************************************************"
63 G4cout << "* G4Track Information: "
64 << " Particle = " << track->GetDefinition()->GetParticleName()
66 << " Track ID = " << track->GetTrackID()
68 << " Parent ID = " << track->GetParentID()
70 G4cout << "*******************************************************"
71 << "**************************************************"
76 #ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
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;
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;
103 void AliSteppingAction::UserSteppingAction(const G4Step* step)
105 // After processing the given number of steps (kCheckNofSteps)
106 // the particle position is compared with the previus one
107 // - in case the distance is less than fgkTolerance value
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.
113 G4Track* track = step->GetTrack();
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();
124 if (fLoopStepCounter) {
125 // count steps after detecting looping track
127 if (fLoopStepCounter == kMaxNofLoopSteps) {
129 // stop the looping track
130 track->SetTrackStatus(fStopAndKill);
132 // reset back parameters
133 fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
134 fKeptStepPoint = G4ThreeVector();
135 fLoopStepCounter = 0;
139 if (stepNumber % kCheckNofSteps == 0) {
140 // detect looping track
141 G4ThreeVector newStepPoint = step->GetPreStepPoint()->GetPosition();
142 G4double trajectory = (newStepPoint-fKeptStepPoint).mag();
143 if (trajectory < fgkTolerance) {
145 // print looping info
146 if (fLoopVerboseLevel > 0) {
147 G4cout << "*** Particle is looping. ***" << G4endl;
148 if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
150 // set loop verbose level
151 fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
155 fKeptStepPoint = newStepPoint;