LDMX Software
|
Defines a map of particle ancestry and particles to be saved. More...
#include <TrackMap.h>
Public Member Functions | |
void | insert (const G4Track *track) |
Add a record in the map for the input track. | |
bool | contains (const G4Track *track) const |
Check if the passed track has already been inserted into the track map. | |
bool | isDescendant (int trackID, int ancestorID, int maximum_depth) const |
Check if the track with the given ID is a descendant of the track with the given ancestor ID up to a given depth. | |
int | findIncident (int trackID) const |
Find a trajectory's nearest parent that is incident on the calorimeter region. | |
bool | isSaved (int trackID) const |
Return true if the given track ID is saved i.e. | |
void | save (const G4Track *track) |
Add a track to be stored into output map. | |
void | traceAncestry () |
Trace the ancestry for the particles that will be stored. | |
void | clear () |
Clear the internal maps. | |
std::map< int, ldmx::SimParticle > & | getParticleMap () |
Get the map of particles to be stored in output event. | |
Private Member Functions | |
bool | isInCalorimeterRegion (const G4Track *track) const |
Was the input track generated inside the calorimeter region? | |
Private Attributes | |
std::unordered_map< int, std::pair< int, bool > > | ancestry_ |
ancestry map of particles in event (child -> parent) | |
std::unordered_map< int, std::vector< int > > | descendents_ |
descendents map of particles in event (parent -> children) | |
std::map< int, ldmx::SimParticle > | particle_map_ |
map of SimParticles that will be stored | |
Defines a map of particle ancestry and particles to be saved.
This class keeps track of the ancestry (child -> parent) and descendents (parent -> children) of ALL particles generated in an event. This allows the particles that are chosen to be saved (via the TrackMap::save method) to have their parent and children faithfully recorded in the output file.
Definition at line 28 of file TrackMap.h.
void simcore::TrackMap::clear | ( | ) |
Clear the internal maps.
This should be called at the beginning of an event. The maps need to persist through the end of the event so that they are available to be written to the output file.
Definition at line 126 of file TrackMap.cxx.
References ancestry_, descendents_, and particle_map_.
Referenced by simcore::g4user::EventAction::BeginOfEventAction().
|
inline |
Check if the passed track has already been inserted into the track map.
Definition at line 40 of file TrackMap.h.
References ancestry_.
Referenced by simcore::g4user::TrackingAction::PreUserTrackingAction().
int simcore::TrackMap::findIncident | ( | int | trackID | ) | const |
Find a trajectory's nearest parent that is incident on the calorimeter region.
We assume that the primary particles have a parent ID of 0.
If this track ID does not have such a trajectory, then the track ID of the primary in its parentage is returned.
trackID | The track ID to search its parentage for the incident |
Definition at line 35 of file TrackMap.cxx.
References ancestry_.
Referenced by simcore::EcalSD::ProcessHits().
|
inline |
Get the map of particles to be stored in output event.
Definition at line 101 of file TrackMap.h.
References particle_map_.
Referenced by simcore::UserAction::getCurrentParticleMap().
void simcore::TrackMap::insert | ( | const G4Track * | track | ) |
Add a record in the map for the input track.
track | G4Track to insert |
Definition at line 29 of file TrackMap.cxx.
References ancestry_, descendents_, and isInCalorimeterRegion().
Referenced by simcore::g4user::TrackingAction::PreUserTrackingAction().
bool simcore::TrackMap::isDescendant | ( | int | trackID, |
int | ancestorID, | ||
int | maximum_depth | ||
) | const |
Check if the track with the given ID is a descendant of the track with the given ancestor ID up to a given depth.
Definition at line 9 of file TrackMap.cxx.
References ancestry_.
|
private |
Was the input track generated inside the calorimeter region?
We rely on the fact that the calorimeter region is named 'CalorimeterRegion' and no other region names contain the string 'Calorimeter'
Definition at line 132 of file TrackMap.cxx.
Referenced by insert().
|
inline |
Return true if the given track ID is saved i.e.
will be stored in output file
trackID | The track ID. |
Definition at line 68 of file TrackMap.h.
References particle_map_.
void simcore::TrackMap::save | ( | const G4Track * | track | ) |
Add a track to be stored into output map.
track | G4Track to store into output |
Definition at line 53 of file TrackMap.cxx.
References ldmx::SimParticle::findProcessType(), simcore::UserTrackInformation::get(), simcore::UserTrackInformation::getInitialMomentum(), particle_map_, and ldmx::SimParticle::setGenStatus().
Referenced by simcore::g4user::TrackingAction::PostUserTrackingAction().
void simcore::TrackMap::traceAncestry | ( | ) |
Trace the ancestry for the particles that will be stored.
This should be done at the end of the event before writing the particle map to the event bus and involves looping through the particles that will be saved.
Use [] instead of at() for descendents_ so that if it wasn't previously created, we will just silently create an empty vector and move on.
Definition at line 110 of file TrackMap.cxx.
References ancestry_, descendents_, and particle_map_.
|
private |
ancestry map of particles in event (child -> parent)
Primary particles are given a "parent" ID of 0 to reflect that they don't have a parent. This is the default in Geant4 and we assume that holds here.
This is helpful for the findIncident method which looks up through a track's history to find the first ancestor which originated outside of the calorimeter region.
The key value is a pair where the first entry is the parent track ID and the second entry is whether the child track is in the calorimeter region.
Definition at line 132 of file TrackMap.h.
Referenced by clear(), contains(), findIncident(), insert(), isDescendant(), and traceAncestry().
|
private |
descendents map of particles in event (parent -> children)
Definition at line 135 of file TrackMap.h.
Referenced by clear(), insert(), and traceAncestry().
|
private |
map of SimParticles that will be stored
Definition at line 138 of file TrackMap.h.
Referenced by clear(), getParticleMap(), isSaved(), save(), and traceAncestry().