CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  unsigned range (unsigned fIndex) {return fIndex % 4;}
16  unsigned capId (unsigned fIndex) {return fIndex / 4;}
17 }
18 
19 float CastorQIECoder::charge (const CastorQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
20  unsigned range = fShape.range (fAdc);
21  return (fShape.center (fAdc) - offset (fCapId, range)) / slope (fCapId, range);
22 }
23 
24 unsigned CastorQIECoder::adc (const CastorQIEShape& fShape, float fCharge, unsigned fCapId) const {
25  // search for the range
26  for (unsigned range = 0; range < 4; range++) {
27  float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
28  unsigned minBin = 32*range;
29  float qieChargeMax = fShape.highEdge (minBin + 31);
30  if (qieCharge <= qieChargeMax) {
31  for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
32  if (qieCharge < fShape.highEdge (bin)) {
33  return bin;
34  }
35  }
36  return minBin; // underflow
37  }
38  else if (range == 3) {
39  return 127; // overflow
40  }
41  }
42  return 0; //should never get here
43 }
44 
45 float CastorQIECoder::offset (unsigned fCapId, unsigned fRange) const {
46  return *((&mOffset00) + index (fRange, fCapId));
47 }
48 
49 float CastorQIECoder::slope (unsigned fCapId, unsigned fRange) const {
50  return *((&mSlope00) + index (fRange, fCapId));
51 }
52 
53 void CastorQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
54  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
55  *((&mOffset00) + index (fRange, fCapId)) = fValue;
56  }
57  else {
58  std::cerr << "CastorQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
59  }
60 }
61 
62 void CastorQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
63  if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
64  *((&mSlope00) + index (fRange, fCapId)) = fValue;
65  }
66  else {
67  std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
68  }
69 }
70 
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] -&gt; 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] -&gt; ADC conversion
float slope(unsigned fCapId, unsigned fRange) const