CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CondFormats/CastorObjects/src/CastorQIECoder.cc

Go to the documentation of this file.
00001 
00007 #include <iostream>
00008 
00009 #include "CondFormats/CastorObjects/interface/CastorQIEShape.h"
00010 #include "CondFormats/CastorObjects/interface/CastorQIECoder.h"
00011 
00012 namespace {
00013   // pack range/capId in the plain index
00014   unsigned index (unsigned fRange, unsigned fCapId) {return fCapId * 4 + fRange;}
00015   unsigned range (unsigned fIndex) {return fIndex % 4;}
00016   unsigned capId (unsigned fIndex) {return fIndex / 4;}
00017 }
00018 
00019 float CastorQIECoder::charge (const CastorQIEShape& fShape, unsigned fAdc, unsigned fCapId) const {
00020   unsigned range = fShape.range (fAdc);
00021   return (fShape.center (fAdc) - offset (fCapId, range)) / slope (fCapId, range);
00022 }
00023 
00024 unsigned CastorQIECoder::adc (const CastorQIEShape& fShape, float fCharge, unsigned fCapId) const {
00025   // search for the range
00026   for (unsigned range = 0; range < 4; range++) {
00027     float qieCharge = fCharge * slope (fCapId, range) + offset (fCapId, range);
00028     unsigned minBin = 32*range;
00029     float qieChargeMax = fShape.highEdge (minBin + 31);
00030     if (qieCharge <= qieChargeMax) {
00031       for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
00032         if (qieCharge < fShape.highEdge (bin)) {
00033           return bin;
00034         }
00035       }
00036       return minBin; // underflow
00037     }
00038     else if (range == 3) {
00039       return 127; // overflow
00040     }
00041   }
00042   return 0; //should never get here
00043 }
00044 
00045 float CastorQIECoder::offset (unsigned fCapId, unsigned fRange) const {
00046   return *((&mOffset00) + index (fRange, fCapId));
00047 }
00048 
00049 float CastorQIECoder::slope (unsigned fCapId, unsigned fRange) const {
00050   return *((&mSlope00) + index (fRange, fCapId));
00051 }
00052   
00053 void CastorQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
00054   if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
00055      *((&mOffset00) + index (fRange, fCapId)) = fValue;
00056   }
00057   else {
00058     std::cerr << "CastorQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00059   }
00060 }
00061 
00062 void CastorQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
00063   if (fCapId < 4U && fRange < 4U) { // fCapId >= 0 and fRange >= 0, since fCapId and fRange are unsigned
00064     *((&mSlope00) + index (fRange, fCapId)) = fValue;
00065   }
00066   else {
00067     std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00068   }
00069 }
00070