GEMC  1.8
Geant4 Monte-Carlo Framework
MSteppingAction.cc
Go to the documentation of this file.
1 // %%%%%%%%%%
2 // G4 headers
3 // %%%%%%%%%%
4 #include "G4ParticleTypes.hh"
5 
6 
7 
8 
9 // %%%%%%%%%%%%%
10 // gemc headers
11 // %%%%%%%%%%%%%
12 
13 #include "MSteppingAction.h"
14 
16 {
17  gemcOpt = Opt;
18  Energy_cut = gemcOpt.args["ENERGY_CUT"].arg;
19  max_x_pos = gemcOpt.args["MAX_X_POS"].arg;
20  max_y_pos = gemcOpt.args["MAX_Y_POS"].arg;
21  max_z_pos = gemcOpt.args["MAX_Z_POS"].arg;
22 
23  oldpos = G4ThreeVector(0,0,0);
24  nsame = 0;
25 }
27 
28 
29 void MSteppingAction::UserSteppingAction(const G4Step* aStep)
30 {
31  G4ThreeVector pos = aStep->GetPostStepPoint()->GetPosition();
32  G4Track* track = aStep->GetTrack();
33  string volname(aStep->GetPreStepPoint()->GetPhysicalVolume()->GetName());
34 
35  if(fabs(pos.x()) > max_x_pos ||
36  fabs(pos.y()) > max_y_pos ||
37  fabs(pos.z()) > max_z_pos ) track->SetTrackStatus(fStopAndKill);
38 
39  if(track->GetKineticEnergy() < Energy_cut )
40  track->SetTrackStatus(fStopAndKill);
41 
42  // Anything passing material "Kryptonite" is killed
43  if(track->GetMaterial()->GetName() == "Kryptonite")
44  {
45  track->SetTrackStatus(fStopAndKill);
46  }
47 
48 
49  if(track->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition())
50  {
51  if(track->GetLogicalVolumeAtVertex()->GetMaterial()->GetName() == "SemiMirror")
52  {
53  track->SetTrackStatus(fStopAndKill);
54  }
55  }
56 
57 
58 
59  // checking if a step is stuck in the same position
60  // for more than 10 steps
61  if(sqrt( (pos - oldpos).x() * (pos - oldpos).x() +
62  (pos - oldpos).y() * (pos - oldpos).y() +
63  (pos - oldpos).z() * (pos - oldpos).z() ) < 0.00001)
64 
65  {
66  nsame++;
67  if(nsame > 10)
68  {
69  cout << " Track is stuck. PID: " << track->GetDefinition()->GetPDGEncoding() << " Volume: "
70  << volname << ". Killing this track. " << endl;
71  cout << " Last step of : " << pos -oldpos << " was at " << pos << " track id: " << track->GetTrackID() << endl;
72 
73  track->SetTrackStatus(fStopAndKill);
74 
75  }
76  }
77  else
78  nsame = 0;
79 
80  oldpos = pos;
81 
82 
83  // limiting steps in one volume to 1000
84  int nsteps = aStep->GetTrack()->GetCurrentStepNumber();
85  if(nsteps >= 1000) aStep->GetTrack()->SetTrackStatus(fStopAndKill);
86 
87 
88 
89 }
90 
double max_x_pos
Max X Position in millimeters.
void UserSteppingAction(const G4Step *)
double Energy_cut
Set to the ENERGY_CUT from options. This avoids a billion lookups in the map.
gemc_opts gemcOpt
gemc options map
double max_y_pos
Max Y Position in millimeters.
G4ThreeVector oldpos
double max_z_pos
Max Z Position in millimeters.
virtual ~MSteppingAction()
MSteppingAction(gemc_opts)
map< string, opts > args
Options map.
Definition: usage.h:68