CMS 3D CMS Logo

SiPixelGainCalibrationServiceBase.h
Go to the documentation of this file.
1 #ifndef CalibTracker_SiPixelESProducers_SiPixelGainCalibrationServiceBase_H
2 #define CalibTracker_SiPixelESProducers_SiPixelGainCalibrationServiceBase_H
3 
4 // ************************************************************************
5 // ************************************************************************
6 // ******* SiPixelOfflineCalibrationServiceBase *******
7 // ******* Author: Vincenzo Chiochia (chiochia@cern.ch) *******
8 // ******* Modified: Evan Friis (evan.friis@cern.ch) *******
9 // ******* Additions: Freya Blekman (freya.blekman@cern.ch) *******
10 // ******* *******
11 // ******* Provides common interface to SiPixel gain calib *******
12 // ******* payloads in offline database *******
13 // ******* *******
14 // ************************************************************************
15 // ************************************************************************
16 
19 
20 // Framework
28 
29 // Abstract base class provides common interface to different payload getters
31 public:
33 
36 
38 
39  // default inplementation from PixelThresholdClusterizer
40  virtual void calibrate(
41  uint32_t detID, DigiIterator b, DigiIterator e, float conversionFactor, float offset, int* electron);
42 
43  virtual float getGain(const uint32_t& detID, const int& col, const int& row) = 0;
44  virtual float getPedestal(const uint32_t& detID, const int& col, const int& row) = 0;
45  virtual bool isDead(const uint32_t& detID, const int& col, const int& row) = 0;
46  virtual bool isDeadColumn(const uint32_t& detID, const int& col, const int& row) = 0;
47  virtual bool isNoisy(const uint32_t& detID, const int& col, const int& row) = 0;
48  virtual bool isNoisyColumn(const uint32_t& detID, const int& col, const int& row) = 0;
49  virtual void setESObjects(const edm::EventSetup& es) = 0;
50  virtual std::vector<uint32_t> getDetIds() = 0;
51  virtual double getGainLow() = 0;
52  virtual double getGainHigh() = 0;
53  virtual double getPedLow() = 0;
54  virtual double getPedHigh() = 0;
55 };
56 
57 // Abstract template class that defines DB access types and payload specific getters
58 template <class thePayloadObject, class theDBRecordType>
60 public:
62 
63  //Abstract methods
64  float getGain(const uint32_t& detID, const int& col, const int& row) override = 0;
65  float getPedestal(const uint32_t& detID, const int& col, const int& row) override = 0;
66 
67  bool isDead(const uint32_t& detID, const int& col, const int& row) override = 0;
68  bool isDeadColumn(const uint32_t& detID, const int& col, const int& row) override = 0;
69 
70  bool isNoisy(const uint32_t& detID, const int& col, const int& row) override = 0;
71  bool isNoisyColumn(const uint32_t& detID, const int& col, const int& row) override = 0;
72 
73  void setESObjects(const edm::EventSetup& es) override;
74 
75  thePayloadObject const& payload() const { return *ped; }
76 
77  std::vector<uint32_t> getDetIds() override;
78  double getGainLow() override;
79  double getGainHigh() override;
80  double getPedLow() override;
81  double getPedHigh() override;
82 
83 protected:
84  float getPedestalByPixel(const uint32_t& detID, const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel);
85  float getGainByPixel(const uint32_t& detID, const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel);
86 
87  // the getByColumn functions caches the data to prevent multiple lookups on averaged quanitities
88  float getPedestalByColumn(
89  const uint32_t& detID, const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn);
90  float getGainByColumn(const uint32_t& detID, const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn);
91 
93  std::string payload, const uint32_t& detID, const int& col, const int& row, double value = -1) const;
94 
98  const thePayloadObject* ped = nullptr;
100  double gainLow_;
101  double gainHigh_;
102  double pedLow_;
103  double pedHigh_;
104 
105  uint32_t old_detID;
106  int old_cols;
107  // Cache data for payloads that average over columns
108 
109  // these two quantities determine what column averaged block we are in - i.e. ROC 1 or ROC 2
112 
121 
123 };
124 
125 template <class thePayloadObject, class theDBRecordType>
128  : conf_(conf), ESetupInit_(false), pedToken_(iC.esConsumes()) {
129  edm::LogInfo("SiPixelGainCalibrationServicePayloadGetter")
130  << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]";
131  // Initialize cache variables
132  old_detID = 0;
133  oldColumnIndexGain_ = -1;
134  oldColumnIndexPed_ = -1;
135  oldColumnValueGain_ = 0.;
136  oldColumnValuePed_ = 0.;
137 
140  oldThisColumnIsDeadGain_ = false;
141  oldThisColumnIsDeadPed_ = false;
143  oldThisColumnIsNoisyPed_ = false;
144 }
145 
146 template <class thePayloadObject, class theDBRecordType>
148  const edm::EventSetup& es) {
149  ped = &es.getData(pedToken_);
150  // ped->initialize(); moved to cond infrastructure
151  numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
152  ESetupInit_ = true;
153 }
154 
155 template <class thePayloadObject, class theDBRecordType>
157  std::vector<uint32_t> vdetId_;
158  ped->getDetIds(vdetId_);
159  return vdetId_;
160 }
161 
162 template <class thePayloadObject, class theDBRecordType>
164  double gainLow_ = ped->getGainLow();
165  return gainLow_;
166 }
167 
168 template <class thePayloadObject, class theDBRecordType>
170  double gainHigh_ = ped->getGainHigh();
171  return gainHigh_;
172 }
173 
174 template <class thePayloadObject, class theDBRecordType>
176  double pedLow_ = ped->getPedLow();
177  return pedLow_;
178 }
179 
180 template <class thePayloadObject, class theDBRecordType>
182  double pedHigh_ = ped->getPedHigh();
183  return pedHigh_;
184 }
185 
186 template <class thePayloadObject, class theDBRecordType>
188  const uint32_t& detID, const int& col, const int& row, bool& isDead, bool& isNoisy) {
189  if (ESetupInit_) {
190  //&&&&&&&&&&&&&&&&&&&&
191  //Access from DB
192  //&&&&&&&&&&&&&&&&&&&&
193  if (detID != old_detID) {
194  old_detID = detID;
195  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
196  old_range = rangeAndNCols.first;
197  old_cols = rangeAndNCols.second;
198  oldColumnIndexGain_ = -1;
199  }
200  //std::cout<<" Pedestal "<<ped->getPed(col, row, old_range, old_cols)<<std::endl;
201  return ped->getPed(col, row, old_range, old_cols, isDead, isNoisy);
202  } else
203  throw cms::Exception("NullPointer") << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByPixel] "
204  "SiPixelGainCalibrationRcd not initialized ";
205 }
206 
207 template <class thePayloadObject, class theDBRecordType>
209  const uint32_t& detID, const int& col, const int& row, bool& isDead, bool& isNoisy) {
210  if (ESetupInit_) {
211  //&&&&&&&&&&&&&&&&&&&&
212  //Access from DB
213  //&&&&&&&&&&&&&&&&&&&&
214  if (detID != old_detID) {
215  old_detID = detID;
216  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
217  old_range = rangeAndNCols.first;
218  old_cols = rangeAndNCols.second;
219  return oldColumnValuePed_;
220  }
221  return ped->getGain(col, row, old_range, old_cols, isDead, isNoisy);
222  } else
223  throw cms::Exception("NullPointer")
224  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByPixel] SiPixelGainCalibrationRcd not initialized ";
225 }
226 
227 template <class thePayloadObject, class theDBRecordType>
229  const uint32_t& detID, const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) {
230  if (ESetupInit_) {
231  //&&&&&&&&&&&&&&&&&&&&
232  //Access from DB
233  //&&&&&&&&&&&&&&&&&&&&
234  // see if we are in the same averaged data block
235  bool inTheSameAveragedDataBlock = false;
236  if (row / numberOfRowsAveragedOver_ == oldAveragedBlockDataPed_)
237  inTheSameAveragedDataBlock = true;
238 
239  if (detID != old_detID) {
240  old_detID = detID;
241  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
242  old_range = rangeAndNCols.first;
243  old_cols = rangeAndNCols.second;
244  oldColumnIndexGain_ = -1;
245  } else if (col == oldColumnIndexPed_ && inTheSameAveragedDataBlock) // same DetID, same column, same data block
246  {
247  isDeadColumn = oldThisColumnIsDeadPed_;
248  isNoisyColumn = oldThisColumnIsNoisyPed_;
249  return oldColumnValuePed_;
250  }
251 
252  oldColumnIndexPed_ = col;
253  oldAveragedBlockDataPed_ = row / numberOfRowsAveragedOver_;
254  oldColumnValuePed_ = ped->getPed(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
255  oldThisColumnIsDeadPed_ = isDeadColumn;
256  oldThisColumnIsNoisyPed_ = isNoisyColumn;
257 
258  return oldColumnValuePed_;
259 
260  } else
261  throw cms::Exception("NullPointer") << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByColumn] "
262  "SiPixelGainCalibrationRcd not initialized ";
263 }
264 
265 template <class thePayloadObject, class theDBRecordType>
267  const uint32_t& detID, const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) {
268  if (ESetupInit_) {
269  //&&&&&&&&&&&&&&&&&&&&
270  //Access from DB
271  //&&&&&&&&&&&&&&&&&&&&
272  bool inTheSameAveragedDataBlock = false;
273  if (row / numberOfRowsAveragedOver_ == oldAveragedBlockDataGain_)
274  inTheSameAveragedDataBlock = true;
275 
276  if (detID != old_detID) {
277  old_detID = detID;
278  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
279  old_range = rangeAndNCols.first;
280  old_cols = rangeAndNCols.second;
281  oldColumnIndexPed_ = -1;
282  } else if (col == oldColumnIndexGain_ && inTheSameAveragedDataBlock) // same DetID, same column
283  {
284  isDeadColumn = oldThisColumnIsDeadGain_;
285  isDeadColumn = oldThisColumnIsNoisyGain_;
286  return oldColumnValueGain_;
287  }
288 
289  oldColumnIndexGain_ = col;
290  oldAveragedBlockDataGain_ = row / numberOfRowsAveragedOver_;
291  oldColumnValueGain_ = ped->getGain(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
292  oldThisColumnIsDeadGain_ = isDeadColumn;
293  oldThisColumnIsNoisyGain_ = isNoisyColumn;
294 
295  return oldColumnValueGain_;
296 
297  } else
298  throw cms::Exception("NullPointer")
299  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByColumn] SiPixelGainCalibrationRcd not initialized ";
300 }
301 
302 template <class thePayloadObject, class theDBRecordType>
304  std::string payload, const uint32_t& detID, const int& col, const int& row, const double value) const {
305  std::cerr << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
306  << "[SiPixelGainCalibrationServicePayloadGetter] ERROR - Slow down, speed racer! You have tried to read "
307  "the ped/gain on a pixel that is flagged as dead/noisy. For payload: "
308  << payload << " DETID: " << detID << " col: " << col << " row: " << row
309  << ". You must check if the pixel is dead/noisy before asking for the ped/gain value, otherwise you will "
310  "get corrupt data! value: "
311  << value << std::endl;
312 
313  // really yell if this occurs
314 
315  edm::LogError("SiPixelGainCalibrationService")
316  << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
317  << "[SiPixelGainCalibrationServicePayloadGetter] ERROR - Slow down, speed racer! You have tried to read the "
318  "ped/gain on a pixel that is flagged as dead/noisy. For payload: "
319  << payload << " DETID: " << detID << " col: " << col << " row: " << row
320  << ". You must check if the pixel is dead/noisy before asking for the ped/gain value, otherwise you will get "
321  "corrupt data! value: "
322  << value << std::endl;
323 }
324 
325 #endif
bool isDeadColumn(const uint32_t &detID, const int &col, const int &row) override=0
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
float getGainByPixel(const uint32_t &detID, const int &col, const int &row, bool &isDeadPixel, bool &isNoisyPixel)
virtual void setESObjects(const edm::EventSetup &es)=0
edm::DetSet< PixelDigi >::const_iterator DigiIterator
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
float getPedestalByPixel(const uint32_t &detID, const int &col, const int &row, bool &isDeadPixel, bool &isNoisyPixel)
PixelRecoRange< float > Range
virtual bool isDeadColumn(const uint32_t &detID, const int &col, const int &row)=0
float getPedestal(const uint32_t &detID, const int &col, const int &row) override=0
virtual std::vector< uint32_t > getDetIds()=0
float getGain(const uint32_t &detID, const int &col, const int &row) override=0
SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
virtual bool isDead(const uint32_t &detID, const int &col, const int &row)=0
Log< level::Error, false > LogError
float getPedestalByColumn(const uint32_t &detID, const int &col, const int &row, bool &isDeadColumn, bool &isNoisyColumn)
float getGainByColumn(const uint32_t &detID, const int &col, const int &row, bool &isDeadColumn, bool &isNoisyColumn)
bool isNoisy(const uint32_t &detID, const int &col, const int &row) override=0
void setESObjects(const edm::EventSetup &es) override
bool isNoisyColumn(const uint32_t &detID, const int &col, const int &row) override=0
Definition: value.py:1
virtual bool isNoisyColumn(const uint32_t &detID, const int &col, const int &row)=0
virtual float getPedestal(const uint32_t &detID, const int &col, const int &row)=0
Log< level::Info, false > LogInfo
static void fillPSetDescription(edm::ParameterSetDescription &desc)
void throwExepctionForBadRead(std::string payload, const uint32_t &detID, const int &col, const int &row, double value=-1) const
double b
Definition: hdecay.h:120
col
Definition: cuy.py:1009
virtual float getGain(const uint32_t &detID, const int &col, const int &row)=0
virtual bool isNoisy(const uint32_t &detID, const int &col, const int &row)=0
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
virtual void calibrate(uint32_t detID, DigiIterator b, DigiIterator e, float conversionFactor, float offset, int *electron)
const edm::ESGetToken< thePayloadObject, theDBRecordType > pedToken_
bool isDead(const uint32_t &detID, const int &col, const int &row) override=0