Belle II Software  release-05-01-25
SteppingAction.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Guofu Cao, Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <simulation/kernel/SteppingAction.h>
12 #include <simulation/kernel/UserInfo.h>
13 #include <framework/logging/Logger.h>
14 #include <framework/gearbox/Unit.h>
15 
16 #include <G4UnitsTable.hh>
17 #include <G4Track.hh>
18 
19 
20 using namespace Belle2;
21 using namespace Simulation;
22 
24 {
25  //Default value for the maximum number of steps
26  m_maxNumberSteps = 100000;
27  if (false) {
28  G4Step* aStep;
29  UserSteppingAction(aStep);
30  }
31 }
32 
33 
35 {
36 
37 }
38 
39 
40 void SteppingAction::UserSteppingAction(const G4Step* step)
41 {
42  G4Track* track = step->GetTrack();
43 
44  //------------------------------
45  // Check for NULL world volume
46  //------------------------------
47  if (track->GetVolume() == NULL) {
48  B2WARNING("SteppingAction: Track in NULL volume, terminating!\n"
49  << "step_no=" << track->GetCurrentStepNumber() << " type=" << track->GetDefinition()->GetParticleName()
50  << "\n position=" << G4BestUnit(track->GetPosition(), "Length") << " momentum=" << G4BestUnit(track->GetMomentum(), "Energy"));
51  track->SetTrackStatus(fStopAndKill);
52  return;
53  }
54 
55  //------------------------------
56  // Check for absorbers
57  //------------------------------
58  for (auto& rAbsorber : m_absorbers) {
59  const G4ThreeVector stepPrePos = step->GetPreStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
60  const G4ThreeVector stepPostPos = step->GetPostStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
61  if (stepPrePos.perp() < (rAbsorber * Unit::cm) && stepPostPos.perp() > (rAbsorber * Unit::cm)) {
62  //B2WARNING("SteppingAction: Track across absorbers, terminating!\n"
63  //<< "step_no=" << track->GetCurrentStepNumber() << " type=" << track->GetDefinition()->GetParticleName()
64  //<< "\n position=" << G4BestUnit(track->GetPosition(), "Length") << " momentum=" << G4BestUnit(track->GetMomentum(), "Energy") << "\n PrePos.perp=" << stepPrePos.perp() << ", PostPos.perp=" << stepPostPos.perp() << " cm" );
65  track->SetTrackStatus(fStopAndKill);
66  return;
67  }
68  }
69 
70  //---------------------------------------
71  // Check for very high number of steps.
72  //---------------------------------------
73  if (track->GetCurrentStepNumber() > m_maxNumberSteps) {
74  B2WARNING("SteppingAction: Too many steps for this track, terminating!\n"
75  << "step_no=" << track->GetCurrentStepNumber() << "type=" << track->GetDefinition()->GetParticleName()
76  << "\n position=" << G4BestUnit(track->GetPosition(), "Length") << " momentum=" << G4BestUnit(track->GetMomentum(), "Energy"));
77  track->SetTrackStatus(fStopAndKill);
78  return;
79  }
80 
81  //-----------------------------------------------------------
82  // Check if there is an attached trajectory. If so, fill it.
83  //-----------------------------------------------------------
84  if (m_storeTrajectories) {
85  TrackInfo* info = dynamic_cast<TrackInfo*>(track->GetUserInformation());
86  if (info && info->getTrajectory()) {
87  MCParticleTrajectory& trajectory = *(info->getTrajectory());
88  if (trajectory.empty()) {
89  const G4ThreeVector stepPos = step->GetPreStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
90  const G4ThreeVector stepMom = step->GetPreStepPoint()->GetMomentum() / CLHEP::MeV * Unit::MeV;
91  trajectory.addPoint(
92  stepPos.x(), stepPos.y(), stepPos.z(),
93  stepMom.x(), stepMom.y(), stepMom.z()
94  );
95  }
96  const G4ThreeVector stepPos = step->GetPostStepPoint()->GetPosition() / CLHEP::mm * Unit::mm;
97  const G4ThreeVector stepMom = step->GetPostStepPoint()->GetMomentum() / CLHEP::MeV * Unit::MeV;
98  trajectory.addPoint(
99  stepPos.x(), stepPos.y(), stepPos.z(),
100  stepMom.x(), stepMom.y(), stepMom.z()
101  );
102  }
103  }
104 }
Belle2::Unit::cm
static const double cm
Standard units with the value = 1.
Definition: Unit.h:57
Belle2::Simulation::SteppingAction::UserSteppingAction
virtual void UserSteppingAction(const G4Step *step)
The method will be called at each step during simulation.
Definition: SteppingAction.cc:40
Belle2::Simulation::UserInfo
UserInfo class which is used to attach additional information to Geant4 particles and tracks.
Definition: UserInfo.h:46
Belle2::MCParticleTrajectory::addPoint
void addPoint(float x, float y, float z, float px, float py, float pz)
Add a point to the trajectory.
Definition: MCParticleTrajectory.h:64
Belle2::Simulation::SteppingAction::~SteppingAction
virtual ~SteppingAction()
Destructor.
Definition: SteppingAction.cc:34
Belle2::Simulation::SteppingAction::m_absorbers
std::vector< float > m_absorbers
The absorbers defined at given radii where tracks across them will be destroyed.
Definition: SteppingAction.h:78
Belle2::Unit::MeV
static const double MeV
[megaelectronvolt]
Definition: Unit.h:124
Belle2::MCParticleTrajectory
Class to save the full simulated trajectory of a particle.
Definition: MCParticleTrajectory.h:32
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Simulation::SteppingAction::m_storeTrajectories
bool m_storeTrajectories
if true, check if the track has attached trajectory info and append step information if necessary
Definition: SteppingAction.h:77
Belle2::Unit::mm
static const double mm
[millimeters]
Definition: Unit.h:80
Belle2::Simulation::SteppingAction::SteppingAction
SteppingAction()
Constructor.
Definition: SteppingAction.cc:23
Belle2::MCParticleTrajectory::empty
bool empty() const
return true if size()==0
Definition: MCParticleTrajectory.h:52
Belle2::Simulation::SteppingAction::m_maxNumberSteps
int m_maxNumberSteps
The maximum number of steps before the track transportation is stopped and the track is killed.
Definition: SteppingAction.h:75