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  const Int_t nCodeMasked_ = 5;
127 
128  const Int_t nBitWarnVFAT_ = 7;
129  const Int_t nBitErrVFAT_ = 6;
130  const Int_t nBitWarnOH_ = 5;
131  const Int_t nBitErrOH_ = 4;
132  const Int_t nBitWarnAMC_ = 3;
133  const Int_t nBitErrAMC_ = 2;
134  const Int_t nBitErrAMC13_ = 1;
135  const Int_t nBitOcc_ = 0;
136 
137  const Int_t nNumVFATs_ = 24;
138 
139  const Int_t nMaxLumi_ = 6000; // From DQMServices/Components/plugins/DQMProvInfo.h
140  //const Int_t nResolutionLumi_ = 5;
142 
143  typedef std::vector<std::vector<Float_t>> TableStatusOcc;
144  typedef std::vector<std::vector<Int_t>> TableStatusNum;
145 
146  std::map<IdChamber, std::vector<StatusInfo>> mapStatusChambersSummary_;
147  std::map<IdVFAT, std::vector<StatusInfo>> mapStatusVFATsSummary_;
148  std::map<IdChamber, NumStatus> mapNumStatusChambersSummary_;
149  std::map<IdVFAT, NumStatus> mapNumStatusVFATsSummary_;
150 
151  std::vector<std::string> listLayer_;
152  std::map<std::string, int> mapIdxLayer_; // All indices in the following objects start at 1
153  std::map<int, int> mapNumChPerChamber_;
154  std::map<int, std::map<int, int>> mapIdxToChamberInOcc_;
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, h2SrcStatusE);
219 
220  if (h2SrcStatusA != nullptr && h2SrcStatusE != nullptr && h2SrcStatusW != nullptr) {
221  MonitorElement *h2Sum = nullptr;
222  createSummaryHist(store, h2SrcStatusE, h2Sum);
223  createTableWatchingSummary();
224 
225  std::vector<MonitorElement *> listOccPlots(listLayer_.size() + 1); // The index starts at 1
226  for (const auto &strSuffix : listLayer_) {
227  if (mapIdxLayer_.find(strSuffix) == mapIdxLayer_.end())
228  continue;
229  auto nIdxLayer = mapIdxLayer_[strSuffix];
230  MonitorElement *h2SrcVFATOcc = store->get(strSrcVFATOcc + strSuffix);
231  if (h2SrcVFATOcc == nullptr)
232  continue;
233  listOccPlots[nIdxLayer] = h2SrcVFATOcc;
234  mapIdxToChamberInOcc_[nIdxLayer] = {};
235  // Obtaining the bin indices of chambers from their labels
236  for (Int_t i = 1; i <= h2SrcVFATOcc->getNbinsX(); i++) {
237  std::string strLabel = h2SrcVFATOcc->getTH2F()->GetXaxis()->GetBinLabel(i);
238  std::string strSrc = strLabel;
239  std::vector<int> listNumExtract;
240 
241  while (!strSrc.empty()) {
242  auto nPosDigit = strSrc.find_first_of("0123456789");
243  if (nPosDigit == std::string::npos)
244  break;
245  std::stringstream ss;
246  ss << strSrc.substr(nPosDigit);
247  Int_t nExtract;
248  ss >> nExtract;
249  if (!ss.eof()) {
250  ss >> strSrc;
251  } else {
252  strSrc = "";
253  }
254  listNumExtract.push_back(nExtract);
255  }
256 
257  if (listNumExtract.empty()) { // Errneous case; but the job should not be dead
258  edm::LogError("GEMDQMHarvester") << "Error: Wrong label of GEM VFAT occupancy plot: " << strLabel;
259  } else {
260  mapIdxToChamberInOcc_[nIdxLayer][listNumExtract[0]] = i;
261  }
262  }
263  }
264 
265  fReportSummary = refineSummaryHistogram(strTitleSummary,
266  h2Sum,
267  listOccPlots,
268  h2SrcStatusA,
269  h2SrcStatusE,
270  h2SrcStatusW,
271  h2SrcStatusEVFAT,
272  h2SrcStatusWVFAT,
273  h2SrcStatusEOH,
274  h2SrcStatusWOH,
275  h2SrcStatusEAMC,
276  h2SrcStatusWAMC,
277  h2SrcStatusEAMC13,
278  nLumiCurr);
279 
280  for (const auto &strSuffix : listLayer_) {
281  if (mapIdxLayer_.find(strSuffix) == mapIdxLayer_.end())
282  continue;
283  auto nIdxLayer = mapIdxLayer_[strSuffix];
284  MonitorElement *h2SrcVFATOcc = store->get(strSrcVFATOcc + strSuffix);
285  MonitorElement *h2SrcVFATStatusW = store->get(strSrcVFATStatusW + strSuffix);
286  MonitorElement *h2SrcVFATStatusE = store->get(strSrcVFATStatusE + strSuffix);
287  if (h2SrcVFATOcc == nullptr || h2SrcVFATStatusW == nullptr || h2SrcVFATStatusE == nullptr)
288  continue;
289 
290  MonitorElement *h2SumVFAT = nullptr;
291  createSummaryVFAT(store, h2SrcVFATStatusE, strSuffix, h2SumVFAT);
292  refineSummaryVFAT(strSuffix, h2SumVFAT, h2SrcVFATOcc, h2SrcVFATStatusE, h2SrcVFATStatusW, nLumiCurr, nIdxLayer);
293  TString strNewTitle = h2SrcVFATStatusE->getTitle();
294  h2SumVFAT->setTitle((const char *)strNewTitle.ReplaceAll("errors", "errors/warnings"));
295  h2SumVFAT->setXTitle(h2SrcVFATStatusE->getAxisTitle(1));
296  h2SumVFAT->setYTitle(h2SrcVFATStatusE->getAxisTitle(2));
297 
298  createLumiFuncHist(store, strSuffix, nIdxLayer, nLumiCurr);
299  }
300  }
301 
302  for (const auto &strSuffix : listLayer_) {
303  if (mapIdxLayer_.find(strSuffix) == mapIdxLayer_.end())
304  continue;
305  Int_t nIdxLayer = mapIdxLayer_[strSuffix];
306  createInactiveChannelFracHist(store, strSuffix, mapNumChPerChamber_[nIdxLayer]);
307  }
308 
309  store->bookFloat("reportSummary")->Fill(fReportSummary);
310 }
311 
313  if (bIsStatusChambersInit_)
314  return;
315 
316  for (const auto &[nIdxLayer, nNumCh] : mapNumChPerChamber_) {
317  for (Int_t i = 1; i <= nNumCh; i++) {
318  mapStatusChambersSummary_[{nIdxLayer, i}] = std::vector<StatusInfo>();
319  mapNumStatusChambersSummary_[{nIdxLayer, i}] = NumStatus();
320  for (Int_t j = 1; j <= nNumVFATs_; j++) {
321  mapStatusVFATsSummary_[{nIdxLayer, i, j}] = std::vector<StatusInfo>();
322  mapNumStatusVFATsSummary_[{nIdxLayer, i, j}] = NumStatus();
323  }
324  }
325  }
326 
327  bIsStatusChambersInit_ = true;
328 }
329 
331  Int_t nBinX = h2Src->getNbinsX(), nBinY = h2Src->getNbinsY();
332 
333  for (Int_t i = 1; i <= nBinX; i++) {
334  h2Dst->setBinLabel(i, h2Src->getTH2F()->GetXaxis()->GetBinLabel(i), 1);
335  }
336  for (Int_t i = 1; i <= nBinY; i++) {
337  h2Dst->setBinLabel(i, h2Src->getTH2F()->GetYaxis()->GetBinLabel(i), 2);
338  }
339  h2Dst->setTitle(h2Src->getTitle());
340  h2Dst->setXTitle(h2Src->getAxisTitle(1));
341  h2Dst->setYTitle(h2Src->getAxisTitle(2));
342 }
343 
345  listLayer_.clear();
346  mapIdxLayer_.clear();
347  mapNumChPerChamber_.clear();
348 
349  if (h2Src != nullptr) { // For online and offline
350  Int_t nBinY = h2Src->getNbinsY();
351  listLayer_.push_back("");
352  Int_t nNumMerge = std::max((Int_t)(h2Src->getBinContent(0, 0) + 0.5), 1);
353 
354  for (Int_t i = 1; i <= nBinY; i++) {
355  std::string strLabelFull = h2Src->getTH2F()->GetYaxis()->GetBinLabel(i);
356  auto nPos = strLabelFull.find(';');
357  auto strLayer = strLabelFull.substr(nPos + 1);
358  Int_t nBinXActual = ((Int_t)(h2Src->getBinContent(0, i) + 0.5)) / nNumMerge;
359  if (nBinXActual > 108) { // When the number seems wrong
360  if (strLayer.find("GE11") != std::string::npos) {
361  nBinXActual = 36;
362  } else if (strLayer.find("GE21") != std::string::npos) {
363  nBinXActual = 18;
364  } else if (strLayer.find("GE01") != std::string::npos) {
365  nBinXActual = 36;
366  }
367  }
368  listLayer_.push_back(strLayer);
369  mapIdxLayer_[strLayer] = i;
370  mapNumChPerChamber_[i] = nBinXActual;
371  }
372  } else { // For others (validation and...?)
373  listLayer_.push_back("");
374  if (store->get("GEM/Digis/occupancy_GE11-M-L1/occ_GE11-M-01L1-S") != nullptr) {
375  listLayer_.push_back("_GE11-P-L2");
376  listLayer_.push_back("_GE11-P-L1");
377  listLayer_.push_back("_GE11-M-L1");
378  listLayer_.push_back("_GE11-M-L2");
379  mapIdxLayer_["_GE11-P-L2"] = 1;
380  mapIdxLayer_["_GE11-P-L1"] = 2;
381  mapIdxLayer_["_GE11-M-L1"] = 3;
382  mapIdxLayer_["_GE11-M-L2"] = 4;
383  mapNumChPerChamber_[1] = 36;
384  mapNumChPerChamber_[2] = 36;
385  mapNumChPerChamber_[3] = 36;
386  mapNumChPerChamber_[4] = 36;
387  }
388  // FIXME: How about GE21 and ME0?
389  }
390 }
391 
393  //store->setCurrentFolder(strDirSummary_);
394 
395  Int_t nBinX = h2Src->getNbinsX(), nBinY = h2Src->getNbinsY();
396  h2Sum = store->book2D("reportSummaryMap", "", nBinX, 0.5, nBinX + 0.5, nBinY, 0.5, nBinY + 0.5);
397  h2Sum->setTitle("Summary plot");
398  h2Sum->setXTitle("Chamber");
399  h2Sum->setYTitle("Layer");
400 
401  for (Int_t i = 1; i <= nBinX; i++)
402  h2Sum->setBinLabel(i, h2Src->getTH2F()->GetXaxis()->GetBinLabel(i), 1);
403  for (Int_t i = 1; i <= nBinY; i++)
404  h2Sum->setBinLabel(i, listLayer_[i].substr(1), 2);
405 }
406 
408  MonitorElement *h2Src,
409  std::string strSuffix,
410  MonitorElement *&h2Sum) {
411  //store->setCurrentFolder(strDirStatus_);
412  //store->setCurrentFolder(strDirSummary_);
413 
414  Int_t nBinX = h2Src->getNbinsX(), nBinY = h2Src->getNbinsY();
415  h2Sum = store->book2D("vfat_statusSummary" + strSuffix, "", nBinX, 0.5, nBinX + 0.5, nBinY, -0.5, nBinY - 0.5);
416  copyLabels(h2Src, h2Sum);
417 }
418 
420  std::string strName, Int_t nIdxX, Int_t nIdxY, Float_t fAll, Float_t fNumOcc, Float_t fNumErr, Float_t fNumWarn) {
421  if (fNumErr < 0)
422  return nCodeMasked_;
423  if (fNumErr > fCutErr_ * fAll) // The error status criterion
424  return nCodeError_;
425  else if (fNumErr > fCutLowErr_ * fAll) // The low-error status criterion
426  return nCodeLowError_;
427  else if (fNumWarn > fCutWarn_ * fAll) // The warning status criterion
428  return nCodeWarning_;
429  else if (fNumOcc > 0)
430  return nCodeFine_;
431 
432  return 0;
433 }
434 
435 // FIXME: Need more study about how to summarize
437  MonitorElement *h2Sum,
438  std::vector<MonitorElement *> &listOccPlots,
439  MonitorElement *h2SrcStatusA,
440  MonitorElement *h2SrcStatusE,
441  MonitorElement *h2SrcStatusW,
442  MonitorElement *h2SrcStatusEVFAT,
443  MonitorElement *h2SrcStatusWVFAT,
444  MonitorElement *h2SrcStatusEOH,
445  MonitorElement *h2SrcStatusWOH,
446  MonitorElement *h2SrcStatusEAMC,
447  MonitorElement *h2SrcStatusWAMC,
448  MonitorElement *h2SrcStatusEAMC13,
449  Int_t nLumiCurr) {
450  Int_t nBinY = h2Sum->getNbinsY();
451  Int_t nAllBin = 0, nFineBin = 0;
452  for (Int_t j = 1; j <= nBinY; j++) {
453  Int_t nBinX = mapNumChPerChamber_[j];
454  auto h2SrcOcc = listOccPlots[j];
455  auto &mapIdxOccChamber = mapIdxToChamberInOcc_[j];
456  Int_t nBinYOcc = 0;
457  if (h2SrcOcc != nullptr) {
458  nBinYOcc = h2SrcOcc->getNbinsY();
459  }
460 
461  h2Sum->setBinContent(0, j, nBinX);
462  for (Int_t i = 1; i <= nBinX; i++) {
463  Float_t fOcc = 0;
464  Int_t nIdxChOcc = mapIdxOccChamber[i];
465  for (Int_t r = 1; r <= nBinYOcc; r++) {
466  fOcc += h2SrcOcc->getBinContent(nIdxChOcc, r);
467  }
468 
469  Float_t fStatusAll = h2SrcStatusA->getBinContent(i, j);
470  Float_t fStatusErr = h2SrcStatusE->getBinContent(i, j);
471  Float_t fStatusWarn = h2SrcStatusW->getBinContent(i, j);
472  Float_t fStatusErrVFAT = h2SrcStatusEVFAT != nullptr ? h2SrcStatusEVFAT->getBinContent(i, j) : 0;
473  Float_t fStatusWarnVFAT = h2SrcStatusWVFAT != nullptr ? h2SrcStatusWVFAT->getBinContent(i, j) : 0;
474  Float_t fStatusErrOH = h2SrcStatusEOH != nullptr ? h2SrcStatusEOH->getBinContent(i, j) : 0;
475  Float_t fStatusWarnOH = h2SrcStatusWOH != nullptr ? h2SrcStatusWOH->getBinContent(i, j) : 0;
476  Float_t fStatusErrAMC = h2SrcStatusEAMC != nullptr ? h2SrcStatusEAMC->getBinContent(i, j) : 0;
477  Float_t fStatusWarnAMC = h2SrcStatusWAMC != nullptr ? h2SrcStatusWAMC->getBinContent(i, j) : 0;
478  Float_t fStatusErrAMC13 = h2SrcStatusEAMC13 != nullptr ? h2SrcStatusEAMC13->getBinContent(i, j) : 0;
479  NumStatus numStatus(fStatusAll,
480  fOcc,
481  fStatusErrVFAT,
482  fStatusWarnVFAT,
483  fStatusErrOH,
484  fStatusWarnOH,
485  fStatusErrAMC,
486  fStatusWarnAMC,
487  fStatusErrAMC13);
488  UpdateStatusChamber(j, i, nLumiCurr, numStatus);
489 
490  Int_t nRes = assessOneBin(strName, i, j, fStatusAll, fOcc, fStatusErr, fStatusWarn);
491  if (nRes == 1)
492  nFineBin++;
493 
494  h2Sum->setBinContent(i, j, (Float_t)nRes);
495  nAllBin++;
496  }
497  }
498 
499  return ((Float_t)nFineBin) / nAllBin;
500 }
501 
503  MonitorElement *h2Sum,
504  MonitorElement *h2SrcOcc,
505  MonitorElement *h2SrcStatusE,
506  MonitorElement *h2SrcStatusW,
507  Int_t nLumiCurr,
508  Int_t nIdxLayer) {
509  Int_t nBinY = h2Sum->getNbinsY();
510  for (Int_t j = 1; j <= nBinY; j++) {
511  Int_t nBinX = h2Sum->getNbinsX();
512  for (Int_t i = 1; i <= nBinX; i++) {
513  Float_t fOcc = h2SrcOcc->getBinContent(i, j);
514  Float_t fStatusErr = h2SrcStatusE->getBinContent(i, j);
515  Float_t fStatusWarn = h2SrcStatusW->getBinContent(i, j);
516  Float_t fStatusAll = fOcc + fStatusErr + fStatusWarn;
517  NumStatus numStatus(fStatusAll, fOcc, fStatusErr, fStatusWarn, 0, 0, 0, 0, 0);
518  UpdateStatusChamber(nIdxLayer, i, j, nLumiCurr, numStatus);
519 
520  Int_t nRes = assessOneBin(strName, i, j, fStatusAll, fOcc, fStatusErr, fStatusWarn);
521  h2Sum->setBinContent(i, j, (Float_t)nRes);
522  }
523  }
524 
525  return 0;
526 }
527 
528 Int_t GEMDQMHarvester::UpdateStatusChamber(Int_t nIdxLayer, Int_t nIdxCh, Int_t nLumiCurr, NumStatus numStatus) {
529  if (!bIsStatusChambersInit_)
530  return 0;
531  if (0 >= nIdxCh || nIdxCh > mapNumChPerChamber_[nIdxLayer])
532  return 0;
533  auto &listStatus = mapStatusChambersSummary_[{nIdxLayer, nIdxCh}];
534  auto &numStatusPrev = mapNumStatusChambersSummary_[{nIdxLayer, nIdxCh}];
535  return UpdateStatusChamber(listStatus, numStatusPrev, nLumiCurr, numStatus);
536 }
537 
539  Int_t nIdxLayer, Int_t nIdxCh, Int_t nIdxVFAT, Int_t nLumiCurr, NumStatus numStatus) {
540  if (!bIsStatusChambersInit_)
541  return 0;
542  if (0 >= nIdxCh || nIdxCh > mapNumChPerChamber_[nIdxLayer])
543  return 0;
544  if (0 >= nIdxVFAT || nIdxVFAT > nNumVFATs_)
545  return 0;
546  auto &listStatus = mapStatusVFATsSummary_[{nIdxLayer, nIdxCh, nIdxVFAT}];
547  auto &numStatusPrev = mapNumStatusVFATsSummary_[{nIdxLayer, nIdxCh, nIdxVFAT}];
548  return UpdateStatusChamber(listStatus, numStatusPrev, nLumiCurr, numStatus);
549 }
550 
551 Int_t GEMDQMHarvester::UpdateStatusChamber(std::vector<StatusInfo> &listStatus,
552  NumStatus &numStatus,
553  Int_t nLumiCurr,
554  NumStatus numStatusNew) {
555  // First of all, the current lumi section will be assessed, of which the result will be stored in nStatus
556  Int_t nStatus = 0;
557 
558  Float_t fNumAddErrVFAT = numStatusNew.fNumErrVFAT_ - numStatus.fNumErrVFAT_;
559  Float_t fNumAddWarnVFAT = numStatusNew.fNumWarnVFAT_ - numStatus.fNumWarnVFAT_;
560  Float_t fNumAddErrOH = numStatusNew.fNumErrOH_ - numStatus.fNumErrOH_;
561  Float_t fNumAddWarnOH = numStatusNew.fNumWarnOH_ - numStatus.fNumWarnOH_;
562  Float_t fNumAddErrAMC = numStatusNew.fNumErrAMC_ - numStatus.fNumErrAMC_;
563  Float_t fNumAddWarnAMC = numStatusNew.fNumWarnAMC_ - numStatus.fNumWarnAMC_;
564  Float_t fNumAddErrAMC13 = numStatusNew.fNumErrAMC13_ - numStatus.fNumErrAMC13_;
565 
566  numStatus.fNumTotal_ = numStatusNew.fNumTotal_;
567  numStatus.fNumOcc_ = numStatusNew.fNumOcc_;
568  numStatus.fNumErrVFAT_ = numStatusNew.fNumErrVFAT_;
569  numStatus.fNumWarnVFAT_ = numStatusNew.fNumWarnVFAT_;
570  numStatus.fNumErrOH_ = numStatusNew.fNumErrOH_;
571  numStatus.fNumWarnOH_ = numStatusNew.fNumWarnOH_;
572  numStatus.fNumErrAMC_ = numStatusNew.fNumErrAMC_;
573  numStatus.fNumWarnAMC_ = numStatusNew.fNumWarnAMC_;
574  numStatus.fNumErrAMC13_ = numStatusNew.fNumErrAMC13_;
575 
576  nStatus = (numStatusNew.fNumOcc_ > 0 ? 1 << nBitOcc_ : 0) | (fNumAddErrAMC13 > 0 ? 1 << nBitErrAMC13_ : 0) |
577  (fNumAddErrAMC > 0 ? 1 << nBitErrAMC_ : 0) | (fNumAddWarnAMC > 0 ? 1 << nBitWarnAMC_ : 0) |
578  (fNumAddErrOH > 0 ? 1 << nBitErrOH_ : 0) | (fNumAddWarnOH > 0 ? 1 << nBitWarnOH_ : 0) |
579  (fNumAddErrVFAT > 0 ? 1 << nBitErrVFAT_ : 0) | (fNumAddWarnVFAT > 0 ? 1 << nBitWarnVFAT_ : 0);
580 
581  // Only used in the next if statement; See statusLast
582  StatusInfo statusNew;
583  statusNew.nLumiStart = nLumiCurr;
584  statusNew.nLumiEnd = nLumiCurr;
585  statusNew.nStatus = nStatus;
586 
587  if (listStatus.empty()) {
588  listStatus.push_back(statusNew);
589  } else {
590  auto &statusLastPre = listStatus.back();
591  if (statusLastPre.nStatus == nStatus) {
592  statusLastPre.nLumiEnd = nLumiCurr;
593  } else {
594  listStatus.push_back(statusNew);
595  }
596  }
597 
598  return 0;
599 }
600 
602  std::string strSuffix,
603  Int_t nIdxLayer,
604  Int_t nLumiCurr) {
605  auto &nNumCh = mapNumChPerChamber_[nIdxLayer];
606 
607  MonitorElement *h2Summary;
608 
609  //Int_t nLumiCurrLowRes = ( ( nLumiCurr - 1 ) / nResolutionLumi_ ) * nResolutionLumi_;
610  Int_t nNumBinLumi = ((nLumiCurr - 1) / nResolutionLumi_) + 1;
611  Int_t nMaxBin = 0;
612 
613  // Creating or Summoning the corresponding histogram
614  if (mapHistLumiFunc_.find(nIdxLayer) == mapHistLumiFunc_.end()) {
615  store->setCurrentFolder(strDirSummary_);
616  h2Summary = store->book2S("chamberStatus_inLumi" + strSuffix,
617  "Chamber status on lumi-block " + strSuffix.substr(1),
618  nMaxLumi_ / nResolutionLumi_,
619  1.0,
620  (Float_t)(nMaxLumi_ + 1),
621  //nNumBinLumi, 1.0, (Float_t)( nLumiCurr + 1 ),
622  nNumCh,
623  0.5,
624  nNumCh + 0.5);
625  mapHistLumiFunc_[nIdxLayer] = h2Summary;
626 
627  h2Summary->setXTitle("Luminosity block");
628  h2Summary->setYTitle("Chamber");
629  for (Int_t i = 1; i <= nNumCh; i++) {
630  h2Summary->setBinLabel(i, Form("%i", i), 2);
631  }
632  } else {
633  h2Summary = mapHistLumiFunc_[nIdxLayer];
634  }
635 
636  for (Int_t nIdxCh = 1; nIdxCh <= nNumCh; nIdxCh++) {
637  auto &listStatus = mapStatusChambersSummary_[{nIdxLayer, nIdxCh}];
638 
639  Int_t nIdxStatus = 0;
640  for (Int_t nIdxLumi = 0; nIdxLumi < nNumBinLumi; nIdxLumi++) {
641  // Lumis covered by these values (nLumiStart <=, <= nLumiEnd) are counted for the current bin
642  Int_t nLumiStart = 1 + nIdxLumi * nResolutionLumi_;
643  Int_t nLumiEnd = (1 + nIdxLumi) * nResolutionLumi_;
644  if (nLumiEnd > nLumiCurr)
645  nLumiEnd = nLumiCurr;
646 
647  Int_t nStatusSum = 0;
648  while (true) { // No worries, nIdxStatus must increase and reach at listStatus.size()
649  // True: It was too past so that
650  // the lumi range of listStatus[ nIdxStatus ] is out of the coverage of the current bin
651  if (listStatus[nIdxStatus].nLumiEnd < nLumiStart) {
652  nIdxStatus++;
653  if (nIdxStatus >= (int)listStatus.size()) {
654  break; // For safety
655  }
656  continue;
657  }
658 
659  nStatusSum = listStatus[nIdxStatus].nStatus;
660 
661  // True: This is the last item of listStatus which is covered by the current bin
662  if (nIdxStatus + 1 >= (int)listStatus.size() || listStatus[nIdxStatus].nLumiEnd >= nLumiEnd) {
663  break;
664  }
665 
666  nIdxStatus++;
667  if (nIdxStatus >= (int)listStatus.size()) {
668  break; // For safety
669  }
670  }
671 
672  h2Summary->setBinContent(nIdxLumi + 1, nIdxCh, nStatusSum);
673  if (nMaxBin < nIdxLumi + 1)
674  nMaxBin = nIdxLumi + 1;
675  }
676  }
677 
678  for (Int_t nX = 1; nX <= nMaxBin; nX++) {
679  h2Summary->setBinContent(nX, 0, 1);
680  }
681 }
682 
684  char cRegion;
685  char cChType = (nIdxCh % 2 == 0 ? 'L' : 'S');
686  Int_t nLayer;
687 
688  if (strSuffix.find("-M-") != std::string::npos)
689  cRegion = 'M';
690  else if (strSuffix.find("-P-") != std::string::npos)
691  cRegion = 'P';
692  else
693  return "";
694 
695  if (strSuffix.find("-L1") != std::string::npos)
696  nLayer = 1;
697  else if (strSuffix.find("-L2") != std::string::npos)
698  nLayer = 2;
699  else
700  return "";
701 
702  return Form(
703  "GEM/Digis/occupancy_GE11-%c-L%i/occ_GE11-%c-%02iL%i-%c", cRegion, nLayer, cRegion, nIdxCh, nLayer, cChType);
704 }
705 
706 // FIXME: The naming convention of GE21 could be changed to be different from GE11
708  char cRegion;
709  char cChType = (nIdxCh % 2 == 0 ? 'L' : 'S');
710  Int_t nLayer;
711  Int_t nModule;
712 
713  if (strSuffix.find("-M-") != std::string::npos)
714  cRegion = 'M';
715  else if (strSuffix.find("-P-") != std::string::npos)
716  cRegion = 'P';
717  else
718  return "";
719 
720  if (strSuffix.find("-L1") != std::string::npos)
721  nLayer = 1;
722  else if (strSuffix.find("-L2") != std::string::npos)
723  nLayer = 2;
724  else
725  return "";
726 
727  if (strSuffix.find("-M1") != std::string::npos)
728  nModule = 1;
729  else if (strSuffix.find("-M2") != std::string::npos)
730  nModule = 2;
731  else if (strSuffix.find("-M3") != std::string::npos)
732  nModule = 3;
733  else if (strSuffix.find("-M4") != std::string::npos)
734  nModule = 4;
735  else if (strSuffix.find("-M5") != std::string::npos)
736  nModule = 5;
737  else if (strSuffix.find("-M6") != std::string::npos)
738  nModule = 6;
739  else if (strSuffix.find("-M7") != std::string::npos)
740  nModule = 7;
741  else if (strSuffix.find("-M8") != std::string::npos)
742  nModule = 8;
743  else
744  return "";
745 
746  return Form("GEM/Digis/occupancy_GE21-%c-L%i-M%i/occ_GE21-%c-%02iL%i-M%i-%c",
747  cRegion,
748  nLayer,
749  nModule,
750  cRegion,
751  nIdxCh,
752  nLayer,
753  nModule,
754  cChType);
755 }
756 
757 std::string getNameChamberOccNull(std::string strSuffix, Int_t nIdxChamber) {
758  return ""; // For an initialization
759 }
760 
762  std::string strSuffix,
763  Int_t nNumChamber) {
764  std::string strTitle = "The fraction of inactive channels in " + strSuffix.substr(1);
765  MonitorElement *h2InactiveChannel =
766  store->book1D("inactive_frac_chamber" + strSuffix, strTitle, nNumChamber, 0.5, nNumChamber + 0.5);
767  h2InactiveChannel->setXTitle("Chamber");
768  h2InactiveChannel->setYTitle("Fraction of inactive channels");
769  for (Int_t i = 1; i <= nNumChamber; i++) {
770  h2InactiveChannel->setBinLabel(i, Form("%i", i), 1);
771  }
772 
773  std::string (*funcNameCh)(std::string, Int_t) = getNameChamberOccNull;
774 
775  if (strSuffix.find("_GE11") != std::string::npos) {
776  funcNameCh = getNameChamberOccGE11;
777  } else if (strSuffix.find("_GE21") != std::string::npos) {
778  funcNameCh = getNameChamberOccGE21;
779  }
780 
781  for (Int_t nIdxCh = 1; nIdxCh <= nNumChamber; nIdxCh++) {
782  std::string strNameCh = funcNameCh(strSuffix, nIdxCh);
783  MonitorElement *h2SrcChamberOcc = store->get(strNameCh);
784  if (h2SrcChamberOcc == nullptr) {
785  // FIXME: It's about sending a message
786  continue;
787  }
788 
789  Int_t nNumBinX = h2SrcChamberOcc->getNbinsX();
790  Int_t nNumBinY = h2SrcChamberOcc->getNbinsY();
791  Int_t nNumAllChannel = nNumBinX * nNumBinY;
792  auto *histData = h2SrcChamberOcc->getTH2F();
793  auto *pdData = histData->GetArray();
794  Int_t nNumChannelInactive = 0;
795  for (Int_t j = 1; j <= nNumBinY; j++)
796  for (Int_t i = 1; i <= nNumBinX; i++) {
797  if (pdData[j * (nNumBinX + 2) + i] <= 0) {
798  nNumChannelInactive++;
799  }
800  }
801  h2InactiveChannel->setBinContent(nIdxCh, ((Double_t)nNumChannelInactive) / nNumAllChannel);
802  }
803 }
804 
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:263
void createInactiveChannelFracHist(edm::Service< DQMStore > &store, std::string strSuffix, Int_t nNumChamber)
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:656
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)
Log< level::Error, false > LogError
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:221
std::map< int, std::map< int, int > > mapIdxToChamberInOcc_
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:712
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