CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GEMDQMHarvester.cc
Go to the documentation of this file.
10 
11 //DQM services
16 
17 #include <TH2F.h>
18 #include <TFile.h>
19 #include <TDirectoryFile.h>
20 #include <TKey.h>
21 
22 using namespace edm;
23 
24 class GEMDQMHarvester : public DQMEDHarvester {
25 public:
27  ~GEMDQMHarvester() override{};
28  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
29 
30  typedef std::tuple<int, int> IdChamber;
31  typedef std::tuple<int, int, int> IdVFAT;
32  typedef struct PreStatusInfo {
34  int nLumiEnd;
35  int nStatus;
36  } StatusInfo;
37 
38  class NumStatus {
39  public:
40  NumStatus(Float_t fNumTotal = 0,
41  Float_t fNumOcc = 0,
42  Float_t fNumErrVFAT = 0,
43  Float_t fNumWarnVFAT = 0,
44  Float_t fNumErrOH = 0,
45  Float_t fNumWarnOH = 0,
46  Float_t fNumErrAMC = 0,
47  Float_t fNumWarnAMC = 0,
48  Float_t fNumErrAMC13 = 0)
49  : fNumTotal_(fNumTotal),
50  fNumOcc_(fNumOcc),
51  fNumErrVFAT_(fNumErrVFAT),
52  fNumWarnVFAT_(fNumWarnVFAT),
53  fNumErrOH_(fNumErrOH),
54  fNumWarnOH_(fNumWarnOH),
55  fNumErrAMC_(fNumErrAMC),
56  fNumWarnAMC_(fNumWarnAMC),
57  fNumErrAMC13_(fNumErrAMC13) {}
58  float fNumTotal_;
59  float fNumOcc_;
60  float fNumErrVFAT_;
62  float fNumErrOH_;
63  float fNumWarnOH_;
64  float fNumErrAMC_;
65  float fNumWarnAMC_;
67  };
68 
69 protected:
70  void dqmEndLuminosityBlock(DQMStore::IBooker &,
72  edm::LuminosityBlock const &iLumi,
73  edm::EventSetup const &) override;
74  void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override{}; // Cannot use; it is called after dqmSaver
75 
76  void drawSummaryHistogram(edm::Service<DQMStore> &store, Int_t nLumiCurr);
77  void createTableWatchingSummary();
78  void copyLabels(MonitorElement *h2Src, MonitorElement *h2Dst);
79  void getGeometryInfo(edm::Service<DQMStore> &store, MonitorElement *h2Src);
80  void createSummaryHist(edm::Service<DQMStore> &store, MonitorElement *h2Src, MonitorElement *&h2Sum);
81  void createSummaryVFAT(edm::Service<DQMStore> &store,
82  MonitorElement *h2Src,
83  std::string strSuffix,
84  MonitorElement *&h2Sum);
85  Float_t refineSummaryHistogram(std::string strName,
86  MonitorElement *h2Sum,
87  std::vector<MonitorElement *> &listOccPlots,
88  MonitorElement *h2SrcStatusA,
89  MonitorElement *h2SrcStatusE,
90  MonitorElement *h2SrcStatusW,
91  MonitorElement *h2SrcStatusEVFAT,
92  MonitorElement *h2SrcStatusWVFAT,
93  MonitorElement *h2SrcStatusEOH,
94  MonitorElement *h2SrcStatusWOH,
95  MonitorElement *h2SrcStatusEAMC,
96  MonitorElement *h2SrcStatusWAMC,
97  MonitorElement *h2SrcStatusEAMC13,
98  Int_t nLumiCurr);
99  Int_t refineSummaryVFAT(std::string strName,
100  MonitorElement *h2Sum,
101  MonitorElement *h2SrcOcc,
102  MonitorElement *h2SrcStatusE,
103  MonitorElement *h2SrcStatusW,
104  Int_t nLumiCurr,
105  Int_t nIdxLayer);
106  Int_t assessOneBin(
107  std::string strName, Int_t nIdxX, Int_t nIdxY, Float_t fAll, Float_t fNumOcc, Float_t fNumErr, Float_t fNumWarn);
108 
109  Int_t UpdateStatusChamber(Int_t nIdxLayer, Int_t nIdxCh, Int_t nLumiCurr, NumStatus numStatus);
110  Int_t UpdateStatusChamber(Int_t nIdxLayer, Int_t nIdxCh, Int_t nIdxVFAT, Int_t nLumiCurr, NumStatus numStatus);
111  Int_t UpdateStatusChamber(std::vector<StatusInfo> &listStatus,
112  NumStatus &numStatus,
113  Int_t nLumiCurr,
114  NumStatus numStatusNew);
115  void createLumiFuncHist(edm::Service<DQMStore> &store, std::string strSuffix, Int_t nIdxLayer, Int_t nLumiCurr);
116  void createInactiveChannelFracHist(edm::Service<DQMStore> &store, std::string strSuffix, Int_t nNumChamber);
117 
118  Float_t fCutErr_, fCutLowErr_, fCutWarn_;
119 
120  const std::string strDirSummary_ = "GEM/EventInfo";
121  const std::string strDirRecHit_ = "GEM/RecHits";
122  const std::string strDirStatus_ = "GEM/DAQStatus";
123 
124  const Int_t nCodeFine_ = 1;
125  const Int_t nCodeError_ = 2;
126  const Int_t nCodeWarning_ = 3;
127  const Int_t nCodeLowError_ = 4;
128 
129  const Int_t nBitWarnVFAT_ = 7;
130  const Int_t nBitErrVFAT_ = 6;
131  const Int_t nBitWarnOH_ = 5;
132  const Int_t nBitErrOH_ = 4;
133  const Int_t nBitWarnAMC_ = 3;
134  const Int_t nBitErrAMC_ = 2;
135  const Int_t nBitErrAMC13_ = 1;
136  const Int_t nBitOcc_ = 0;
137 
138  const Int_t nNumVFATs_ = 24;
139 
140  const Int_t nMaxLumi_ = 6000; // From DQMServices/Components/plugins/DQMProvInfo.h
141  //const Int_t nResolutionLumi_ = 5;
143 
144  typedef std::vector<std::vector<Float_t>> TableStatusOcc;
145  typedef std::vector<std::vector<Int_t>> TableStatusNum;
146 
147  std::map<IdChamber, std::vector<StatusInfo>> mapStatusChambersSummary_;
148  std::map<IdVFAT, std::vector<StatusInfo>> mapStatusVFATsSummary_;
149  std::map<IdChamber, NumStatus> mapNumStatusChambersSummary_;
150  std::map<IdVFAT, NumStatus> mapNumStatusVFATsSummary_;
151 
152  std::vector<std::string> listLayer_;
153  std::map<std::string, int> mapIdxLayer_; // All indices in the following objects start at 1
154  std::map<int, int> mapNumChPerChamber_;
155  std::map<int, MonitorElement *> mapHistLumiFunc_;
157 };
158 
160  fCutErr_ = cfg.getParameter<double>("cutErr");
161  fCutLowErr_ = cfg.getParameter<double>("cutLowErr");
162  fCutWarn_ = cfg.getParameter<double>("cutWarn");
163  nResolutionLumi_ = cfg.getParameter<int>("resolutionLumi");
164  bIsStatusChambersInit_ = false;
165 }
166 
169  desc.add<double>("cutErr", 0.05);
170  desc.add<double>("cutLowErr", 0.00);
171  desc.add<double>("cutWarn", 0.05);
172  desc.add<int>("resolutionLumi", 1);
173  descriptions.add("GEMDQMHarvester", desc);
174 }
175 
178  edm::LuminosityBlock const &iLumi,
179  edm::EventSetup const &) {
181  Int_t nLumiCurr = iLumi.id().luminosityBlock();
182  drawSummaryHistogram(store, nLumiCurr);
183 }
184 
186  Float_t fReportSummary = -1.0;
187 
188  std::string strSrcStatusA = "GEM/DAQStatus/chamberAllStatus";
189  std::string strSrcStatusE = "GEM/DAQStatus/chamberErrors";
190  std::string strSrcStatusW = "GEM/DAQStatus/chamberWarnings";
191  std::string strSrcStatusEVFAT = "GEM/DAQStatus/chamberVFATErrors";
192  std::string strSrcStatusWVFAT = "GEM/DAQStatus/chamberVFATWarnings";
193  std::string strSrcStatusEOH = "GEM/DAQStatus/chamberOHErrors";
194  std::string strSrcStatusWOH = "GEM/DAQStatus/chamberOHWarnings";
195  std::string strSrcStatusEAMC = "GEM/DAQStatus/chamberAMCErrors";
196  std::string strSrcStatusWAMC = "GEM/DAQStatus/chamberAMCWarnings";
197  std::string strSrcStatusEAMC13 = "GEM/DAQStatus/chamberAMC13Errors";
198 
199  std::string strSrcVFATOcc = "GEM/Digis/occ";
200  std::string strSrcVFATStatusW = "GEM/DAQStatus/vfat_statusWarnSum";
201  std::string strSrcVFATStatusE = "GEM/DAQStatus/vfat_statusErrSum";
202 
203  store->setCurrentFolder(strDirSummary_);
204 
205  MonitorElement *h2SrcStatusA = store->get(strSrcStatusA);
206  MonitorElement *h2SrcStatusE = store->get(strSrcStatusE);
207  MonitorElement *h2SrcStatusW = store->get(strSrcStatusW);
208  MonitorElement *h2SrcStatusEVFAT = store->get(strSrcStatusEVFAT);
209  MonitorElement *h2SrcStatusWVFAT = store->get(strSrcStatusWVFAT);
210  MonitorElement *h2SrcStatusEOH = store->get(strSrcStatusEOH);
211  MonitorElement *h2SrcStatusWOH = store->get(strSrcStatusWOH);
212  MonitorElement *h2SrcStatusEAMC = store->get(strSrcStatusEAMC);
213  MonitorElement *h2SrcStatusWAMC = store->get(strSrcStatusWAMC);
214  MonitorElement *h2SrcStatusEAMC13 = store->get(strSrcStatusEAMC13);
215 
216  std::string strTitleSummary = "summary";
217 
218  getGeometryInfo(store, h2SrcStatusEOH);
219 
220  if (h2SrcStatusA != nullptr && h2SrcStatusE != nullptr && h2SrcStatusW != nullptr && h2SrcStatusEVFAT != nullptr &&
221  h2SrcStatusWVFAT != nullptr && h2SrcStatusEOH != nullptr && h2SrcStatusWOH != nullptr &&
222  h2SrcStatusEAMC != nullptr && h2SrcStatusWAMC != nullptr && h2SrcStatusEAMC13 != nullptr) {
223  MonitorElement *h2Sum = nullptr;
224  createSummaryHist(store, h2SrcStatusEOH, h2Sum);
225  createTableWatchingSummary();
226 
227  std::vector<MonitorElement *> listOccPlots(listLayer_.size() + 1); // The index starts at 1
228  for (const auto &strSuffix : listLayer_) {
229  if (mapIdxLayer_.find(strSuffix) == mapIdxLayer_.end())
230  continue;
231  auto nIdxLayer = mapIdxLayer_[strSuffix];
232  MonitorElement *h2SrcVFATOcc = store->get(strSrcVFATOcc + strSuffix);
233  if (h2SrcVFATOcc == nullptr)
234  continue;
235  listOccPlots[nIdxLayer] = h2SrcVFATOcc;
236  }
237 
238  fReportSummary = refineSummaryHistogram(strTitleSummary,
239  h2Sum,
240  listOccPlots,
241  h2SrcStatusA,
242  h2SrcStatusE,
243  h2SrcStatusW,
244  h2SrcStatusEVFAT,
245  h2SrcStatusWVFAT,
246  h2SrcStatusEOH,
247  h2SrcStatusWOH,
248  h2SrcStatusEAMC,
249  h2SrcStatusWAMC,
250  h2SrcStatusEAMC13,
251  nLumiCurr);
252 
253  for (const auto &strSuffix : listLayer_) {
254  if (mapIdxLayer_.find(strSuffix) == mapIdxLayer_.end())
255  continue;
256  auto nIdxLayer = mapIdxLayer_[strSuffix];
257  MonitorElement *h2SrcVFATOcc = store->get(strSrcVFATOcc + strSuffix);
258  MonitorElement *h2SrcVFATStatusW = store->get(strSrcVFATStatusW + strSuffix);
259  MonitorElement *h2SrcVFATStatusE = store->get(strSrcVFATStatusE + strSuffix);
260  if (h2SrcVFATOcc == nullptr || h2SrcVFATStatusW == nullptr || h2SrcVFATStatusE == nullptr)
261  continue;
262 
263  MonitorElement *h2SumVFAT = nullptr;
264  createSummaryVFAT(store, h2SrcVFATStatusE, strSuffix, h2SumVFAT);
265  refineSummaryVFAT(strSuffix, h2SumVFAT, h2SrcVFATOcc, h2SrcVFATStatusE, h2SrcVFATStatusW, nLumiCurr, nIdxLayer);
266  TString strNewTitle = h2SrcVFATStatusE->getTitle();
267  h2SumVFAT->setTitle((const char *)strNewTitle.ReplaceAll("errors", "errors/warnings"));
268  h2SumVFAT->setXTitle(h2SrcVFATStatusE->getAxisTitle(1));
269  h2SumVFAT->setYTitle(h2SrcVFATStatusE->getAxisTitle(2));
270 
271  createLumiFuncHist(store, strSuffix, nIdxLayer, nLumiCurr);
272  }
273  }
274 
275  for (const auto &strSuffix : listLayer_) {
276  if (mapIdxLayer_.find(strSuffix) == mapIdxLayer_.end())
277  continue;
278  auto nNumChamber = mapNumChPerChamber_[mapIdxLayer_[strSuffix]];
279  createInactiveChannelFracHist(store, strSuffix, nNumChamber);
280  }
281 
282  store->bookFloat("reportSummary")->Fill(fReportSummary);
283 }
284 
286  if (bIsStatusChambersInit_)
287  return;
288 
289  for (const auto &[nIdxLayer, nNumCh] : mapNumChPerChamber_) {
290  for (Int_t i = 1; i <= nNumCh; i++) {
291  mapStatusChambersSummary_[{nIdxLayer, i}] = std::vector<StatusInfo>();
292  mapNumStatusChambersSummary_[{nIdxLayer, i}] = NumStatus();
293  for (Int_t j = 1; j <= nNumVFATs_; j++) {
294  mapStatusVFATsSummary_[{nIdxLayer, i, j}] = std::vector<StatusInfo>();
295  mapNumStatusVFATsSummary_[{nIdxLayer, i, j}] = NumStatus();
296  }
297  }
298  }
299 
300  bIsStatusChambersInit_ = true;
301 }
302 
304  Int_t nBinX = h2Src->getNbinsX(), nBinY = h2Src->getNbinsY();
305 
306  for (Int_t i = 1; i <= nBinX; i++) {
307  h2Dst->setBinLabel(i, h2Src->getTH2F()->GetXaxis()->GetBinLabel(i), 1);
308  }
309  for (Int_t i = 1; i <= nBinY; i++) {
310  h2Dst->setBinLabel(i, h2Src->getTH2F()->GetYaxis()->GetBinLabel(i), 2);
311  }
312  h2Dst->setTitle(h2Src->getTitle());
313  h2Dst->setXTitle(h2Src->getAxisTitle(1));
314  h2Dst->setYTitle(h2Src->getAxisTitle(2));
315 }
316 
318  if (h2Src != nullptr) { // For online and offline
319  listLayer_.clear();
320  mapIdxLayer_.clear();
321  mapNumChPerChamber_.clear();
322 
323  Int_t nBinY = h2Src->getNbinsY();
324  listLayer_.push_back("");
325 
326  for (Int_t i = 1; i <= nBinY; i++) {
327  std::string strLabelFull = h2Src->getTH2F()->GetYaxis()->GetBinLabel(i);
328  Int_t nBinXActual = (Int_t)(h2Src->getBinContent(0, i) + 0.5);
329  auto nPos = strLabelFull.find(';');
330  auto strLayer = strLabelFull.substr(nPos + 1);
331  listLayer_.push_back(strLayer);
332  mapIdxLayer_[strLayer] = i;
333  mapNumChPerChamber_[i] = nBinXActual;
334  }
335  } else { // For others (validation and...?)
336  listLayer_.push_back("");
337  if (store->get("GEM/Digis/occupancy_GE11-M-L1/occ_GE11-M-01L1-S") != nullptr) {
338  listLayer_.push_back("_GE11-P-L2");
339  listLayer_.push_back("_GE11-P-L1");
340  listLayer_.push_back("_GE11-M-L1");
341  listLayer_.push_back("_GE11-M-L2");
342  mapIdxLayer_["_GE11-P-L2"] = 1;
343  mapIdxLayer_["_GE11-P-L1"] = 2;
344  mapIdxLayer_["_GE11-M-L1"] = 3;
345  mapIdxLayer_["_GE11-M-L2"] = 4;
346  mapNumChPerChamber_[1] = 36;
347  mapNumChPerChamber_[2] = 36;
348  mapNumChPerChamber_[3] = 36;
349  mapNumChPerChamber_[4] = 36;
350  }
351  // FIXME: How about GE21 and ME0?
352  }
353 }
354 
356  //store->setCurrentFolder(strDirSummary_);
357 
358  Int_t nBinX = h2Src->getNbinsX(), nBinY = h2Src->getNbinsY();
359  h2Sum = store->book2D("reportSummaryMap", "", nBinX, 0.5, nBinX + 0.5, nBinY, 0.5, nBinY + 0.5);
360  h2Sum->setTitle("Summary plot");
361  h2Sum->setXTitle("Chamber");
362  h2Sum->setYTitle("Layer");
363 
364  for (Int_t i = 1; i <= nBinX; i++)
365  h2Sum->setBinLabel(i, h2Src->getTH2F()->GetXaxis()->GetBinLabel(i), 1);
366  for (Int_t i = 1; i <= nBinY; i++)
367  h2Sum->setBinLabel(i, listLayer_[i].substr(1), 2);
368 }
369 
371  MonitorElement *h2Src,
372  std::string strSuffix,
373  MonitorElement *&h2Sum) {
374  //store->setCurrentFolder(strDirStatus_);
375  //store->setCurrentFolder(strDirSummary_);
376 
377  Int_t nBinX = h2Src->getNbinsX(), nBinY = h2Src->getNbinsY();
378  h2Sum = store->book2D("vfat_statusSummary" + strSuffix, "", nBinX, 0.5, nBinX + 0.5, nBinY, -0.5, nBinY - 0.5);
379  copyLabels(h2Src, h2Sum);
380 }
381 
383  std::string strName, Int_t nIdxX, Int_t nIdxY, Float_t fAll, Float_t fNumOcc, Float_t fNumErr, Float_t fNumWarn) {
384  if (fNumErr > fCutErr_ * fAll) // The error status criterion
385  return nCodeError_;
386  else if (fNumErr > fCutLowErr_ * fAll) // The low-error status criterion
387  return nCodeLowError_;
388  else if (fNumWarn > fCutWarn_ * fAll) // The warning status criterion
389  return nCodeWarning_;
390  else if (fNumOcc > 0)
391  return nCodeFine_;
392 
393  return 0;
394 }
395 
396 // FIXME: Need more study about how to summarize
398  MonitorElement *h2Sum,
399  std::vector<MonitorElement *> &listOccPlots,
400  MonitorElement *h2SrcStatusA,
401  MonitorElement *h2SrcStatusE,
402  MonitorElement *h2SrcStatusW,
403  MonitorElement *h2SrcStatusEVFAT,
404  MonitorElement *h2SrcStatusWVFAT,
405  MonitorElement *h2SrcStatusEOH,
406  MonitorElement *h2SrcStatusWOH,
407  MonitorElement *h2SrcStatusEAMC,
408  MonitorElement *h2SrcStatusWAMC,
409  MonitorElement *h2SrcStatusEAMC13,
410  Int_t nLumiCurr) {
411  Int_t nBinY = h2Sum->getNbinsY();
412  Int_t nAllBin = 0, nFineBin = 0;
413  for (Int_t j = 1; j <= nBinY; j++) {
414  Int_t nBinX = (Int_t)(h2SrcStatusE->getBinContent(0, j) + 0.5);
415  auto h2SrcOcc = listOccPlots[j];
416  Int_t nBinYOcc = 0;
417  if (h2SrcOcc != nullptr) {
418  nBinYOcc = h2SrcOcc->getNbinsY();
419  }
420 
421  h2Sum->setBinContent(0, j, nBinX);
422  for (Int_t i = 1; i <= nBinX; i++) {
423  Float_t fOcc = 0;
424  for (Int_t r = 1; r <= nBinYOcc; r++) {
425  fOcc += h2SrcOcc->getBinContent(i, r);
426  }
427 
428  Float_t fStatusAll = h2SrcStatusA->getBinContent(i, j);
429  Float_t fStatusErr = h2SrcStatusE->getBinContent(i, j);
430  Float_t fStatusWarn = h2SrcStatusW->getBinContent(i, j);
431  Float_t fStatusErrVFAT = h2SrcStatusEVFAT->getBinContent(i, j);
432  Float_t fStatusWarnVFAT = h2SrcStatusWVFAT->getBinContent(i, j);
433  Float_t fStatusErrOH = h2SrcStatusEOH->getBinContent(i, j);
434  Float_t fStatusWarnOH = h2SrcStatusWOH->getBinContent(i, j);
435  Float_t fStatusErrAMC = h2SrcStatusEAMC->getBinContent(i, j);
436  Float_t fStatusWarnAMC = h2SrcStatusWAMC->getBinContent(i, j);
437  Float_t fStatusErrAMC13 = h2SrcStatusEAMC13->getBinContent(i, j);
438  NumStatus numStatus(fStatusAll,
439  fOcc,
440  fStatusErrVFAT,
441  fStatusWarnVFAT,
442  fStatusErrOH,
443  fStatusWarnOH,
444  fStatusErrAMC,
445  fStatusWarnAMC,
446  fStatusErrAMC13);
447  UpdateStatusChamber(j, i, nLumiCurr, numStatus);
448 
449  Int_t nRes = assessOneBin(strName, i, j, fStatusAll, fOcc, fStatusErr, fStatusWarn);
450  if (nRes == 1)
451  nFineBin++;
452 
453  h2Sum->setBinContent(i, j, (Float_t)nRes);
454  nAllBin++;
455  }
456  }
457 
458  return ((Float_t)nFineBin) / nAllBin;
459 }
460 
462  MonitorElement *h2Sum,
463  MonitorElement *h2SrcOcc,
464  MonitorElement *h2SrcStatusE,
465  MonitorElement *h2SrcStatusW,
466  Int_t nLumiCurr,
467  Int_t nIdxLayer) {
468  Int_t nBinY = h2Sum->getNbinsY();
469  for (Int_t j = 1; j <= nBinY; j++) {
470  Int_t nBinX = h2Sum->getNbinsX();
471  for (Int_t i = 1; i <= nBinX; i++) {
472  Float_t fOcc = h2SrcOcc->getBinContent(i, j);
473  Float_t fStatusErr = h2SrcStatusE->getBinContent(i, j);
474  Float_t fStatusWarn = h2SrcStatusW->getBinContent(i, j);
475  Float_t fStatusAll = fOcc + fStatusErr + fStatusWarn;
476  NumStatus numStatus(fStatusAll, fOcc, fStatusErr, fStatusWarn, 0, 0, 0, 0, 0);
477  UpdateStatusChamber(nIdxLayer, i, j, nLumiCurr, numStatus);
478 
479  Int_t nRes = assessOneBin(strName, i, j, fStatusAll, fOcc, fStatusErr, fStatusWarn);
480  h2Sum->setBinContent(i, j, (Float_t)nRes);
481  }
482  }
483 
484  return 0;
485 }
486 
487 Int_t GEMDQMHarvester::UpdateStatusChamber(Int_t nIdxLayer, Int_t nIdxCh, Int_t nLumiCurr, NumStatus numStatus) {
488  if (!bIsStatusChambersInit_)
489  return 0;
490  if (0 >= nIdxCh || nIdxCh > mapNumChPerChamber_[nIdxLayer])
491  return 0;
492  auto &listStatus = mapStatusChambersSummary_[{nIdxLayer, nIdxCh}];
493  auto &numStatusPrev = mapNumStatusChambersSummary_[{nIdxLayer, nIdxCh}];
494  return UpdateStatusChamber(listStatus, numStatusPrev, nLumiCurr, numStatus);
495 }
496 
498  Int_t nIdxLayer, Int_t nIdxCh, Int_t nIdxVFAT, Int_t nLumiCurr, NumStatus numStatus) {
499  if (!bIsStatusChambersInit_)
500  return 0;
501  if (0 >= nIdxCh || nIdxCh > mapNumChPerChamber_[nIdxLayer])
502  return 0;
503  if (0 >= nIdxVFAT || nIdxVFAT > nNumVFATs_)
504  return 0;
505  auto &listStatus = mapStatusVFATsSummary_[{nIdxLayer, nIdxCh, nIdxVFAT}];
506  auto &numStatusPrev = mapNumStatusVFATsSummary_[{nIdxLayer, nIdxCh, nIdxVFAT}];
507  return UpdateStatusChamber(listStatus, numStatusPrev, nLumiCurr, numStatus);
508 }
509 
510 Int_t GEMDQMHarvester::UpdateStatusChamber(std::vector<StatusInfo> &listStatus,
511  NumStatus &numStatus,
512  Int_t nLumiCurr,
513  NumStatus numStatusNew) {
514  // First of all, the current lumi section will be assessed, of which the result will be stored in nStatus
515  Int_t nStatus = 0;
516 
517  Float_t fNumAddErrVFAT = numStatusNew.fNumErrVFAT_ - numStatus.fNumErrVFAT_;
518  Float_t fNumAddWarnVFAT = numStatusNew.fNumWarnVFAT_ - numStatus.fNumWarnVFAT_;
519  Float_t fNumAddErrOH = numStatusNew.fNumErrOH_ - numStatus.fNumErrOH_;
520  Float_t fNumAddWarnOH = numStatusNew.fNumWarnOH_ - numStatus.fNumWarnOH_;
521  Float_t fNumAddErrAMC = numStatusNew.fNumErrAMC_ - numStatus.fNumErrAMC_;
522  Float_t fNumAddWarnAMC = numStatusNew.fNumWarnAMC_ - numStatus.fNumWarnAMC_;
523  Float_t fNumAddErrAMC13 = numStatusNew.fNumErrAMC13_ - numStatus.fNumErrAMC13_;
524 
525  numStatus.fNumTotal_ = numStatusNew.fNumTotal_;
526  numStatus.fNumOcc_ = numStatusNew.fNumOcc_;
527  numStatus.fNumErrVFAT_ = numStatusNew.fNumErrVFAT_;
528  numStatus.fNumWarnVFAT_ = numStatusNew.fNumWarnVFAT_;
529  numStatus.fNumErrOH_ = numStatusNew.fNumErrOH_;
530  numStatus.fNumWarnOH_ = numStatusNew.fNumWarnOH_;
531  numStatus.fNumErrAMC_ = numStatusNew.fNumErrAMC_;
532  numStatus.fNumWarnAMC_ = numStatusNew.fNumWarnAMC_;
533  numStatus.fNumErrAMC13_ = numStatusNew.fNumErrAMC13_;
534 
535  nStatus = (numStatusNew.fNumOcc_ > 0 ? 1 << nBitOcc_ : 0) | (fNumAddErrAMC13 > 0 ? 1 << nBitErrAMC13_ : 0) |
536  (fNumAddErrAMC > 0 ? 1 << nBitErrAMC_ : 0) | (fNumAddWarnAMC > 0 ? 1 << nBitWarnAMC_ : 0) |
537  (fNumAddErrOH > 0 ? 1 << nBitErrOH_ : 0) | (fNumAddWarnOH > 0 ? 1 << nBitWarnOH_ : 0) |
538  (fNumAddErrVFAT > 0 ? 1 << nBitErrVFAT_ : 0) | (fNumAddWarnVFAT > 0 ? 1 << nBitWarnVFAT_ : 0);
539 
540  // Only used in the next if statement; See statusLast
541  StatusInfo statusNew;
542  statusNew.nLumiStart = nLumiCurr;
543  statusNew.nLumiEnd = nLumiCurr;
544  statusNew.nStatus = nStatus;
545 
546  if (listStatus.empty()) {
547  listStatus.push_back(statusNew);
548  } else {
549  auto &statusLastPre = listStatus.back();
550  if (statusLastPre.nStatus == nStatus) {
551  statusLastPre.nLumiEnd = nLumiCurr;
552  } else {
553  listStatus.push_back(statusNew);
554  }
555  }
556 
557  return 0;
558 }
559 
561  std::string strSuffix,
562  Int_t nIdxLayer,
563  Int_t nLumiCurr) {
564  auto &nNumCh = mapNumChPerChamber_[nIdxLayer];
565 
566  MonitorElement *h2Summary;
567 
568  //Int_t nLumiCurrLowRes = ( ( nLumiCurr - 1 ) / nResolutionLumi_ ) * nResolutionLumi_;
569  Int_t nNumBinLumi = ((nLumiCurr - 1) / nResolutionLumi_) + 1;
570  Int_t nMaxBin = 0;
571 
572  // Creating or Summoning the corresponding histogram
573  if (mapHistLumiFunc_.find(nIdxLayer) == mapHistLumiFunc_.end()) {
574  store->setCurrentFolder(strDirSummary_);
575  h2Summary = store->book2S("chamberStatus_inLumi" + strSuffix,
576  "Chamber status on lumi-block " + strSuffix.substr(1),
577  nMaxLumi_ / nResolutionLumi_,
578  1.0,
579  (Float_t)(nMaxLumi_ + 1),
580  //nNumBinLumi, 1.0, (Float_t)( nLumiCurr + 1 ),
581  nNumCh,
582  0.5,
583  nNumCh + 0.5);
584  mapHistLumiFunc_[nIdxLayer] = h2Summary;
585 
586  h2Summary->setXTitle("Luminosity block");
587  h2Summary->setYTitle("Chamber");
588  for (Int_t i = 1; i <= nNumCh; i++) {
589  h2Summary->setBinLabel(i, Form("%i", i), 2);
590  }
591  } else {
592  h2Summary = mapHistLumiFunc_[nIdxLayer];
593  }
594 
595  for (Int_t nIdxCh = 1; nIdxCh <= nNumCh; nIdxCh++) {
596  auto &listStatus = mapStatusChambersSummary_[{nIdxLayer, nIdxCh}];
597 
598  Int_t nIdxStatus = 0;
599  for (Int_t nIdxLumi = 0; nIdxLumi < nNumBinLumi; nIdxLumi++) {
600  // Lumis covered by these values (nLumiStart <=, <= nLumiEnd) are counted for the current bin
601  Int_t nLumiStart = 1 + nIdxLumi * nResolutionLumi_;
602  Int_t nLumiEnd = (1 + nIdxLumi) * nResolutionLumi_;
603  if (nLumiEnd > nLumiCurr)
604  nLumiEnd = nLumiCurr;
605 
606  Int_t nStatusSum = 0;
607  while (true) { // No worries, nIdxStatus must increase and reach at listStatus.size()
608  // True: It was too past so that
609  // the lumi range of listStatus[ nIdxStatus ] is out of the coverage of the current bin
610  if (listStatus[nIdxStatus].nLumiEnd < nLumiStart) {
611  nIdxStatus++;
612  if (nIdxStatus >= (int)listStatus.size()) {
613  break; // For safety
614  }
615  continue;
616  }
617 
618  nStatusSum = listStatus[nIdxStatus].nStatus;
619 
620  // True: This is the last item of listStatus which is covered by the current bin
621  if (nIdxStatus + 1 >= (int)listStatus.size() || listStatus[nIdxStatus].nLumiEnd >= nLumiEnd) {
622  break;
623  }
624 
625  nIdxStatus++;
626  if (nIdxStatus >= (int)listStatus.size()) {
627  break; // For safety
628  }
629  }
630 
631  nStatusSum &= ~(1 << nBitOcc_); // No need of displaying the digi occupancy
632  h2Summary->setBinContent(nIdxLumi + 1, nIdxCh, nStatusSum);
633  if (nMaxBin < nIdxLumi + 1)
634  nMaxBin = nIdxLumi + 1;
635  }
636  }
637 
638  for (Int_t nX = 1; nX <= nMaxBin; nX++) {
639  h2Summary->setBinContent(nX, 0, 1);
640  }
641 }
642 
644  std::string strRegion;
645  std::string strChType = (nIdxCh % 2 == 0 ? "L" : "S");
646  Int_t nLayer;
647 
648  if (strSuffix.find("-M-") != std::string::npos)
649  strRegion = "M";
650  else if (strSuffix.find("-P-") != std::string::npos)
651  strRegion = "P";
652  else
653  return "";
654 
655  if (strSuffix.find("-L1") != std::string::npos)
656  nLayer = 1;
657  else if (strSuffix.find("-L2") != std::string::npos)
658  nLayer = 2;
659  else
660  return "";
661 
662  return Form("GEM/Digis/occupancy_GE11-%s-L%i/occ_GE11-%s-%02iL%i-%s",
663  strRegion.c_str(),
664  nLayer,
665  strRegion.c_str(),
666  nIdxCh,
667  nLayer,
668  strChType.c_str());
669 }
670 
671 std::string getNameChamberOccGE21(std::string strSuffix, Int_t nIdxChamber) {
672  return ""; // FIXME
673 }
674 
675 std::string getNameChamberOccNull(std::string strSuffix, Int_t nIdxChamber) {
676  return ""; // For an initialization
677 }
678 
680  std::string strSuffix,
681  Int_t nNumChamber) {
682  std::string strTitle = "The fraction of inactive channels in " + strSuffix.substr(1);
683  MonitorElement *h2InactiveChannel =
684  store->book1D("inactive_frac_chamber" + strSuffix, strTitle, nNumChamber, 0.5, nNumChamber + 0.5);
685  h2InactiveChannel->setXTitle("Chamber");
686  h2InactiveChannel->setYTitle("Fraction of inactive channels");
687  for (Int_t i = 1; i <= nNumChamber; i++) {
688  h2InactiveChannel->setBinLabel(i, Form("%i", i), 1);
689  }
690 
691  std::string (*funcNameCh)(std::string, Int_t) = getNameChamberOccNull;
692 
693  if (strSuffix.find("_GE11") != std::string::npos) {
694  funcNameCh = getNameChamberOccGE11;
695  } else if (strSuffix.find("_GE21") != std::string::npos) {
696  funcNameCh = getNameChamberOccGE21;
697  }
698 
699  for (Int_t nIdxCh = 1; nIdxCh <= nNumChamber; nIdxCh++) {
700  std::string strNameCh = funcNameCh(strSuffix, nIdxCh);
701  MonitorElement *h2SrcChamberOcc = store->get(strNameCh);
702  if (h2SrcChamberOcc == nullptr) {
703  // FIXME: It's about sending a message
704  continue;
705  }
706 
707  Int_t nNumBinX = h2SrcChamberOcc->getNbinsX();
708  Int_t nNumBinY = h2SrcChamberOcc->getNbinsY();
709  Int_t nNumChannelInactive = 0;
710  for (Int_t i = 1; i <= nNumBinX; i++)
711  for (Int_t j = 1; j <= nNumBinY; j++) {
712  if (h2SrcChamberOcc->getBinContent(i, j) <= 0) {
713  nNumChannelInactive++;
714  }
715  }
716 
717  Int_t nNumAllChannel = nNumBinX * nNumBinY;
718  h2InactiveChannel->setBinContent(nIdxCh, ((Double_t)nNumChannelInactive) / nNumAllChannel);
719  }
720 }
721 
LuminosityBlockID id() const
virtual std::string getTitle() const
get MonitorElement title
virtual void setTitle(const std::string &title)
set (ie. change) histogram/profile title
std::map< std::string, int > mapIdxLayer_
virtual TH2F * getTH2F() const
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
tuple cfg
Definition: looper.py:296
void createSummaryVFAT(edm::Service< DQMStore > &store, MonitorElement *h2Src, std::string strSuffix, MonitorElement *&h2Sum)
MonitorElement * book2S(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:254
virtual int getNbinsY() const
get # of bins in Y-axis
void createInactiveChannelFracHist(edm::Service< DQMStore > &store, std::string strSuffix, Int_t nNumChamber)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
~GEMDQMHarvester() override
virtual std::string getAxisTitle(int axis=1) const
get x-, y- or z-axis title (axis=1, 2, 3 respectively)
void copyLabels(MonitorElement *h2Src, MonitorElement *h2Dst)
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &iLumi, edm::EventSetup const &) override
std::map< IdChamber, std::vector< StatusInfo > > mapStatusChambersSummary_
std::map< IdVFAT, NumStatus > mapNumStatusVFATsSummary_
void createTableWatchingSummary()
std::string getNameChamberOccNull(std::string strSuffix, Int_t nIdxChamber)
std::vector< std::string > listLayer_
void Fill(long long x)
std::map< IdVFAT, std::vector< StatusInfo > > mapStatusVFATsSummary_
void drawSummaryHistogram(edm::Service< DQMStore > &store, Int_t nLumiCurr)
virtual void setXTitle(std::string const &title)
virtual int getNbinsX() const
get # of bins in X-axis
std::tuple< int, int > IdChamber
std::vector< std::vector< Float_t > > TableStatusOcc
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
std::string getNameChamberOccGE11(std::string strSuffix, Int_t nIdxCh)
Bool_t bIsStatusChambersInit_
NumStatus(Float_t fNumTotal=0, Float_t fNumOcc=0, Float_t fNumErrVFAT=0, Float_t fNumWarnVFAT=0, Float_t fNumErrOH=0, Float_t fNumWarnOH=0, Float_t fNumErrAMC=0, Float_t fNumWarnAMC=0, Float_t fNumErrAMC13=0)
std::map< int, MonitorElement * > mapHistLumiFunc_
Int_t assessOneBin(std::string strName, Int_t nIdxX, Int_t nIdxY, Float_t fAll, Float_t fNumOcc, Float_t fNumErr, Float_t fNumWarn)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
virtual double getBinContent(int binx) const
get content of bin (1-D)
std::string getNameChamberOccGE21(std::string strSuffix, Int_t nIdxChamber)
void getGeometryInfo(edm::Service< DQMStore > &store, MonitorElement *h2Src)
virtual void setYTitle(std::string const &title)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
GEMDQMHarvester(const edm::ParameterSet &)
LuminosityBlockNumber_t luminosityBlock() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Int_t UpdateStatusChamber(Int_t nIdxLayer, Int_t nIdxCh, Int_t nLumiCurr, NumStatus numStatus)
std::map< IdChamber, NumStatus > mapNumStatusChambersSummary_
std::vector< std::vector< Int_t > > TableStatusNum
void createSummaryHist(edm::Service< DQMStore > &store, MonitorElement *h2Src, MonitorElement *&h2Sum)
Int_t refineSummaryVFAT(std::string strName, MonitorElement *h2Sum, MonitorElement *h2SrcOcc, MonitorElement *h2SrcStatusE, MonitorElement *h2SrcStatusW, Int_t nLumiCurr, Int_t nIdxLayer)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Float_t refineSummaryHistogram(std::string strName, MonitorElement *h2Sum, std::vector< MonitorElement * > &listOccPlots, MonitorElement *h2SrcStatusA, MonitorElement *h2SrcStatusE, MonitorElement *h2SrcStatusW, MonitorElement *h2SrcStatusEVFAT, MonitorElement *h2SrcStatusWVFAT, MonitorElement *h2SrcStatusEOH, MonitorElement *h2SrcStatusWOH, MonitorElement *h2SrcStatusEAMC, MonitorElement *h2SrcStatusWAMC, MonitorElement *h2SrcStatusEAMC13, Int_t nLumiCurr)
std::map< int, int > mapNumChPerChamber_
void createLumiFuncHist(edm::Service< DQMStore > &store, std::string strSuffix, Int_t nIdxLayer, Int_t nLumiCurr)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::tuple< int, int, int > IdVFAT
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override