CMS 3D CMS Logo

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