Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHG4TruthInfoContainer.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHG4TruthInfoContainer.h
1 // Tell emacs that this is a C++ source
2 // -*- C++ -*-.
3 #ifndef G4MAIN_PHG4TRUTHINFOCONTAINER_H
4 #define G4MAIN_PHG4TRUTHINFOCONTAINER_H
5 
6 #include <phool/PHObject.h>
7 
8 #include <iostream>
9 #include <iterator> // for distance
10 #include <map>
11 #include <utility>
12 
13 class PHG4Shower;
14 class PHG4Particle;
15 class PHG4VtxPoint;
16 
18 {
19  public:
20  typedef std::map<int, PHG4Particle*> Map;
21  typedef Map::iterator Iterator;
22  typedef Map::const_iterator ConstIterator;
23  typedef std::pair<Iterator, Iterator> Range;
24  typedef std::pair<ConstIterator, ConstIterator> ConstRange;
25 
26  typedef std::map<int, PHG4VtxPoint*> VtxMap;
27  typedef VtxMap::iterator VtxIterator;
28  typedef VtxMap::const_iterator ConstVtxIterator;
29  typedef std::pair<VtxIterator, VtxIterator> VtxRange;
30  typedef std::pair<ConstVtxIterator, ConstVtxIterator> ConstVtxRange;
31 
32  typedef std::map<int, PHG4Shower*> ShowerMap;
33  typedef ShowerMap::iterator ShowerIterator;
34  typedef ShowerMap::const_iterator ConstShowerIterator;
35  typedef std::pair<ShowerIterator, ShowerIterator> ShowerRange;
36  typedef std::pair<ConstShowerIterator, ConstShowerIterator> ConstShowerRange;
37 
39  ~PHG4TruthInfoContainer() override;
40 
41  // from PHObject
42 // cppcheck-suppress [virtualCallInConstructor]
43  void Reset() override;
44  void identify(std::ostream& os = std::cout) const override;
45 
46  // --- particle storage ------------------------------------------------------
47 
49  ConstIterator AddParticle(const int particleid, PHG4Particle* newparticle);
51  void delete_particle(int trackid);
52 
53  PHG4Particle* GetParticle(const int trackid);
54  PHG4Particle* GetPrimaryParticle(const int trackid);
55 
56  bool is_primary(const PHG4Particle* p) const;
57 
59  Range GetParticleRange() { return Range(particlemap.begin(), particlemap.end()); }
60  ConstRange GetParticleRange() const { return ConstRange(particlemap.begin(), particlemap.end()); }
61 
62  Range GetPrimaryParticleRange() { return Range(particlemap.upper_bound(0), particlemap.end()); }
63  ConstRange GetPrimaryParticleRange() const { return ConstRange(particlemap.upper_bound(0), particlemap.end()); }
64 
65  Range GetSecondaryParticleRange() { return Range(particlemap.begin(), particlemap.upper_bound(0)); }
66  ConstRange GetSecondaryParticleRange() const { return ConstRange(particlemap.begin(), particlemap.upper_bound(0)); }
67 
69  unsigned int size(void) const { return particlemap.size(); }
71  {
72  return std::distance(particlemap.upper_bound(0), particlemap.end());
73  }
74 
76  const Map& GetMap() const { return particlemap; }
77 
78  int maxtrkindex() const;
79  int mintrkindex() const;
80 
85  std::pair<std::map<int, int>::const_iterator,
86  std::map<int, int>::const_iterator>
88  {
89  return std::make_pair(particle_embed_flags.begin(), particle_embed_flags.end());
90  }
91 
96  void AddEmbededTrkId(const int id, const int flag)
97  {
98  particle_embed_flags.insert(std::make_pair(id, flag));
99  }
100 
105  int isEmbeded(const int trackid) const;
106 
107  // --- vertex storage --------------------------------------------------------
108 
110  ConstVtxIterator AddVertex(const int vtxid, PHG4VtxPoint* vertex);
111  void delete_vtx(VtxIterator viter);
112  void delete_vtx(int vtxid);
113 
114  PHG4VtxPoint* GetVtx(const int vtxid);
115  PHG4VtxPoint* GetPrimaryVtx(const int vtxid);
116 
117  bool is_primary_vtx(const PHG4VtxPoint* v) const;
118 
120  VtxRange GetVtxRange() { return VtxRange(vtxmap.begin(), vtxmap.end()); }
121  ConstVtxRange GetVtxRange() const { return ConstVtxRange(vtxmap.begin(), vtxmap.end()); }
122 
123  VtxRange GetPrimaryVtxRange() { return VtxRange(vtxmap.upper_bound(0), vtxmap.end()); }
124  ConstVtxRange GetPrimaryVtxRange() const { return ConstVtxRange(vtxmap.upper_bound(0), vtxmap.end()); }
125 
126  VtxRange GetSecondaryVtxRange() { return VtxRange(vtxmap.begin(), vtxmap.upper_bound(0)); }
127  ConstVtxRange GetSecondaryVtxRange() const { return ConstVtxRange(vtxmap.begin(), vtxmap.upper_bound(0)); }
128 
130  unsigned int GetNumVertices() const { return vtxmap.size(); }
131 
133  const VtxMap& GetVtxMap() const { return vtxmap; }
134 
135  int maxvtxindex() const;
136  int minvtxindex() const;
137 
140  int GetPrimaryVertexIndex() const;
141 
146  std::pair<std::map<int, int>::const_iterator,
147  std::map<int, int>::const_iterator>
149  {
150  return std::make_pair(vertex_embed_flags.begin(), vertex_embed_flags.end());
151  }
152 
157  void AddEmbededVtxId(const int id, const int flag)
158  {
159  vertex_embed_flags.insert(std::make_pair(id, flag));
160  }
161 
166  int isEmbededVtx(const int vtxid) const;
167 
168  // --- shower storage ------------------------------------------------------
169 
171  ConstShowerIterator AddShower(const int showerid, PHG4Shower* newshower);
173 
174  PHG4Shower* GetShower(const int showerid);
175  PHG4Shower* GetPrimaryShower(const int showerid);
176 
180 
181  ShowerRange GetPrimaryShowerRange() { return ShowerRange(showermap.upper_bound(0), showermap.end()); }
182  ConstShowerRange GetPrimaryShowerRange() const { return ConstShowerRange(showermap.upper_bound(0), showermap.end()); }
183 
184  ShowerRange GetSecondaryShowerRange() { return ShowerRange(showermap.begin(), showermap.upper_bound(0)); }
185  ConstShowerRange GetSecondaryShowerRange() const { return ConstShowerRange(showermap.begin(), showermap.upper_bound(0)); }
186 
188  unsigned int shower_size(void) const { return showermap.size(); }
189 
191  const ShowerMap& GetShowerMap() const { return showermap; }
192 
193  int maxshowerindex() const;
194  int minshowerindex() const;
195 
196  private:
210 
224 
228 
229  // embed flag storage, will typically be set for only a few entries or none at all
230  std::map<int, int> particle_embed_flags; //< trackid => embed flag
231  std::map<int, int> vertex_embed_flags; //< vtxid => embed flag
232 
233  ClassDefOverride(PHG4TruthInfoContainer, 1)
234 };
235 
240 
245 
252 
254 {
255  return lhs.GetMap() == rhs.GetMap() && lhs.GetVtxMap() == rhs.GetVtxMap() && lhs.GetShowerMap() == rhs.GetShowerMap();
256 }
257 
258 inline bool operator!=(const PHG4TruthInfoContainer& lhs, const PHG4TruthInfoContainer& rhs) { return !(lhs == rhs); }
260 
261 #endif