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
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
00021
00022 return (fShape.center (fAdc) - 0) / 1;
00023 }
00024
00025 unsigned CastorQIECoder::adc (const CastorQIEShape& fShape, float fCharge, unsigned fCapId) const {
00026
00027 for (unsigned range = 0; range < 4; range++) {
00028
00029 float qieCharge = fCharge * 1 + 0;
00030 unsigned minBin = 32*range;
00031 float qieChargeMax = fShape.highEdge (minBin + 31);
00032 if (qieCharge <= qieChargeMax) {
00033 for (unsigned bin = minBin; bin <= minBin + 31; bin++) {
00034 if (qieCharge < fShape.highEdge (bin)) {
00035 return bin;
00036 }
00037 }
00038 return minBin;
00039 }
00040 else if (range == 3) {
00041 return 127;
00042 }
00043 }
00044 return 0;
00045 }
00046
00047 float CastorQIECoder::offset (unsigned fCapId, unsigned fRange) const {
00048 return *((&mOffset00) + index (fRange, fCapId));
00049 }
00050
00051 float CastorQIECoder::slope (unsigned fCapId, unsigned fRange) const {
00052 return *((&mSlope00) + index (fRange, fCapId));
00053 }
00054
00055 void CastorQIECoder::setOffset (unsigned fCapId, unsigned fRange, float fValue) {
00056 if (fCapId < 4U && fRange < 4U) {
00057 *((&mOffset00) + index (fRange, fCapId)) = fValue;
00058 }
00059 else {
00060 std::cerr << "CastorQIECoder::setOffset-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00061 }
00062 }
00063
00064 void CastorQIECoder::setSlope (unsigned fCapId, unsigned fRange, float fValue) {
00065 if (fCapId < 4U && fRange < 4U) {
00066 *((&mSlope00) + index (fRange, fCapId)) = fValue;
00067 }
00068 else {
00069 std::cerr << "CastorQIECoder::setSlope-> Wrong parameters capid/range: " << fCapId << '/' << fRange << std::endl;
00070 }
00071 }
00072