This repository was archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrackMap.h
More file actions
139 lines (121 loc) · 4.04 KB
/
Copy pathTrackMap.h
File metadata and controls
139 lines (121 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef SIMCORE_TRACKMAP_H_
#define SIMCORE_TRACKMAP_H_
// STL
#include <unordered_map>
// Geant4
#include "G4Event.hh"
#include "G4Track.hh"
// LDMX
#include "SimCore/Event/SimParticle.h"
#include "SimCore/UserTrackInformation.h"
#include "SimCore/UserPrimaryParticleInformation.h"
namespace simcore {
/**
* @class TrackMap
* @brief 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.
*/
class TrackMap {
public:
/**
* Add a record in the map for the input track.
* @param track G4Track to insert
*/
void insert(const G4Track* track);
/**
* Check if the passed track has already been inserted
* into the track map.
*/
inline bool contains(const G4Track* track) const {
return ancestry_.find(track->GetTrackID()) != ancestry_.end();
}
/**
* 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.
*
* @param trackID The track ID to search its parentage for the incident
*/
int findIncident(int trackID) const;
/**
* Return true if the given track ID is saved
* i.e. will be stored in output file
*
* @param trackID The track ID.
* @return True if the track ID has been inserted in output particle map
*/
inline bool isSaved(int trackID) const {
return particle_map_.find(trackID) != particle_map_.end();
}
/**
* Add a track to be stored into output map
* @note We assume that the track is at the end of processing
* so that its current kinematics can be labeled as the "end-point"
* kinematics.
* @param track G4Track to store into output
*/
void save(const G4Track* track);
/**
* 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.
*/
void traceAncestry();
/**
* 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.
*/
void clear();
/**
* Get the map of particles to be stored in output event.
*/
std::map<int,ldmx::SimParticle> &getParticleMap() {
return particle_map_;
}
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'
*/
bool isInCalorimeterRegion(const G4Track* track) const;
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.
*
* @see isInCalorimeterRegion for how we check if a track
* originated in the calorimeter region.
*/
std::unordered_map<int,std::pair<int,bool>> ancestry_;
/// descendents map of particles in event (parent -> children)
std::unordered_map<int,std::vector<int>> descendents_;
/// map of SimParticles that will be stored
std::map<int,ldmx::SimParticle> particle_map_;
};
} // namespace simcore
#endif