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
26 
27 // Abstract base class provides common interface to different payload getters
29  public:
30 
32 
33 
36 
37  // default inplementation from PixelThresholdClusterizer
38  virtual void calibrate(uint32_t detID, DigiIterator b, DigiIterator e, float conversionFactor, float offset, int * electron);
39 
40  virtual float getGain ( const uint32_t& detID , const int& col , const int& row)=0;
41  virtual float getPedestal ( const uint32_t& detID , const int& col , const int& row)=0;
42  virtual bool isDead ( const uint32_t& detID , const int& col , const int& row)=0;
43  virtual bool isDeadColumn ( const uint32_t& detID , const int& col , const int& row)=0;
44  virtual bool isNoisy ( const uint32_t& detID , const int& col , const int& row)=0;
45  virtual bool isNoisyColumn ( const uint32_t& detID , const int& col , const int& row)=0;
46  virtual void setESObjects(const edm::EventSetup& es )=0;
47  virtual std::vector<uint32_t> getDetIds()=0;
48  virtual double getGainLow()=0;
49  virtual double getGainHigh()=0;
50  virtual double getPedLow()=0;
51  virtual double getPedHigh()=0;
52 
53 };
54 
55 
56 // Abstract template class that defines DB access types and payload specific getters
57 template<class thePayloadObject, class theDBRecordType>
59 
60  public:
63 
64  //Abstract methods
65  float getGain(const uint32_t& detID, const int& col, const int& row) override =0;
66  float getPedestal(const uint32_t& detID, const int& col, const int& row) override =0;
67 
68  bool isDead ( const uint32_t& detID, const int& col, const int& row ) override =0;
69  bool isDeadColumn ( const uint32_t& detID, const int& col, const int& row ) override =0;
70 
71  bool isNoisy ( const uint32_t& detID, const int& col, const int& row ) override =0;
72  bool isNoisyColumn ( const uint32_t& detID, const int& col, const int& row ) override =0;
73 
74  void setESObjects(const edm::EventSetup& es ) override;
75 
76  std::vector<uint32_t> getDetIds() override;
77  double getGainLow() override;
78  double getGainHigh() override;
79  double getPedLow() override;
80  double getPedHigh() override;
81 
82  protected:
83 
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(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
89  float getGainByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
90 
91  void throwExepctionForBadRead(std::string payload, const uint32_t& detID, const int& col, const int& row, double value = -1) const;
92 
93 
98  double gainLow_;
99  double gainHigh_;
100  double pedLow_;
101  double pedHigh_;
102 
103  uint32_t old_detID;
104  int old_cols;
105  // Cache data for payloads that average over columns
106 
107  // these two quantities determine what column averaged block we are in - i.e. ROC 1 or ROC 2
110 
119 
121 };
122 
123 template<class thePayloadObject, class theDBRecordType>
125  conf_(conf),
126  ESetupInit_(false)
127 {
128 
129  edm::LogInfo("SiPixelGainCalibrationServicePayloadGetter") << "[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 
146 template<class thePayloadObject, class theDBRecordType>
148 
149  es.get<theDBRecordType>().get(ped);
150  // ped->initialize(); moved to cond infrastructure
151  numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
152  ESetupInit_ = true;
153 
154 }
155 
156 template<class thePayloadObject, class theDBRecordType>
158 
159  std::vector<uint32_t> vdetId_;
160  ped->getDetIds(vdetId_);
161  return vdetId_;
162 
163 }
164 
165 template<class thePayloadObject, class theDBRecordType>
167  double gainLow_ = ped->getGainLow();
168  return gainLow_;
169 }
170 
171 template<class thePayloadObject, class theDBRecordType>
173  double gainHigh_ = ped->getGainHigh();
174  return gainHigh_;
175 }
176 
177 template<class thePayloadObject, class theDBRecordType>
179  double pedLow_ = ped->getPedLow();
180  return pedLow_;
181 }
182 
183 template<class thePayloadObject, class theDBRecordType>
185  double pedHigh_ = ped->getPedHigh();
186  return pedHigh_;
187 }
188 
189 template<class thePayloadObject, class theDBRecordType>
190 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
191  if(ESetupInit_) {
192  //&&&&&&&&&&&&&&&&&&&&
193  //Access from DB
194  //&&&&&&&&&&&&&&&&&&&&
195  if (detID != old_detID){
196  old_detID=detID;
197  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
198  old_range = rangeAndNCols.first;
199  old_cols = rangeAndNCols.second;
200  oldColumnIndexGain_ = -1;
201  }
202  //std::cout<<" Pedestal "<<ped->getPed(col, row, old_range, old_cols)<<std::endl;
203  return ped->getPed(col, row, old_range, old_cols, isDead, isNoisy);
204  } else throw cms::Exception("NullPointer")
205  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByPixel] SiPixelGainCalibrationRcd not initialized ";
206 }
207 
208 
209 template<class thePayloadObject, class theDBRecordType>
210 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
211  if(ESetupInit_) {
212  //&&&&&&&&&&&&&&&&&&&&
213  //Access from DB
214  //&&&&&&&&&&&&&&&&&&&&
215  if (detID != old_detID){
216  old_detID=detID;
217  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
218  old_range = rangeAndNCols.first;
219  old_cols = rangeAndNCols.second;
220  return oldColumnValuePed_;
221  }
222  return ped->getGain(col, row, old_range, old_cols, isDead, isNoisy);
223  } else throw cms::Exception("NullPointer")
224  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByPixel] SiPixelGainCalibrationRcd not initialized ";
225 }
226 
227 
228 template<class thePayloadObject, class theDBRecordType>
230  if(ESetupInit_) {
231  //&&&&&&&&&&&&&&&&&&&&
232  //Access from DB
233  //&&&&&&&&&&&&&&&&&&&&
234  // see if we are in the same averaged data block
235  bool inTheSameAveragedDataBlock = false;
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  }
246  else if (col == oldColumnIndexPed_ && inTheSameAveragedDataBlock) // same DetID, same column, same data block
247  {
248  isDeadColumn = oldThisColumnIsDeadPed_;
249  isNoisyColumn = oldThisColumnIsNoisyPed_;
250  return oldColumnValuePed_;
251  }
252 
255  oldColumnValuePed_ = ped->getPed(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
258 
259  return oldColumnValuePed_;
260 
261  } else throw cms::Exception("NullPointer")
262  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByColumn] SiPixelGainCalibrationRcd not initialized ";
263 }
264 
265 
266 template<class thePayloadObject, class theDBRecordType>
268  if(ESetupInit_) {
269  //&&&&&&&&&&&&&&&&&&&&
270  //Access from DB
271  //&&&&&&&&&&&&&&&&&&&&
272  bool inTheSameAveragedDataBlock = false;
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  }
283  else if (col == oldColumnIndexGain_ && inTheSameAveragedDataBlock) // same DetID, same column
284  {
285  isDeadColumn = oldThisColumnIsDeadGain_;
286  isDeadColumn = oldThisColumnIsNoisyGain_;
287  return oldColumnValueGain_;
288  }
289 
292  oldColumnValueGain_ = ped->getGain(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
295 
296  return oldColumnValueGain_;
297 
298  } else throw cms::Exception("NullPointer")
299  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByColumn] SiPixelGainCalibrationRcd not initialized ";
300 }
301 
302 template<class thePayloadObject, class theDBRecordType>
304 {
305  std::cerr << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
306  << "[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: "
307  << 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;
308 
309  // really yell if this occurs
310 
311  edm::LogError("SiPixelGainCalibrationService") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
312  << "[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: "
313  << 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;
314 }
315 
316 
317 #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
const T & get() const
Definition: EventSetup.h:58
double b
Definition: hdecay.h:120
SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet &conf)
col
Definition: cuy.py:1008
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:33
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