File indexing completed on 2024-04-06 12:02:28
0001 #include "CondFormats/PPSObjects/interface/CTPPSPixelGainCalibration.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <algorithm>
0004 #include <cstring>
0005
0006
0007
0008
0009 CTPPSPixelGainCalibration::CTPPSPixelGainCalibration() : minPed_(0.), maxPed_(255.), minGain_(0.), maxGain_(255.) {
0010 DetRegistry myreg;
0011 myreg.detid = 0;
0012 myreg.ibegin = 0;
0013 myreg.iend = 0;
0014 myreg.ncols = 0;
0015 myreg.nrows = 0;
0016 indexes = myreg;
0017 edm::LogInfo("CTPPSPixelGainCalibration") << "Default instance of CTPPSPixelGainCalibration";
0018 }
0019
0020 CTPPSPixelGainCalibration::CTPPSPixelGainCalibration(const uint32_t& detId,
0021 const uint32_t& sensorSize = 24960,
0022 const uint32_t& nCols = 156)
0023 : minPed_(0.), maxPed_(255.), minGain_(0.), maxGain_(255.) {
0024 DetRegistry myreg;
0025 myreg.detid = detId;
0026 myreg.ibegin = 0;
0027 myreg.iend = sensorSize;
0028 myreg.ncols = nCols;
0029 myreg.nrows = sensorSize / nCols;
0030 indexes = myreg;
0031 edm::LogInfo("CTPPSPixelGainCalibration")
0032 << "Instance of CTPPSPixelGainCalibration setting detId = " << detId << " and npix = " << sensorSize
0033 << " and ncols = " << nCols << " and nrows= " << myreg.nrows;
0034 }
0035
0036
0037 CTPPSPixelGainCalibration::CTPPSPixelGainCalibration(float minPed, float maxPed, float minGain, float maxGain)
0038 : minPed_(minPed), maxPed_(maxPed), minGain_(minGain), maxGain_(maxGain) {
0039 DetRegistry myreg;
0040 myreg.detid = 0;
0041 myreg.ibegin = 0;
0042 myreg.iend = 0;
0043 myreg.ncols = 0;
0044 myreg.nrows = 0;
0045 indexes = myreg;
0046 edm::LogInfo("CTPPSPixelGainCalibration") << "Instance of CTPPSPixelGainCalibration setting mininums and maximums";
0047 }
0048
0049 CTPPSPixelGainCalibration::CTPPSPixelGainCalibration(const uint32_t& detid,
0050 const std::vector<float>& peds,
0051 const std::vector<float>& gains,
0052 float minPed,
0053 float maxPed,
0054 float minGain,
0055 float maxGain)
0056 : minPed_(minPed), maxPed_(maxPed), minGain_(minGain), maxGain_(maxGain) {
0057 setGainsPeds(detid, peds, gains);
0058 edm::LogInfo("CTPPSPixelGainCalibration")
0059 << "Instance of CTPPSPixelGainCalibration setting detId = " << detid << "and vectors of peds and gains";
0060 }
0061
0062 void CTPPSPixelGainCalibration::setGainsPeds(const uint32_t& detid,
0063 const std::vector<float>& peds,
0064 const std::vector<float>& gains) {
0065 int sensorSize = peds.size();
0066 int gainsSize = gains.size();
0067 if (gainsSize != sensorSize)
0068 throw cms::Exception("CTPPSPixelGainCalibration payload configuration error")
0069 << "[CTPPSPixelGainCalibration::CTPPSPixelGainCalibration] peds and gains vector sizes don't match for detid "
0070 << detid << " size peds = " << sensorSize << " size gains = " << gainsSize;
0071 DetRegistry myreg;
0072 myreg.detid = detid;
0073 myreg.ibegin = 0;
0074 myreg.iend = sensorSize;
0075 myreg.ncols =
0076 sensorSize /
0077 160;
0078 myreg.nrows = 160;
0079 indexes = myreg;
0080 for (int i = 0; i < sensorSize; ++i)
0081 putData(i, peds[i], gains[i]);
0082 }
0083
0084 void CTPPSPixelGainCalibration::putData(uint32_t ipix, float ped, float gain) {
0085 if (v_pedestals.size() > ipix)
0086 {
0087 if (ped >= 0 && gain >= 0)
0088 throw cms::Exception("CTPPSPixelGainCalibration fill error")
0089 << "[CTPPSPixelGainCalibration::putData] attempting to fill the vectors that are already filled detid = "
0090 << indexes.detid << " ipix " << ipix;
0091 else
0092 {
0093 edm::LogInfo("CTPPSPixelGainCalibration") << "resetting pixel calibration for noisy or dead flag";
0094 resetPixData(ipix, ped, gain);
0095 }
0096 } else if (v_pedestals.size() < ipix)
0097 throw cms::Exception("CTPPSPixelGainCalibration fill error")
0098 << "[CTPPSPixelGainCalibration::putData] the order got scrambled detid = " << indexes.detid << " ipix " << ipix;
0099 else {
0100 v_pedestals.push_back(ped);
0101 v_gains.push_back(gain);
0102 }
0103 }
0104
0105 void CTPPSPixelGainCalibration::setIndexes(const uint32_t& detid) {
0106 indexes.detid = detid;
0107 indexes.ibegin = 0;
0108 indexes.iend = v_pedestals.size();
0109 indexes.ncols = indexes.iend / 160;
0110 indexes.nrows = 160;
0111 }
0112
0113 void CTPPSPixelGainCalibration::resetPixData(uint32_t ipix, float ped, float gain) {
0114 if (v_pedestals.size() <= ipix) {
0115 edm::LogError("CTPPSPixelGainCalibration") << "this element ipix = " << ipix << " has not been set yet";
0116 return;
0117 }
0118 v_pedestals[ipix] = ped;
0119 v_gains[ipix] = gain;
0120 }
0121
0122 float CTPPSPixelGainCalibration::getPed(const int& col, const int& row) const {
0123 int nCols = indexes.ncols;
0124 int nRows = indexes.nrows;
0125 if (col >= nCols || row >= nRows) {
0126 throw cms::Exception("CorruptedData")
0127 << "[CTPPSPixelGainCalibration::getPed] Pixel out of range: col " << col << " row " << row;
0128 }
0129
0130 int ipix = col + row * nCols;
0131 float tmpped = getPed(ipix );
0132
0133 return tmpped;
0134 }
0135
0136 float CTPPSPixelGainCalibration::getGain(const int& col, const int& row) const {
0137 int nCols = indexes.ncols;
0138 int nRows = indexes.nrows;
0139 if (col >= nCols || row >= nRows) {
0140 throw cms::Exception("CorruptedData")
0141 << "[CTPPSPixelGainCalibration::getGain] Pixel out of range: col " << col << " row " << row;
0142 }
0143
0144 int ipix = col + row * nCols;
0145 float tmpgain = getGain(ipix);
0146
0147 return tmpgain;
0148 }