CMS 3D CMS Logo

SiPixelStatusHarvester.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * author
6  */
7 
8 // CMSSW FW
21 // Pixel geometry and cabling map
24 // Condition Format
26 
27 // CondOutput
29 // Dataformat of SiPixel status in ALCAPROMPT data
31 //#include "CondCore/Utilities/bin/cmscond_export_iov.cpp"
32 //#include "CondCore/Utilities/interface/Utilities.h"
33 // harvest helper class
35 // header file
37 
38 // output format
39 #include "TH1.h"
40 #include "TTree.h"
41 #include "TString.h"
42 
43 #include <iostream>
44 #include <cstring>
45 
46 using namespace edm;
47 //class MonitorElement;
48 
49 //--------------------------------------------------------------------------------------------------
51  : HistogramManagerHolder(iConfig, consumesCollector()),
52  thresholdL1_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
53  .getUntrackedParameter<double>("thresholdL1")),
54  thresholdL2_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
55  .getUntrackedParameter<double>("thresholdL2")),
56  thresholdL3_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
57  .getUntrackedParameter<double>("thresholdL3")),
58  thresholdL4_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
59  .getUntrackedParameter<double>("thresholdL4")),
60  thresholdRNG1_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
61  .getUntrackedParameter<double>("thresholdRNG1")),
62  thresholdRNG2_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
63  .getUntrackedParameter<double>("thresholdRNG2")),
64  outputBase_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
65  .getUntrackedParameter<std::string>("outputBase")),
66  aveDigiOcc_(
67  iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters").getUntrackedParameter<int>("aveDigiOcc")),
68  nLumi_(iConfig.getParameter<edm::ParameterSet>("SiPixelStatusManagerParameters")
69  .getUntrackedParameter<int>("resetEveryNLumi")),
70  moduleName_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
71  .getUntrackedParameter<std::string>("moduleName")),
72  label_(iConfig.getParameter<ParameterSet>("SiPixelStatusManagerParameters")
73  .getUntrackedParameter<std::string>("label")),
75  trackerTopologyToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::EndRun>()),
78  SiPixelStatusManager* siPixelStatusManager = new SiPixelStatusManager(iConfig, consumesCollector());
79  siPixelStatusManager_ = *siPixelStatusManager;
80  debug_ = iConfig.getUntrackedParameter<bool>("debug");
81  recordName_ = iConfig.getUntrackedParameter<std::string>("recordName", "SiPixelQualityFromDbRcd");
82 
83  sensorSize_.clear();
84  pixelO2O_.clear();
85 
87  endLumiBlock_ = 0;
88  countLumi_ = 0;
89 }
90 
91 //--------------------------------------------------------------------------------------------------
93 
94 //--------------------------------------------------------------------------------------------------
96 
97 //--------------------------------------------------------------------------------------------------
99  edm::Run const&,
100  edm::EventSetup const& iSetup) {
101  for (auto& histoman : histo) {
102  histoman.book(iBooker, iSetup);
103  }
104 }
105 
106 //--------------------------------------------------------------------------------------------------
108 
109 //--------------------------------------------------------------------------------------------------
111  // tracker geometry and cabling map to convert offline row/column (module) to online row/column
113  const TrackerTopology* trackerTopology = &iSetup.getData(trackerTopologyToken_);
114  const SiPixelFedCablingMap* siPixelFedCablingMap = &iSetup.getData(siPixelFedCablingMapToken_);
115  cablingMap_ = siPixelFedCablingMap;
116 
117  // Pixel Phase-1 helper class
118  coord_.init(trackerTopology, trackerGeometry_, siPixelFedCablingMap);
119 
120  for (TrackerGeometry::DetContainer::const_iterator it = trackerGeometry_->dets().begin();
121  it != trackerGeometry_->dets().end();
122  it++) {
123  const PixelGeomDetUnit* pgdu = dynamic_cast<const PixelGeomDetUnit*>((*it));
124  if (pgdu == nullptr)
125  continue;
126  DetId detId = (*it)->geographicalId();
127  int detid = detId.rawId();
128 
129  const PixelTopology* topo = static_cast<const PixelTopology*>(&pgdu->specificTopology());
130  // number of row/columns for a given module
131  int rowsperroc = topo->rowsperroc();
132  int colsperroc = topo->colsperroc();
133 
134  int nROCrows = pgdu->specificTopology().nrows() / rowsperroc;
135  int nROCcolumns = pgdu->specificTopology().ncolumns() / colsperroc;
136  unsigned int nrocs = nROCrows * nROCcolumns;
138 
139  std::map<int, std::pair<int, int>> rocToOfflinePixel;
140 
141  std::vector<sipixelobjects::CablingPathToDetUnit> path = (cablingMap_->det2PathMap()).find(detId.rawId())->second;
142  typedef std::vector<sipixelobjects::CablingPathToDetUnit>::const_iterator IT;
143  for (IT it = path.begin(); it != path.end(); ++it) {
144  // Pixel ROC building from path in cabling map
146  int idInDetUnit = (int)roc->idInDetUnit();
147 
148  // local to global conversion
149  sipixelobjects::LocalPixel::RocRowCol local = {rowsperroc / 2, colsperroc / 2};
151 
152  rocToOfflinePixel[idInDetUnit] = std::pair<int, int>(global.row, global.col);
153  }
154 
155  pixelO2O_[detid] = rocToOfflinePixel;
156  }
157 
158  // Permananent bad components
160 
161  // read in SiPixel occupancy data in ALCARECO/ALCAPROMPT
163  std::map<edm::LuminosityBlockNumber_t, std::map<int, std::vector<int>>> FEDerror25Map =
165  std::map<edm::LuminosityBlockNumber_t, SiPixelDetectorStatus> siPixelStatusMap =
167 
168  // DB service
170 
171  if (poolDbService.isAvailable()) { // if(poolDbService.isAvailable() )
172 
173  // start producing tag for permanent component removed
174  SiPixelQuality siPixelQualityPermBad;
175  const std::vector<SiPixelQuality::disabledModuleType> badComponentList = badPixelInfo_->getBadComponentList();
176  for (unsigned int i = 0; i < badComponentList.size(); i++) {
177  siPixelQualityPermBad.addDisabledModule(badComponentList[i]);
178 
179  uint32_t detId = badComponentList[i].DetID;
180  int detid = int(detId);
181  unsigned int nroc = sensorSize_[detid];
182 
183  for (int iroc = 0; iroc < int(nroc); iroc++) {
184  if (badPixelInfo_->IsRocBad(detId, short(iroc))) {
185  std::map<int, std::pair<int, int>> rocToOfflinePixel = pixelO2O_[detid];
186  int row = rocToOfflinePixel[iroc].first;
187  int column = rocToOfflinePixel[iroc].second;
188  histo[PERMANENTBADROC].fill(detId, nullptr, column, row);
189  }
190  }
191  }
192  if (debug_ == true) { // only produced for debugging reason
193  cond::Time_t thisIOV = (cond::Time_t)iRun.id().run();
194  poolDbService->writeOneIOV<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_ + "_permanentBad");
195  }
196 
197  // IOV for final payloads. FEDerror25 and pcl
198  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> finalIOV;
199  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> fedError25IOV;
200  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> pclIOV;
201 
202  // container for SiPixelQuality for the whole run
203  std::map<int, SiPixelQuality> siPixelQualityStuckTBM_Tag;
204 
205  // stuckTBM tag from FED error 25 with permanent component removed
206  for (SiPixelStatusManager::FEDerror25Map_iterator it = FEDerror25Map.begin(); it != FEDerror25Map.end(); it++) {
207  cond::Time_t thisIOV = 1;
208  edm::LuminosityBlockID lu(iRun.id().run(), it->first);
209  thisIOV = (cond::Time_t)(lu.value());
210 
211  int interval = 0;
212  // interval is the number of lumi sections in the IOV
214  if (nextIt != FEDerror25Map.end())
215  interval = int(nextIt->first - it->first);
216  else
217  interval = int(endLumiBlock_ - it->first + 1); // +1 because need to include the last lumi section
218 
219  SiPixelQuality siPixelQuality_stuckTBM;
220  SiPixelQuality siPixelQuality_FEDerror25;
221 
222  std::map<int, std::vector<int>> tmpFEDerror25 = it->second;
223  for (std::map<int, std::vector<int>>::iterator ilist = tmpFEDerror25.begin(); ilist != tmpFEDerror25.end();
224  ilist++) {
225  int detid = ilist->first;
226  uint32_t detId = uint32_t(detid);
227 
228  SiPixelQuality::disabledModuleType BadModule_stuckTBM, BadModule_FEDerror25;
229 
230  BadModule_stuckTBM.DetID = uint32_t(detid);
231  BadModule_FEDerror25.DetID = uint32_t(detid);
232  BadModule_stuckTBM.errorType = 3;
233  BadModule_FEDerror25.errorType = 3;
234 
235  BadModule_stuckTBM.BadRocs = 0;
236  BadModule_FEDerror25.BadRocs = 0;
237  std::vector<uint32_t> BadRocList_stuckTBM, BadRocList_FEDerror25;
238  std::vector<int> list = ilist->second;
239 
240  for (unsigned int i = 0; i < list.size(); i++) {
241  int iroc = list[i];
242  std::map<int, std::pair<int, int>> rocToOfflinePixel = pixelO2O_[detid];
243  int row = rocToOfflinePixel[iroc].first;
244  int column = rocToOfflinePixel[iroc].second;
245 
246  BadRocList_FEDerror25.push_back(uint32_t(iroc));
247  for (int iLumi = 0; iLumi < interval; iLumi++) {
248  histo[FEDERRORROC].fill(detId, nullptr, column, row); // 1.0/nLumiBlock_);
249  }
250 
251  // only include rocs that are not permanent known bad
252  if (!badPixelInfo_->IsRocBad(detId, short(iroc))) { // stuckTBM = FEDerror25 - permanent bad
253  BadRocList_stuckTBM.push_back(uint32_t(iroc));
254  for (int iLumi = 0; iLumi < interval; iLumi++) {
255  histo[STUCKTBMROC].fill(detId, nullptr, column, row); //, 1.0/nLumiBlock_);
256  }
257  }
258  }
259 
260  // change module error type if all ROCs are bad
261  if (BadRocList_stuckTBM.size() == sensorSize_[detid])
262  BadModule_stuckTBM.errorType = 0;
263 
264  short badrocs_stuckTBM = 0;
265  for (std::vector<uint32_t>::iterator iter = BadRocList_stuckTBM.begin(); iter != BadRocList_stuckTBM.end();
266  ++iter) {
267  badrocs_stuckTBM += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
268  }
269  // fill the badmodule only if there is(are) bad ROC(s) in it
270  if (badrocs_stuckTBM != 0) {
271  BadModule_stuckTBM.BadRocs = badrocs_stuckTBM;
272  siPixelQuality_stuckTBM.addDisabledModule(BadModule_stuckTBM);
273  }
274 
275  // change module error type if all ROCs are bad
276  if (BadRocList_FEDerror25.size() == sensorSize_[detid])
277  BadModule_FEDerror25.errorType = 0;
278 
279  short badrocs_FEDerror25 = 0;
280  for (std::vector<uint32_t>::iterator iter = BadRocList_FEDerror25.begin(); iter != BadRocList_FEDerror25.end();
281  ++iter) {
282  badrocs_FEDerror25 += 1 << *iter; // 1 << *iter = 2^{*iter} using bitwise shift
283  }
284  // fill the badmodule only if there is(are) bad ROC(s) in it
285  if (badrocs_FEDerror25 != 0) {
286  BadModule_FEDerror25.BadRocs = badrocs_FEDerror25;
287  siPixelQuality_FEDerror25.addDisabledModule(BadModule_FEDerror25);
288  }
289 
290  } // loop over modules
291 
292  siPixelQualityStuckTBM_Tag[it->first] = siPixelQuality_stuckTBM;
293 
294  finalIOV[it->first] = it->first;
295  fedError25IOV[it->first] = it->first;
296 
297  if (debug_ == true) // only produced for debugging reason
298  poolDbService->writeOneIOV<SiPixelQuality>(siPixelQuality_FEDerror25, thisIOV, recordName_ + "_FEDerror25");
299  }
300 
301  // IOV for PCL output tags that "combines" permanent bad/stuckTBM/other
302  for (SiPixelStatusManager::siPixelStatusMap_iterator it = siPixelStatusMap.begin(); it != siPixelStatusMap.end();
303  it++) {
304  finalIOV[it->first] = it->first;
305  pclIOV[it->first] = it->first;
306  }
307 
308  // loop over final IOV
309  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator itIOV;
310 
311  // container for SiPixelQuality for the whole run
312  std::map<int, SiPixelQuality> siPixelQualityPCL_Tag;
313  std::map<int, SiPixelQuality> siPixelQualityPrompt_Tag;
314  std::map<int, SiPixelQuality> siPixelQualityOther_Tag;
315 
316  for (itIOV = finalIOV.begin(); itIOV != finalIOV.end(); itIOV++) {
317  int interval = 0;
318  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator nextItIOV = std::next(itIOV);
319  if (nextItIOV != finalIOV.end())
320  interval = int(nextItIOV->first - itIOV->first);
321  else
322  interval = int(endLumiBlock_ - itIOV->first + 1);
323 
324  edm::LuminosityBlockNumber_t lumiFEDerror25 = SiPixelStatusHarvester::stepIOV(itIOV->first, fedError25IOV);
325  edm::LuminosityBlockNumber_t lumiPCL = SiPixelStatusHarvester::stepIOV(itIOV->first, pclIOV);
326 
327  // get badROC list due to FEDerror25 = stuckTBM + permanent bad components
328  std::map<int, std::vector<int>> tmpFEDerror25 = FEDerror25Map[lumiFEDerror25];
329  // get SiPixelDetectorStatus
330  SiPixelDetectorStatus tmpSiPixelStatus = siPixelStatusMap[lumiPCL];
331  double DetAverage = tmpSiPixelStatus.perRocDigiOcc();
332 
333  // For the IOV of which the statistics is too low, for e.g., a cosmic run
334  // When using dynamicLumibased harvester or runbased harvester
335  // this only happens when the full run is lack of statistics
336  if (DetAverage < aveDigiOcc_) {
337  edm::LogInfo("SiPixelStatusHarvester")
338  << "Tag requested for prompt in low statistics IOV in the " << outputBase_ << " harvester" << std::endl;
339  siPixelQualityPCL_Tag[itIOV->first] = siPixelQualityPermBad;
340  siPixelQualityPrompt_Tag[itIOV->first] = siPixelQualityPermBad;
341 
342  // loop over modules to fill the PROMPT DQM plots with permanent bad components
343  std::map<int, SiPixelModuleStatus> detectorStatus = tmpSiPixelStatus.getDetectorStatus();
344  std::map<int, SiPixelModuleStatus>::iterator itModEnd = detectorStatus.end();
345  for (std::map<int, SiPixelModuleStatus>::iterator itMod = detectorStatus.begin(); itMod != itModEnd; ++itMod) {
346  int detid = itMod->first;
347  uint32_t detId = uint32_t(detid);
348  SiPixelModuleStatus modStatus = itMod->second;
349 
350  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
351  if (badPixelInfo_->IsRocBad(detId, short(iroc))) {
352  std::map<int, std::pair<int, int>> rocToOfflinePixel = pixelO2O_[detid];
353  int row = rocToOfflinePixel[iroc].first;
354  int column = rocToOfflinePixel[iroc].second;
355  for (int iLumi = 0; iLumi < interval; iLumi++) {
356  histo[PROMPTBADROC].fill(detId, nullptr, column, row); //, 1.0/nLumiBlock_);
357  histo[PERMANENTBADROC].fill(detId, nullptr, column, row); //, 1.0/nLumiBlock_);
358  }
359 
360  } // if permanent BAD
361 
362  } // loop over ROCs
363 
364  } // loop over modules
365 
366  // add empty bad components to "other" tag
367  edm::LogInfo("SiPixelStatusHarvester")
368  << "Tag requested for other in low statistics IOV in the " << outputBase_ << " harvester" << std::endl;
369  siPixelQualityOther_Tag[itIOV->first] = SiPixelQuality();
370 
371  continue;
372  }
373 
374  // create the DB object
375  // payload including all : PCL = permanent bad (low DIGI ROC) + other + stuckTBM
376  SiPixelQuality siPixelQualityPCL;
377  SiPixelQuality siPixelQualityOther;
378  // Prompt = permanent bad(low DIGI + low eff/damaged ROCs + other)
379  SiPixelQuality siPixelQualityPrompt;
380 
381  // loop over modules
382  std::map<int, SiPixelModuleStatus> detectorStatus = tmpSiPixelStatus.getDetectorStatus();
383  std::map<int, SiPixelModuleStatus>::iterator itModEnd = detectorStatus.end();
384  for (std::map<int, SiPixelModuleStatus>::iterator itMod = detectorStatus.begin(); itMod != itModEnd; ++itMod) {
385  // create the bad module list for PCL and other
386  SiPixelQuality::disabledModuleType BadModulePCL, BadModuleOther;
387 
388  int detid = itMod->first;
389  uint32_t detId = uint32_t(detid);
390 
391  double DetAverage_local = SiPixelStatusHarvester::perLayerRingAverage(detid, tmpSiPixelStatus);
392  double local_threshold = 0.0;
393 
394  int layer = coord_.layer(DetId(detid));
395  int ring = coord_.ring(DetId(detid));
396 
397  if (layer == 1)
398  local_threshold = thresholdL1_;
399  if (layer == 2)
400  local_threshold = thresholdL2_;
401  if (layer == 3)
402  local_threshold = thresholdL3_;
403  if (layer == 4)
404  local_threshold = thresholdL4_;
405 
406  if (ring == 1)
407  local_threshold = thresholdRNG1_;
408  if (ring == 2)
409  local_threshold = thresholdRNG2_;
410 
411  BadModulePCL.DetID = uint32_t(detid);
412  BadModuleOther.DetID = uint32_t(detid);
413  BadModulePCL.errorType = 3;
414  BadModuleOther.errorType = 3;
415  BadModulePCL.BadRocs = 0;
416  BadModuleOther.BadRocs = 0;
417 
418  std::vector<uint32_t> BadRocListPCL, BadRocListOther;
419 
420  // module status and FEDerror25 status for module with DetId detId
421  SiPixelModuleStatus modStatus = itMod->second;
422  std::vector<int> listFEDerror25 = tmpFEDerror25[detid];
423 
424  std::map<int, std::pair<int, int>> rocToOfflinePixel = pixelO2O_[detid];
425  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
426  unsigned int rocOccupancy = modStatus.digiOccROC(iroc);
427 
428  int row = rocToOfflinePixel[iroc].first;
429  int column = rocToOfflinePixel[iroc].second;
430 
431  // Bad ROC are from low DIGI Occ ROCs
432  if (rocOccupancy < local_threshold * DetAverage_local) { // if BAD
433 
434  //PCL bad roc list
435  BadRocListPCL.push_back(uint32_t(iroc));
436  for (int iLumi = 0; iLumi < interval; iLumi++) {
437  histo[BADROC].fill(detId, nullptr, column, row); //, 1.0/nLumiBlock_);
438  }
439 
440  //FEDerror25 list
441  std::vector<int>::iterator it = std::find(listFEDerror25.begin(), listFEDerror25.end(), iroc);
442 
443  // other source of bad components = PCL bad - FEDerror25 - permanent bad
444  if (it == listFEDerror25.end() && !(badPixelInfo_->IsRocBad(detId, short(iroc)))) {
445  // if neither permanent nor FEDerror25
446  BadRocListOther.push_back(uint32_t(iroc));
447  for (int iLumi = 0; iLumi < interval; iLumi++) {
448  histo[OTHERBADROC].fill(detId, nullptr, column, row); //, 1.0/nLumiBlock_);
449  }
450  }
451 
452  } // if BAD
453 
454  } // loop over ROCs
455 
456  // errorType 0 means the full module is bad
457  if (BadRocListPCL.size() == sensorSize_[detid])
458  BadModulePCL.errorType = 0;
459  if (BadRocListOther.size() == sensorSize_[detid])
460  BadModuleOther.errorType = 0;
461 
462  // PCL
463  short badrocsPCL = 0;
464  for (std::vector<uint32_t>::iterator iterPCL = BadRocListPCL.begin(); iterPCL != BadRocListPCL.end();
465  ++iterPCL) {
466  badrocsPCL += 1 << *iterPCL; // 1 << *iter = 2^{*iter} using bitwise shift
467  }
468  if (badrocsPCL != 0) {
469  BadModulePCL.BadRocs = badrocsPCL;
470  siPixelQualityPCL.addDisabledModule(BadModulePCL);
471  }
472 
473  // Other
474  short badrocsOther = 0;
475  for (std::vector<uint32_t>::iterator iterOther = BadRocListOther.begin(); iterOther != BadRocListOther.end();
476  ++iterOther) {
477  badrocsOther += 1 << *iterOther; // 1 << *iter = 2^{*iter} using bitwise shift
478  }
479  if (badrocsOther != 0) {
480  BadModuleOther.BadRocs = badrocsOther;
481  siPixelQualityOther.addDisabledModule(BadModuleOther);
482  }
483 
484  // start constructing bad components for prompt = "other" + permanent
485  SiPixelQuality::disabledModuleType BadModulePrompt;
486  BadModulePrompt.DetID = uint32_t(detid);
487  BadModulePrompt.errorType = 3;
488  BadModulePrompt.BadRocs = 0;
489 
490  std::vector<uint32_t> BadRocListPrompt;
491  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
492  // if in permannet bad tag or is in other tag
493  if (badPixelInfo_->IsRocBad(detId, short(iroc)) || ((badrocsOther >> short(iroc)) & 0x1)) {
494  BadRocListPrompt.push_back(uint32_t(iroc));
495 
496  std::map<int, std::pair<int, int>> rocToOfflinePixel = pixelO2O_[detid];
497  int row = rocToOfflinePixel[iroc].first;
498  int column = rocToOfflinePixel[iroc].second;
499  for (int iLumi = 0; iLumi < interval; iLumi++) {
500  histo[PROMPTBADROC].fill(detId, nullptr, column, row); //, 1.0/nLumiBlock_);
501  }
502  } // if bad
503  } // loop over all ROCs
504 
505  // errorType 0 means the full module is bad
506  if (BadRocListPrompt.size() == sensorSize_[detid])
507  BadModulePrompt.errorType = 0;
508 
509  short badrocsPrompt = 0;
510  for (std::vector<uint32_t>::iterator iterPrompt = BadRocListPrompt.begin();
511  iterPrompt != BadRocListPrompt.end();
512  ++iterPrompt) {
513  badrocsPrompt += 1 << *iterPrompt; // 1 << *iter = 2^{*iter} using bitwise shift
514  }
515  if (badrocsPrompt != 0) {
516  BadModulePrompt.BadRocs = badrocsPrompt;
517  siPixelQualityPrompt.addDisabledModule(BadModulePrompt);
518  }
519 
520  } // end module loop
521 
522  // PCL
523  siPixelQualityPCL_Tag[itIOV->first] = siPixelQualityPCL;
524  // Prompt
525  siPixelQualityPrompt_Tag[itIOV->first] = siPixelQualityPrompt;
526  // Other
527  siPixelQualityOther_Tag[itIOV->first] = siPixelQualityOther;
528 
529  } // loop over IOV
530 
531  // Now construct the tags made of payloads
532  // and only append newIOV if this payload differs wrt last
533 
534  //PCL
535  if (debug_ == true) // only produced for debugging reason
536  SiPixelStatusHarvester::constructTag(siPixelQualityPCL_Tag, poolDbService, "PCL", iRun);
537  // other
538  SiPixelStatusHarvester::constructTag(siPixelQualityOther_Tag, poolDbService, "other", iRun);
539  // prompt
540  SiPixelStatusHarvester::constructTag(siPixelQualityPrompt_Tag, poolDbService, "prompt", iRun);
541  // stuckTBM
542  SiPixelStatusHarvester::constructTag(siPixelQualityStuckTBM_Tag, poolDbService, "stuckTBM", iRun);
543 
544  // Add a dummy IOV starting from last lumisection+1 to close the tag for the run
545  if ((outputBase_ == "nLumibased" || outputBase_ == "dynamicLumibased") && !finalIOV.empty()) {
546  itIOV = std::prev(finalIOV.end()); // go to last element in the pixel quality tag
547  SiPixelQuality lastPrompt = siPixelQualityPrompt_Tag[itIOV->first];
548  SiPixelQuality lastOther = siPixelQualityOther_Tag[itIOV->first];
549 
550  // add permanent bad components to last lumi+1 IF AND ONLY IF the last payload of prompt is not equal to permanent bad components
551  edm::LuminosityBlockID lu(iRun.id().run(), endLumiBlock_ + 1);
552  cond::Time_t thisIOV = (cond::Time_t)(lu.value());
553  if (!SiPixelStatusHarvester::equal(lastPrompt, siPixelQualityPermBad))
554  poolDbService->writeOneIOV<SiPixelQuality>(siPixelQualityPermBad, thisIOV, recordName_ + "_prompt");
555 
556  // add empty bad components to last lumi+1 IF AND ONLY IF the last payload of other is not equal to empty
557  SiPixelQuality siPixelQualityDummy;
558  if (!SiPixelStatusHarvester::equal(lastOther, siPixelQualityDummy))
559  poolDbService->writeOneIOV<SiPixelQuality>(siPixelQualityDummy, thisIOV, recordName_ + "_other");
560  }
561  } // end of if(poolDbService.isAvailable() )
562 }
563 
564 //--------------------------------------------------------------------------------------------------
566  countLumi_++;
567 }
568 
569 //--------------------------------------------------------------------------------------------------
572  // update endLumiBlock_ by current lumi block
573  if (endLumiBlock_ < iLumi.luminosityBlock())
574  endLumiBlock_ = iLumi.luminosityBlock();
575 }
576 
577 // step function for IOV
579  edm::LuminosityBlockNumber_t pin, std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t> IOV) {
580  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator itIOV;
581  for (itIOV = IOV.begin(); itIOV != IOV.end(); itIOV++) {
582  std::map<edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t>::iterator nextItIOV;
583  nextItIOV = itIOV;
584  nextItIOV++;
585 
586  if (nextItIOV != IOV.end()) {
587  if (pin >= itIOV->first && pin < nextItIOV->first) {
588  return itIOV->first;
589  }
590  } else {
591  if (pin >= itIOV->first) {
592  return itIOV->first;
593  }
594  }
595  }
596 
597  // return the firstIOV in case all above fail
598  return (IOV.begin())->first;
599 }
600 
601 //--------------------------------------------------------------------------------------------------
603  std::vector<SiPixelQuality::disabledModuleType> badRocListA;
604  std::vector<SiPixelQuality::disabledModuleType> badRocListB;
605 
606  for (unsigned int ia = 0; ia < (a.getBadComponentList()).size(); ia++) {
607  badRocListA.push_back((a.getBadComponentList())[ia]);
608  }
609  for (unsigned int ib = 0; ib < (b.getBadComponentList()).size(); ib++) {
610  badRocListB.push_back((b.getBadComponentList())[ib]);
611  }
612 
613  if (badRocListA.size() != badRocListB.size())
614  return false;
615 
616  // ordering ROCs by DetId
617  std::sort(badRocListA.begin(), badRocListA.end(), SiPixelQuality::BadComponentStrictWeakOrdering());
618  std::sort(badRocListB.begin(), badRocListB.end(), SiPixelQuality::BadComponentStrictWeakOrdering());
619 
620  for (unsigned int i = 0; i < badRocListA.size(); i++) {
621  uint32_t detIdA = badRocListA[i].DetID;
622  uint32_t detIdB = badRocListB[i].DetID;
623  if (detIdA != detIdB)
624  return false;
625  else {
626  unsigned short BadRocsA = badRocListA[i].BadRocs;
627  unsigned short BadRocsB = badRocListB[i].BadRocs;
628  if (BadRocsA != BadRocsB)
629  return false;
630  }
631  }
632 
633  //if the module list is the same, and for each module, roc list is the same
634  //the two SiPixelQualitys are equal
635  return true;
636 }
637 
638 //--------------------------------------------------------------------------------------------------
639 void SiPixelStatusHarvester::constructTag(std::map<int, SiPixelQuality> siPixelQualityTag,
642  edm::Run const& iRun) {
643  for (std::map<int, SiPixelQuality>::iterator qIt = siPixelQualityTag.begin(); qIt != siPixelQualityTag.end(); ++qIt) {
644  edm::LuminosityBlockID lu(iRun.id().run(), qIt->first);
645  cond::Time_t thisIOV = (cond::Time_t)(lu.value());
646 
647  SiPixelQuality thisPayload = qIt->second;
648  if (qIt == siPixelQualityTag.begin())
649  poolDbService->writeOneIOV<SiPixelQuality>(thisPayload, thisIOV, recordName_ + "_" + tagName);
650  else {
651  SiPixelQuality prevPayload = (std::prev(qIt))->second;
652  if (!SiPixelStatusHarvester::equal(thisPayload,
653  prevPayload)) // only append newIOV if this payload differs wrt last
654  poolDbService->writeOneIOV<SiPixelQuality>(thisPayload, thisIOV, recordName_ + "_" + tagName);
655  }
656  }
657 }
658 
659 //--------------------------------------------------------------------------------------------------------
661  unsigned long int ave(0);
662  int nrocs(0);
663 
664  int layer = coord_.layer(DetId(detid));
665  int ring = coord_.ring(DetId(detid));
666 
667  std::map<int, SiPixelModuleStatus> detectorStatus = tmpSiPixelStatus.getDetectorStatus();
668  std::map<int, SiPixelModuleStatus>::iterator itModEnd = detectorStatus.end();
669  for (std::map<int, SiPixelModuleStatus>::iterator itMod = detectorStatus.begin(); itMod != itModEnd; ++itMod) {
670  if (layer != coord_.layer(DetId(itMod->first)))
671  continue;
672  if (ring != coord_.ring(DetId(itMod->first)))
673  continue;
674  unsigned long int inc = itMod->second.digiOccMOD();
675  ave += inc;
676  nrocs += itMod->second.nrocs();
677  }
678 
679  if (nrocs > 0)
680  return ave * 1.0 / nrocs;
681  else
682  return 0.0;
683 }
684 
687  int layer = coord_.layer(DetId(detid));
688 
689  if (layer > 0) {
691  substructure = "BpixLYR";
692  substructure += L;
693  } else {
694  substructure = "FpixRNG";
695  int ring = coord_.ring(DetId(detid));
697  substructure += R;
698  }
699 
700  return substructure;
701 }
702 
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
size
Write out results.
void addDisabledModule(disabledModuleType module)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::map< int, unsigned int > sensorSize_
bool IsRocBad(const uint32_t &detid, const short &rocNb) const
edm::ESGetToken< SiPixelQuality, SiPixelQualityFromDbRcd > siPixelQualityToken_
virtual const sipixelobjects::PixelROC * findItem(const sipixelobjects::CablingPathToDetUnit &) const =0
virtual int ncolumns() const =0
void constructTag(std::map< int, SiPixelQuality > siPixelQualityTag, edm::Service< cond::service::PoolDBOutputService > &poolDbService, std::string tagName, edm::Run const &iRun)
for(int i=first, nt=offsets[nh];i< nt;i+=gridDim.x *blockDim.x)
edm::LuminosityBlockNumber_t endLumiBlock_
virtual int rowsperroc() const =0
void bookHistograms(DQMStore::IBooker &iBooker, edm::Run const &, const edm::EventSetup &) final
virtual int nrows() const =0
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopologyToken_
int ring(const DetId &)
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
void analyze(const edm::Event &iEvent, const edm::EventSetup &) final
edm::LuminosityBlockNumber_t stepIOV(edm::LuminosityBlockNumber_t pin, std::map< edm::LuminosityBlockNumber_t, edm::LuminosityBlockNumber_t > IOV)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
unsigned int LuminosityBlockNumber_t
SiPixelStatusManager siPixelStatusManager_
identify pixel inside single ROC
Definition: LocalPixel.h:7
static std::string to_string(const XMLCh *ch)
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > siPixelFedCablingMapToken_
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
T getUntrackedParameter(std::string const &, T const &) const
int layer(const DetId &)
U second(std::pair< T, U > const &p)
std::map< int, std::map< int, std::pair< int, int > > > pixelO2O_
int iEvent
Definition: GenABIO.cc:224
virtual std::map< uint32_t, std::vector< sipixelobjects::CablingPathToDetUnit > > det2PathMap() const =0
const std::vector< disabledModuleType > getBadComponentList() const
unsigned long long Time_t
Definition: Time.h:14
std::string substructure(int detid)
const SiPixelQuality * badPixelInfo_
virtual int colsperroc() const =0
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus > & getBadComponents()
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
const std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > > & getFEDerror25Rocs()
Transition
Definition: Transition.h:12
void init(const TrackerTopology *, const TrackerGeometry *, const SiPixelFedCablingMap *)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const SiPixelFedCabling * cablingMap_
std::vector< LinkConnSpec >::const_iterator IT
const TrackerGeometry * trackerGeometry_
bool equal(SiPixelQuality a, SiPixelQuality b)
void dqmEndRun(const edm::Run &, const edm::EventSetup &) final
RunID const & id() const
Definition: RunBase.h:39
Log< level::Info, false > LogInfo
std::map< int, SiPixelModuleStatus > getDetectorStatus()
Definition: DetId.h:17
SiPixelStatusHarvester(const edm::ParameterSet &)
double b
Definition: hdecay.h:120
row and collumn in ROC representation
Definition: LocalPixel.h:13
double perLayerRingAverage(int detid, SiPixelDetectorStatus tmpSiPixelStatus)
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) final
std::vector< HistogramManager > histo
HLT enums.
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
double a
Definition: hdecay.h:121
bool isAvailable() const
Definition: Service.h:40
unsigned int digiOccROC(int iroc)
return ROC status (= hits on ROC iroc)
void readLumi(const edm::LuminosityBlock &)
std::map< edm::LuminosityBlockNumber_t, std::map< int, std::vector< int > > >::iterator FEDerror25Map_iterator
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
RunNumber_t run() const
Definition: RunID.h:26
std::map< edm::LuminosityBlockNumber_t, SiPixelDetectorStatus >::iterator siPixelStatusMap_iterator
Definition: Run.h:45
ib
Definition: cuy.py:661