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 
14  private:
15  //do not store
16  std::vector<float> fractions_;
17  //store
18  std::vector<uint8_t> fractionsI_;
19  public:
20  explicit HcalDepthEnergyFractions(const std::vector<float>& v):
21  fractions_(v),fractionsI_() { initUint8Vector(); }
22  HcalDepthEnergyFractions():fractions_(),fractionsI_() { }
23 
24  // produce vector of uint8 from vector of float
25  void initUint8Vector() {
26  fractionsI_.clear();
27  for (auto frac : fractions_) 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_) fractions_.push_back(float(fracI)/200.);
34  }
35 
36  // reset vectors
37  void reset(std::vector<float> v) {
38  fractions_ = v;
40  }
41 
42  // provide a full vector for each depth
43  const std::vector<float>& fractions() const {
44  return fractions_;
45  }
46 
47  // provide info for individual depth
48  float fraction(unsigned int i) const {
49  if (i<fractions_.size()) return fractions_[i];
50  else return -1.;
51  }
52 
53  // provide a full vector (in uint8_t) for each depth
54  const std::vector<uint8_t>& fractionsI() const {
55  return fractionsI_;
56  }
57 
58  // provide info for individual depth (uint8_t)
59  int fractionI(unsigned int i) const {
60  if (i<fractionsI_.size()) return int(fractionsI_[i]);
61  else return -1; // physical range 0-200
62  }
63 
64  };
65 
66 }
67 
68 #endif
69 
Definition: HeavyIon.h:7
const std::vector< uint8_t > & fractionsI() const
void reset(std::vector< float > v)
float fraction(unsigned int i) const
const std::vector< float > & fractions() const
HcalDepthEnergyFractions(const std::vector< float > &v)
int fractionI(unsigned int i) const