ECCE @ EIC 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  void Reset() override;
43  void identify(std::ostream& os = std::cout) const override;
44 
45  // --- particle storage ------------------------------------------------------
46 
48  ConstIterator AddParticle(const int particleid, PHG4Particle* newparticle);
50  void delete_particle(int trackid);
51 
52  PHG4Particle* GetParticle(const int trackid);
53  PHG4Particle* GetPrimaryParticle(const int trackid);
54 
55  bool is_primary(const PHG4Particle* p) const;
56 
58  Range GetParticleRange() { return Range(particlemap.begin(), particlemap.end()); }
59  ConstRange GetParticleRange() const { return ConstRange(particlemap.begin(), particlemap.end()); }
60 
61  Range GetPrimaryParticleRange() { return Range(particlemap.upper_bound(0), particlemap.end()); }
62  ConstRange GetPrimaryParticleRange() const { return ConstRange(particlemap.upper_bound(0), particlemap.end()); }
63 
64  Range GetSecondaryParticleRange() { return Range(particlemap.begin(), particlemap.upper_bound(0)); }
65  ConstRange GetSecondaryParticleRange() const { return ConstRange(particlemap.begin(), particlemap.upper_bound(0)); }
66 
68  unsigned int size(void) const { return particlemap.size(); }
70  {
71  return std::distance(particlemap.upper_bound(0), particlemap.end());
72  }
73 
75  const Map& GetMap() const { return particlemap; }
76 
77  int maxtrkindex() const;
78  int mintrkindex() const;
79 
84  std::pair<std::map<int, int>::const_iterator,
85  std::map<int, int>::const_iterator>
87  {
88  return std::make_pair(particle_embed_flags.begin(), particle_embed_flags.end());
89  }
90 
95  void AddEmbededTrkId(const int id, const int flag)
96  {
97  particle_embed_flags.insert(std::make_pair(id, flag));
98  }
99 
104  int isEmbeded(const int trackid) const;
105 
106  // --- vertex storage --------------------------------------------------------
107 
109  ConstVtxIterator AddVertex(const int vtxid, PHG4VtxPoint* vertex);
110  void delete_vtx(VtxIterator viter);
111  void delete_vtx(int vtxid);
112 
113  PHG4VtxPoint* GetVtx(const int vtxid);
114  PHG4VtxPoint* GetPrimaryVtx(const int vtxid);
115 
116  bool is_primary_vtx(const PHG4VtxPoint* v) const;
117 
119  VtxRange GetVtxRange() { return VtxRange(vtxmap.begin(), vtxmap.end()); }
120  ConstVtxRange GetVtxRange() const { return ConstVtxRange(vtxmap.begin(), vtxmap.end()); }
121 
122  VtxRange GetPrimaryVtxRange() { return VtxRange(vtxmap.upper_bound(0), vtxmap.end()); }
123  ConstVtxRange GetPrimaryVtxRange() const { return ConstVtxRange(vtxmap.upper_bound(0), vtxmap.end()); }
124 
125  VtxRange GetSecondaryVtxRange() { return VtxRange(vtxmap.begin(), vtxmap.upper_bound(0)); }
126  ConstVtxRange GetSecondaryVtxRange() const { return ConstVtxRange(vtxmap.begin(), vtxmap.upper_bound(0)); }
127 
129  unsigned int GetNumVertices() const { return vtxmap.size(); }
130 
132  const VtxMap& GetVtxMap() const { return vtxmap; }
133 
134  int maxvtxindex() const;
135  int minvtxindex() const;
136 
139  int GetPrimaryVertexIndex() const;
140 
145  std::pair<std::map<int, int>::const_iterator,
146  std::map<int, int>::const_iterator>
148  {
149  return std::make_pair(vertex_embed_flags.begin(), vertex_embed_flags.end());
150  }
151 
156  void AddEmbededVtxId(const int id, const int flag)
157  {
158  vertex_embed_flags.insert(std::make_pair(id, flag));
159  }
160 
165  int isEmbededVtx(const int vtxid) const;
166 
167  // --- shower storage ------------------------------------------------------
168 
170  ConstShowerIterator AddShower(const int showerid, PHG4Shower* newshower);
172 
173  PHG4Shower* GetShower(const int showerid);
174  PHG4Shower* GetPrimaryShower(const int showerid);
175 
179 
180  ShowerRange GetPrimaryShowerRange() { return ShowerRange(showermap.upper_bound(0), showermap.end()); }
181  ConstShowerRange GetPrimaryShowerRange() const { return ConstShowerRange(showermap.upper_bound(0), showermap.end()); }
182 
183  ShowerRange GetSecondaryShowerRange() { return ShowerRange(showermap.begin(), showermap.upper_bound(0)); }
184  ConstShowerRange GetSecondaryShowerRange() const { return ConstShowerRange(showermap.begin(), showermap.upper_bound(0)); }
185 
187  unsigned int shower_size(void) const { return showermap.size(); }
188 
190  const ShowerMap& GetShowerMap() const { return showermap; }
191 
192  int maxshowerindex() const;
193  int minshowerindex() const;
194 
195  private:
209 
223 
227 
228  // embed flag storage, will typically be set for only a few entries or none at all
229  std::map<int, int> particle_embed_flags; //< trackid => embed flag
230  std::map<int, int> vertex_embed_flags; //< vtxid => embed flag
231 
232  ClassDefOverride(PHG4TruthInfoContainer, 1)
233 };
234 
235 
240 
241 bool operator==(const PHG4TruthInfoContainer::Map::value_type& lhs, const PHG4TruthInfoContainer::Map::value_type& rhs);
242 bool operator==(const PHG4TruthInfoContainer::VtxMap::value_type& lhs, const PHG4TruthInfoContainer::VtxMap::value_type& rhs);
243 bool operator==(const PHG4TruthInfoContainer::ShowerMap::value_type& lhs, const PHG4TruthInfoContainer::ShowerMap::value_type& rhs);
245 
252 
253 inline bool operator==(const PHG4TruthInfoContainer& lhs, const PHG4TruthInfoContainer& rhs)
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