Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // Tell emacs that this is a C++ source
0002 //  -*- C++ -*-.
0003 #ifndef G4MAIN_PHG4HITCONTAINER_H
0004 #define G4MAIN_PHG4HITCONTAINER_H
0005 
0006 #include "PHG4HitDefs.h"
0007 
0008 #include <phool/PHObject.h>
0009 
0010 #include <iostream>
0011 #include <map>
0012 #include <set>
0013 #include <string>
0014 #include <utility>
0015 
0016 class PHG4Hit;
0017 
0018 class PHG4HitContainer : public PHObject
0019 {
0020  public:
0021   typedef std::map<PHG4HitDefs::keytype, PHG4Hit *> Map;
0022   typedef Map::iterator Iterator;
0023   typedef Map::const_iterator ConstIterator;
0024   typedef std::pair<Iterator, Iterator> Range;
0025   typedef std::pair<ConstIterator, ConstIterator> ConstRange;
0026   typedef std::set<unsigned int>::const_iterator LayerIter;
0027 
0028   PHG4HitContainer();  //< used only by ROOT for DST readback
0029   PHG4HitContainer(const std::string &nodename);
0030 
0031   ~PHG4HitContainer() override {}
0032 
0033   void Reset() override;
0034 
0035   void identify(std::ostream &os = std::cout) const override;
0036 
0037   //! container ID should follow definition of PHG4HitDefs::get_volume_id(DST nodename)
0038   void SetID(int i) { id = i; }
0039   int GetID() const { return id; }
0040 
0041   ConstIterator AddHit(PHG4Hit *newhit);
0042 
0043   ConstIterator AddHit(const unsigned int detid, PHG4Hit *newhit);
0044 
0045   Iterator findOrAddHit(PHG4HitDefs::keytype key);
0046 
0047   PHG4Hit *findHit(PHG4HitDefs::keytype key);
0048 
0049   PHG4HitDefs::keytype genkey(const unsigned int detid);
0050 
0051   //! return all hits matching a given detid
0052   ConstRange getHits(const unsigned int detid) const;
0053 
0054   //! return all hist
0055   ConstRange getHits(void) const;
0056 
0057   unsigned int size(void) const
0058   {
0059     return hitmap.size();
0060   }
0061   unsigned int num_layers(void) const
0062   {
0063     return layers.size();
0064   }
0065   std::pair<LayerIter, LayerIter> getLayers() const
0066   {
0067     return make_pair(layers.begin(), layers.end());
0068   }
0069   void AddLayer(const unsigned int ilayer) { layers.insert(ilayer); }
0070   void RemoveZeroEDep();
0071   PHG4HitDefs::keytype getmaxkey(const unsigned int detid);
0072 
0073  protected:
0074   int id;  //< unique identifier from hash of node name. Defined following PHG4HitDefs::get_volume_id
0075   Map hitmap;
0076   std::set<unsigned int> layers;  // layers is not reset since layers must not change event by event
0077 
0078   ClassDefOverride(PHG4HitContainer, 1)
0079 };
0080 
0081 #endif