LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ExampleGeneralAction.cc
Go to the documentation of this file.
1 // This file provides the class declaration for the
2 // @ExampleGeneralAction@ action object, which manages the turn counter
3 // and keeps track of whether the current muon has been stored and how many
4 // total muons have been stored in the run.
5 
6 // Authors: Tasha Arvanitis, Adam Lyon
7 // Date: August 2012
8 
11 
12 // G4 includes
13 #include "Geant4/G4EventManager.hh"
14 #include "Geant4/G4MuonMinus.hh"
15 #include "Geant4/G4MuonPlus.hh"
16 #include "Geant4/G4Run.hh"
17 #include "Geant4/G4Step.hh"
18 #include "Geant4/G4Track.hh"
19 #include "Geant4/G4TrackingManager.hh"
20 
21 using std::string;
22 
24  : artg4tk::TrackingActionBase(p.get<string>("name", "exampleGeneral"))
25  , artg4tk::RunActionBase(p.get<string>("name", "exampleGeneral"))
26  , artg4tk::SteppingActionBase(p.get<string>("name", "exampleGeneral"))
27 {}
28 
29 // Overload PreUserTrackingAction method to decide whether or not to
30 // track a given particle
31 void
33 {
34  // Get the tracking manager so we can tell it whether or not to store
35  // the trajectory.
36  G4TrackingManager* trackingMan = G4EventManager::GetEventManager()->GetTrackingManager();
37 
38  // Create trajectory only for primaries
39  if (currTrack->GetParentID() == 0) {
40  trackingMan->SetStoreTrajectory(true);
41  }
42  else {
43  trackingMan->SetStoreTrajectory(false);
44  }
45 }
46 
47 // Use BeginOfRunAction to initialize the random number store.
48 void
50 {
51  G4cout << "### Run " << currRun->GetRunID() << " start." << G4endl;
52 
53  artg4tk::ArtG4RunManager::GetRunManager()->SetRandomNumberStore(true);
54 }
55 
56 // Use UserSteppingAction (called for each step) to suspend any tracks that
57 // enter the calorimeter.
58 void
60 {
61  // This method suspends any tracks of live, primary non-muons that enter
62  // the calorimeter.
63 
64  // Get the track in question.
65  G4Track* theTrack = currStep->GetTrack();
66 
67  // check if the track is dead - if so, we don't need to suspend, so just
68  // return.
69  if (theTrack->GetTrackStatus() != fAlive) {
70  return;
71  }
72 
73  // check if it is a non-primary particle - if so, we don't need to suspend.
74  if (theTrack->GetParentID() != 0) {
75  return;
76  }
77 
78  // check if it's a muon - if so, we don't need to suspend it.
79  G4ParticleDefinition* particleType = theTrack->GetDefinition();
80  if ((particleType == G4MuonPlus::MuonPlusDefinition()) ||
81  (particleType == G4MuonMinus::MuonMinusDefinition())) {
82  return;
83  }
84 
85  // First, check whether the step started inside the calorimeter. If so,
86  // we don't need to suspend it.
87  G4StepPoint* thePrePoint = currStep->GetPreStepPoint();
88  G4VPhysicalVolume* thePrePV = thePrePoint->GetPhysicalVolume();
89  G4String thePrePVname = thePrePV->GetName();
90  if (thePrePVname(0, 4) == "calo") {
91  return;
92  }
93 
94  // Check whether the step ended outside the calorimeter. If so, we don't
95  // need to suspend it.
96  G4StepPoint* thePostPoint = currStep->GetPostStepPoint();
97  G4VPhysicalVolume* thePostPV = thePostPoint->GetPhysicalVolume();
98  G4String thePostPVname = thePostPV->GetName();
99  if (thePostPVname(0, 4) != "calo") {
100  return;
101  }
102 
103  // Any step that has survived all those checks:
104  // * is alive
105  // * is a primary
106  // * is a non-muon
107  // * started outside the calorimeter
108  // * ended inside the calorimeter
109 
110  // Now suspend the track
111  theTrack->SetTrackStatus(fSuspend);
112 }
void beginOfRunAction(const G4Run *currentRun) override
ExampleGeneralActionService(fhicl::ParameterSet const &)
void userSteppingAction(const G4Step *theStep) override
void preUserTrackingAction(const G4Track *currTrack) override
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120