CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/CalibFormats/CastorObjects/src/CastorChannelCoder.cc

Go to the documentation of this file.
00001 
00008 #include <iostream>
00009 
00010 #include "CalibFormats/CastorObjects/interface/CastorChannelCoder.h"
00011 #include "CalibFormats/CastorObjects/interface/QieShape.h"
00012 
00013 CastorChannelCoder::CastorChannelCoder (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 CastorChannelCoder::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 << "CastorChannelCoder::charge-> " << fAdc << '/' << fCapId 
00026 //          << " result: " << charge << std::endl;
00027   return charge;
00028 }
00029 
00030 int CastorChannelCoder::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 << "CastorChannelCoder::adc-> " << fCharge << '/' << fCapId 
00050   //        << " result: " << adc << std::endl;
00051   return adc;
00052 }
00053