File indexing completed on 2024-04-06 11:58:11
0001
0002
0003
0004
0005
0006
0007 #include <iostream>
0008
0009 #include "CalibFormats/CastorObjects/interface/CastorChannelCoder.h"
0010 #include "CalibFormats/CastorObjects/interface/QieShape.h"
0011
0012 CastorChannelCoder::CastorChannelCoder(const float fOffset[16], const float fSlope[16]) {
0013 for (int range = 0; range < 4; range++) {
0014 for (int capId = 0; capId < 4; capId++) {
0015 mOffset[capId][range] = fOffset[index(capId, range)];
0016 mSlope[capId][range] = fSlope[index(capId, range)];
0017 }
0018 }
0019 }
0020
0021 double CastorChannelCoder::charge(const reco::castor::QieShape& fShape, int fAdc, int fCapId) const {
0022 int range = (fAdc >> 6) & 0x3;
0023 double charge = fShape.linearization(fAdc) / mSlope[fCapId][range] + mOffset[fCapId][range];
0024
0025
0026 return charge;
0027 }
0028
0029 int CastorChannelCoder::adc(const reco::castor::QieShape& fShape, double fCharge, int fCapId) const {
0030 int adc = -1;
0031
0032 for (int range = 0; range < 4; range++) {
0033 double qieCharge = (fCharge - mOffset[fCapId][range]) * mSlope[fCapId][range];
0034 double qieChargeMax = fShape.linearization(32 * range + 31) + 0.5 * fShape.binSize(32 * range + 31);
0035 if (range == 3 && qieCharge > qieChargeMax)
0036 adc = 127;
0037 if (qieCharge > qieChargeMax)
0038 continue;
0039 for (int bin = 32 * range; bin < 32 * (range + 1); bin++) {
0040 if (qieCharge < fShape.linearization(bin) + 0.5 * fShape.binSize(bin)) {
0041 adc = bin;
0042 break;
0043 }
0044 }
0045 if (adc >= 0)
0046 break;
0047 }
0048 if (adc < 0)
0049 adc = 0;
0050
0051
0052
0053 return adc;
0054 }