Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:12

0001 /** 
0002 \class HcalQIEData
0003 \author Fedor Ratnikov (UMd)
0004 POOL object to store QIE coder parameters for one channel
0005 $Author: ratnikov
0006 $Date: 2010/12/06 20:04:16 $
0007 $Revision: 1.3 $
0008 */
0009 
0010 #include <iostream>
0011 
0012 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
0013 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
0014 
0015 namespace {
0016   // pack range/capId in the plain index
0017   inline unsigned index(unsigned fRange, unsigned fCapId) { return fCapId * 4 + fRange; }
0018 }  // namespace
0019 
0020 float HcalQIECoder::charge(const HcalQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
0021   unsigned range = fShape.range(fAdc);
0022   return (fShape.center(fAdc) - offset(fCapId, range)) / slope(fCapId, range);
0023 }
0024 
0025 unsigned HcalQIECoder::adc(const HcalQIEShape& fShape, float fCharge, unsigned fCapId) const {
0026   // search for the range
0027   for (unsigned range = 0; range < 4; range++) {
0028     float qieCharge = fCharge * slope(fCapId, range) + offset(fCapId, range);
0029     unsigned nbin = fShape.nbins();  // it's just 64 = 2*32 ! (for QIE10)
0030     unsigned minBin = nbin * range;
0031     unsigned maxBin = minBin + nbin - 1;
0032     float qieChargeMax = fShape.highEdge(maxBin);
0033     if (qieCharge <= qieChargeMax) {
0034       for (unsigned bin = minBin; bin <= maxBin; bin++) {
0035         if (qieCharge < fShape.highEdge(bin)) {
0036           return bin;
0037         }
0038       }
0039       return minBin;  // underflow
0040     } else if (range == 3) {
0041       return (4 * nbin - 1);  // overflow
0042     }
0043   }
0044   return 0;  //should never get here
0045 }
0046 
0047 float HcalQIECoder::offset(unsigned fCapId, unsigned fRange) const { return *((&mOffset00) + index(fRange, fCapId)); }
0048 
0049 float HcalQIECoder::slope(unsigned fCapId, unsigned fRange) const { return *((&mSlope00) + index(fRange, fCapId)); }
0050 
0051 void HcalQIECoder::setOffset(unsigned fCapId, unsigned fRange, float fValue) {
0052   if (fCapId < 4U && fRange < 4U) {  // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
0053     *((&mOffset00) + index(fRange, fCapId)) = fValue;
0054   } else {
0055     std::cerr << "HcalQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
0056   }
0057 }
0058 
0059 void HcalQIECoder::setSlope(unsigned fCapId, unsigned fRange, float fValue) {
0060   if (fCapId < 4U && fRange < 4U) {  // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
0061     *((&mSlope00) + index(fRange, fCapId)) = fValue;
0062   } else {
0063     std::cerr << "HcalQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
0064   }
0065 }