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  thePayloadObject const & payload() const { return *ped; }
77 
78  std::vector<uint32_t> getDetIds() override;
79  double getGainLow() override;
80  double getGainHigh() override;
81  double getPedLow() override;
82  double getPedHigh() override;
83 
84  protected:
85 
86  float getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel) ;
87  float getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel) ;
88 
89  // the getByColumn functions caches the data to prevent multiple lookups on averaged quanitities
90  float getPedestalByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
91  float getGainByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
92 
93  void throwExepctionForBadRead(std::string payload, const uint32_t& detID, const int& col, const int& row, double value = -1) const;
94 
95 
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>
127  conf_(conf),
128  ESetupInit_(false)
129 {
130 
131  edm::LogInfo("SiPixelGainCalibrationServicePayloadGetter") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]";
132  // Initialize cache variables
133  old_detID = 0;
134  oldColumnIndexGain_ = -1;
135  oldColumnIndexPed_ = -1;
136  oldColumnValueGain_ = 0.;
137  oldColumnValuePed_ = 0.;
138 
141  oldThisColumnIsDeadGain_ = false;
142  oldThisColumnIsDeadPed_ = false;
144  oldThisColumnIsNoisyPed_ = false;
145 
146 }
147 
148 template<class thePayloadObject, class theDBRecordType>
150 
151  es.get<theDBRecordType>().get(ped);
152  // ped->initialize(); moved to cond infrastructure
153  numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
154  ESetupInit_ = true;
155 
156 }
157 
158 template<class thePayloadObject, class theDBRecordType>
160 
161  std::vector<uint32_t> vdetId_;
162  ped->getDetIds(vdetId_);
163  return vdetId_;
164 
165 }
166 
167 template<class thePayloadObject, class theDBRecordType>
169  double gainLow_ = ped->getGainLow();
170  return gainLow_;
171 }
172 
173 template<class thePayloadObject, class theDBRecordType>
175  double gainHigh_ = ped->getGainHigh();
176  return gainHigh_;
177 }
178 
179 template<class thePayloadObject, class theDBRecordType>
181  double pedLow_ = ped->getPedLow();
182  return pedLow_;
183 }
184 
185 template<class thePayloadObject, class theDBRecordType>
187  double pedHigh_ = ped->getPedHigh();
188  return pedHigh_;
189 }
190 
191 template<class thePayloadObject, class theDBRecordType>
192 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
193  if(ESetupInit_) {
194  //&&&&&&&&&&&&&&&&&&&&
195  //Access from DB
196  //&&&&&&&&&&&&&&&&&&&&
197  if (detID != old_detID){
198  old_detID=detID;
199  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
200  old_range = rangeAndNCols.first;
201  old_cols = rangeAndNCols.second;
202  oldColumnIndexGain_ = -1;
203  }
204  //std::cout<<" Pedestal "<<ped->getPed(col, row, old_range, old_cols)<<std::endl;
205  return ped->getPed(col, row, old_range, old_cols, isDead, isNoisy);
206  } else throw cms::Exception("NullPointer")
207  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByPixel] SiPixelGainCalibrationRcd not initialized ";
208 }
209 
210 
211 template<class thePayloadObject, class theDBRecordType>
212 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
213  if(ESetupInit_) {
214  //&&&&&&&&&&&&&&&&&&&&
215  //Access from DB
216  //&&&&&&&&&&&&&&&&&&&&
217  if (detID != old_detID){
218  old_detID=detID;
219  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
220  old_range = rangeAndNCols.first;
221  old_cols = rangeAndNCols.second;
222  return oldColumnValuePed_;
223  }
224  return ped->getGain(col, row, old_range, old_cols, isDead, isNoisy);
225  } else throw cms::Exception("NullPointer")
226  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByPixel] SiPixelGainCalibrationRcd not initialized ";
227 }
228 
229 
230 template<class thePayloadObject, class theDBRecordType>
232  if(ESetupInit_) {
233  //&&&&&&&&&&&&&&&&&&&&
234  //Access from DB
235  //&&&&&&&&&&&&&&&&&&&&
236  // see if we are in the same averaged data block
237  bool inTheSameAveragedDataBlock = false;
239  inTheSameAveragedDataBlock = true;
240 
241  if (detID != old_detID){
242  old_detID=detID;
243  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
244  old_range = rangeAndNCols.first;
245  old_cols = rangeAndNCols.second;
246  oldColumnIndexGain_ = -1;
247  }
248  else if (col == oldColumnIndexPed_ && inTheSameAveragedDataBlock) // same DetID, same column, same data block
249  {
250  isDeadColumn = oldThisColumnIsDeadPed_;
251  isNoisyColumn = oldThisColumnIsNoisyPed_;
252  return oldColumnValuePed_;
253  }
254 
257  oldColumnValuePed_ = ped->getPed(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
260 
261  return oldColumnValuePed_;
262 
263  } else throw cms::Exception("NullPointer")
264  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByColumn] SiPixelGainCalibrationRcd not initialized ";
265 }
266 
267 
268 template<class thePayloadObject, class theDBRecordType>
270  if(ESetupInit_) {
271  //&&&&&&&&&&&&&&&&&&&&
272  //Access from DB
273  //&&&&&&&&&&&&&&&&&&&&
274  bool inTheSameAveragedDataBlock = false;
276  inTheSameAveragedDataBlock = true;
277 
278  if (detID != old_detID){
279  old_detID=detID;
280  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
281  old_range = rangeAndNCols.first;
282  old_cols = rangeAndNCols.second;
283  oldColumnIndexPed_ = -1;
284  }
285  else if (col == oldColumnIndexGain_ && inTheSameAveragedDataBlock) // same DetID, same column
286  {
287  isDeadColumn = oldThisColumnIsDeadGain_;
288  isDeadColumn = oldThisColumnIsNoisyGain_;
289  return oldColumnValueGain_;
290  }
291 
294  oldColumnValueGain_ = ped->getGain(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
297 
298  return oldColumnValueGain_;
299 
300  } else throw cms::Exception("NullPointer")
301  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByColumn] SiPixelGainCalibrationRcd not initialized ";
302 }
303 
304 template<class thePayloadObject, class theDBRecordType>
306 {
307  std::cerr << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
308  << "[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: "
309  << 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;
310 
311  // really yell if this occurs
312 
313  edm::LogError("SiPixelGainCalibrationService") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
314  << "[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: "
315  << 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;
316 }
317 
318 
319 #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
double b
Definition: hdecay.h:120
SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet &conf)
T get() const
Definition: EventSetup.h:63
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: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