GEMC  2.3
Geant4 Monte-Carlo Framework
MSteppingAction.cc
Go to the documentation of this file.
1 // G4 headers
2 #include "G4ParticleTypes.hh"
3 
4 // gemc headers
5 #include "MSteppingAction.h"
6 
8 {
9  gemcOpt = Opt;
10  energyCut = gemcOpt.optMap["ENERGY_CUT"].arg;
11  max_x_pos = gemcOpt.optMap["MAX_X_POS"].arg;
12  max_y_pos = gemcOpt.optMap["MAX_Y_POS"].arg;
13  max_z_pos = gemcOpt.optMap["MAX_Z_POS"].arg;
14 
15 // oldpos = G4ThreeVector(0,0,0);
16 // nsame = 0;
17 }
18 
19 MSteppingAction::~MSteppingAction(){ cout << " > Closing Stepping Action." << endl;}
20 
21 
22 void MSteppingAction::UserSteppingAction(const G4Step* aStep)
23 {
24  G4ThreeVector pos = aStep->GetPostStepPoint()->GetPosition();
25  G4Track* track = aStep->GetTrack();
26 
27  if(fabs(pos.x()) > max_x_pos ||
28  fabs(pos.y()) > max_y_pos ||
29  fabs(pos.z()) > max_z_pos ) track->SetTrackStatus(fStopAndKill);
30 
31  if(track->GetKineticEnergy() < energyCut)
32  track->SetTrackStatus(fStopAndKill);
33 
34  // Anything passing material "Kryptonite" is killed
35  if(track->GetMaterial()->GetName() == "Kryptonite")
36  {
37  track->SetTrackStatus(fStopAndKill);
38  }
39 
40 
41  if(track->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition())
42  {
43  // killing photon if above 100 steps
44  // notice we rarely go above 20 steps for all normal CC detectors
45  if(track->GetCurrentStepNumber() > 100)
46  track->SetTrackStatus(fStopAndKill);
47 
48  if(track->GetLogicalVolumeAtVertex()->GetMaterial()->GetName() == "SemiMirror")
49  track->SetTrackStatus(fStopAndKill);
50  }
51 
52  // limiting steps in one volume to 10000
53  // it may be the new version of geant4, or
54  // accurate magnetic fields, but it does happen that sometimes
55  // a track get stuck into a magnetic field infinite loop
56  if(track->GetCurrentStepNumber() > 10000)
57  track->SetTrackStatus(fStopAndKill);
58 
59 
60 // // checking if a step is stuck in the same position
61 // // for more than 10 steps
62 // // this should be revisited
63 // if(sqrt( (pos - oldpos).x() * (pos - oldpos).x() +
64 // (pos - oldpos).y() * (pos - oldpos).y() +
65 // (pos - oldpos).z() * (pos - oldpos).z() ) < 0.0000001*mm)
66 //
67 // {
68 // nsame++;
69 // if(nsame > 100)
70 // {
71 // cout << " Track is stuck. PID: " << track->GetDefinition()->GetPDGEncoding() << " Volume: " << volname ;
72 // cout << " Last step at : " << pos << " old step was at " << oldpos << " track id: " << track->GetTrackID() << endl;
73 //
74 // cout << ". Killing this track. " << endl;
75 //
76 // track->SetTrackStatus(fStopAndKill);
77 //
78 // }
79 // }
80 // else
81 // nsame = 0;
82 //
83 // oldpos = pos;
84 
85  // limiting steps in one volume to 1000
86  // int nsteps = aStep->GetTrack()->GetCurrentStepNumber();
87  //if(nsteps >= 1000) aStep->GetTrack()->SetTrackStatus(fStopAndKill);
88 
89 }
90 
double max_x_pos
Max X Position in millimeters.
void UserSteppingAction(const G4Step *)
goptions gemcOpt
gemc options map
double max_y_pos
Max Y Position in millimeters.
double max_z_pos
Max Z Position in millimeters.
map< string, aopt > optMap
Options map.
Definition: options.h:75
virtual ~MSteppingAction()
MSteppingAction(goptions)
double energyCut
Set to the ENERGY_CUT from options. This avoids a billion lookups in the map.