CMS 3D CMS Logo

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