Go to the documentation of this file.00001
00010 #include <iostream>
00011
00012 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
00013 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
00014
00015 namespace {
00016
00017 unsigned index (unsigned fRange, unsigned fCapId) {return fCapId * 4 + fRange;}
00018 unsigned range (unsigned fIndex) {return fIndex % 4;}
00019 unsigned capId (unsigned fIndex) {return fIndex / 4;}
00020 }
00021
00022 float HcalQIECoder::charge (const HcalQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
00023 unsigned range = fShape.range (fAdc);
00024 return (fShape.center (fAdc) - offset (fCapId, range)) / slope (fCapId, range);
00025 }
00026
00027 unsigned HcalQIECoder::adc (const HcalQIEShape& fShape, float fCharge, unsigned fCapId) const {
00028
00029 for (unsigned range = 0; range < 4; range++) {
00030 float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
00031 unsigned minBin = 32*range;
00032 float qieChargeMax = fShape.highEdge (minBin + 31);
00033 if (qieCharge <= qieChargeMax) {
00034 for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
00035 if (qieCharge < fShape.highEdge (bin)) {
00036 return bin;
00037 }
00038 }
00039 return minBin;
00040 }
00041 else if (range == 3) {
00042 return 127;
00043 }
00044 }
00045 return 0;
00046 }
00047
00048 float HcalQIECoder::offset (unsigned fCapId, unsigned fRange) const {
00049 return *((&mOffset00) + index (fRange, fCapId));
00050 }
00051
00052 float HcalQIECoder::slope (unsigned fCapId, unsigned fRange) const {
00053 return *((&mSlope00) + index (fRange, fCapId));
00054 }
00055
00056 void HcalQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
00057 if (fCapId < 4U && fRange < 4U) {
00058 *((&mOffset00) + index (fRange, fCapId)) = fValue;
00059 }
00060 else {
00061 std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00062 }
00063 }
00064
00065 void HcalQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
00066 if (fCapId < 4U && fRange < 4U) {
00067 *((&mSlope00) + index (fRange, fCapId)) = fValue;
00068 }
00069 else {
00070 std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00071 }
00072 }
00073