Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:53

0001 #ifndef DataFormats_PatCandidates_HcalDepthEnergyFractions_h
0002 #define DataFormats_PatCandidates_HcalDepthEnergyFractions_h
0003 
0004 #include <vector>
0005 #include <cstdint>
0006 
0007 namespace pat {
0008 
0009   //
0010   // Hcal depth energy fracrtion struct
0011   //
0012   class HcalDepthEnergyFractions {
0013   private:
0014     //do not store
0015     std::vector<float> fractions_;
0016     //store
0017     std::vector<uint8_t> fractionsI_;
0018 
0019   public:
0020     explicit HcalDepthEnergyFractions(const std::vector<float>& v) : fractions_(v), fractionsI_() { initUint8Vector(); }
0021     HcalDepthEnergyFractions() : fractions_(), fractionsI_() {}
0022 
0023     // produce vector of uint8 from vector of float
0024     void initUint8Vector() {
0025       fractionsI_.clear();
0026       for (auto frac : fractions_)
0027         fractionsI_.push_back((uint8_t)(frac * 200.));
0028     }
0029 
0030     // produce vector of float from vector of uint8_t
0031     void initFloatVector() {
0032       fractions_.clear();
0033       for (auto fracI : fractionsI_)
0034         fractions_.push_back(float(fracI) / 200.);
0035     }
0036 
0037     // reset vectors
0038     void reset(std::vector<float> v) {
0039       fractions_ = v;
0040       initUint8Vector();
0041     }
0042 
0043     // provide a full vector for each depth
0044     const std::vector<float>& fractions() const { return fractions_; }
0045 
0046     // provide info for individual depth
0047     float fraction(unsigned int i) const {
0048       if (i < fractions_.size())
0049         return fractions_[i];
0050       else
0051         return -1.;
0052     }
0053 
0054     // provide a full vector (in uint8_t) for each depth
0055     const std::vector<uint8_t>& fractionsI() const { return fractionsI_; }
0056 
0057     // provide info for individual depth (uint8_t)
0058     int fractionI(unsigned int i) const {
0059       if (i < fractionsI_.size())
0060         return int(fractionsI_[i]);
0061       else
0062         return -1;  // physical range 0-200
0063     }
0064   };
0065 
0066 }  // namespace pat
0067 
0068 #endif