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  inline unsigned range (unsigned fIndex) {return fIndex % 4;}
19  inline unsigned capId (unsigned fIndex) {return fIndex / 4;}
20 }
21 
22 float HcalQIECoder::charge (const HcalQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
23  unsigned range = fShape.range (fAdc);
24  return (fShape.center (fAdc) - offset (fCapId, range)) / slope (fCapId, range);
25 }
26 
27 unsigned HcalQIECoder::adc (const HcalQIEShape& fShape, float fCharge, unsigned fCapId) const {
28  // search for the range
29  for (unsigned range = 0; range < 4; range++) {
30  float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
31  unsigned nbin = fShape.nbins(); // it's just 64 = 2*32 ! (for QIE10)
32  unsigned minBin = nbin * range;
33  unsigned maxBin = minBin + nbin - 1;
34  float qieChargeMax = fShape.highEdge (maxBin);
35  if (qieCharge <= qieChargeMax) {
36  for (unsigned bin = minBin; bin <= maxBin; bin++) {
37  if (qieCharge < fShape.highEdge (bin)) {
38  return bin;
39  }
40  }
41  return minBin; // underflow
42  }
43  else if (range == 3) {
44  return ( 4 * nbin - 1); // overflow
45  }
46  }
47  return 0; //should never get here
48 }
49 
50 float HcalQIECoder::offset (unsigned fCapId, unsigned fRange) const {
51  return *((&mOffset00) + index (fRange, fCapId));
52 }
53 
54 float HcalQIECoder::slope (unsigned fCapId, unsigned fRange) const {
55  return *((&mSlope00) + index (fRange, fCapId));
56 }
57 
58 void HcalQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
59  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
60  *((&mOffset00) + index (fRange, fCapId)) = fValue;
61  }
62  else {
63  std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
64  }
65 }
66 
67 void HcalQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
68  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
69  *((&mSlope00) + index (fRange, fCapId)) = fValue;
70  }
71  else {
72  std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
73  }
74 }
75 
float slope(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:54
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:58
float offset(unsigned fCapId, unsigned fRange) const
Definition: HcalQIECoder.cc:50
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:27
unsigned range(unsigned fAdc) const
Definition: HcalQIEShape.h:25
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
Definition: HcalQIECoder.cc:67
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:22
unsigned nbins() const
Definition: HcalQIEShape.h:33