CMS 3D CMS Logo

HcalDepthEnergyFractions.h
Go to the documentation of this file.
1 #ifndef DataFormats_PatCandidates_HcalDepthEnergyFractions_h
2 #define DataFormats_PatCandidates_HcalDepthEnergyFractions_h
3 
4 #include <vector>
5 #include <cstdint>
6 
7 namespace pat {
8 
9  //
10  // Hcal depth energy fracrtion struct
11  //
13  private:
14  //do not store
15  std::vector<float> fractions_;
16  //store
17  std::vector<uint8_t> fractionsI_;
18 
19  public:
20  explicit HcalDepthEnergyFractions(const std::vector<float>& v) : fractions_(v), fractionsI_() { initUint8Vector(); }
22 
23  // produce vector of uint8 from vector of float
24  void initUint8Vector() {
25  fractionsI_.clear();
26  for (auto frac : fractions_)
27  fractionsI_.push_back((uint8_t)(frac * 200.));
28  }
29 
30  // produce vector of float from vector of uint8_t
31  void initFloatVector() {
32  fractions_.clear();
33  for (auto fracI : fractionsI_)
34  fractions_.push_back(float(fracI) / 200.);
35  }
36 
37  // reset vectors
38  void reset(std::vector<float> v) {
39  fractions_ = v;
41  }
42 
43  // provide a full vector for each depth
44  const std::vector<float>& fractions() const { return fractions_; }
45 
46  // provide info for individual depth
47  float fraction(unsigned int i) const {
48  if (i < fractions_.size())
49  return fractions_[i];
50  else
51  return -1.;
52  }
53 
54  // provide a full vector (in uint8_t) for each depth
55  const std::vector<uint8_t>& fractionsI() const { return fractionsI_; }
56 
57  // provide info for individual depth (uint8_t)
58  int fractionI(unsigned int i) const {
59  if (i < fractionsI_.size())
60  return int(fractionsI_[i]);
61  else
62  return -1; // physical range 0-200
63  }
64  };
65 
66 } // namespace pat
67 
68 #endif
Definition: HeavyIon.h:7
void reset(std::vector< float > v)
float fraction(unsigned int i) const
HcalDepthEnergyFractions(const std::vector< float > &v)
int fractionI(unsigned int i) const
const std::vector< float > & fractions() const
const std::vector< uint8_t > & fractionsI() const