Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:19

0001 /** \class CastorChannelCoder
0002     
0003     Container for ADC<->fQ conversion constants for HCAL/Castor QIE
0004    $Original author: ratnikov
0005 */
0006 
0007 #include <iostream>
0008 
0009 #include "CalibFormats/CastorObjects/interface/CastorChannelCoder.h"
0010 #include "CalibFormats/CastorObjects/interface/QieShape.h"
0011 
0012 CastorChannelCoder::CastorChannelCoder(const float fOffset[16], const float fSlope[16]) {  // [CapId][Range]
0013   for (int range = 0; range < 4; range++) {
0014     for (int capId = 0; capId < 4; capId++) {
0015       mOffset[capId][range] = fOffset[index(capId, range)];
0016       mSlope[capId][range] = fSlope[index(capId, range)];
0017     }
0018   }
0019 }
0020 
0021 double CastorChannelCoder::charge(const reco::castor::QieShape& fShape, int fAdc, int fCapId) const {
0022   int range = (fAdc >> 6) & 0x3;
0023   double charge = fShape.linearization(fAdc) / mSlope[fCapId][range] + mOffset[fCapId][range];
0024   //   std::cout << "CastorChannelCoder::charge-> " << fAdc << '/' << fCapId
0025   //        << " result: " << charge << std::endl;
0026   return charge;
0027 }
0028 
0029 int CastorChannelCoder::adc(const reco::castor::QieShape& fShape, double fCharge, int fCapId) const {
0030   int adc = -1;  //nothing found yet
0031   // search for the range
0032   for (int range = 0; range < 4; range++) {
0033     double qieCharge = (fCharge - mOffset[fCapId][range]) * mSlope[fCapId][range];
0034     double qieChargeMax = fShape.linearization(32 * range + 31) + 0.5 * fShape.binSize(32 * range + 31);
0035     if (range == 3 && qieCharge > qieChargeMax)
0036       adc = 127;  // overflow
0037     if (qieCharge > qieChargeMax)
0038       continue;  // next range
0039     for (int bin = 32 * range; bin < 32 * (range + 1); bin++) {
0040       if (qieCharge < fShape.linearization(bin) + 0.5 * fShape.binSize(bin)) {
0041         adc = bin;
0042         break;
0043       }
0044     }
0045     if (adc >= 0)
0046       break;  // found
0047   }
0048   if (adc < 0)
0049     adc = 0;  // underflow
0050 
0051   //   std::cout << "CastorChannelCoder::adc-> " << fCharge << '/' << fCapId
0052   //        << " result: " << adc << std::endl;
0053   return adc;
0054 }