CMS 3D CMS Logo

SiPixelGainCalibrationForHLT.cc
Go to the documentation of this file.
3 #include <cstring>
4 #include <algorithm>
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  initialize();
19  if (deadFlag_ > 0xFF)
20  throw cms::Exception("GainCalibration Payload configuration error")
21  << "[SiPixelGainCalibrationHLT::SiPixelGainCalibrationHLT] Dead flag was set to " << deadFlag_
22  << ", and it must be set less than or equal to 255";
23 }
24 //
25 SiPixelGainCalibrationForHLT::SiPixelGainCalibrationForHLT(float minPed, float maxPed, float minGain, float maxGain)
26  : minPed_(minPed),
27  maxPed_(maxPed),
28  minGain_(minGain),
29  maxGain_(maxGain),
30  numberOfRowsToAverageOver_(80),
31  nBinsToUseForEncoding_(253),
32  deadFlag_(255),
33  noisyFlag_(254) {
34  initialize();
35  if (deadFlag_ > 0xFF)
36  throw cms::Exception("GainCalibration Payload configuration error")
37  << "[SiPixelGainCalibrationHLT::SiPixelGainCalibrationHLT] Dead flag was set to " << deadFlag_
38  << ", and it must be set less than or equal to 255";
39 }
40 
42  pedPrecision = (maxPed_ - minPed_) / static_cast<float>(nBinsToUseForEncoding_);
43  gainPrecision = (maxGain_ - minGain_) / static_cast<float>(nBinsToUseForEncoding_);
44 }
45 
46 bool SiPixelGainCalibrationForHLT::put(const uint32_t& DetId, Range input, const int& nCols) {
47  // put in SiPixelGainCalibrationForHLT of DetId
48 
49  Registry::iterator p =
51  if (p != indexes.end() && p->detid == DetId)
52  return false;
53 
54  size_t sd = input.second - input.first;
55  DetRegistry detregistry;
56  detregistry.detid = DetId;
57  detregistry.ibegin = v_pedestals.size();
58  detregistry.iend = v_pedestals.size() + sd;
59  detregistry.ncols = nCols;
60  indexes.insert(p, detregistry);
61 
62  v_pedestals.insert(v_pedestals.end(), input.first, input.second);
63  return true;
64 }
65 
66 const int SiPixelGainCalibrationForHLT::getNCols(const uint32_t& DetId) const {
67  // get number of columns of DetId
70  if (p == indexes.end() || p->detid != DetId)
71  return 0;
72  else {
73  return p->ncols;
74  }
75 }
76 
78  // get SiPixelGainCalibrationForHLT Range of DetId
79 
82  if (p == indexes.end() || p->detid != DetId)
84  else
85  return SiPixelGainCalibrationForHLT::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend);
86 }
87 
88 const std::pair<const SiPixelGainCalibrationForHLT::Range, const int> SiPixelGainCalibrationForHLT::getRangeAndNCols(
89  const uint32_t& DetId) const {
92  if (p == indexes.end() || p->detid != DetId)
93  return std::make_pair(SiPixelGainCalibrationForHLT::Range(v_pedestals.end(), v_pedestals.end()), 0);
94  else
95  return std::make_pair(
96  SiPixelGainCalibrationForHLT::Range(v_pedestals.begin() + p->ibegin, v_pedestals.begin() + p->iend), p->ncols);
97 }
98 
99 void SiPixelGainCalibrationForHLT::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 ped, float gain, std::vector<char>& vped, bool thisColumnIsDead, bool thisColumnIsNoisy) {
110  float theEncodedGain = 0;
111  float theEncodedPed = 0;
112  if (!thisColumnIsDead && !thisColumnIsNoisy) {
113  theEncodedGain = encodeGain(gain);
114  theEncodedPed = encodePed(ped);
115  }
116 
117  unsigned int ped_ = (static_cast<unsigned int>(theEncodedPed)) & 0xFF;
118  unsigned int gain_ = (static_cast<unsigned int>(theEncodedGain)) & 0xFF;
119 
120  if (thisColumnIsDead) {
121  ped_ = deadFlag_ & 0xFF;
122  gain_ = deadFlag_ & 0xFF;
123  } else if (thisColumnIsNoisy) {
124  ped_ = noisyFlag_ & 0xFF;
125  gain_ = noisyFlag_ & 0xFF;
126  }
127 
128  unsigned int data = (ped_ << 8) | gain_;
129  vped.resize(vped.size() + 2);
130  // insert in vector of char
131  ::memcpy((void*)(&vped[vped.size() - 2]), (void*)(&data), 2);
132 }
133 
134 std::pair<float, float> SiPixelGainCalibrationForHLT::getPedAndGain(const int& col,
135  const int& row,
136  const Range& range,
137  const int& nCols,
138  bool& isDeadColumn,
139  bool& isNoisyColumn) const {
140  // determine what averaged data block we are in (there should be 1 or 2 of these depending on if plaquette is 1 by X or 2 by X
141  unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
142  unsigned int lengthOfAveragedDataInEachColumn = 2; // we always only have two values per column averaged block
143  unsigned int numberOfDataBlocksToSkip = row / numberOfRowsToAverageOver_;
144  const unsigned int pos = col * lengthOfColumnData + lengthOfAveragedDataInEachColumn * numberOfDataBlocksToSkip;
145  const unsigned int gain = *(range.first + pos) & 0xFF;
146  const unsigned int ped = *(range.first + pos + 1) & 0xFF;
147 
148  isDeadColumn = ped == deadFlag_;
149  isNoisyColumn = ped == noisyFlag_;
150 
151  /*
152  int maxRow = (lengthOfColumnData/lengthOfAveragedDataInEachColumn)*numberOfRowsToAverageOver_ - 1;
153  if (col >= nCols || row > maxRow){
154  throw cms::Exception("CorruptedData")
155  << "[SiPixelGainCalibrationForHLT::getPed] Pixel out of range: col " << col << " row: " << row;
156  }
157  */
158 
159  return std::make_pair(decodePed(ped), decodeGain(gain));
160 }
161 
163  const int& row,
164  const Range& range,
165  const int& nCols,
166  bool& isDeadColumn,
167  bool& isNoisyColumn) const {
168  // TODO MERGE THIS FUNCTION WITH GET GAIN, then provide wrappers ( VI done, see above)
169 
170  // determine what averaged data block we are in (there should be 1 or 2 of these depending on if plaquette is 1 by X or 2 by X
171  unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
172  unsigned int lengthOfAveragedDataInEachColumn = 2; // we always only have two values per column averaged block
173  unsigned int numberOfDataBlocksToSkip = row / numberOfRowsToAverageOver_;
174  const unsigned int ped =
175  *(range.first + 1 + col * lengthOfColumnData + lengthOfAveragedDataInEachColumn * numberOfDataBlocksToSkip) &
176  0xFF;
177 
178  if (ped == deadFlag_)
179  isDeadColumn = true;
180  else if (ped == noisyFlag_)
181  isNoisyColumn = true;
182 
183  int maxRow = (lengthOfColumnData / lengthOfAveragedDataInEachColumn) * numberOfRowsToAverageOver_ - 1;
184  if (col >= nCols || row > maxRow) {
185  throw cms::Exception("CorruptedData")
186  << "[SiPixelGainCalibrationForHLT::getPed] Pixel out of range: col " << col << " row: " << row;
187  }
188  return decodePed(ped);
189 }
190 
192  const int& row,
193  const Range& range,
194  const int& nCols,
195  bool& isDeadColumn,
196  bool& isNoisyColumn) const {
197  // determine what averaged data block we are in (there should be 1 or 2 of these depending on if plaquette is 1 by X or 2 by X
198  unsigned int lengthOfColumnData = (range.second - range.first) / nCols;
199  unsigned int lengthOfAveragedDataInEachColumn = 2; // we always only have two values per column averaged block
200  unsigned int numberOfDataBlocksToSkip = row / numberOfRowsToAverageOver_;
201  const unsigned int gain =
202  *(range.first + col * lengthOfColumnData + lengthOfAveragedDataInEachColumn * numberOfDataBlocksToSkip) & 0xFF;
203 
204  if (gain == deadFlag_)
205  isDeadColumn = true;
206  else if (gain == noisyFlag_)
207  isNoisyColumn = true;
208 
209  int maxRow = (lengthOfColumnData / lengthOfAveragedDataInEachColumn) * numberOfRowsToAverageOver_ - 1;
210  if (col >= nCols || row > maxRow) {
211  throw cms::Exception("CorruptedData")
212  << "[SiPixelGainCalibrationForHLT::getGain] Pixel out of range: col " << col << " row: " << row;
213  }
214  return decodeGain(gain);
215 }
216 
218  if (gain < minGain_ || gain > maxGain_) {
219  throw cms::Exception("InsertFailure") << "[SiPixelGainCalibrationForHLT::encodeGain] Trying to encode gain ("
220  << gain << ") out of range [" << minGain_ << "," << maxGain_ << "]\n";
221  } else {
222  float precision = (maxGain_ - minGain_) / static_cast<float>(nBinsToUseForEncoding_);
223  float encodedGain = (float)((gain - minGain_) / precision);
224  return encodedGain;
225  }
226 }
227 
229  if (ped < minPed_ || ped > maxPed_) {
230  throw cms::Exception("InsertFailure") << "[SiPixelGainCalibrationForHLT::encodePed] Trying to encode pedestal ("
231  << ped << ") out of range [" << minPed_ << "," << maxPed_ << "]\n";
232  } else {
233  float precision = (maxPed_ - minPed_) / static_cast<float>(nBinsToUseForEncoding_);
234  float encodedPed = (float)((ped - minPed_) / precision);
235  return encodedPed;
236  }
237 }
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
input
static const std::string input
Definition: EdmProvDump.cc:48
SiPixelGainCalibrationForHLT::getPedAndGain
std::pair< float, float > getPedAndGain(const int &col, const int &row, const Range &range, const int &nCols, bool &isDeadColumn, bool &isNoisyColumn) const
Definition: SiPixelGainCalibrationForHLT.cc:134
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
SiPixelGainCalibrationForHLT::decodePed
float decodePed(unsigned int ped) const
Definition: SiPixelGainCalibrationForHLT.h:111
SiPixelGainCalibrationForHLT::SiPixelGainCalibrationForHLT
SiPixelGainCalibrationForHLT()
Definition: SiPixelGainCalibrationForHLT.cc:9
SiPixelGainCalibrationForHLT::minPed_
float minPed_
Definition: SiPixelGainCalibrationForHLT.h:115
SiPixelGainCalibrationForHLT::DetRegistry::ibegin
uint32_t ibegin
Definition: SiPixelGainCalibrationForHLT.h:38
SiPixelGainCalibrationForHLT::getPed
float getPed(const int &col, const int &row, const Range &range, const int &nCols, bool &isDeadColumn, bool &isNoisyColumn) const
Definition: SiPixelGainCalibrationForHLT.cc:162
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cuy.col
col
Definition: cuy.py:1010
pos
Definition: PixelAliasList.h:18
SiPixelGainCalibrationForHLT::v_pedestals
std::vector< char > v_pedestals
Definition: SiPixelGainCalibrationForHLT.h:113
SiPixelGainCalibrationForHLT::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiPixelGainCalibrationForHLT.h:51
SiPixelGainCalibrationForHLT::numberOfRowsToAverageOver_
unsigned int numberOfRowsToAverageOver_
Definition: SiPixelGainCalibrationForHLT.h:120
SiPixelGainCalibrationForHLT.h
SiPixelGainCalibrationForHLT::minGain_
float minGain_
Definition: SiPixelGainCalibrationForHLT.h:115
SiPixelGainCalibrationForHLT::maxPed_
float maxPed_
Definition: SiPixelGainCalibrationForHLT.h:115
SiPixelGainCalibrationForHLT::put
bool put(const uint32_t &detID, Range input, const int &nCols)
Definition: SiPixelGainCalibrationForHLT.cc:46
DetId
Definition: DetId.h:17
SiPixelGainCalibrationForHLT::setData
void setData(float ped, float gain, std::vector< char > &vped, bool thisColumnIsDead=false, bool thisColumnIsNoisy=false)
Definition: SiPixelGainCalibrationForHLT.cc:108
SiPixelGainCalibrationForHLT::encodeGain
float encodeGain(const float &gain)
Definition: SiPixelGainCalibrationForHLT.cc:217
SiPixelGainCalibrationForHLT::getNCols
const int getNCols(const uint32_t &detID) const
Definition: SiPixelGainCalibrationForHLT.cc:66
SiPixelGainCalibrationForHLT::noisyFlag_
unsigned int noisyFlag_
Definition: SiPixelGainCalibrationForHLT.h:124
mps_fire.end
end
Definition: mps_fire.py:242
SiPixelGainCalibrationForHLT::getDetIds
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: SiPixelGainCalibrationForHLT.cc:99
SiPixelGainCalibrationForHLT::decodeGain
float decodeGain(unsigned int gain) const
Definition: SiPixelGainCalibrationForHLT.h:110
SiPixelGainCalibrationForHLT::DetRegistry
Definition: SiPixelGainCalibrationForHLT.h:36
SiPixelGainCalibrationForHLT::gainPrecision
float gainPrecision
Definition: SiPixelGainCalibrationForHLT.h:117
SiPixelGainCalibrationForHLT::encodePed
float encodePed(const float &ped)
Definition: SiPixelGainCalibrationForHLT.cc:228
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
common_cff.precision
precision
Definition: common_cff.py:44
SiPixelGainCalibrationForHLT::pedPrecision
float pedPrecision
Definition: SiPixelGainCalibrationForHLT.h:117
sistrip::extrainfo::gain_
static const char gain_[]
Definition: ConstantsForDqm.h:39
SiPixelGainCalibrationForHLT::DetRegistry::detid
uint32_t detid
Definition: SiPixelGainCalibrationForHLT.h:37
SiPixelGainCalibrationForHLT::maxGain_
float maxGain_
Definition: SiPixelGainCalibrationForHLT.h:115
SiPixelGainCalibrationForHLT::indexes
std::vector< DetRegistry > indexes
Definition: SiPixelGainCalibrationForHLT.h:114
SiPixelGainCalibrationForHLT::initialize
void initialize()
Definition: SiPixelGainCalibrationForHLT.cc:41
SiPixelGainCalibrationForHLT::DetRegistry::ncols
int ncols
Definition: SiPixelGainCalibrationForHLT.h:40
SiPixelGainCalibrationForHLT::getRangeAndNCols
const std::pair< const Range, const int > getRangeAndNCols(const uint32_t &detID) const
Definition: SiPixelGainCalibrationForHLT.cc:88
PedestalClient_cfi.gain
gain
Definition: PedestalClient_cfi.py:37
SiPixelGainCalibrationForHLT::RegistryIterator
Registry::const_iterator RegistryIterator
Definition: SiPixelGainCalibrationForHLT.h:53
SiPixelGainCalibrationForHLT::deadFlag_
unsigned int deadFlag_
Definition: SiPixelGainCalibrationForHLT.h:123
SiPixelGainCalibrationForHLT::getGain
float getGain(const int &col, const int &row, const Range &range, const int &nCols, bool &isDeadColumn, bool &isNoisyColumn) const
Definition: SiPixelGainCalibrationForHLT.cc:191
SiPixelGainCalibrationForHLT::getRange
const Range getRange(const uint32_t &detID) const
Definition: SiPixelGainCalibrationForHLT.cc:77
SiPixelGainCalibrationForHLT::StrictWeakOrdering
Definition: SiPixelGainCalibrationForHLT.h:45
Exception
Definition: hltDiff.cc:245
Exception.h
sd
double sd
Definition: CascadeWrapper.h:113
SiPixelGainCalibrationForHLT::DetRegistry::iend
uint32_t iend
Definition: SiPixelGainCalibrationForHLT.h:39
SiPixelGainCalibrationForHLT::data
std::vector< char > const & data() const
Definition: SiPixelGainCalibrationForHLT.h:74
SiPixelGainCalibrationForHLT::nBinsToUseForEncoding_
unsigned int nBinsToUseForEncoding_
Definition: SiPixelGainCalibrationForHLT.h:122