Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:47

0001 #ifndef DataFormats_CaloRecHit_CaloID_h
0002 #define DataFormats_CaloRecHit_CaloID_h
0003 
0004 /** \class reco::CaloID 
0005  *  
0006  * ID information for all calorimeters. 
0007  *
0008  * \author Colin Bernet, LLR
0009  *
0010  *
0011  */
0012 
0013 #include <iosfwd>
0014 
0015 namespace reco {
0016 
0017   class CaloID {
0018   public:
0019     enum Detectors {
0020       DET_ECAL_BARREL = 0,
0021       DET_ECAL_ENDCAP,
0022       DET_PS1,
0023       DET_PS2,
0024       DET_HCAL_BARREL,
0025       DET_HCAL_ENDCAP,
0026       DET_HF,
0027       DET_HF_EM,
0028       DET_HF_HAD,
0029       DET_HO,
0030       DET_HGCAL_ENDCAP,
0031       DET_NONE
0032     };
0033 
0034     /// default constructor. Sets energy and position to zero
0035     CaloID() : detectors_(0) {}
0036 
0037     CaloID(Detectors det) : detectors_(0) { setDetector(det, true); }
0038 
0039     /// abstract class
0040     virtual ~CaloID() {}
0041 
0042     /// tells the CaloID that it describes a given detector
0043     void setDetector(CaloID::Detectors theDetector, bool value);
0044 
0045     /// \return packed detector information
0046     unsigned detectors() const { return detectors_; }
0047 
0048     /// \return true if this CaloID is in a given detector
0049     bool detector(CaloID::Detectors theDetector) const;
0050 
0051     /// \return true if this CaloID describes a single detector
0052     bool isSingleDetector() const {
0053       // check that detectors_ is a power of 2
0054       return static_cast<bool>(detectors_ && !((detectors_ - 1) & detectors_));
0055     }
0056 
0057     /// \return the described detector if isSingleDetector(),
0058     /// and DET_NONE otherwise.
0059     Detectors detector() const;
0060 
0061     friend std::ostream& operator<<(std::ostream& out, const CaloID& id);
0062 
0063   private:
0064     /// \return lsb position in an integer
0065     int leastSignificantBitPosition(unsigned n) const;
0066 
0067     /// packs the detector information into a bitmask.
0068     /// a CaloID can describe several detectors (bit or)
0069     unsigned detectors_;
0070   };
0071 
0072   std::ostream& operator<<(std::ostream& out, const CaloID& id);
0073 
0074 }  // namespace reco
0075 
0076 #endif