CMS 3D CMS Logo

SiPixelGainCalibration.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  numberOfRowsToAverageOver_(1),
15  nBinsToUseForEncoding_(253),
16  deadFlag_(255),
17  noisyFlag_(254) {
18  if (deadFlag_ > 0xFF)
19  throw cms::Exception("GainCalibration Payload configuration error")
20  << "[SiPixelGainCalibration::SiPixelGainCalibration] Dead flag was set to " << deadFlag_
21  << ", and it must be set less than or equal to 255";
22 }
23 //
24 SiPixelGainCalibration::SiPixelGainCalibration(float minPed, float maxPed, float minGain, float maxGain)
25  : minPed_(minPed),
26  maxPed_(maxPed),
27  minGain_(minGain),
28  maxGain_(maxGain),
29  numberOfRowsToAverageOver_(1),
30  nBinsToUseForEncoding_(253),
31  deadFlag_(255),
32  noisyFlag_(254) {
33  if (deadFlag_ > 0xFF)
34  throw cms::Exception("GainCalibration Payload configuration error")
35  << "[SiPixelGainCalibration::SiPixelGainCalibration] Dead flag was set to " << deadFlag_
36  << ", and it must be set less than or equal to 255";
37 }
38 
39 bool SiPixelGainCalibration::put(const uint32_t& DetId, Range input, const int& nCols) {
40  // put in SiPixelGainCalibration of DetId
41 
42  Registry::iterator p =
44  if (p != indexes.end() && p->detid == DetId)
45  return false;
46 
47  size_t sd = input.second - input.first;
48  DetRegistry detregistry;
49  detregistry.detid = DetId;
50  detregistry.ncols = nCols;
51  detregistry.ibegin = v_pedestals.size();
52  detregistry.iend = v_pedestals.size() + sd;
53  indexes.insert(p, detregistry);
54 
55  v_pedestals.insert(v_pedestals.end(), input.first, input.second);
56  return true;
57 }
58 
59 const int SiPixelGainCalibration::getNCols(const uint32_t& DetId) const {
60  // get number of columns of DetId
63  if (p == indexes.end() || p->detid != DetId)
64  return 0;
65  else
66  return p->ncols;
67 }
68 
70  // get SiPixelGainCalibration Range of DetId
71 
74  if (p == indexes.end() || p->detid != DetId)
76  else
77  return SiPixelGainCalibration::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend);
78 }
79 
80 const std::pair<const SiPixelGainCalibration::Range, const int> SiPixelGainCalibration::getRangeAndNCols(
81  const uint32_t& DetId) const {
84  if (p == indexes.end() || p->detid != DetId)
85  return std::make_pair(SiPixelGainCalibration::Range(v_pedestals.end(), v_pedestals.end()), 0);
86  else
87  return std::make_pair(SiPixelGainCalibration::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend),
88  p->ncols);
89 }
90 
91 void SiPixelGainCalibration::getDetIds(std::vector<uint32_t>& DetIds_) const {
92  // returns vector of DetIds in map
96  DetIds_.push_back(p->detid);
97  }
98 }
99 
101  float ped, float gain, std::vector<char>& vped, bool isDeadPixel, bool isNoisyPixel) {
102  float theEncodedGain = 0;
103  float theEncodedPed = 0;
104  if (!isDeadPixel && !isNoisyPixel) {
105  theEncodedGain = encodeGain(gain);
106  theEncodedPed = encodePed(ped);
107  }
108 
109  unsigned int ped_ = (static_cast<unsigned int>(theEncodedPed)) & 0xFF;
110  unsigned int gain_ = (static_cast<unsigned int>(theEncodedGain)) & 0xFF;
111 
112  if (isDeadPixel) {
113  ped_ = deadFlag_ & 0xFF;
114  gain_ = deadFlag_ & 0xFF;
115  }
116  if (isNoisyPixel) {
117  ped_ = noisyFlag_ & 0xFF;
118  gain_ = noisyFlag_ & 0xFF;
119  }
120  unsigned int data = (ped_ << 8) | gain_;
121  vped.resize(vped.size() + 2);
122  // insert in vector of char
123  ::memcpy((void*)(&vped[vped.size() - 2]), (void*)(&data), 2);
124 }
125 
127  const int& col, const int& row, const Range& range, const int& nCols, bool& isDead, bool& isNoisy) const {
128  int nRows = (range.second - range.first) / 2 / nCols;
129  const unsigned int ped = *(range.first + 1 + (col * nRows + row) * 2) & 0xFF;
130  if (col >= nCols || row >= nRows) {
131  throw cms::Exception("CorruptedData")
132  << "[SiPixelGainCalibration::getPed] Pixel out of range: col " << col << " row " << row;
133  }
134  if (ped == deadFlag_)
135  isDead = true;
136  if (ped == noisyFlag_)
137  isNoisy = true;
138  return decodePed(ped);
139 }
140 
142  const int& col, const int& row, const Range& range, const int& nCols, bool& isDead, bool& isNoisy) const {
143  int nRows = (range.second - range.first) / 2 / nCols;
144  const unsigned int gain = *(range.first + (col * nRows + row) * 2) & 0xFF;
145  if (col >= nCols || row >= nRows) {
146  throw cms::Exception("CorruptedData")
147  << "[SiPixelGainCalibration::getPed] Pixel out of range: col " << col << " row " << row;
148  }
149  if (gain == deadFlag_)
150  isDead = true;
151  if (gain == noisyFlag_)
152  isNoisy = true;
153  return decodeGain(gain);
154 }
155 
157  if (gain < minGain_ || gain > maxGain_) {
158  throw cms::Exception("InsertFailure") << "[SiPixelGainCalibration::encodeGain] Trying to encode gain (" << gain
159  << ") out of range [" << minGain_ << "," << maxGain_ << "]\n";
160  } else {
161  double precision = (maxGain_ - minGain_) / static_cast<float>(nBinsToUseForEncoding_);
162  float encodedGain = (float)((gain - minGain_) / precision);
163  return encodedGain;
164  }
165 }
166 
168  if (ped < minPed_ || ped > maxPed_) {
169  throw cms::Exception("InsertFailure") << "[SiPixelGainCalibration::encodePed] Trying to encode pedestal (" << ped
170  << ") out of range [" << minPed_ << "," << maxPed_ << "]\n";
171  } else {
172  double precision = (maxPed_ - minPed_) / static_cast<float>(nBinsToUseForEncoding_);
173  float encodedPed = (float)((ped - minPed_) / precision);
174  return encodedPed;
175  }
176 }
177 
178 float SiPixelGainCalibration::decodePed(unsigned int ped) const {
179  double precision = (maxPed_ - minPed_) / static_cast<float>(nBinsToUseForEncoding_);
180  float decodedPed = (float)(ped * precision + minPed_);
181  return decodedPed;
182 }
183 
184 float SiPixelGainCalibration::decodeGain(unsigned int gain) const {
185  double precision = (maxGain_ - minGain_) / static_cast<float>(nBinsToUseForEncoding_);
186  float decodedGain = (float)(gain * precision + minGain_);
187  return decodedGain;
188 }
std::vector< char > v_pedestals
std::vector< DetRegistry > indexes
bool put(const uint32_t &detID, Range input, const int &nCols)
const std::pair< const Range, const int > getRangeAndNCols(const uint32_t &detID) const
static std::string const input
Definition: EdmProvDump.cc:50
float getGain(const int &col, const int &row, const Range &range, const int &nCols, bool &isDead, bool &isNoisy) const
float encodePed(const float &ped)
float decodePed(unsigned int ped) const
Definition: DetId.h:17
Registry::const_iterator RegistryIterator
const Range getRange(const uint32_t &detID) const
const int getNCols(const uint32_t &detID) const
std::pair< ContainerIterator, ContainerIterator > Range
void getDetIds(std::vector< uint32_t > &DetIds_) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static const char gain_[]
col
Definition: cuy.py:1009
float getPed(const int &col, const int &row, const Range &range, const int &nCols, bool &isDead, bool &isNoisy) const
void setData(float ped, float gain, std::vector< char > &vped, bool thisPixelIsDead=false, bool thisPixelIsNoisy=false)
float decodeGain(unsigned int gain) const
float encodeGain(const float &gain)