File indexing completed on 2025-08-05 08:18:11
0001
0002
0003 #ifndef G4MAIN_PHG4TRUTHINFOCONTAINER_H
0004 #define G4MAIN_PHG4TRUTHINFOCONTAINER_H
0005
0006 #include <phool/PHObject.h>
0007
0008 #include <iostream>
0009 #include <iterator> // for distance
0010 #include <map>
0011 #include <utility>
0012
0013 class PHG4Shower;
0014 class PHG4Particle;
0015 class PHG4VtxPoint;
0016
0017 class PHG4TruthInfoContainer : public PHObject
0018 {
0019 public:
0020 typedef std::map<int, PHG4Particle*> Map;
0021 typedef Map::iterator Iterator;
0022 typedef Map::const_iterator ConstIterator;
0023 typedef std::pair<Iterator, Iterator> Range;
0024 typedef std::pair<ConstIterator, ConstIterator> ConstRange;
0025
0026 typedef std::map<int, PHG4VtxPoint*> VtxMap;
0027 typedef VtxMap::iterator VtxIterator;
0028 typedef VtxMap::const_iterator ConstVtxIterator;
0029 typedef std::pair<VtxIterator, VtxIterator> VtxRange;
0030 typedef std::pair<ConstVtxIterator, ConstVtxIterator> ConstVtxRange;
0031
0032 typedef std::map<int, PHG4Shower*> ShowerMap;
0033 typedef ShowerMap::iterator ShowerIterator;
0034 typedef ShowerMap::const_iterator ConstShowerIterator;
0035 typedef std::pair<ShowerIterator, ShowerIterator> ShowerRange;
0036 typedef std::pair<ConstShowerIterator, ConstShowerIterator> ConstShowerRange;
0037
0038 PHG4TruthInfoContainer();
0039 ~PHG4TruthInfoContainer() override;
0040
0041
0042
0043 void Reset() override;
0044 void identify(std::ostream& os = std::cout) const override;
0045
0046
0047
0048
0049 ConstIterator AddParticle(const int particleid, PHG4Particle* newparticle);
0050 ConstIterator AddsPHENIXPrimaryParticle(const int particleid, PHG4Particle* newparticle);
0051 void delete_particle(Iterator piter);
0052 void delete_particle(int trackid);
0053
0054 PHG4Particle* GetParticle(const int trackid);
0055 PHG4Particle* GetParticle(const int trackid) const;
0056 PHG4Particle* GetPrimaryParticle(const int trackid);
0057
0058 PHG4Particle* GetsPHENIXPrimaryParticle(const int trackid);
0059
0060 bool is_primary(const PHG4Particle* p) const;
0061
0062 bool is_sPHENIX_primary(const PHG4Particle* p) const;
0063
0064
0065 Range GetParticleRange() { return Range(particlemap.begin(), particlemap.end()); }
0066 ConstRange GetParticleRange() const { return ConstRange(particlemap.begin(), particlemap.end()); }
0067
0068 Range GetPrimaryParticleRange() { return Range(particlemap.upper_bound(0), particlemap.end()); }
0069 ConstRange GetPrimaryParticleRange() const { return ConstRange(particlemap.upper_bound(0), particlemap.end()); }
0070
0071 Range GetSPHENIXPrimaryParticleRange() { return Range(sPHENIXprimaryparticlemap.begin(), sPHENIXprimaryparticlemap.end()); }
0072 ConstRange GetSPHENIXPrimaryParticleRange() const { return ConstRange(sPHENIXprimaryparticlemap.begin(), sPHENIXprimaryparticlemap.end());}
0073
0074 Range GetSecondaryParticleRange() { return Range(particlemap.begin(), particlemap.upper_bound(0)); }
0075 ConstRange GetSecondaryParticleRange() const { return ConstRange(particlemap.begin(), particlemap.upper_bound(0)); }
0076
0077
0078 unsigned int size(void) const { return particlemap.size(); }
0079 int GetNumPrimaryVertexParticles()
0080 {
0081 return std::distance(particlemap.upper_bound(0), particlemap.end());
0082 }
0083
0084
0085 const Map& GetMap() const { return particlemap; }
0086
0087 const Map& GetSPHENIXPrimaryParticleMap() const { return sPHENIXprimaryparticlemap; }
0088
0089 int maxtrkindex() const;
0090 int mintrkindex() const;
0091
0092
0093
0094
0095
0096 std::pair<std::map<int, int>::const_iterator,
0097 std::map<int, int>::const_iterator>
0098 GetEmbeddedTrkIds() const
0099 {
0100 return std::make_pair(particle_embed_flags.begin(), particle_embed_flags.end());
0101 }
0102
0103
0104
0105
0106
0107 void AddEmbededTrkId(const int id, const int flag)
0108 {
0109 particle_embed_flags.insert(std::make_pair(id, flag));
0110 }
0111
0112
0113
0114
0115
0116 int isEmbeded(const int trackid) const;
0117
0118
0119
0120
0121 ConstVtxIterator AddVertex(const int vtxid, PHG4VtxPoint* vertex);
0122 void delete_vtx(VtxIterator viter);
0123 void delete_vtx(int vtxid);
0124
0125 PHG4VtxPoint* GetVtx(const int vtxid);
0126 PHG4VtxPoint* GetPrimaryVtx(const int vtxid);
0127
0128 bool is_primary_vtx(const PHG4VtxPoint* v) const;
0129
0130
0131 VtxRange GetVtxRange() { return VtxRange(vtxmap.begin(), vtxmap.end()); }
0132 ConstVtxRange GetVtxRange() const { return ConstVtxRange(vtxmap.begin(), vtxmap.end()); }
0133
0134 VtxRange GetPrimaryVtxRange() { return VtxRange(vtxmap.upper_bound(0), vtxmap.end()); }
0135 ConstVtxRange GetPrimaryVtxRange() const { return ConstVtxRange(vtxmap.upper_bound(0), vtxmap.end()); }
0136
0137 VtxRange GetSecondaryVtxRange() { return VtxRange(vtxmap.begin(), vtxmap.upper_bound(0)); }
0138 ConstVtxRange GetSecondaryVtxRange() const { return ConstVtxRange(vtxmap.begin(), vtxmap.upper_bound(0)); }
0139
0140
0141 unsigned int GetNumVertices() const { return vtxmap.size(); }
0142
0143
0144 const VtxMap& GetVtxMap() const { return vtxmap; }
0145
0146 int maxvtxindex() const;
0147 int minvtxindex() const;
0148
0149
0150
0151 int GetPrimaryVertexIndex() const;
0152
0153
0154
0155
0156
0157 std::pair<std::map<int, int>::const_iterator,
0158 std::map<int, int>::const_iterator>
0159 GetEmbeddedVtxIds() const
0160 {
0161 return std::make_pair(vertex_embed_flags.begin(), vertex_embed_flags.end());
0162 }
0163
0164
0165
0166
0167
0168 void AddEmbededVtxId(const int id, const int flag)
0169 {
0170 vertex_embed_flags.insert(std::make_pair(id, flag));
0171 }
0172
0173
0174
0175
0176
0177 int isEmbededVtx(const int vtxid) const;
0178
0179
0180
0181
0182 ConstShowerIterator AddShower(const int showerid, PHG4Shower* newshower);
0183 void delete_shower(ShowerIterator piter);
0184
0185 PHG4Shower* GetShower(const int showerid);
0186 PHG4Shower* GetPrimaryShower(const int showerid);
0187
0188
0189 ShowerRange GetShowerRange() { return ShowerRange(showermap.begin(), showermap.end()); }
0190 ConstShowerRange GetShowerRange() const { return ConstShowerRange(showermap.begin(), showermap.end()); }
0191
0192 ShowerRange GetPrimaryShowerRange() { return ShowerRange(showermap.upper_bound(0), showermap.end()); }
0193 ConstShowerRange GetPrimaryShowerRange() const { return ConstShowerRange(showermap.upper_bound(0), showermap.end()); }
0194
0195 ShowerRange GetSecondaryShowerRange() { return ShowerRange(showermap.begin(), showermap.upper_bound(0)); }
0196 ConstShowerRange GetSecondaryShowerRange() const { return ConstShowerRange(showermap.begin(), showermap.upper_bound(0)); }
0197
0198
0199 unsigned int shower_size(void) const { return showermap.size(); }
0200
0201
0202 const ShowerMap& GetShowerMap() const { return showermap; }
0203
0204 int maxshowerindex() const;
0205 int minshowerindex() const;
0206
0207 private:
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220 Map particlemap;
0221
0222 Map sPHENIXprimaryparticlemap;
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236 VtxMap vtxmap;
0237
0238
0239
0240 ShowerMap showermap;
0241
0242
0243 std::map<int, int> particle_embed_flags;
0244 std::map<int, int> vertex_embed_flags;
0245
0246 ClassDefOverride(PHG4TruthInfoContainer, 2)
0247 };
0248
0249
0250
0251
0252
0253
0254 bool operator==(const PHG4TruthInfoContainer::Map::value_type& lhs, const PHG4TruthInfoContainer::Map::value_type& rhs);
0255 bool operator==(const PHG4TruthInfoContainer::VtxMap::value_type& lhs, const PHG4TruthInfoContainer::VtxMap::value_type& rhs);
0256 bool operator==(const PHG4TruthInfoContainer::ShowerMap::value_type& lhs, const PHG4TruthInfoContainer::ShowerMap::value_type& rhs);
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266 inline bool operator==(const PHG4TruthInfoContainer& lhs, const PHG4TruthInfoContainer& rhs)
0267 {
0268 return lhs.GetMap() == rhs.GetMap() && lhs.GetVtxMap() == rhs.GetVtxMap() && lhs.GetShowerMap() == rhs.GetShowerMap();
0269 }
0270
0271 inline bool operator!=(const PHG4TruthInfoContainer& lhs, const PHG4TruthInfoContainer& rhs) { return !(lhs == rhs); }
0272
0273
0274 #endif