Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:11

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
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   // from PHObject
0042   // cppcheck-suppress [virtualCallInConstructor]
0043   void Reset() override;
0044   void identify(std::ostream& os = std::cout) const override;
0045 
0046   // --- particle storage ------------------------------------------------------
0047 
0048   //! Add a particle that the user has created
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   //! Get a range of iterators covering the entire container
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   //! track -> particle map size
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   //! Get the Particle Map storage
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   //! Retrieve the embedding ID for the HepMC subevent or track to be analyzed.
0093   //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0094   //! negative IDs are backgrounds, .e.g out of time pile up collisions
0095   //! Usually, ID = 0 means the primary Au+Au collision background
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   //! Set the embedding ID for the HepMC subevent or track to be analyzed.
0104   //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0105   //! negative IDs are backgrounds, .e.g out of time pile up collisions
0106   //! Usually, ID = 0 means the primary Au+Au collision background
0107   void AddEmbededTrkId(const int id, const int flag)
0108   {
0109     particle_embed_flags.insert(std::make_pair(id, flag));
0110   }
0111 
0112   //! Retrieve the embedding ID for the HepMC subevent or track to be analyzed.
0113   //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0114   //! negative IDs are backgrounds, .e.g out of time pile up collisions
0115   //! Usually, ID = 0 means the primary Au+Au collision background
0116   int isEmbeded(const int trackid) const;
0117 
0118   // --- vertex storage --------------------------------------------------------
0119 
0120   //! Add a vertex and return an iterator to the user
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   //! Get a range of iterators covering the entire vertex container
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   //! Get the number of vertices stored
0141   unsigned int GetNumVertices() const { return vtxmap.size(); }
0142 
0143   //! Get the Vertex Map storage
0144   const VtxMap& GetVtxMap() const { return vtxmap; }
0145 
0146   int maxvtxindex() const;
0147   int minvtxindex() const;
0148 
0149   //! Return ID of the truth primary vertex with highest embedding ID.
0150   //! For vertex with identical embedding ID, return first one simulated in Geant4.
0151   int GetPrimaryVertexIndex() const;
0152 
0153   //! Retrieve the embedding ID for the HepMC subevent or track to be analyzed.
0154   //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0155   //! negative IDs are backgrounds, .e.g out of time pile up collisions
0156   //! Usually, ID = 0 means the primary Au+Au collision background
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   //! Set the embedding ID for the HepMC subevent or track to be analyzed.
0165   //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0166   //! negative IDs are backgrounds, .e.g out of time pile up collisions
0167   //! Usually, ID = 0 means the primary Au+Au collision background
0168   void AddEmbededVtxId(const int id, const int flag)
0169   {
0170     vertex_embed_flags.insert(std::make_pair(id, flag));
0171   }
0172 
0173   //! Retrieve the embedding ID for the HepMC subevent or track to be analyzed.
0174   //! positive ID is the embedded event of interest, e.g. jetty event from pythia
0175   //! negative IDs are backgrounds, .e.g out of time pile up collisions
0176   //! Usually, ID = 0 means the primary Au+Au collision background
0177   int isEmbededVtx(const int vtxid) const;
0178 
0179   // --- shower storage ------------------------------------------------------
0180 
0181   //! Add a shower that the user has created
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   //! Get a range of iterators covering the entire container
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   //! shower size
0199   unsigned int shower_size(void) const { return showermap.size(); }
0200 
0201   //! Get the Shower Map storage
0202   const ShowerMap& GetShowerMap() const { return showermap; }
0203 
0204   int maxshowerindex() const;
0205   int minshowerindex() const;
0206 
0207  private:
0208   /// particle storage map format description:
0209   /// primary particles are appended in the positive direction
0210   /// secondary particles are appended in the negative direction
0211   /// +N   primary particle id => particle*
0212   /// +N-1
0213   /// ...
0214   /// +1   primary particle id => particle*
0215   /// 0    no entry
0216   /// -1   secondary particle id => particle*
0217   /// ...
0218   /// -M+1
0219   /// -M   secondary particle id => particle*
0220   Map particlemap;
0221 
0222   Map sPHENIXprimaryparticlemap;  // for sPHENIX primary particle identification
0223 
0224   /// vertex storage map format description:
0225   /// primary vertexes are appended in the positive direction
0226   /// secondary vertexes are appended in the negative direction
0227   /// +N   primary vertex id => vertex*
0228   /// +N-1
0229   /// ...
0230   /// +1   primary vertex id => vertex*
0231   /// 0    no entry
0232   /// -1   secondary vertex id => vertex*
0233   /// ...
0234   /// -M+1
0235   /// -M   secondary vertex id => vertex*
0236   VtxMap vtxmap;
0237 
0238   /// shower map
0239   /// showers encapsulate the secondaries and hits from a primary particle
0240   ShowerMap showermap;
0241 
0242   // embed flag storage, will typically be set for only a few entries or none at all
0243   std::map<int, int> particle_embed_flags;  //< trackid => embed flag
0244   std::map<int, int> vertex_embed_flags;    //< vtxid => embed flag
0245 
0246   ClassDefOverride(PHG4TruthInfoContainer, 2)
0247 };
0248 
0249 /**
0250  * Equality operators for the types used in the publicly accessible internal
0251  * containers of PHG4TruthInfoContainer.
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  * Equality operators for PHG4TruthInfoContainer. Note that the comparison is
0261  * performed only on the publicly accessible internal containers, i.e.
0262  * PHG4TruthInfoContainer::particlemap, PHG4TruthInfoContainer::vtxmap, and
0263  * PHG4TruthInfoContainer::showermap.
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