Belle II Software  release-08-01-10
SteppingAction Class Reference

The Class for the stepping action. More...

#include <SteppingAction.h>

Inheritance diagram for SteppingAction:
Collaboration diagram for SteppingAction:

Public Member Functions

 SteppingAction ()
 Constructor.
 
virtual ~SteppingAction ()
 Destructor.
 
void setMaxNumberSteps (int maxSteps)
 Sets the maximum number of steps before a track is stopped and killed. More...
 
void setStoreTrajectories (bool store)
 Sets the trajectory option to enable storing of the simulated particle trajectories.
 
void setAbsorbersR (const std::vector< float > &vec)
 Sets the radii of absorbers for killing tracks across them. More...
 
virtual void UserSteppingAction (const G4Step *step)
 The method will be called at each step during simulation. More...
 

Protected Attributes

int m_maxNumberSteps
 The maximum number of steps before the track transportation is stopped and the track is killed.
 
bool m_storeTrajectories = false
 if true, check if the track has attached trajectory info and append step information if necessary
 
std::vector< float > m_absorbers
 The absorbers defined at given radii where tracks across them will be destroyed.
 

Detailed Description

The Class for the stepping action.

This class is called for each step during the Geant4 transportation. It implements protection mechanisms to remove unreasonable tracks.

Definition at line 29 of file SteppingAction.h.

Member Function Documentation

◆ setAbsorbersR()

void setAbsorbersR ( const std::vector< float > &  vec)
inline

Sets the radii of absorbers for killing tracks across them.

This set is used in the PXD only simulation for PXD gain calibration.

Parameters
vecThe c++ vector with the radii of absorbers in cm

Definition at line 55 of file SteppingAction.h.

55 { m_absorbers = vec; };
std::vector< float > m_absorbers
The absorbers defined at given radii where tracks across them will be destroyed.

◆ setMaxNumberSteps()

void setMaxNumberSteps ( int  maxSteps)
inline

Sets the maximum number of steps before a track is stopped and killed.

Parameters
maxStepsThe maximum number of steps.

Definition at line 46 of file SteppingAction.h.

◆ UserSteppingAction()

void UserSteppingAction ( const G4Step *  step)
virtual

The method will be called at each step during simulation.

Parameters
stepThe pointer of current step.

Definition at line 38 of file SteppingAction.cc.

39 {
40  G4Track* track = step->GetTrack();
41 
42  //------------------------------
43  // Check for NULL world volume
44  //------------------------------
45  if (track->GetVolume() == NULL) {
46  B2WARNING("SteppingAction: Track in NULL volume, terminating!\n"
47  << "step_no=" << track->GetCurrentStepNumber() << " type=" << track->GetDefinition()->GetParticleName()
48  << "\n position=" << G4BestUnit(track->GetPosition(), "Length") << " momentum=" << G4BestUnit(track->GetMomentum(), "Energy"));
49  track->SetTrackStatus(fStopAndKill);
50  return;
51  }
52 
53  //------------------------------
54  // Check for absorbers
55  //------------------------------
56  for (auto& rAbsorber : m_absorbers) {
57  const G4ThreeVector stepPrePos = step->GetPreStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
58  const G4ThreeVector stepPostPos = step->GetPostStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
59  if (stepPrePos.perp() < (rAbsorber * Unit::cm) && stepPostPos.perp() > (rAbsorber * Unit::cm)) {
60  //B2WARNING("SteppingAction: Track across absorbers, terminating!\n"
61  //<< "step_no=" << track->GetCurrentStepNumber() << " type=" << track->GetDefinition()->GetParticleName()
62  //<< "\n position=" << G4BestUnit(track->GetPosition(), "Length") << " momentum=" << G4BestUnit(track->GetMomentum(), "Energy") << "\n PrePos.perp=" << stepPrePos.perp() << ", PostPos.perp=" << stepPostPos.perp() << " cm" );
63  track->SetTrackStatus(fStopAndKill);
64  return;
65  }
66  }
67 
68  //---------------------------------------
69  // Check for very high number of steps.
70  //---------------------------------------
71  if (track->GetCurrentStepNumber() > m_maxNumberSteps) {
72  B2WARNING("SteppingAction: Too many steps for this track, terminating!\n"
73  << "step_no=" << track->GetCurrentStepNumber() << "type=" << track->GetDefinition()->GetParticleName()
74  << "\n position=" << G4BestUnit(track->GetPosition(), "Length") << " momentum=" << G4BestUnit(track->GetMomentum(), "Energy"));
75  track->SetTrackStatus(fStopAndKill);
76  return;
77  }
78 
79  //-----------------------------------------------------------
80  // Check if there is an attached trajectory. If so, fill it.
81  //-----------------------------------------------------------
82  if (m_storeTrajectories) {
83  TrackInfo* info = dynamic_cast<TrackInfo*>(track->GetUserInformation());
84  if (info && info->getTrajectory()) {
85  MCParticleTrajectory& trajectory = *(info->getTrajectory());
86  if (trajectory.empty()) {
87  const G4ThreeVector stepPos = step->GetPreStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
88  const G4ThreeVector stepMom = step->GetPreStepPoint()->GetMomentum() / CLHEP::MeV * Unit::MeV;
89  trajectory.addPoint(
90  stepPos.x(), stepPos.y(), stepPos.z(),
91  stepMom.x(), stepMom.y(), stepMom.z()
92  );
93  }
94  const G4ThreeVector stepPos = step->GetPostStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
95  const G4ThreeVector stepMom = step->GetPostStepPoint()->GetMomentum() / CLHEP::MeV * Unit::MeV;
96  trajectory.addPoint(
97  stepPos.x(), stepPos.y(), stepPos.z(),
98  stepMom.x(), stepMom.y(), stepMom.z()
99  );
100  }
101  }
102 }
Class to save the full simulated trajectory of a particle.
void addPoint(float x, float y, float z, float px, float py, float pz)
Add a point to the trajectory.
bool empty() const
return true if size()==0
int m_maxNumberSteps
The maximum number of steps before the track transportation is stopped and the track is killed.
bool m_storeTrajectories
if true, check if the track has attached trajectory info and append step information if necessary
static const double mm
[millimeters]
Definition: Unit.h:70
static const double MeV
[megaelectronvolt]
Definition: Unit.h:114
static const double cm
Standard units with the value = 1.
Definition: Unit.h:47

The documentation for this class was generated from the following files: