LDMX Software
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
simcore::g4user::TrackingAction Class Reference

Implementation of user tracking action. More...

#include <TrackingAction.h>

Public Member Functions

 TrackingAction ()
 Class constructor.
 
virtual ~TrackingAction ()
 Class destructor.
 
void PreUserTrackingAction (const G4Track *aTrack)
 Implementation of pre-tracking action.
 
void PostUserTrackingAction (const G4Track *aTrack)
 Implementation of post-tracking action.
 
TrackMapgetTrackMap ()
 Get a handle to the current TrackMap for the event.
 
void registerAction (UserAction *trackingAction)
 Register a user action of type RunAction with this class.
 

Static Public Member Functions

static TrackingActionget ()
 Get a pointer to the current UserTrackingAction from the G4RunManager.
 

Private Attributes

std::vector< UserAction * > trackingActions_
 custom user actions to be called before and after processing a track
 
TrackMap trackMap_
 Stores parentage information for all tracks in the event.
 

Detailed Description

Implementation of user tracking action.

Here, we manage the interaction between our track storage machinery (TrackMap) and Geant4's tracking manager (G4TrackingManager).

Definition at line 36 of file TrackingAction.h.

Constructor & Destructor Documentation

◆ TrackingAction()

simcore::g4user::TrackingAction::TrackingAction ( )
inline

Class constructor.

Definition at line 41 of file TrackingAction.h.

41{}

◆ ~TrackingAction()

virtual simcore::g4user::TrackingAction::~TrackingAction ( )
inlinevirtual

Class destructor.

Definition at line 46 of file TrackingAction.h.

46{}

Member Function Documentation

◆ get()

static TrackingAction * simcore::g4user::TrackingAction::get ( )
inlinestatic

Get a pointer to the current UserTrackingAction from the G4RunManager.

Returns
A pointer to the current UserTrackingAction.

Definition at line 116 of file TrackingAction.h.

116 {
117 return static_cast<TrackingAction*>(const_cast<G4UserTrackingAction*>(
118 G4RunManager::GetRunManager()->GetUserTrackingAction()));
119 }
TrackingAction()
Class constructor.

Referenced by simcore::g4user::EventAction::BeginOfEventAction(), simcore::UserAction::getCurrentParticleMap(), simcore::SensitiveDetector::getTrackMap(), and biasing::utility::StepPrinter::stepping().

◆ getTrackMap()

TrackMap & simcore::g4user::TrackingAction::getTrackMap ( )
inline

Get a handle to the current TrackMap for the event.

Returns
A pointer to the current TrackMap for the event.

Definition at line 110 of file TrackingAction.h.

110{ return trackMap_; }
TrackMap trackMap_
Stores parentage information for all tracks in the event.

References trackMap_.

Referenced by simcore::g4user::EventAction::BeginOfEventAction(), simcore::UserAction::getCurrentParticleMap(), simcore::SensitiveDetector::getTrackMap(), and biasing::utility::StepPrinter::stepping().

◆ PostUserTrackingAction()

void simcore::g4user::TrackingAction::PostUserTrackingAction ( const G4Track *  aTrack)

Implementation of post-tracking action.

We start by calling any other tracking actions' PostUserTrackingAction methods.

If the track should be saved (it's save flag is set to true) and it is being stopped, then we save it in the track map.

Note
This is where we make the final decision on if a particle should be saved into the output file.
See also
TrackMap::save for how a G4Track is translated into our output SimParticle object.
Parameters
aTrackThe Geant4 track.

If a track is to-be saved and it is being killed, save the track into the map. This is where a track is chosen to be put into the output particle map. If its save flag is true for any reason at this point, then it will be in the output map.

Definition at line 68 of file TrackingAction.cxx.

68 {
69 // Activate user tracking actions
70 for (auto& trackingAction : trackingActions_)
71 trackingAction->PostUserTrackingAction(track);
72
80 auto track_info{UserTrackInformation::get(track)};
81 if (track_info->getSaveFlag() and
82 track->GetTrackStatus() == G4TrackStatus::fStopAndKill) {
83 trackMap_.save(track);
84 }
85}
void save(const G4Track *track)
Add a track to be stored into output map.
Definition TrackMap.cxx:53
static UserTrackInformation * get(const G4Track *track)
get
void PostUserTrackingAction(const G4Track *aTrack)
Implementation of post-tracking action.
std::vector< UserAction * > trackingActions_
custom user actions to be called before and after processing a track

References simcore::UserTrackInformation::get(), simcore::TrackMap::save(), trackingActions_, and trackMap_.

◆ PreUserTrackingAction()

void simcore::g4user::TrackingAction::PreUserTrackingAction ( const G4Track *  aTrack)

Implementation of pre-tracking action.

This is called whenever a track is going to start being processed.

Note
A track could go through this function more than once in an event if it is suspended.

We first check if we have seen this track before by looking inside of our track map.

If we have seen it before, then we simply give the track to our PreUserTrackingActions.

If we haven't seen it before, then we must do some setup.

  • Make an instance of UserTrackInformation and attach it to the track after setting the initial momentum and vertex volume.
  • Using the gen status of the track and the region the track was produced in, decide if we will store the track by default. (Other user tracking actions can change the save flag in the track information.)

We choose to store the track by default if any of the following are true about the track

  • it is a primary (gen status is one)
  • it was created in a region without region info
  • it was created in a region where the 'StoreSecondaries' flag was set to true.

No matter what, we insert the track into the track map for book-keeping.

Finally, before we wrap up, we call any other tracking actions' 'PreUserTrackingAction' methods.

Parameters
aTrackThe Geant4 track.

Always save a particle if any of the following are true it has gen status == 1 (primary) it is in a region without region info it is in a region that is marked to store secondaries DON'T change the save-status even if these are false The track's save-status is false by default when the track-info is constructed and the track's save-status could have been modified by a user action prior to the track being processed for the first time. For example, this happens if the user wants to save the secondaries of a particular track.

Definition at line 17 of file TrackingAction.cxx.

17 {
18 if (not trackMap_.contains(track)) {
19 // New Track
20
21 // get track information and initialize our new track
22 // this will create a new track info object if it doesn't exist
23 auto track_info{UserTrackInformation::get(track)};
24 track_info->initialize(track);
25
26 // Get the region info for where the track was created (could be NULL)
27 auto regionInfo = (UserRegionInformation*)track->GetLogicalVolumeAtVertex()
28 ->GetRegion()
29 ->GetUserInformation();
30
31 // Get the gen status if track was primary
32 int curGenStatus = -1;
33 if (track->GetDynamicParticle()->GetPrimaryParticle()) {
34 auto primaryInfo = dynamic_cast<UserPrimaryParticleInformation*>(
35 track->GetDynamicParticle()
36 ->GetPrimaryParticle()
37 ->GetUserInformation());
38 if (primaryInfo) {
39 curGenStatus = primaryInfo->getHepEvtStatus();
40 }
41 }
42
55 if (curGenStatus == 1 or !regionInfo or regionInfo->getStoreSecondaries()) {
56 track_info->setSaveFlag(true);
57 }
58
59 // insert this track into the event's track map
60 trackMap_.insert(track);
61 }
62
63 // Activate user tracking actions
64 for (auto& trackingAction : trackingActions_)
65 trackingAction->PreUserTrackingAction(track);
66}
bool contains(const G4Track *track) const
Check if the passed track has already been inserted into the track map.
Definition TrackMap.h:40
void insert(const G4Track *track)
Add a record in the map for the input track.
Definition TrackMap.cxx:29
void initialize(const G4Track *track)
Initialize the track information with the passed track.
void PreUserTrackingAction(const G4Track *aTrack)
Implementation of pre-tracking action.

References simcore::TrackMap::contains(), simcore::UserTrackInformation::get(), simcore::UserPrimaryParticleInformation::getHepEvtStatus(), simcore::UserTrackInformation::initialize(), simcore::TrackMap::insert(), trackingActions_, and trackMap_.

◆ registerAction()

void simcore::g4user::TrackingAction::registerAction ( UserAction trackingAction)
inline

Register a user action of type RunAction with this class.

Parameters
actionUser action of type RunAction

Definition at line 126 of file TrackingAction.h.

126 {
127 trackingActions_.push_back(trackingAction);
128 }

References trackingActions_.

Member Data Documentation

◆ trackingActions_

std::vector<UserAction*> simcore::g4user::TrackingAction::trackingActions_
private

custom user actions to be called before and after processing a track

Definition at line 132 of file TrackingAction.h.

Referenced by PostUserTrackingAction(), PreUserTrackingAction(), and registerAction().

◆ trackMap_

TrackMap simcore::g4user::TrackingAction::trackMap_
private

Stores parentage information for all tracks in the event.

Definition at line 135 of file TrackingAction.h.

Referenced by getTrackMap(), PostUserTrackingAction(), and PreUserTrackingAction().


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