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 } // namespace
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  } else if (range == 3) {
36  return 127; // overflow
37  }
38  }
39  return 0; //should never get here
40 }
41 
42 float CastorQIECoder::offset(unsigned fCapId, unsigned fRange) const { return *((&mOffset00) + index(fRange, fCapId)); }
43 
44 float CastorQIECoder::slope(unsigned fCapId, unsigned fRange) const { return *((&mSlope00) + index(fRange, fCapId)); }
45 
46 void CastorQIECoder::setOffset(unsigned fCapId, unsigned fRange, float fValue) {
47  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
48  *((&mOffset00) + index(fRange, fCapId)) = fValue;
49  } else {
50  std::cerr << "CastorQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
51  }
52 }
53 
54 void CastorQIECoder::setSlope(unsigned fCapId, unsigned fRange, float fValue) {
55  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
56  *((&mSlope00) + index(fRange, fCapId)) = fValue;
57  } else {
58  std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
59  }
60 }
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)
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