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
27 
28 // Abstract base class provides common interface to different payload getters
30 public:
32 
35 
37 
38  // default inplementation from PixelThresholdClusterizer
39  virtual void calibrate(
40  uint32_t detID, DigiIterator b, DigiIterator e, float conversionFactor, float offset, int* electron);
41 
42  virtual float getGain(const uint32_t& detID, const int& col, const int& row) = 0;
43  virtual float getPedestal(const uint32_t& detID, const int& col, const int& row) = 0;
44  virtual bool isDead(const uint32_t& detID, const int& col, const int& row) = 0;
45  virtual bool isDeadColumn(const uint32_t& detID, const int& col, const int& row) = 0;
46  virtual bool isNoisy(const uint32_t& detID, const int& col, const int& row) = 0;
47  virtual bool isNoisyColumn(const uint32_t& detID, const int& col, const int& row) = 0;
48  virtual void setESObjects(const edm::EventSetup& es) = 0;
49  virtual std::vector<uint32_t> getDetIds() = 0;
50  virtual double getGainLow() = 0;
51  virtual double getGainHigh() = 0;
52  virtual double getPedLow() = 0;
53  virtual double getPedHigh() = 0;
54 };
55 
56 // Abstract template class that defines DB access types and payload specific getters
57 template <class thePayloadObject, class theDBRecordType>
59 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 
92  void throwExepctionForBadRead(
93  std::string payload, const uint32_t& detID, const int& col, const int& row, double value = -1) const;
94 
99  double gainLow_;
100  double gainHigh_;
101  double pedLow_;
102  double pedHigh_;
103 
104  uint32_t old_detID;
105  int old_cols;
106  // Cache data for payloads that average over columns
107 
108  // these two quantities determine what column averaged block we are in - i.e. ROC 1 or ROC 2
111 
120 
122 };
123 
124 template <class thePayloadObject, class theDBRecordType>
126  const edm::ParameterSet& conf)
127  : conf_(conf), ESetupInit_(false) {
128  edm::LogInfo("SiPixelGainCalibrationServicePayloadGetter")
129  << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]";
130  // Initialize cache variables
131  old_detID = 0;
132  oldColumnIndexGain_ = -1;
133  oldColumnIndexPed_ = -1;
134  oldColumnValueGain_ = 0.;
135  oldColumnValuePed_ = 0.;
136 
139  oldThisColumnIsDeadGain_ = false;
140  oldThisColumnIsDeadPed_ = false;
142  oldThisColumnIsNoisyPed_ = false;
143 }
144 
145 template <class thePayloadObject, class theDBRecordType>
147  const edm::EventSetup& es) {
148  es.get<theDBRecordType>().get(ped);
149  // ped->initialize(); moved to cond infrastructure
150  numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
151  ESetupInit_ = true;
152 }
153 
154 template <class thePayloadObject, class theDBRecordType>
156  std::vector<uint32_t> vdetId_;
157  ped->getDetIds(vdetId_);
158  return vdetId_;
159 }
160 
161 template <class thePayloadObject, class theDBRecordType>
163  double gainLow_ = ped->getGainLow();
164  return gainLow_;
165 }
166 
167 template <class thePayloadObject, class theDBRecordType>
169  double gainHigh_ = ped->getGainHigh();
170  return gainHigh_;
171 }
172 
173 template <class thePayloadObject, class theDBRecordType>
175  double pedLow_ = ped->getPedLow();
176  return pedLow_;
177 }
178 
179 template <class thePayloadObject, class theDBRecordType>
181  double pedHigh_ = ped->getPedHigh();
182  return pedHigh_;
183 }
184 
185 template <class thePayloadObject, class theDBRecordType>
187  const uint32_t& detID, const int& col, const int& row, bool& isDead, bool& isNoisy) {
188  if (ESetupInit_) {
189  //&&&&&&&&&&&&&&&&&&&&
190  //Access from DB
191  //&&&&&&&&&&&&&&&&&&&&
192  if (detID != old_detID) {
193  old_detID = detID;
194  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
195  old_range = rangeAndNCols.first;
196  old_cols = rangeAndNCols.second;
197  oldColumnIndexGain_ = -1;
198  }
199  //std::cout<<" Pedestal "<<ped->getPed(col, row, old_range, old_cols)<<std::endl;
200  return ped->getPed(col, row, old_range, old_cols, isDead, isNoisy);
201  } else
202  throw cms::Exception("NullPointer") << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByPixel] "
203  "SiPixelGainCalibrationRcd not initialized ";
204 }
205 
206 template <class thePayloadObject, class theDBRecordType>
208  const uint32_t& detID, const int& col, const int& row, bool& isDead, bool& isNoisy) {
209  if (ESetupInit_) {
210  //&&&&&&&&&&&&&&&&&&&&
211  //Access from DB
212  //&&&&&&&&&&&&&&&&&&&&
213  if (detID != old_detID) {
214  old_detID = detID;
215  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
216  old_range = rangeAndNCols.first;
217  old_cols = rangeAndNCols.second;
218  return oldColumnValuePed_;
219  }
220  return ped->getGain(col, row, old_range, old_cols, isDead, isNoisy);
221  } else
222  throw cms::Exception("NullPointer")
223  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByPixel] SiPixelGainCalibrationRcd not initialized ";
224 }
225 
226 template <class thePayloadObject, class theDBRecordType>
228  const uint32_t& detID, const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) {
229  if (ESetupInit_) {
230  //&&&&&&&&&&&&&&&&&&&&
231  //Access from DB
232  //&&&&&&&&&&&&&&&&&&&&
233  // see if we are in the same averaged data block
234  bool inTheSameAveragedDataBlock = false;
236  inTheSameAveragedDataBlock = true;
237 
238  if (detID != old_detID) {
239  old_detID = detID;
240  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
241  old_range = rangeAndNCols.first;
242  old_cols = rangeAndNCols.second;
243  oldColumnIndexGain_ = -1;
244  } else if (col == oldColumnIndexPed_ && inTheSameAveragedDataBlock) // same DetID, same column, same data block
245  {
246  isDeadColumn = oldThisColumnIsDeadPed_;
247  isNoisyColumn = oldThisColumnIsNoisyPed_;
248  return oldColumnValuePed_;
249  }
250 
253  oldColumnValuePed_ = ped->getPed(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
256 
257  return oldColumnValuePed_;
258 
259  } else
260  throw cms::Exception("NullPointer") << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByColumn] "
261  "SiPixelGainCalibrationRcd not initialized ";
262 }
263 
264 template <class thePayloadObject, class theDBRecordType>
266  const uint32_t& detID, const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) {
267  if (ESetupInit_) {
268  //&&&&&&&&&&&&&&&&&&&&
269  //Access from DB
270  //&&&&&&&&&&&&&&&&&&&&
271  bool inTheSameAveragedDataBlock = false;
273  inTheSameAveragedDataBlock = true;
274 
275  if (detID != old_detID) {
276  old_detID = detID;
277  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
278  old_range = rangeAndNCols.first;
279  old_cols = rangeAndNCols.second;
280  oldColumnIndexPed_ = -1;
281  } else if (col == oldColumnIndexGain_ && inTheSameAveragedDataBlock) // same DetID, same column
282  {
283  isDeadColumn = oldThisColumnIsDeadGain_;
284  isDeadColumn = oldThisColumnIsNoisyGain_;
285  return oldColumnValueGain_;
286  }
287 
290  oldColumnValueGain_ = ped->getGain(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
293 
294  return oldColumnValueGain_;
295 
296  } else
297  throw cms::Exception("NullPointer")
298  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByColumn] SiPixelGainCalibrationRcd not initialized ";
299 }
300 
301 template <class thePayloadObject, class theDBRecordType>
303  std::string payload, const uint32_t& detID, const int& col, const int& row, const double value) const {
304  std::cerr << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
305  << "[SiPixelGainCalibrationServicePayloadGetter] ERROR - Slow down, speed racer! You have tried to read "
306  "the ped/gain on a pixel that is flagged as dead/noisy. For payload: "
307  << payload << " DETID: " << detID << " col: " << col << " row: " << row
308  << ". You must check if the pixel is dead/noisy before asking for the ped/gain value, otherwise you will "
309  "get corrupt data! value: "
310  << value << std::endl;
311 
312  // really yell if this occurs
313 
314  edm::LogError("SiPixelGainCalibrationService")
315  << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
316  << "[SiPixelGainCalibrationServicePayloadGetter] ERROR - Slow down, speed racer! You have tried to read the "
317  "ped/gain on a pixel that is flagged as dead/noisy. For payload: "
318  << payload << " DETID: " << detID << " col: " << col << " row: " << row
319  << ". You must check if the pixel is dead/noisy before asking for the ped/gain value, otherwise you will get "
320  "corrupt data! value: "
321  << value << std::endl;
322 }
323 
324 #endif
bool isDeadColumn(const uint32_t &detID, const int &col, const int &row) override=0
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
float getPedestalByPixel(const uint32_t &detID, const int &col, const int &row, bool &isDeadPixel, bool &isNoisyPixel)
virtual bool isDeadColumn(const uint32_t &detID, const int &col, const int &row)=0
PixelRecoRange< float > Range
virtual std::vector< uint32_t > getDetIds()=0
virtual bool isDead(const uint32_t &detID, const int &col, const int &row)=0
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)
void throwExepctionForBadRead(std::string payload, const uint32_t &detID, const int &col, const int &row, double value=-1) const
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
static void fillPSetDescription(edm::ParameterSetDescription &desc)
double b
Definition: hdecay.h:118
SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet &conf)
T get() const
Definition: EventSetup.h:73
col
Definition: cuy.py:1010
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:32
virtual void calibrate(uint32_t detID, DigiIterator b, DigiIterator e, float conversionFactor, float offset, int *electron)
bool isDead(const uint32_t &detID, const int &col, const int &row) override=0