LDMX Software
TrackingAction.cxx
2
3// LDMX
4#include "SimCore/G4User/TrackMap.h"
7#include "SimCore/G4User/UserTrackInformation.h"
8
9// Geant4
10#include "G4PrimaryParticle.hh"
11
12// STL
13namespace simcore::g4user {
14
15void TrackingAction::PreUserTrackingAction(const G4Track* track) {
16 if (not track_map_.contains(track)) {
17 // New Track
18
19 // get track information and initialize our new track
20 // this will create a new track info object if it doesn't exist
21 auto track_info{UserTrackInformation::get(track)};
22 track_info->initialize(track);
23
24 // Get the region info for where the track was created (could be NULL)
25 auto region_info = static_cast<UserRegionInformation*>(
26 track->GetLogicalVolumeAtVertex()->GetRegion()->GetUserInformation());
27
28 // Get the gen status if track was primary
29 int cur_gen_status = -1;
30 if (track->GetDynamicParticle()->GetPrimaryParticle()) {
31 auto primary_info = dynamic_cast<UserPrimaryParticleInformation*>(
32 track->GetDynamicParticle()
33 ->GetPrimaryParticle()
34 ->GetUserInformation());
35 if (primary_info) {
36 cur_gen_status = primary_info->getHepEvtStatus();
37 }
38 }
39
52 if (cur_gen_status == 1 or !region_info or
53 region_info->getStoreSecondaries()) {
54 track_info->setSaveFlag(true);
55 }
56
57 // insert this track into the event's track map
58 track_map_.insert(track);
59 }
60
61 // Activate user tracking actions
62 for (auto& tracking_action : tracking_actions_)
63 tracking_action->preUserTrackingAction(track);
64}
65
66void TrackingAction::PostUserTrackingAction(const G4Track* track) {
67 // Activate user tracking actions
68 for (auto& tracking_action : tracking_actions_)
69 tracking_action->postUserTrackingAction(track);
70
78 auto track_info{UserTrackInformation::get(track)};
79 if (track_info->getSaveFlag() and
80 track->GetTrackStatus() == G4TrackStatus::fStopAndKill) {
81 track_map_.save(track);
82 }
83}
84
85} // namespace simcore::g4user
Class which implements the user tracking action.
Class that provides extra information for Geant4 primary particles.
Class which provides extra information for a detector region.
bool contains(const G4Track *track) const
Check if the passed track has already been inserted into the track map.
Definition TrackMap.h:37
void save(const G4Track *track)
Add a track to be stored into output map.
Definition TrackMap.cxx:54
void insert(const G4Track *track)
Add a record in the map for the input track.
Definition TrackMap.cxx:30
Defines extra information attached to a Geant4 primary particle.
Defines extra information for a detector region.
static UserTrackInformation * get(const G4Track *track)
get
void PreUserTrackingAction(const G4Track *aTrack) override
Implementation of pre-tracking action.
void PostUserTrackingAction(const G4Track *aTrack) override
Implementation of post-tracking action.
std::vector< std::shared_ptr< UserAction > > tracking_actions_
custom user actions to be called before and after processing a track
TrackMap track_map_
Stores parentage information for all tracks in the event.