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