CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  unsigned index (unsigned fRange, unsigned fCapId) {return fCapId * 4 + fRange;}
18  unsigned range (unsigned fIndex) {return fIndex % 4;}
19  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 minBin = 32*range;
32  float qieChargeMax = fShape.highEdge (minBin + 31);
33  if (qieCharge <= qieChargeMax) {
34  for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
35  if (qieCharge < fShape.highEdge (bin)) {
36  return bin;
37  }
38  }
39  return minBin; // underflow
40  }
41  else if (range == 3) {
42  return 127; // 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:44
unsigned adc(const HcalQIEShape &fShape, float fCharge, unsigned fCapId) const
fC + capid [0..3] -&gt; 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:65
float highEdge(unsigned fAdc) const
Definition: HcalQIEShape.cc:52
float mOffset00
Definition: HcalQIECoder.h:39
float mSlope00
Definition: HcalQIECoder.h:55
float charge(const HcalQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -&gt; fC conversion.
Definition: HcalQIECoder.cc:22