CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
17 // Framework
23 #include <iostream>
24 #include <utility>
25 
26 // Abstract base class provides common interface to different payload getters
28  public:
31  virtual float getGain ( const uint32_t& detID , const int& col , const int& row)=0;
32  virtual float getPedestal ( const uint32_t& detID , const int& col , const int& row)=0;
33  virtual bool isDead ( const uint32_t& detID , const int& col , const int& row)=0;
34  virtual bool isDeadColumn ( const uint32_t& detID , const int& col , const int& row)=0;
35  virtual bool isNoisy ( const uint32_t& detID , const int& col , const int& row)=0;
36  virtual bool isNoisyColumn ( const uint32_t& detID , const int& col , const int& row)=0;
37  virtual void setESObjects(const edm::EventSetup& es )=0;
38  virtual std::vector<uint32_t> getDetIds()=0;
39  virtual double getGainLow()=0;
40  virtual double getGainHigh()=0;
41  virtual double getPedLow()=0;
42  virtual double getPedHigh()=0;
43 };
44 
45 
46 // Abstract template class that defines DB access types and payload specific getters
47 template<class thePayloadObject, class theDBRecordType>
49 
50  public:
53 
54  //Abstract methods
55  virtual float getGain(const uint32_t& detID, const int& col, const int& row)=0;
56  virtual float getPedestal(const uint32_t& detID, const int& col, const int& row)=0;
57 
58  virtual bool isDead ( const uint32_t& detID, const int& col, const int& row )=0;
59  virtual bool isDeadColumn ( const uint32_t& detID, const int& col, const int& row )=0;
60 
61  virtual bool isNoisy ( const uint32_t& detID, const int& col, const int& row )=0;
62  virtual bool isNoisyColumn ( const uint32_t& detID, const int& col, const int& row )=0;
63 
64  void setESObjects(const edm::EventSetup& es );
65 
66  std::vector<uint32_t> getDetIds();
67  double getGainLow();
68  double getGainHigh();
69  double getPedLow();
70  double getPedHigh();
71 
72  protected:
73 
74  float getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel) ;
75  float getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel) ;
76 
77  // the getByColumn functions caches the data to prevent multiple lookups on averaged quanitities
78  float getPedestalByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
79  float getGainByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
80 
81  void throwExepctionForBadRead(std::string payload, const uint32_t& detID, const int& col, const int& row, double value = -1) const;
82 
83  private:
84 
89  double gainLow_;
90  double gainHigh_;
91  double pedLow_;
92  double pedHigh_;
93 
94  uint32_t old_detID;
95  int old_cols;
96  // Cache data for payloads that average over columns
97 
98  // these two quantities determine what column averaged block we are in - i.e. ROC 1 or ROC 2
101 
110 
112 };
113 
114 template<class thePayloadObject, class theDBRecordType>
116  conf_(conf),
117  ESetupInit_(false)
118 {
119 
120  edm::LogInfo("SiPixelGainCalibrationServicePayloadGetter") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]";
121  // Initialize cache variables
122  old_detID = 0;
123  oldColumnIndexGain_ = -1;
124  oldColumnIndexPed_ = -1;
125  oldColumnValueGain_ = 0.;
126  oldColumnValuePed_ = 0.;
127 
130  oldThisColumnIsDeadGain_ = false;
131  oldThisColumnIsDeadPed_ = false;
133  oldThisColumnIsNoisyPed_ = false;
134 
135 }
136 
137 template<class thePayloadObject, class theDBRecordType>
139 
140  es.get<theDBRecordType>().get(ped);
141  numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
142  ESetupInit_ = true;
143 
144 }
145 
146 template<class thePayloadObject, class theDBRecordType>
148 
149  std::vector<uint32_t> vdetId_;
150  ped->getDetIds(vdetId_);
151  return vdetId_;
152 
153 }
154 
155 template<class thePayloadObject, class theDBRecordType>
157  double gainLow_ = ped->getGainLow();
158  return gainLow_;
159 }
160 
161 template<class thePayloadObject, class theDBRecordType>
163  double gainHigh_ = ped->getGainHigh();
164  return gainHigh_;
165 }
166 
167 template<class thePayloadObject, class theDBRecordType>
169  double pedLow_ = ped->getPedLow();
170  return pedLow_;
171 }
172 
173 template<class thePayloadObject, class theDBRecordType>
175  double pedHigh_ = ped->getPedHigh();
176  return pedHigh_;
177 }
178 
179 template<class thePayloadObject, class theDBRecordType>
180 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
181  if(ESetupInit_) {
182  //&&&&&&&&&&&&&&&&&&&&
183  //Access from DB
184  //&&&&&&&&&&&&&&&&&&&&
185  if (detID != old_detID){
186  old_detID=detID;
187  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
188  old_range = rangeAndNCols.first;
189  old_cols = rangeAndNCols.second;
190  }
191  //std::cout<<" Pedestal "<<ped->getPed(col, row, old_range, old_cols)<<std::endl;
192  return ped->getPed(col, row, old_range, old_cols, isDead, isNoisy);
193  } else throw cms::Exception("NullPointer")
194  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByPixel] SiPixelGainCalibrationRcd not initialized ";
195 }
196 
197 
198 template<class thePayloadObject, class theDBRecordType>
199 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
200  if(ESetupInit_) {
201  //&&&&&&&&&&&&&&&&&&&&
202  //Access from DB
203  //&&&&&&&&&&&&&&&&&&&&
204  if (detID != old_detID){
205  old_detID=detID;
206  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
207  old_range = rangeAndNCols.first;
208  old_cols = rangeAndNCols.second;
209  }
210  return ped->getGain(col, row, old_range, old_cols, isDead, isNoisy);
211  } else throw cms::Exception("NullPointer")
212  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByPixel] SiPixelGainCalibrationRcd not initialized ";
213 }
214 
215 
216 template<class thePayloadObject, class theDBRecordType>
217 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getPedestalByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) {
218  if(ESetupInit_) {
219  //&&&&&&&&&&&&&&&&&&&&
220  //Access from DB
221  //&&&&&&&&&&&&&&&&&&&&
222  // see if we are in the same averaged data block
223  bool inTheSameAveragedDataBlock = false;
224  if ( row / numberOfRowsAveragedOver_ == oldAveragedBlockDataPed_ )
225  inTheSameAveragedDataBlock = true;
226 
227  if (detID != old_detID){
228  old_detID=detID;
229  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
230  old_range = rangeAndNCols.first;
231  old_cols = rangeAndNCols.second;
232  }
233  else if (col == oldColumnIndexPed_ && inTheSameAveragedDataBlock) // same DetID, same column, same data block
234  {
235  isDeadColumn = oldThisColumnIsDeadPed_;
236  isNoisyColumn = oldThisColumnIsNoisyPed_;
237  return oldColumnValuePed_;
238  }
239 
240  oldColumnIndexPed_ = col;
241  oldAveragedBlockDataPed_ = row / numberOfRowsAveragedOver_;
242  oldColumnValuePed_ = ped->getPed(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
243  oldThisColumnIsDeadPed_ = isDeadColumn;
244  oldThisColumnIsNoisyPed_ = isNoisyColumn;
245 
246  return oldColumnValuePed_;
247 
248  } else throw cms::Exception("NullPointer")
249  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByColumn] SiPixelGainCalibrationRcd not initialized ";
250 }
251 
252 
253 template<class thePayloadObject, class theDBRecordType>
254 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getGainByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) {
255  if(ESetupInit_) {
256  //&&&&&&&&&&&&&&&&&&&&
257  //Access from DB
258  //&&&&&&&&&&&&&&&&&&&&
259  bool inTheSameAveragedDataBlock = false;
260  if ( row / numberOfRowsAveragedOver_ == oldAveragedBlockDataGain_ )
261  inTheSameAveragedDataBlock = true;
262 
263  if (detID != old_detID){
264  old_detID=detID;
265  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
266  old_range = rangeAndNCols.first;
267  old_cols = rangeAndNCols.second;
268  }
269  else if (col == oldColumnIndexGain_ && inTheSameAveragedDataBlock) // same DetID, same column
270  {
271  isDeadColumn = oldThisColumnIsDeadGain_;
272  isDeadColumn = oldThisColumnIsNoisyGain_;
273  return oldColumnValueGain_;
274  }
275 
276  oldColumnIndexGain_ = col;
277  oldAveragedBlockDataGain_ = row / numberOfRowsAveragedOver_;
278  oldColumnValueGain_ = ped->getGain(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
279  oldThisColumnIsDeadGain_ = isDeadColumn;
280  oldThisColumnIsNoisyGain_ = isNoisyColumn;
281 
282  return oldColumnValueGain_;
283 
284  } else throw cms::Exception("NullPointer")
285  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByColumn] SiPixelGainCalibrationRcd not initialized ";
286 }
287 
288 template<class thePayloadObject, class theDBRecordType>
289 void SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::throwExepctionForBadRead(std::string payload, const uint32_t& detID, const int& col, const int& row, const double value) const
290 {
291  std::cerr << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
292  << "[SiPixelGainCalibrationServicePayloadGetter] ERROR - Slow down, speed racer! You have tried to read the ped/gain on a pixel that is flagged as dead/noisy. For payload: " << payload << " DETID: "
293  << detID << " col: " << col << " row: " << row << ". You must check if the pixel is dead/noisy before asking for the ped/gain value, otherwise you will get corrupt data! value: " << value << std::endl;
294 
295  // really yell if this occurs
296 
297  edm::LogError("SiPixelGainCalibrationService") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
298  << "[SiPixelGainCalibrationServicePayloadGetter] ERROR - Slow down, speed racer! You have tried to read the ped/gain on a pixel that is flagged as dead/noisy. For payload: " << payload << " DETID: "
299  << detID << " col: " << col << " row: " << row << ". You must check if the pixel is dead/noisy before asking for the ped/gain value, otherwise you will get corrupt data! value: " << value << std::endl;
300 }
301 
302 
303 #endif
float getGainByPixel(const uint32_t &detID, const int &col, const int &row, bool &isDeadPixel, bool &isNoisyPixel)
virtual void setESObjects(const edm::EventSetup &es)=0
virtual bool isNoisyColumn(const uint32_t &detID, const int &col, const int &row)=0
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
virtual bool isDeadColumn(const uint32_t &detID, const int &col, const int &row)=0
virtual std::vector< uint32_t > getDetIds()=0
virtual float getGain(const uint32_t &detID, const int &col, const int &row)=0
virtual bool isDead(const uint32_t &detID, const int &col, const int &row)=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)
virtual float getPedestal(const uint32_t &detID, const int &col, const int &row)=0
void throwExepctionForBadRead(std::string payload, const uint32_t &detID, const int &col, const int &row, double value=-1) const
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
tuple conf
Definition: dbtoconf.py:185
PixelRecoRange< float > Range
const T & get() const
Definition: EventSetup.h:55
SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet &conf)
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
virtual bool isNoisy(const uint32_t &detID, const int &col, const int &row)=0