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 }
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  }
41  else if (range == 3) {
42  return ( 4 * nbin - 1); // overflow
43  }
44  }
45  return 0; //should never get here
46 }
47 
48 float HcalQIECoder::offset (unsigned fCapId, unsigned fRange) const {
49  return *((&mOffset00) + index (fRange, fCapId));
50 }
51 
52 float HcalQIECoder::slope (unsigned fCapId, unsigned fRange) const {
53  return *((&mSlope00) + index (fRange, fCapId));
54 }
55 
56 void HcalQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
57  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
58  *((&mOffset00) + index (fRange, fCapId)) = fValue;
59  }
60  else {
61  std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
62  }
63 }
64 
65 void HcalQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
66  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
67  *((&mSlope00) + index (fRange, fCapId)) = fValue;
68  }
69  else {
70  std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
71  }
72 }
73 
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:52
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:56
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:48
float center(unsigned fAdc) const
Definition: HcalQIEShape.cc:38
bin
set the eta bin as selection string.
unsigned adc(const HcalQIEShape &fShape, float fCharge, unsigned fCapId) const
fC + capid [0..3] -> ADC conversion
Definition: HcalQIECoder.cc:25
unsigned range(unsigned fAdc) const
Definition: HcalQIEShape.h:25
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:65
float highEdge(unsigned fAdc) const
Definition: HcalQIEShape.cc:46
float mOffset00
Definition: HcalQIECoder.h:41
float mSlope00
Definition: HcalQIECoder.h:57
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
Definition: HcalQIECoder.cc:20
unsigned nbins() const
Definition: HcalQIEShape.h:33