forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
HcalQIECoder.cc
75 lines (65 loc) · 2.53 KB
/
HcalQIECoder.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
\class HcalQIEData
\author Fedor Ratnikov (UMd)
POOL object to store QIE coder parameters for one channel
$Author: ratnikov
$Date: 2010/12/06 20:04:16 $
$Revision: 1.3 $
*/
#include <iostream>
#include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
#include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
namespace {
// pack range/capId in the plain index
inline unsigned index (unsigned fRange, unsigned fCapId) {return fCapId * 4 + fRange;}
inline unsigned range (unsigned fIndex) {return fIndex % 4;}
inline unsigned capId (unsigned fIndex) {return fIndex / 4;}
}
float HcalQIECoder::charge (const HcalQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
unsigned range = fShape.range (fAdc);
return (fShape.center (fAdc) - offset (fCapId, range)) / slope (fCapId, range);
}
unsigned HcalQIECoder::adc (const HcalQIEShape& fShape, float fCharge, unsigned fCapId) const {
// search for the range
for (unsigned range = 0; range < 4; range++) {
float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
unsigned nbin = fShape.nbins(); // it's just 64 = 2*32 ! (for QIE10)
unsigned minBin = nbin * range;
unsigned maxBin = minBin + nbin - 1;
float qieChargeMax = fShape.highEdge (maxBin);
if (qieCharge <= qieChargeMax) {
for (unsigned bin = minBin; bin <= maxBin; bin++) {
if (qieCharge < fShape.highEdge (bin)) {
return bin;
}
}
return minBin; // underflow
}
else if (range == 3) {
return ( 4 * nbin - 1); // overflow
}
}
return 0; //should never get here
}
float HcalQIECoder::offset (unsigned fCapId, unsigned fRange) const {
return *((&mOffset00) + index (fRange, fCapId));
}
float HcalQIECoder::slope (unsigned fCapId, unsigned fRange) const {
return *((&mSlope00) + index (fRange, fCapId));
}
void HcalQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
*((&mOffset00) + index (fRange, fCapId)) = fValue;
}
else {
std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
}
}
void HcalQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
*((&mSlope00) + index (fRange, fCapId)) = fValue;
}
else {
std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
}
}