]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliSteppingAction.cxx
This commit was generated by cvs2svn to compensate for changes in r1459,
[u/mrichter/AliRoot.git] / AliGeant4 / AliSteppingAction.cxx
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
13 const G4double AliSteppingAction::fgTolerance = 1e-6*mm;
14
15 AliSteppingAction::AliSteppingAction()
16   : fKeptStepPoint(G4ThreeVector()),
17     fLoopVerboseLevel(1),
18     fStandardVerboseLevel(0),
19     fLoopStepCounter(0)
20 {
21 //
22   fMessenger = new AliSteppingActionMessenger(this);
23 }
24
25 AliSteppingAction::AliSteppingAction(const AliSteppingAction& right) {
26 //
27   AliGlobals::Exception("AliSteppingAction is protected from copying.");
28 }
29
30 AliSteppingAction::~AliSteppingAction() {
31 //
32   delete fMessenger;
33 }
34
35 // operators
36
37 AliSteppingAction& 
38 AliSteppingAction::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
50 void 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
59   G4cout << endl;
60   G4cout << "*******************************************************"
61          << "**************************************************"
62          << endl;
63   G4cout << "* G4Track Information: " 
64          << "  Particle = " << track->GetDefinition()->GetParticleName() 
65          << "," 
66          << "   Track ID = " << track->GetTrackID() 
67          << "," 
68          << "   Parent ID = " << track->GetParentID() 
69          << endl;
70   G4cout << "*******************************************************"
71          << "**************************************************"
72          << endl;
73   G4cout << endl;
74       
75   // print header    
76 #ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
77     G4cout << setw( 5) << "Step#"  << " "
78            << setw( 8) << "X"      << "     "
79            << setw( 8) << "Y"      << "     "  
80            << setw( 8) << "Z"      << "     "
81            << setw( 9) << "KineE"  << "     "
82            << setw( 8) << "dE"     << "     "  
83            << setw(12) << "StepLeng"   << " "  
84            << setw(12) << "TrackLeng"  << " "
85            << setw(12) << "NextVolume" << " "
86            << setw( 8) << "ProcName"   << endl;      
87 #else
88     G4cout << setw( 5) << "Step#"      << " "
89            << setw( 8) << "X(mm)"      << " "
90            << setw( 8) << "Y(mm)"      << " "  
91            << setw( 8) << "Z(mm)"      << " "
92            << setw( 9) << "KinE(MeV)"  << " "
93            << setw( 8) << "dE(MeV)"    << " "  
94            << setw( 8) << "StepLeng"   << " "  
95            << setw( 9) << "TrackLeng"  << " "
96            << setw(11) << "NextVolume" << " "
97            << setw( 8) << "ProcName"   << endl;      
98 #endif
99 }
100
101 // public methods
102
103 void 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
107 // - in case the distance is less than fgTolerance 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.
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();
143     if (trajectory < fgTolerance) {
144
145       // print looping info
146       if (fLoopVerboseLevel > 0) {
147         G4cout << "*** Particle is looping. ***" << endl;
148         if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
149       } 
150       // set loop verbose level 
151       fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
152       
153       fLoopStepCounter++;
154     }  
155     fKeptStepPoint = newStepPoint;
156   }  
157 }