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 = (UserRegionInformation*)track->GetLogicalVolumeAtVertex()
28 ->GetRegion()
29 ->GetUserInformation();
30
31 // Get the gen status if track was primary
32 int cur_gen_status = -1;
33 if (track->GetDynamicParticle()->GetPrimaryParticle()) {
34 auto primary_info = dynamic_cast<UserPrimaryParticleInformation*>(
35 track->GetDynamicParticle()
36 ->GetPrimaryParticle()
37 ->GetUserInformation());
38 if (primary_info) {
39 cur_gen_status = primary_info->getHepEvtStatus();
40 }
41 }
42
55 if (cur_gen_status == 1 or !region_info or
56 region_info->getStoreSecondaries()) {
57 track_info->setSaveFlag(true);
58 }
59
60 // insert this track into the event's track map
61 track_map_.insert(track);
62 }
63
64 // Activate user tracking actions
65 for (auto& tracking_action : tracking_actions_)
66 tracking_action->PreUserTrackingAction(track);
67}
68
69void TrackingAction::PostUserTrackingAction(const G4Track* track) {
70 // Activate user tracking actions
71 for (auto& tracking_action : tracking_actions_)
72 tracking_action->PostUserTrackingAction(track);
73
81 auto track_info{UserTrackInformation::get(track)};
82 if (track_info->getSaveFlag() and
83 track->GetTrackStatus() == G4TrackStatus::fStopAndKill) {
84 track_map_.save(track);
85 }
86}
87
88} // 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 PostUserTrackingAction(const G4Track *aTrack)
Implementation of post-tracking action.
void PreUserTrackingAction(const G4Track *aTrack)
Implementation of pre-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.