Go to the documentation of this file.00001
00008 #include <iostream>
00009
00010 #include "CalibFormats/CastorObjects/interface/CastorChannelCoder.h"
00011 #include "CalibFormats/CastorObjects/interface/QieShape.h"
00012
00013 CastorChannelCoder::CastorChannelCoder (const float fOffset [16], const float fSlope [16]) {
00014 for (int range = 0; range < 4; range++) {
00015 for (int capId = 0; capId < 4; capId++) {
00016 mOffset [capId][range] = fOffset [index (capId, range)];
00017 mSlope [capId][range] = fSlope [index (capId, range)];
00018 }
00019 }
00020 }
00021
00022 double CastorChannelCoder::charge (const QieShape& fShape, int fAdc, int fCapId) const {
00023 int range = (fAdc >> 6) & 0x3;
00024 double charge = fShape.linearization (fAdc) / mSlope [fCapId][range] + mOffset [fCapId][range];
00025
00026
00027 return charge;
00028 }
00029
00030 int CastorChannelCoder::adc (const QieShape& fShape, double fCharge, int fCapId) const {
00031
00032 int adc = -1;
00033
00034 for (int range = 0; range < 4; range++) {
00035 double qieCharge = (fCharge - mOffset [fCapId][range]) * mSlope [fCapId][range];
00036 double qieChargeMax = fShape.linearization (32*range+31) + 0.5 * fShape.binSize (32*range+31);
00037 if (range == 3 && qieCharge > qieChargeMax) adc = 127;
00038 if (qieCharge > qieChargeMax) continue;
00039 for (int bin = 32*range; bin < 32*(range+1); bin++) {
00040 if (qieCharge < fShape.linearization (bin) + 0.5 * fShape.binSize (bin)) {
00041 adc = bin;
00042 break;
00043 }
00044 }
00045 if (adc >= 0) break;
00046 }
00047 if (adc < 0) adc = 0;
00048
00049
00050
00051 return adc;
00052 }
00053