CMS 3D CMS Logo

CTPPSPixelGainCalibration.cc
Go to the documentation of this file.
3 #include <algorithm>
4 #include <cstring>
5 
6 //
7 // Constructors
8 //
9 CTPPSPixelGainCalibration::CTPPSPixelGainCalibration() : minPed_(0.), maxPed_(255.), minGain_(0.), maxGain_(255.) {
10  DetRegistry myreg;
11  myreg.detid = 0;
12  myreg.ibegin = 0;
13  myreg.iend = 0;
14  myreg.ncols = 0;
15  myreg.nrows = 0;
16  indexes = myreg;
17  edm::LogInfo("CTPPSPixelGainCalibration") << "Default instance of CTPPSPixelGainCalibration";
18 }
19 
21  const uint32_t& sensorSize = 24960,
22  const uint32_t& nCols = 156)
23  : minPed_(0.), maxPed_(255.), minGain_(0.), maxGain_(255.) {
24  DetRegistry myreg;
25  myreg.detid = detId;
26  myreg.ibegin = 0;
27  myreg.iend = sensorSize;
28  myreg.ncols = nCols;
29  myreg.nrows = sensorSize / nCols;
30  indexes = myreg;
31  edm::LogInfo("CTPPSPixelGainCalibration")
32  << "Instance of CTPPSPixelGainCalibration setting detId = " << detId << " and npix = " << sensorSize
33  << " and ncols = " << nCols << " and nrows= " << myreg.nrows;
34 }
35 
36 //
37 CTPPSPixelGainCalibration::CTPPSPixelGainCalibration(float minPed, float maxPed, float minGain, float maxGain)
38  : minPed_(minPed), maxPed_(maxPed), minGain_(minGain), maxGain_(maxGain) {
39  DetRegistry myreg;
40  myreg.detid = 0;
41  myreg.ibegin = 0;
42  myreg.iend = 0;
43  myreg.ncols = 0;
44  myreg.nrows = 0;
45  indexes = myreg;
46  edm::LogInfo("CTPPSPixelGainCalibration") << "Instance of CTPPSPixelGainCalibration setting mininums and maximums";
47 }
48 
50  const std::vector<float>& peds,
51  const std::vector<float>& gains,
52  float minPed,
53  float maxPed,
54  float minGain,
55  float maxGain)
56  : minPed_(minPed), maxPed_(maxPed), minGain_(minGain), maxGain_(maxGain) {
57  setGainsPeds(detid, peds, gains);
58  edm::LogInfo("CTPPSPixelGainCalibration")
59  << "Instance of CTPPSPixelGainCalibration setting detId = " << detid << "and vectors of peds and gains";
60 }
61 
62 void CTPPSPixelGainCalibration::setGainsPeds(const uint32_t& detid,
63  const std::vector<float>& peds,
64  const std::vector<float>& gains) {
65  int sensorSize = peds.size();
66  int gainsSize = gains.size();
67  if (gainsSize != sensorSize)
68  throw cms::Exception("CTPPSPixelGainCalibration payload configuration error")
69  << "[CTPPSPixelGainCalibration::CTPPSPixelGainCalibration] peds and gains vector sizes don't match for detid "
70  << detid << " size peds = " << sensorSize << " size gains = " << gainsSize;
71  DetRegistry myreg;
72  myreg.detid = detid;
73  myreg.ibegin = 0;
74  myreg.iend = sensorSize;
75  myreg.ncols =
76  sensorSize /
77  160; // each ROC is made of 80 rows and 52 columns, each sensor is made of 160 rows and either 104 or 156 columns (2x2 or 2x3 ROCs)
78  myreg.nrows = 160; // for now this is hardwired.
79  indexes = myreg;
80  for (int i = 0; i < sensorSize; ++i)
81  putData(i, peds[i], gains[i]);
82 }
83 
84 void CTPPSPixelGainCalibration::putData(uint32_t ipix, float ped, float gain) {
85  if (v_pedestals.size() > ipix) //if the vector is too big, this pixel has already been set
86  {
87  if (ped >= 0 && gain >= 0)
88  throw cms::Exception("CTPPSPixelGainCalibration fill error")
89  << "[CTPPSPixelGainCalibration::putData] attempting to fill the vectors that are already filled detid = "
90  << indexes.detid << " ipix " << ipix;
91  else // in case it is for setting the noisy or dead flag of already filled pixel you are allowed to reset it
92  {
93  edm::LogInfo("CTPPSPixelGainCalibration") << "resetting pixel calibration for noisy or dead flag";
94  resetPixData(ipix, ped, gain);
95  }
96  } else if (v_pedestals.size() < ipix)
97  throw cms::Exception("CTPPSPixelGainCalibration fill error")
98  << "[CTPPSPixelGainCalibration::putData] the order got scrambled detid = " << indexes.detid << " ipix " << ipix;
99  else { //the size has to match exactly the index, the index - 0 pixel starts the vector, the one with index 1 should be pushed back in a vector of size== 1 (to become size==2) so on and o forth
100  v_pedestals.push_back(ped);
101  v_gains.push_back(gain);
102  }
103 }
104 
105 void CTPPSPixelGainCalibration::setIndexes(const uint32_t& detid) {
106  indexes.detid = detid;
107  indexes.ibegin = 0;
108  indexes.iend = v_pedestals.size();
109  indexes.ncols = indexes.iend / 160; // nrows is 160 in CTPPS
110  indexes.nrows = 160;
111 }
112 
113 void CTPPSPixelGainCalibration::resetPixData(uint32_t ipix, float ped, float gain) {
114  if (v_pedestals.size() <= ipix) {
115  edm::LogError("CTPPSPixelGainCalibration") << "this element ipix = " << ipix << " has not been set yet";
116  return;
117  }
118  v_pedestals[ipix] = ped; //modify value to already exisiting element
119  v_gains[ipix] = gain;
120 }
121 
122 float CTPPSPixelGainCalibration::getPed(const int& col, const int& row) const {
123  int nCols = indexes.ncols;
124  int nRows = indexes.nrows;
125  if (col >= nCols || row >= nRows) {
126  throw cms::Exception("CorruptedData")
127  << "[CTPPSPixelGainCalibration::getPed] Pixel out of range: col " << col << " row " << row;
128  }
129 
130  int ipix = col + row * nCols;
131  float tmpped = getPed(ipix /*,isDead,isNoisy*/);
132 
133  return tmpped;
134 }
135 
136 float CTPPSPixelGainCalibration::getGain(const int& col, const int& row) const {
137  int nCols = indexes.ncols;
138  int nRows = indexes.nrows;
139  if (col >= nCols || row >= nRows) {
140  throw cms::Exception("CorruptedData")
141  << "[CTPPSPixelGainCalibration::getGain] Pixel out of range: col " << col << " row " << row;
142  }
143 
144  int ipix = col + row * nCols;
145  float tmpgain = getGain(ipix);
146 
147  return tmpgain;
148 }
float getPed(const int &col, const int &row) const
void resetPixData(uint32_t ipix, float ped, float gain)
Log< level::Error, false > LogError
float getGain(const int &col, const int &row) const
void setGainsPeds(const uint32_t &detId, const std::vector< float > &peds, const std::vector< float > &gains)
constexpr float gains[NGAINS]
Definition: EcalConstants.h:20
Log< level::Info, false > LogInfo
col
Definition: cuy.py:1009
void setIndexes(const uint32_t &detId)
void putData(uint32_t ipix, float ped, float gain)