CMS 3D CMS Logo

SiPixelGainCalibrationOffline.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_(80),
15  nBinsToUseForEncoding_(253),
16  deadFlag_(255),
17  noisyFlag_(254) {
18  if (deadFlag_ > 0xFF)
19  throw cms::Exception("GainCalibration Payload configuration error")
20  << "[SiPixelGainCalibrationOffline::SiPixelGainCalibrationOffline] Dead flag was set to " << deadFlag_
21  << ", and it must be set less than or equal to 255";
22  if (noisyFlag_ > 0xFF)
23  throw cms::Exception("GainCalibration Payload configuration error")
24  << "[SiPixelGainCalibrationOffline::SiPixelGainCalibrationOffline] Noisy flag was set to " << noisyFlag_
25  << ", and it must be set less than or equal to 255";
26 }
27 //
28 SiPixelGainCalibrationOffline::SiPixelGainCalibrationOffline(float minPed, float maxPed, float minGain, float maxGain)
29  : minPed_(minPed),
30  maxPed_(maxPed),
31  minGain_(minGain),
32  maxGain_(maxGain),
33  numberOfRowsToAverageOver_(80),
34  nBinsToUseForEncoding_(253),
35  deadFlag_(255),
36  noisyFlag_(254) {
37  if (deadFlag_ > 0xFF)
38  throw cms::Exception("GainCalibration Payload configuration error")
39  << "[SiPixelGainCalibrationOffline::SiPixelGainCalibrationOffline] Dead flag was set to " << deadFlag_
40  << ", and it must be set less than or equal to 255";
41  if (noisyFlag_ > 0xFF)
42  throw cms::Exception("GainCalibration Payload configuration error")
43  << "[SiPixelGainCalibrationOffline::SiPixelGainCalibrationOffline] Noisy flag was set to " << noisyFlag_
44  << ", and it must be set less than or equal to 255";
45 }
46 
47 bool SiPixelGainCalibrationOffline::put(const uint32_t& DetId, Range input, const int& nCols) {
48  // put in SiPixelGainCalibrationOffline of DetId
49 
50  Registry::iterator p =
52  if (p != indexes.end() && p->detid == DetId)
53  return false;
54 
55  size_t sd = input.second - input.first;
56  DetRegistry detregistry;
57  detregistry.detid = DetId;
58  detregistry.ncols = nCols;
59  detregistry.ibegin = v_pedestals.size();
60  detregistry.iend = v_pedestals.size() + sd;
61  indexes.insert(p, detregistry);
62 
63  v_pedestals.insert(v_pedestals.end(), input.first, input.second);
64  return true;
65 }
66 
67 const int SiPixelGainCalibrationOffline::getNCols(const uint32_t& DetId) const {
68  // get number of columns of DetId
71  if (p == indexes.end() || p->detid != DetId)
72  return 0;
73  else
74  return p->ncols;
75 }
76 
78  // get SiPixelGainCalibrationOffline Range of DetId
79 
82  if (p == indexes.end() || p->detid != DetId)
84  else
85  return SiPixelGainCalibrationOffline::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend);
86 }
87 
88 const std::pair<const SiPixelGainCalibrationOffline::Range, const int> SiPixelGainCalibrationOffline::getRangeAndNCols(
89  const uint32_t& DetId) const {
92  if (p == indexes.end() || p->detid != DetId)
93  return std::make_pair(SiPixelGainCalibrationOffline::Range(v_pedestals.end(), v_pedestals.end()), 0);
94  else
95  return std::make_pair(
96  SiPixelGainCalibrationOffline::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend), p->ncols);
97 }
98 
99 void SiPixelGainCalibrationOffline::getDetIds(std::vector<uint32_t>& DetIds_) const {
100  // returns vector of DetIds in map
104  DetIds_.push_back(p->detid);
105  }
106 }
107 
109  float gain, const int& nRows, std::vector<char>& vped, bool thisColumnIsDead, bool thisColumnIsNoisy) {
110  float theEncodedGain = 0;
111  if (!thisColumnIsDead && !thisColumnIsNoisy)
112  theEncodedGain = encodeGain(gain);
113 
114  unsigned int gain_ = (static_cast<unsigned int>(theEncodedGain)) & 0xFF;
115 
116  // if this whole column is dead, set a char based dead flag in the blob.
117  if (thisColumnIsDead)
118  gain_ = deadFlag_ & 0xFF;
119  if (thisColumnIsNoisy)
120  gain_ = noisyFlag_ & 0xFF;
121 
122  vped.resize(vped.size() + 1);
123  //check to make sure the column is being placed in the right place in the blob
124  if (nRows != (int)numberOfRowsToAverageOver_) {
125  throw cms::Exception("GainCalibration Payload configuration error")
126  << "[SiPixelGainCalibrationOffline::setDataGain] You are setting a gain averaged over nRows = " << nRows
127  << " where this payload is set ONLY to average over " << numberOfRowsToAverageOver_ << " nRows";
128  }
129 
130  if (vped.size() % (nRows + 1) != 0) {
131  throw cms::Exception("FillError")
132  << "[SiPixelGainCalibrationOffline::setDataGain] Column gain average (OR SETTING AN ENTIRE COLUMN DEAD/NOISY) "
133  "must be filled after the pedestal for each row has been added. An additional source of this error would be "
134  "setting a pixel dead/noisy AND setting its pedestal";
135  }
136  // insert in vector of char
137  ::memcpy((void*)(&vped[vped.size() - 1]), (void*)(&gain_), 1);
138 }
139 
141  std::vector<char>& vped,
142  bool thisPixelIsDead,
143  bool thisPixelIsNoisy) {
144  float theEncodedPedestal = encodePed(pedestal);
145 
146  unsigned int ped_ = (static_cast<unsigned int>(theEncodedPedestal)) & 0xFF;
147 
148  if (thisPixelIsDead)
149  ped_ = deadFlag_ & 0xFF;
150  if (thisPixelIsNoisy)
151  ped_ = noisyFlag_ & 0xFF;
152 
153  vped.resize(vped.size() + 1);
154  // insert in vector of char
155  ::memcpy((void*)(&vped[vped.size() - 1]), (void*)(&ped_), 1);
156 }
157 
159  const int& col, const int& row, const Range& range, const int& nCols, bool& isDead, bool& isNoisy) const {
160  unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
161  // determine what row averaged range we are in (i.e. ROC 1 or ROC 2)
162  unsigned int lengthOfAveragedDataInEachColumn = numberOfRowsToAverageOver_ + 1;
163  unsigned int numberOfAveragedDataBlocksToSkip = row / numberOfRowsToAverageOver_;
164  unsigned int offSetInCorrectDataBlock = row % numberOfRowsToAverageOver_;
165 
166  const unsigned int datum =
167  *(range.first + col * lengthOfColumnData + numberOfAveragedDataBlocksToSkip * lengthOfAveragedDataInEachColumn +
168  offSetInCorrectDataBlock) &
169  0xFF;
170 
171  int maxRow = lengthOfColumnData - (lengthOfColumnData % numberOfRowsToAverageOver_) - 1;
172  if (col >= nCols || row > maxRow) {
173  throw cms::Exception("CorruptedData")
174  << "[SiPixelGainCalibrationOffline::getPed] Pixel out of range: col " << col << " row " << row;
175  }
176 
177  if (datum == deadFlag_)
178  isDead = true;
179  if (datum == noisyFlag_)
180  isNoisy = true;
181 
182  return decodePed(datum);
183 }
184 
186  const int& row,
187  const Range& range,
188  const int& nCols,
189  bool& isDeadColumn,
190  bool& isNoisyColumn) const {
191  unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
192  // determine what row averaged range we are in (i.e. ROC 1 or ROC 2)
193  unsigned int lengthOfAveragedDataInEachColumn = numberOfRowsToAverageOver_ + 1;
194  unsigned int numberOfAveragedDataBlocksToSkip = row / numberOfRowsToAverageOver_;
195 
196  // gain average is stored in the last location of current row averaged column data block
197  const unsigned int datum = *(range.first + col * lengthOfColumnData +
198  ((numberOfAveragedDataBlocksToSkip + 1) * lengthOfAveragedDataInEachColumn) - 1) &
199  0xFF;
200 
201  if (datum == deadFlag_)
202  isDeadColumn = true;
203  if (datum == noisyFlag_)
204  isNoisyColumn = true;
205 
206  int maxRow = lengthOfColumnData - (lengthOfColumnData % numberOfRowsToAverageOver_) - 1;
207  if (col >= nCols || row > maxRow) {
208  throw cms::Exception("CorruptedData")
209  << "[SiPixelGainCalibrationOffline::getPed] Pixel out of range: col " << col << " row " << row;
210  }
211 
212  return decodeGain(datum);
213 }
214 
216  if (gain < minGain_ || gain > maxGain_) {
217  throw cms::Exception("InsertFailure") << "[SiPixelGainCalibrationOffline::encodeGain] Trying to encode gain ("
218  << gain << ") out of range [" << minGain_ << "," << maxGain_ << "]\n";
219  } else {
220  double precision = (maxGain_ - minGain_) / static_cast<float>(nBinsToUseForEncoding_);
221  float encodedGain = (float)((gain - minGain_) / precision);
222  return encodedGain;
223  }
224 }
225 
227  if (ped < minPed_ || ped > maxPed_) {
228  throw cms::Exception("InsertFailure") << "[SiPixelGainCalibrationOffline::encodePed] Trying to encode pedestal ("
229  << ped << ") out of range [" << minPed_ << "," << maxPed_ << "]\n";
230  } else {
231  double precision = (maxPed_ - minPed_) / static_cast<float>(nBinsToUseForEncoding_);
232  float encodedPed = (float)((ped - minPed_) / precision);
233  return encodedPed;
234  }
235 }
236 
237 float SiPixelGainCalibrationOffline::decodePed(unsigned int ped) const {
238  double precision = (maxPed_ - minPed_) / static_cast<float>(nBinsToUseForEncoding_);
239  float decodedPed = (float)(ped * precision + minPed_);
240  return decodedPed;
241 }
242 
244  double precision = (maxGain_ - minGain_) / static_cast<float>(nBinsToUseForEncoding_);
245  float decodedGain = (float)(gain * precision + minGain_);
246  return decodedGain;
247 }
SiPixelGainCalibrationOffline::DetRegistry
Definition: SiPixelGainCalibrationOffline.h:35
SiPixelGainCalibrationOffline::minGain_
float minGain_
Definition: SiPixelGainCalibrationOffline.h:113
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
SiPixelGainCalibrationOffline::RegistryIterator
Registry::const_iterator RegistryIterator
Definition: SiPixelGainCalibrationOffline.h:52
input
static const std::string input
Definition: EdmProvDump.cc:48
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
SiPixelGainCalibrationOffline::decodePed
float decodePed(unsigned int ped) const
Definition: SiPixelGainCalibrationOffline.cc:237
SiPixelGainCalibrationOffline::v_pedestals
std::vector< char > v_pedestals
Definition: SiPixelGainCalibrationOffline.h:111
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cuy.col
col
Definition: cuy.py:1010
SiPixelGainCalibrationOffline::numberOfRowsToAverageOver_
unsigned int numberOfRowsToAverageOver_
Definition: SiPixelGainCalibrationOffline.h:116
SiPixelGainCalibrationOffline::setDataPedestal
void setDataPedestal(float pedestal, std::vector< char > &vped, bool thisPixelIsDead=false, bool thisPixelIsNoisy=false)
Definition: SiPixelGainCalibrationOffline.cc:140
SiPixelGainCalibrationOffline::StrictWeakOrdering
Definition: SiPixelGainCalibrationOffline.h:44
SiPixelGainCalibrationOffline::getRangeAndNCols
const std::pair< const Range, const int > getRangeAndNCols(const uint32_t &detID) const
Definition: SiPixelGainCalibrationOffline.cc:88
SiPixelGainCalibrationOffline::maxPed_
float maxPed_
Definition: SiPixelGainCalibrationOffline.h:113
end
#define end
Definition: vmac.h:39
SiPixelGainCalibrationOffline::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiPixelGainCalibrationOffline.h:50
DetId
Definition: DetId.h:17
SiPixelGainCalibrationOffline::setDataGain
void setDataGain(float gain, const int &nRows, std::vector< char > &vped, bool thisColumnIsDead=false, bool thisColumnIsNoisy=false)
Definition: SiPixelGainCalibrationOffline.cc:108
SiPixelGainCalibrationOffline::DetRegistry::iend
uint32_t iend
Definition: SiPixelGainCalibrationOffline.h:38
SiPixelGainCalibrationOffline::deadFlag_
unsigned int deadFlag_
Definition: SiPixelGainCalibrationOffline.h:119
SiPixelGainCalibrationOffline::SiPixelGainCalibrationOffline
SiPixelGainCalibrationOffline()
Definition: SiPixelGainCalibrationOffline.cc:9
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
SiPixelGainCalibrationOffline::decodeGain
float decodeGain(unsigned int gain) const
Definition: SiPixelGainCalibrationOffline.cc:243
SiPixelGainCalibrationOffline.h
SiPixelGainCalibrationOffline::encodePed
float encodePed(const float &ped)
Definition: SiPixelGainCalibrationOffline.cc:226
common_cff.precision
precision
Definition: common_cff.py:44
SiPixelGainCalibrationOffline::encodeGain
float encodeGain(const float &gain)
Definition: SiPixelGainCalibrationOffline.cc:215
sistrip::extrainfo::gain_
static const char gain_[]
Definition: ConstantsForDqm.h:39
SiPixelGainCalibrationOffline::getNCols
const int getNCols(const uint32_t &detID) const
Definition: SiPixelGainCalibrationOffline.cc:67
EcalCondDBWriter_cfi.pedestal
pedestal
Definition: EcalCondDBWriter_cfi.py:49
SiPixelGainCalibrationOffline::noisyFlag_
unsigned int noisyFlag_
Definition: SiPixelGainCalibrationOffline.h:120
SiPixelGainCalibrationOffline::DetRegistry::detid
uint32_t detid
Definition: SiPixelGainCalibrationOffline.h:36
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
SiPixelGainCalibrationOffline::getDetIds
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: SiPixelGainCalibrationOffline.cc:99
SiPixelGainCalibrationOffline::getRange
const Range getRange(const uint32_t &detID) const
Definition: SiPixelGainCalibrationOffline.cc:77
SiPixelGainCalibrationOffline::getPed
float getPed(const int &col, const int &row, const Range &range, const int &nCols, bool &isDead, bool &isNoisy) const
Definition: SiPixelGainCalibrationOffline.cc:158
Exception
Definition: hltDiff.cc:246
SiPixelGainCalibrationOffline::indexes
std::vector< DetRegistry > indexes
Definition: SiPixelGainCalibrationOffline.h:112
SiPixelGainCalibrationOffline::maxGain_
float maxGain_
Definition: SiPixelGainCalibrationOffline.h:113
SiPixelGainCalibrationOffline::DetRegistry::ncols
int ncols
Definition: SiPixelGainCalibrationOffline.h:39
SiPixelGainCalibrationOffline::minPed_
float minPed_
Definition: SiPixelGainCalibrationOffline.h:113
Exception.h
sd
double sd
Definition: CascadeWrapper.h:113
SiPixelGainCalibrationOffline::nBinsToUseForEncoding_
unsigned int nBinsToUseForEncoding_
Definition: SiPixelGainCalibrationOffline.h:118
begin
#define begin
Definition: vmac.h:32
SiPixelGainCalibrationOffline::getGain
float getGain(const int &col, const int &row, const Range &range, const int &nCols, bool &isDeadColumn, bool &isNoisyColumn) const
Definition: SiPixelGainCalibrationOffline.cc:185
SiPixelGainCalibrationOffline::put
bool put(const uint32_t &detID, Range input, const int &nCols)
Definition: SiPixelGainCalibrationOffline.cc:47
SiPixelGainCalibrationOffline::DetRegistry::ibegin
uint32_t ibegin
Definition: SiPixelGainCalibrationOffline.h:37