File indexing completed on 2024-04-06 12:01:58
0001
0002
0003
0004
0005
0006
0007 #include <iostream>
0008
0009 #include "CondFormats/CastorObjects/interface/CastorQIEShape.h"
0010 #include "CondFormats/CastorObjects/interface/CastorQIECoder.h"
0011
0012 namespace {
0013
0014 unsigned index(unsigned fRange, unsigned fCapId) { return fCapId * 4 + fRange; }
0015 }
0016
0017 float CastorQIECoder::charge(const CastorQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
0018 unsigned range = fShape.range(fAdc);
0019 return (fShape.center(fAdc) - offset(fCapId, range)) / slope(fCapId, range);
0020 }
0021
0022 unsigned CastorQIECoder::adc(const CastorQIEShape& fShape, float fCharge, unsigned fCapId) const {
0023
0024 for (unsigned range = 0; range < 4; range++) {
0025 float qieCharge = fCharge * slope(fCapId, range) + offset(fCapId, range);
0026 unsigned minBin = 32 * range;
0027 float qieChargeMax = fShape.highEdge(minBin + 31);
0028 if (qieCharge <= qieChargeMax) {
0029 for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
0030 if (qieCharge < fShape.highEdge(bin)) {
0031 return bin;
0032 }
0033 }
0034 return minBin;
0035 } else if (range == 3) {
0036 return 127;
0037 }
0038 }
0039 return 0;
0040 }
0041
0042 float CastorQIECoder::offset(unsigned fCapId, unsigned fRange) const { return *((&mOffset00) + index(fRange, fCapId)); }
0043
0044 float CastorQIECoder::slope(unsigned fCapId, unsigned fRange) const { return *((&mSlope00) + index(fRange, fCapId)); }
0045
0046 void CastorQIECoder::setOffset(unsigned fCapId, unsigned fRange, float fValue) {
0047 if (fCapId < 4U && fRange < 4U) {
0048 *((&mOffset00) + index(fRange, fCapId)) = fValue;
0049 } else {
0050 std::cerr << "CastorQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
0051 }
0052 }
0053
0054 void CastorQIECoder::setSlope(unsigned fCapId, unsigned fRange, float fValue) {
0055 if (fCapId < 4U && fRange < 4U) {
0056 *((&mSlope00) + index(fRange, fCapId)) = fValue;
0057 } else {
0058 std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
0059 }
0060 }