CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/CalibFormats/HcalObjects/src/HcalChannelCoder.cc

Go to the documentation of this file.
00001 
00008 #include <iostream>
00009 
00010 #include "CalibFormats/HcalObjects/interface/HcalChannelCoder.h"
00011 #include "CalibFormats/HcalObjects/interface/QieShape.h"
00012 
00013 HcalChannelCoder::HcalChannelCoder (const float fOffset [16], const float fSlope [16]) { // [CapId][Range]
00014   for (int range = 0; range < 4; range++) {
00015     for (int capId = 0; capId < 4; capId++) {
00016       mOffset [capId][range] = fOffset [index (capId, range)];
00017       mSlope [capId][range] = fSlope [index (capId, range)];
00018     }
00019   }
00020 }
00021 
00022 double HcalChannelCoder::charge (const QieShape& fShape, int fAdc, int fCapId) const {
00023   int range = (fAdc >> 6) & 0x3;
00024   double charge = fShape.linearization (fAdc) / mSlope [fCapId][range] + mOffset [fCapId][range];
00025 //   std::cout << "HcalChannelCoder::charge-> " << fAdc << '/' << fCapId 
00026 //          << " result: " << charge << std::endl;
00027   return charge;
00028 }
00029 
00030 int HcalChannelCoder::adc (const QieShape& fShape, double fCharge, int fCapId) const {
00031 
00032   int adc = -1; //nothing found yet
00033   // search for the range
00034   for (int range = 0; range < 4; range++) {
00035     double qieCharge = (fCharge - mOffset [fCapId][range]) * mSlope [fCapId][range];
00036     double qieChargeMax = fShape.linearization (32*range+31) + 0.5 * fShape.binSize (32*range+31);
00037     if (range == 3 && qieCharge > qieChargeMax) adc = 127; // overflow
00038     if (qieCharge > qieChargeMax) continue; // next range
00039     for (int bin = 32*range; bin < 32*(range+1); bin++) {
00040       if (qieCharge < fShape.linearization (bin) + 0.5 * fShape.binSize (bin)) {
00041         adc = bin;
00042         break;
00043       }
00044     }
00045     if (adc >= 0) break; // found
00046   }
00047   if (adc < 0) adc = 0; // underflow
00048 
00049 //   std::cout << "HcalChannelCoder::adc-> " << fCharge << '/' << fCapId 
00050 //          << " result: " << adc << std::endl;
00051   return adc;
00052 }
00053