CMS 3D CMS Logo

HcalQIECoder.cc
Go to the documentation of this file.
1 
10 #include <iostream>
11 
14 
15 namespace {
16  // pack range/capId in the plain index
17  inline unsigned index(unsigned fRange, unsigned fCapId) { return fCapId * 4 + fRange; }
18 } // namespace
19 
20 float HcalQIECoder::charge(const HcalQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
21  unsigned range = fShape.range(fAdc);
22  return (fShape.center(fAdc) - offset(fCapId, range)) / slope(fCapId, range);
23 }
24 
25 unsigned HcalQIECoder::adc(const HcalQIEShape& fShape, float fCharge, unsigned fCapId) const {
26  // search for the range
27  for (unsigned range = 0; range < 4; range++) {
28  float qieCharge = fCharge * slope(fCapId, range) + offset(fCapId, range);
29  unsigned nbin = fShape.nbins(); // it's just 64 = 2*32 ! (for QIE10)
30  unsigned minBin = nbin * range;
31  unsigned maxBin = minBin + nbin - 1;
32  float qieChargeMax = fShape.highEdge(maxBin);
33  if (qieCharge <= qieChargeMax) {
34  for (unsigned bin = minBin; bin <= maxBin; bin++) {
35  if (qieCharge < fShape.highEdge(bin)) {
36  return bin;
37  }
38  }
39  return minBin; // underflow
40  } else if (range == 3) {
41  return (4 * nbin - 1); // overflow
42  }
43  }
44  return 0; //should never get here
45 }
46 
47 float HcalQIECoder::offset(unsigned fCapId, unsigned fRange) const { return *((&mOffset00) + index(fRange, fCapId)); }
48 
49 float HcalQIECoder::slope(unsigned fCapId, unsigned fRange) const { return *((&mSlope00) + index(fRange, fCapId)); }
50 
51 void HcalQIECoder::setOffset(unsigned fCapId, unsigned fRange, float fValue) {
52  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
53  *((&mOffset00) + index(fRange, fCapId)) = fValue;
54  } else {
55  std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
56  }
57 }
58 
59 void HcalQIECoder::setSlope(unsigned fCapId, unsigned fRange, float fValue) {
60  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
61  *((&mSlope00) + index(fRange, fCapId)) = fValue;
62  } else {
63  std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
64  }
65 }
constexpr unsigned int maxBin
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:51
unsigned range(unsigned fAdc) const
Definition: HcalQIEShape.h:25
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:47
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:49
float highEdge(unsigned fAdc) const
Definition: HcalQIEShape.cc:46
unsigned adc(const HcalQIEShape &fShape, float fCharge, unsigned fCapId) const
fC + capid [0..3] -> ADC conversion
Definition: HcalQIECoder.cc:25
float center(unsigned fAdc) const
Definition: HcalQIEShape.cc:36
unsigned nbins() const
Definition: HcalQIEShape.h:33
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:59
float mOffset00
Definition: HcalQIECoder.h:40
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
Definition: HcalQIECoder.cc:20
constexpr unsigned int minBin
float mSlope00
Definition: HcalQIECoder.h:56