CMS 3D CMS Logo

CastorQIECoder.cc
Go to the documentation of this file.
1 
7 #include <iostream>
8 
11 
12 namespace {
13  // pack range/capId in the plain index
14  unsigned index (unsigned fRange, unsigned fCapId) {return fCapId * 4 + fRange;}
15 }
16 
17 float CastorQIECoder::charge (const CastorQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
18  unsigned range = fShape.range (fAdc);
19  return (fShape.center (fAdc) - offset (fCapId, range)) / slope (fCapId, range);
20 }
21 
22 unsigned CastorQIECoder::adc (const CastorQIEShape& fShape, float fCharge, unsigned fCapId) const {
23  // search for the range
24  for (unsigned range = 0; range < 4; range++) {
25  float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
26  unsigned minBin = 32*range;
27  float qieChargeMax = fShape.highEdge (minBin + 31);
28  if (qieCharge <= qieChargeMax) {
29  for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
30  if (qieCharge < fShape.highEdge (bin)) {
31  return bin;
32  }
33  }
34  return minBin; // underflow
35  }
36  else if (range == 3) {
37  return 127; // overflow
38  }
39  }
40  return 0; //should never get here
41 }
42 
43 float CastorQIECoder::offset (unsigned fCapId, unsigned fRange) const {
44  return *((&mOffset00) + index (fRange, fCapId));
45 }
46 
47 float CastorQIECoder::slope (unsigned fCapId, unsigned fRange) const {
48  return *((&mSlope00) + index (fRange, fCapId));
49 }
50 
51 void CastorQIECoder::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  }
55  else {
56  std::cerr << "CastorQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
57  }
58 }
59 
60 void CastorQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
61  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
62  *((&mSlope00) + index (fRange, fCapId)) = fValue;
63  }
64  else {
65  std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
66  }
67 }
68 
void setSlope(unsigned fCapId, unsigned fRange, float fValue)
unsigned range(unsigned fAdc) const
float highEdge(unsigned fAdc) const
float charge(const CastorQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
void setOffset(unsigned fCapId, unsigned fRange, float fValue)
bin
set the eta bin as selection string.
float center(unsigned fAdc) const
float offset(unsigned fCapId, unsigned fRange) const
unsigned adc(const CastorQIEShape &fShape, float fCharge, unsigned fCapId) const
fC + capid [0..3] -> ADC conversion
float slope(unsigned fCapId, unsigned fRange) const