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#include "G4VUserPrimaryParticleInformation.hh"
12
13// STL
14#include <iostream>
15namespace simcore::g4user {
16
17void TrackingAction::PreUserTrackingAction(const G4Track* track) {
18 if (not track_map_.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 region_info = static_cast<UserRegionInformation*>(
28 track->GetLogicalVolumeAtVertex()->GetRegion()->GetUserInformation());
29
30 // Get the gen status if track was primary
31 int cur_gen_status = -1;
32 if (track->GetDynamicParticle()->GetPrimaryParticle()) {
33 auto primary_info = dynamic_cast<UserPrimaryParticleInformation*>(
34 track->GetDynamicParticle()
35 ->GetPrimaryParticle()
36 ->GetUserInformation());
37 if (primary_info) {
38 cur_gen_status = primary_info->getHepEvtStatus();
39 }
40 }
41
54 if (cur_gen_status == 1 or !region_info or
55 region_info->getStoreSecondaries()) {
56 track_info->setSaveFlag(true);
57 }
58
59 // insert this track into the event's track map
60 track_map_.insert(track);
61 }
62
63 // Activate user tracking actions
64 for (auto& tracking_action : tracking_actions_)
65 tracking_action->preUserTrackingAction(track);
66}
67
68void TrackingAction::PostUserTrackingAction(const G4Track* track) {
69 // Activate user tracking actions
70 for (auto& tracking_action : tracking_actions_)
71 tracking_action->postUserTrackingAction(track);
72
80 auto track_info{UserTrackInformation::get(track)};
81 if (track_info->getSaveFlag() and
82 track->GetTrackStatus() == G4TrackStatus::fStopAndKill) {
83 track_map_.save(track);
84 }
85}
86
87} // 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:40
void save(const G4Track *track)
Add a track to be stored into output map.
Definition TrackMap.cxx:53
void insert(const G4Track *track)
Add a record in the map for the input track.
Definition TrackMap.cxx:29
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.