LDMX Software
TrackingAction.cxx
2
3// LDMX
4#include "SimCore/TrackMap.h"
7#include "SimCore/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 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}
67
68void TrackingAction::PostUserTrackingAction(const G4Track* track) {
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}
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 initialize(const G4Track *track)
Initialize the track information with the passed track.
void PostUserTrackingAction(const G4Track *aTrack)
Implementation of post-tracking action.
void PreUserTrackingAction(const G4Track *aTrack)
Implementation of pre-tracking action.
TrackMap trackMap_
Stores parentage information for all tracks in the event.
std::vector< UserAction * > trackingActions_
custom user actions to be called before and after processing a track