CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CondFormats/HcalObjects/src/HcalQIECoder.cc

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   // pack range/capId in the plain index
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   // search for the range
00029   for (unsigned range = 0; range < 4; range++) {
00030     float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
00031     unsigned nbin   = 32 * (mQIEIndex+1); // it's just 64 = 2*32 !
00032     unsigned minBin = nbin * range;
00033     unsigned maxBin = minBin + nbin - 1;
00034     float qieChargeMax = fShape.highEdge (maxBin);
00035     if (qieCharge <= qieChargeMax) {
00036       for (unsigned bin = minBin; bin <= maxBin; bin++) {
00037         if (qieCharge < fShape.highEdge (bin)) {
00038           return bin;
00039         }
00040       }
00041       return minBin; // underflow
00042     }
00043     else if (range == 3) {
00044       return ( 4 * nbin - 1); // overflow
00045     }
00046   }
00047   return 0; //should never get here
00048 }
00049 
00050 float HcalQIECoder::offset (unsigned fCapId, unsigned fRange) const {
00051   return *((&mOffset00) + index (fRange, fCapId));
00052 }
00053 
00054 float HcalQIECoder::slope (unsigned fCapId, unsigned fRange) const {
00055   return *((&mSlope00) + index (fRange, fCapId));
00056 }
00057   
00058 void HcalQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
00059   if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
00060     *((&mOffset00) + index (fRange, fCapId)) = fValue;
00061   }
00062   else {
00063     std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00064   }
00065 }
00066 
00067 void HcalQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
00068   if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
00069     *((&mSlope00) + index (fRange, fCapId)) = fValue;
00070   }
00071   else {
00072     std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00073   }
00074 }
00075