Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:58

0001 /** 
0002 \class CastorQIEData
0003 \author Panos Katsas (UoA)
0004 POOL object to store QIE coder parameters for one channel
0005 */
0006 
0007 #include <iostream>
0008 
0009 #include "CondFormats/CastorObjects/interface/CastorQIEShape.h"
0010 #include "CondFormats/CastorObjects/interface/CastorQIECoder.h"
0011 
0012 namespace {
0013   // pack range/capId in the plain index
0014   unsigned index(unsigned fRange, unsigned fCapId) { return fCapId * 4 + fRange; }
0015 }  // namespace
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   // search for the range
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;  // underflow
0035     } else if (range == 3) {
0036       return 127;  // overflow
0037     }
0038   }
0039   return 0;  //should never get here
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) {  // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
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) {  // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
0056     *((&mSlope00) + index(fRange, fCapId)) = fValue;
0057   } else {
0058     std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
0059   }
0060 }