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:
31 
33 
34 
37 
39 
40  // default inplementation from PixelThresholdClusterizer
41  virtual void calibrate(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 
58 
59 // Abstract template class that defines DB access types and payload specific getters
60 template<class thePayloadObject, class theDBRecordType>
62 
63  public:
66 
67  //Abstract methods
68  float getGain(const uint32_t& detID, const int& col, const int& row) override =0;
69  float getPedestal(const uint32_t& detID, const int& col, const int& row) override =0;
70 
71  bool isDead ( const uint32_t& detID, const int& col, const int& row ) override =0;
72  bool isDeadColumn ( const uint32_t& detID, const int& col, const int& row ) override =0;
73 
74  bool isNoisy ( const uint32_t& detID, const int& col, const int& row ) override =0;
75  bool isNoisyColumn ( const uint32_t& detID, const int& col, const int& row ) override =0;
76 
77  void setESObjects(const edm::EventSetup& es ) override;
78 
79  thePayloadObject const & payload() const { return *ped; }
80 
81  std::vector<uint32_t> getDetIds() override;
82  double getGainLow() override;
83  double getGainHigh() override;
84  double getPedLow() override;
85  double getPedHigh() override;
86 
87  protected:
88 
89  float getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel) ;
90  float getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDeadPixel, bool& isNoisyPixel) ;
91 
92  // the getByColumn functions caches the data to prevent multiple lookups on averaged quanitities
93  float getPedestalByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
94  float getGainByColumn(const uint32_t& detID,const int& col, const int& row, bool& isDeadColumn, bool& isNoisyColumn) ;
95 
96  void throwExepctionForBadRead(std::string payload, const uint32_t& detID, const int& col, const int& row, double value = -1) const;
97 
98 
103  double gainLow_;
104  double gainHigh_;
105  double pedLow_;
106  double pedHigh_;
107 
108  uint32_t old_detID;
109  int old_cols;
110  // Cache data for payloads that average over columns
111 
112  // these two quantities determine what column averaged block we are in - i.e. ROC 1 or ROC 2
115 
124 
126 };
127 
128 template<class thePayloadObject, class theDBRecordType>
130  conf_(conf),
131  ESetupInit_(false)
132 {
133 
134  edm::LogInfo("SiPixelGainCalibrationServicePayloadGetter") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]";
135  // Initialize cache variables
136  old_detID = 0;
137  oldColumnIndexGain_ = -1;
138  oldColumnIndexPed_ = -1;
139  oldColumnValueGain_ = 0.;
140  oldColumnValuePed_ = 0.;
141 
144  oldThisColumnIsDeadGain_ = false;
145  oldThisColumnIsDeadPed_ = false;
147  oldThisColumnIsNoisyPed_ = false;
148 
149 }
150 
151 template<class thePayloadObject, class theDBRecordType>
153 
154  es.get<theDBRecordType>().get(ped);
155  // ped->initialize(); moved to cond infrastructure
156  numberOfRowsAveragedOver_ = ped->getNumberOfRowsToAverageOver();
157  ESetupInit_ = true;
158 
159 }
160 
161 template<class thePayloadObject, class theDBRecordType>
163 
164  std::vector<uint32_t> vdetId_;
165  ped->getDetIds(vdetId_);
166  return vdetId_;
167 
168 }
169 
170 template<class thePayloadObject, class theDBRecordType>
172  double gainLow_ = ped->getGainLow();
173  return gainLow_;
174 }
175 
176 template<class thePayloadObject, class theDBRecordType>
178  double gainHigh_ = ped->getGainHigh();
179  return gainHigh_;
180 }
181 
182 template<class thePayloadObject, class theDBRecordType>
184  double pedLow_ = ped->getPedLow();
185  return pedLow_;
186 }
187 
188 template<class thePayloadObject, class theDBRecordType>
190  double pedHigh_ = ped->getPedHigh();
191  return pedHigh_;
192 }
193 
194 template<class thePayloadObject, class theDBRecordType>
195 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getPedestalByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
196  if(ESetupInit_) {
197  //&&&&&&&&&&&&&&&&&&&&
198  //Access from DB
199  //&&&&&&&&&&&&&&&&&&&&
200  if (detID != old_detID){
201  old_detID=detID;
202  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
203  old_range = rangeAndNCols.first;
204  old_cols = rangeAndNCols.second;
205  oldColumnIndexGain_ = -1;
206  }
207  //std::cout<<" Pedestal "<<ped->getPed(col, row, old_range, old_cols)<<std::endl;
208  return ped->getPed(col, row, old_range, old_cols, isDead, isNoisy);
209  } else throw cms::Exception("NullPointer")
210  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByPixel] SiPixelGainCalibrationRcd not initialized ";
211 }
212 
213 
214 template<class thePayloadObject, class theDBRecordType>
215 float SiPixelGainCalibrationServicePayloadGetter<thePayloadObject,theDBRecordType>::getGainByPixel(const uint32_t& detID,const int& col, const int& row, bool& isDead, bool& isNoisy) {
216  if(ESetupInit_) {
217  //&&&&&&&&&&&&&&&&&&&&
218  //Access from DB
219  //&&&&&&&&&&&&&&&&&&&&
220  if (detID != old_detID){
221  old_detID=detID;
222  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
223  old_range = rangeAndNCols.first;
224  old_cols = rangeAndNCols.second;
225  return oldColumnValuePed_;
226  }
227  return ped->getGain(col, row, old_range, old_cols, isDead, isNoisy);
228  } else throw cms::Exception("NullPointer")
229  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByPixel] SiPixelGainCalibrationRcd not initialized ";
230 }
231 
232 
233 template<class thePayloadObject, class theDBRecordType>
235  if(ESetupInit_) {
236  //&&&&&&&&&&&&&&&&&&&&
237  //Access from DB
238  //&&&&&&&&&&&&&&&&&&&&
239  // see if we are in the same averaged data block
240  bool inTheSameAveragedDataBlock = false;
242  inTheSameAveragedDataBlock = true;
243 
244  if (detID != old_detID){
245  old_detID=detID;
246  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
247  old_range = rangeAndNCols.first;
248  old_cols = rangeAndNCols.second;
249  oldColumnIndexGain_ = -1;
250  }
251  else if (col == oldColumnIndexPed_ && inTheSameAveragedDataBlock) // same DetID, same column, same data block
252  {
253  isDeadColumn = oldThisColumnIsDeadPed_;
254  isNoisyColumn = oldThisColumnIsNoisyPed_;
255  return oldColumnValuePed_;
256  }
257 
260  oldColumnValuePed_ = ped->getPed(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
263 
264  return oldColumnValuePed_;
265 
266  } else throw cms::Exception("NullPointer")
267  << "[SiPixelGainCalibrationServicePayloadGetter::getPedestalByColumn] SiPixelGainCalibrationRcd not initialized ";
268 }
269 
270 
271 template<class thePayloadObject, class theDBRecordType>
273  if(ESetupInit_) {
274  //&&&&&&&&&&&&&&&&&&&&
275  //Access from DB
276  //&&&&&&&&&&&&&&&&&&&&
277  bool inTheSameAveragedDataBlock = false;
279  inTheSameAveragedDataBlock = true;
280 
281  if (detID != old_detID){
282  old_detID=detID;
283  std::pair<const typename thePayloadObject::Range, const int> rangeAndNCols = ped->getRangeAndNCols(detID);
284  old_range = rangeAndNCols.first;
285  old_cols = rangeAndNCols.second;
286  oldColumnIndexPed_ = -1;
287  }
288  else if (col == oldColumnIndexGain_ && inTheSameAveragedDataBlock) // same DetID, same column
289  {
290  isDeadColumn = oldThisColumnIsDeadGain_;
291  isDeadColumn = oldThisColumnIsNoisyGain_;
292  return oldColumnValueGain_;
293  }
294 
297  oldColumnValueGain_ = ped->getGain(col, row, old_range, old_cols, isDeadColumn, isNoisyColumn);
300 
301  return oldColumnValueGain_;
302 
303  } else throw cms::Exception("NullPointer")
304  << "[SiPixelGainCalibrationServicePayloadGetter::getGainByColumn] SiPixelGainCalibrationRcd not initialized ";
305 }
306 
307 template<class thePayloadObject, class theDBRecordType>
309 {
310  std::cerr << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
311  << "[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: "
312  << 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;
313 
314  // really yell if this occurs
315 
316  edm::LogError("SiPixelGainCalibrationService") << "[SiPixelGainCalibrationServicePayloadGetter::SiPixelGainCalibrationServicePayloadGetter]"
317  << "[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: "
318  << 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;
319 }
320 
321 
322 #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:120
SiPixelGainCalibrationServicePayloadGetter(const edm::ParameterSet &conf)
T get() const
Definition: EventSetup.h:71
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: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