CMS 3D CMS Logo

L1TTestsSummary.cc
Go to the documentation of this file.
2 
11 #include <cstdio>
12 #include <sstream>
13 #include <cmath>
14 #include <vector>
15 #include <TMath.h>
16 #include <climits>
17 #include <TFile.h>
18 #include <TDirectory.h>
19 #include <TProfile.h>
20 
21 using namespace std;
22 using namespace edm;
23 
24 //____________________________________________________________________________
25 // Function: L1TTestsSummary
26 // Description: This is the constructor, basic variable initialization
27 // Inputs:
28 // * const edm::ParameterSet& ps = Parameter for this analyzer
29 //____________________________________________________________________________
31  if (mVerbose) {
32  cout << "[L1TTestsSummary:] Called constructor" << endl;
33  }
34 
35  // Get parameters
36  mParameters = ps;
37  mVerbose = ps.getUntrackedParameter<bool>("verbose", true);
38  mMonitorL1TRate = ps.getUntrackedParameter<bool>("MonitorL1TRate", true);
39  mMonitorL1TSync = ps.getUntrackedParameter<bool>("MonitorL1TSync", true);
40  mMonitorL1TOccupancy = ps.getUntrackedParameter<bool>("MonitorL1TOccupancy", true);
41 
42  mL1TRatePath = ps.getUntrackedParameter<string>("L1TRatePath", "L1T/L1TRate/Certification/");
43  mL1TSyncPath = ps.getUntrackedParameter<string>("L1TSyncPath", "L1T/L1TSync/Certification/");
44  mL1TOccupancyPath = ps.getUntrackedParameter<string>("L1TOccupancyPath", "L1T/L1TOccupancy/Certification/");
45 }
46 
47 //____________________________________________________________________________
48 // Function: ~L1TTestsSummary
49 // Description: This is the destructor, basic variable deletion
50 //____________________________________________________________________________
52  if (mVerbose) {
53  cout << "[L1TTestsSummary:] Called destructor" << endl;
54  }
55 }
56 
57 //____________________________________________________________________________
58 // Function: beginRun
59 // Description: This is will be run at the begining of each run
60 // Inputs:
61 // * const Run& r = Run information
62 // * const EventSetup& context = Event Setup information
63 //____________________________________________________________________________
65  if (mVerbose) {
66  cout << "[L1TTestsSummary:] Called beginRun" << endl;
67  }
68 
69  int maxLS = 2500;
70 
71  if (mMonitorL1TRate) {
72  if (mVerbose) {
73  cout << "[L1TTestsSummary:] Initializing L1TRate Module Monitoring" << endl;
74  }
75 
76  igetter.setCurrentFolder(mL1TRatePath);
77  vector<string> histToMonitor = igetter.getMEs();
78  int histLines = histToMonitor.size() + 1;
79 
80  ibooker.setCurrentFolder("L1T/L1TTestsSummary/");
81  mL1TRateMonitor = ibooker.book2D(
82  "RateQualitySummary", "L1T Rates Monitor Summary", maxLS, +0.5, double(maxLS) + 0.5, histLines, 0, histLines);
83  mL1TRateMonitor->setAxisTitle("Lumi Section", 1);
84 
85  mL1TRateMonitor->setBinLabel(1, "Summary", 2);
86  for (unsigned int i = 0; i < histToMonitor.size(); i++) {
87  string name = igetter.get(mL1TRatePath + histToMonitor[i])->getTH1()->GetName();
88  mL1TRateMonitor->setBinLabel(i + 2, name, 2);
89  }
90  }
91  if (mMonitorL1TSync) {
92  if (mVerbose) {
93  cout << "[L1TTestsSummary:] Initializing L1TSync Module Monitoring" << endl;
94  }
95 
96  igetter.setCurrentFolder(mL1TSyncPath);
97  vector<string> histToMonitor = igetter.getMEs();
98  int histLines = histToMonitor.size() + 1;
99 
100  ibooker.setCurrentFolder("L1T/L1TTestsSummary/");
101  mL1TSyncMonitor = ibooker.book2D("SyncQualitySummary",
102  "L1T Synchronization Monitor Summary",
103  maxLS,
104  0.5,
105  double(maxLS) + 0.5,
106  histLines,
107  0,
108  histLines);
109  mL1TSyncMonitor->setAxisTitle("Lumi Section", 1);
110 
111  mL1TSyncMonitor->setBinLabel(1, "Summary", 2);
112  for (unsigned int i = 0; i < histToMonitor.size(); i++) {
113  string name = igetter.get(mL1TSyncPath + histToMonitor[i])->getTH1()->GetName();
114  mL1TSyncMonitor->setBinLabel(i + 2, name, 2);
115  }
116  }
117  if (mMonitorL1TOccupancy) {
118  if (mVerbose) {
119  cout << "[L1TTestsSummary:] Initializing L1TOccupancy Module Monitoring" << endl;
120  }
121 
122  igetter.setCurrentFolder(mL1TOccupancyPath);
123  vector<string> histToMonitor = igetter.getMEs();
124  int histLines = histToMonitor.size() + 1;
125 
126  ibooker.setCurrentFolder("L1T/L1TTestsSummary/");
127  mL1TOccupancyMonitor = ibooker.book2D(
128  "OccupancySummary", "L1T Occupancy Monitor Summary", maxLS, +0.5, double(maxLS) + 0.5, histLines, 0, histLines);
129  mL1TOccupancyMonitor->setAxisTitle("Lumi Section", 1);
130 
131  mL1TOccupancyMonitor->setBinLabel(1, "Summary", 2);
132  for (unsigned int i = 0; i < histToMonitor.size(); i++) {
133  string name = igetter.get(mL1TOccupancyPath + histToMonitor[i])->getTH1()->GetName();
134  mL1TOccupancyMonitor->setBinLabel(i + 2, name, 2);
135  }
136  }
137 
138  //-> Making the summary of summaries
139  int testsToMonitor = 1;
140  if (mMonitorL1TRate) {
141  testsToMonitor++;
142  }
143  if (mMonitorL1TSync) {
144  testsToMonitor++;
145  }
146  if (mMonitorL1TOccupancy) {
147  testsToMonitor++;
148  }
149 
150  // Creating
151  ibooker.setCurrentFolder("L1T/L1TTestsSummary/");
152  mL1TSummary = ibooker.book2D(
153  "L1TQualitySummary", "L1 Tests Summary", maxLS, +0.5, double(maxLS) + 0.5, testsToMonitor, 0, testsToMonitor);
154  mL1TSummary->setAxisTitle("Lumi Section", 1);
155  mL1TSummary->setBinLabel(1, "L1T Summary", 2);
156 
157  int it = 2;
158  if (mMonitorL1TRate) {
159  mL1TSummary->setBinLabel(it, "Rates", 2);
160  binYRate = it;
161  it++;
162  }
163  if (mMonitorL1TSync) {
164  mL1TSummary->setBinLabel(it, "Synchronization", 2);
165  binYSync = it;
166  it++;
167  }
168  if (mMonitorL1TOccupancy) {
169  mL1TSummary->setBinLabel(it, "Occupancy", 2);
170  binYOccpancy = it;
171  }
172 }
173 
174 //____________________________________________________________________________
175 // Function: endRun
176 // Description: This is will be run at the end of each run
177 // Inputs:
178 // * const Run& r = Run information
179 // * const EventSetup& context = Event Setup information
180 //____________________________________________________________________________
182  book(ibooker, igetter);
183 
184  if (mVerbose) {
185  cout << "[L1TTestsSummary:] Called endRun()" << endl;
186  }
187 
188  if (mMonitorL1TRate) {
189  updateL1TRateMonitor(ibooker, igetter);
190  }
191  if (mMonitorL1TSync) {
192  updateL1TSyncMonitor(ibooker, igetter);
193  }
194  if (mMonitorL1TOccupancy) {
195  updateL1TOccupancyMonitor(ibooker, igetter);
196  }
197  updateL1TSummary(ibooker, igetter);
198 }
199 
200 //____________________________________________________________________________
201 // Function: endLuminosityBlock
202 // Description: This is will be run at the end of each luminosity block
203 // Inputs:
204 // * const LuminosityBlock& lumiSeg = Luminosity Block information
205 // * const EventSetup& context = Event Setup information
206 //____________________________________________________________________________
208  DQMStore::IGetter &igetter,
209  const edm::LuminosityBlock &lumiSeg,
210  const edm::EventSetup &c) {
211  int eventLS = lumiSeg.id().luminosityBlock();
212 
213  book(ibooker, igetter);
214 
215  mProcessedLS.push_back(eventLS);
216 
217  if (mVerbose) {
218  cout << "[L1TTestsSummary:] Called endLuminosityBlock()" << endl;
219  cout << "[L1TTestsSummary:] Lumisection: " << eventLS << endl;
220  }
221 
222  if (mMonitorL1TRate) {
223  updateL1TRateMonitor(ibooker, igetter);
224  }
225  if (mMonitorL1TSync) {
226  updateL1TSyncMonitor(ibooker, igetter);
227  }
228  if (mMonitorL1TOccupancy) {
229  updateL1TOccupancyMonitor(ibooker, igetter);
230  }
231  updateL1TSummary(ibooker, igetter);
232 }
233 
234 //____________________________________________________________________________
235 // Function: updateL1TRateMonitor
236 // Description:
237 //____________________________________________________________________________
239  igetter.setCurrentFolder(mL1TRatePath);
240  vector<string> histToMonitor = igetter.getMEs();
241 
242  for (unsigned int i = 0; i < histToMonitor.size(); i++) {
243  MonitorElement *me = igetter.get(mL1TRatePath + histToMonitor[i]);
244  if (mVerbose) {
245  cout << "[L1TTestsSummary:] Found ME: " << me->getTH1()->GetName() << endl;
246  }
247 
248  const QReport *myQReport = me->getQReport("L1TRateTest"); //get QReport associated to your ME
249  if (myQReport) {
250  float qtresult = myQReport->getQTresult(); // get QT result value
251  int qtstatus = myQReport->getStatus(); // get QT status value (see table below)
252  const string &qtmessage = myQReport->getMessage(); // get the whole QT result message
253  vector<DQMChannel> qtBadChannels = myQReport->getBadChannels();
254 
255  if (mVerbose) {
256  cout << "[L1TTestsSummary:] Found QReport for ME: " << me->getTH1()->GetName() << endl;
257  cout << "[L1TTestsSummary:] Result=" << qtresult << " status=" << qtstatus << " message=" << qtmessage << endl;
258  cout << "[L1TTestsSummary:] Bad Channels size=" << qtBadChannels.size() << endl;
259  }
260 
261  for (unsigned int i = 0; i < mProcessedLS.size() - 1; i++) {
262  int binx = mL1TRateMonitor->getTH2F()->GetXaxis()->FindBin(mProcessedLS[i]);
263  int biny = mL1TRateMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
264  mL1TRateMonitor->setBinContent(binx, biny, 100);
265  }
266 
267  for (unsigned int a = 0; a < qtBadChannels.size(); a++) {
268  for (unsigned int b = 0; b < mProcessedLS.size() - 1; b++) {
269  // Converting bin to value
270  double valueBinBad = me->getTH1()->GetBinCenter(qtBadChannels[a].getBin());
271 
272  if (valueBinBad == (mProcessedLS[b])) {
273  int binx = mL1TRateMonitor->getTH2F()->GetXaxis()->FindBin(valueBinBad);
274  int biny = mL1TRateMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
275  mL1TRateMonitor->setBinContent(binx, biny, 300);
276  }
277  }
278  }
279  }
280  }
281 
282  //-> Filling the summaries
283  int nBinX = mL1TRateMonitor->getTH2F()->GetXaxis()->GetNbins();
284  int nBinY = mL1TRateMonitor->getTH2F()->GetYaxis()->GetNbins();
285  for (int binx = 1; binx <= nBinX; binx++) {
286  int GlobalStatus = 0;
287  for (int biny = 2; biny <= nBinY; biny++) {
288  double flag = mL1TRateMonitor->getBinContent(binx, biny);
289  if (GlobalStatus < flag) {
290  GlobalStatus = flag;
291  }
292  }
293 
294  // NOTE: Assumes mL1TSummary has same size then mL1TRateMonitor
295  mL1TRateMonitor->setBinContent(binx, 1, GlobalStatus);
296  mL1TSummary->setBinContent(binx, binYRate, GlobalStatus);
297  }
298 }
299 
300 //____________________________________________________________________________
301 // Function: updateL1TSyncMonitor
302 // Description:
303 // Note: Values certified by L1TRates are always about currentLS-1 since we
304 // use rate averages from the previous LS from GT
305 //____________________________________________________________________________
307  igetter.setCurrentFolder(mL1TSyncPath);
308  vector<string> histToMonitor = igetter.getMEs();
309 
310  for (unsigned int i = 0; i < histToMonitor.size(); i++) {
311  MonitorElement *me = igetter.get(mL1TSyncPath + histToMonitor[i]);
312  if (mVerbose) {
313  cout << "[L1TTestsSummary:] Found ME: " << me->getTH1()->GetName() << endl;
314  }
315 
316  const QReport *myQReport = me->getQReport("L1TSyncTest"); //get QReport associated to your ME
317  if (myQReport) {
318  float qtresult = myQReport->getQTresult(); // get QT result value
319  int qtstatus = myQReport->getStatus(); // get QT status value (see table below)
320  const string &qtmessage = myQReport->getMessage(); // get the whole QT result message
321  vector<DQMChannel> qtBadChannels = myQReport->getBadChannels();
322 
323  if (mVerbose) {
324  cout << "[L1TTestsSummary:] Found QReport for ME: " << me->getTH1()->GetName() << endl;
325  cout << "[L1TTestsSummary:] Result=" << qtresult << " status=" << qtstatus << " message=" << qtmessage << endl;
326  cout << "[L1TTestsSummary:] Bad Channels size=" << qtBadChannels.size() << endl;
327  }
328 
329  for (unsigned int i = 0; i < mProcessedLS.size(); i++) {
330  int binx = mL1TSyncMonitor->getTH2F()->GetXaxis()->FindBin(mProcessedLS[i]);
331  int biny = mL1TSyncMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
332  mL1TSyncMonitor->setBinContent(binx, biny, 100);
333  }
334 
335  for (unsigned int a = 0; a < qtBadChannels.size(); a++) {
336  for (unsigned int b = 0; b < mProcessedLS.size(); b++) {
337  // Converting bin to value
338  double valueBinBad = me->getTH1()->GetBinCenter(qtBadChannels[a].getBin());
339 
340  if (valueBinBad == mProcessedLS[b]) {
341  int binx = mL1TSyncMonitor->getTH2F()->GetXaxis()->FindBin(valueBinBad);
342  int biny = mL1TSyncMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
343  mL1TSyncMonitor->setBinContent(binx, biny, 300);
344  }
345  }
346  }
347  }
348  }
349 
350  //-> Filling the summaries
351  int nBinX = mL1TSyncMonitor->getTH2F()->GetXaxis()->GetNbins();
352  int nBinY = mL1TSyncMonitor->getTH2F()->GetYaxis()->GetNbins();
353  for (int binx = 1; binx <= nBinX; binx++) {
354  int GlobalStatus = 0;
355  for (int biny = 2; biny <= nBinY; biny++) {
356  double flag = mL1TSyncMonitor->getBinContent(binx, biny);
357  if (GlobalStatus < flag) {
358  GlobalStatus = flag;
359  }
360  }
361 
362  // NOTE: Assumes mL1TSummary has same size then mL1TSyncMonitor
363  mL1TSyncMonitor->setBinContent(binx, 1, GlobalStatus);
364  mL1TSummary->setBinContent(binx, binYSync, GlobalStatus);
365  }
366 }
367 
368 //____________________________________________________________________________
369 // Function: updateL1TOccupancyMonitor
370 // Description:
371 //____________________________________________________________________________
373  igetter.setCurrentFolder(mL1TOccupancyPath);
374  vector<string> histToMonitor = igetter.getMEs();
375 
376  for (unsigned int i = 0; i < histToMonitor.size(); i++) {
377  MonitorElement *me = igetter.get(mL1TOccupancyPath + histToMonitor[i]);
378  if (mVerbose) {
379  cout << "[L1TTestsSummary:] Found ME: " << me->getTH1()->GetName() << endl;
380  }
381 
382  const QReport *myQReport = me->getQReport("L1TOccupancyTest"); //get QReport associated to your ME
383  if (myQReport) {
384  float qtresult = myQReport->getQTresult(); // get QT result value
385  int qtstatus = myQReport->getStatus(); // get QT status value (see table below)
386  const string &qtmessage = myQReport->getMessage(); // get the whole QT result message
387  vector<DQMChannel> qtBadChannels = myQReport->getBadChannels();
388 
389  if (mVerbose) {
390  cout << "[L1TTestsSummary:] Found QReport for ME: " << me->getTH1()->GetName() << endl;
391  cout << "[L1TTestsSummary:] Result=" << qtresult << " status=" << qtstatus << " message=" << qtmessage << endl;
392  cout << "[L1TTestsSummary:] Bad Channels size=" << qtBadChannels.size() << endl;
393  }
394 
395  for (unsigned int i = 0; i < mProcessedLS.size(); i++) {
396  int binx = mL1TOccupancyMonitor->getTH2F()->GetXaxis()->FindBin(mProcessedLS[i]);
397  int biny = mL1TOccupancyMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
398  mL1TOccupancyMonitor->setBinContent(binx, biny, 100);
399  }
400 
401  for (unsigned int a = 0; a < qtBadChannels.size(); a++) {
402  for (unsigned int b = 0; b < mProcessedLS.size(); b++) {
403  // Converting bin to value
404  double valueBinBad = me->getTH1()->GetBinCenter(qtBadChannels[a].getBin());
405 
406  if (valueBinBad == mProcessedLS[b]) {
407  int binx = mL1TOccupancyMonitor->getTH2F()->GetXaxis()->FindBin(valueBinBad);
408  int biny = mL1TOccupancyMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
409  mL1TOccupancyMonitor->setBinContent(binx, biny, 300);
410  }
411  }
412  }
413  }
414  }
415 
416  //-> Filling the summaries
417  int nBinX = mL1TOccupancyMonitor->getTH2F()->GetXaxis()->GetNbins();
418  int nBinY = mL1TOccupancyMonitor->getTH2F()->GetYaxis()->GetNbins();
419  for (int binx = 1; binx <= nBinX; binx++) {
420  int GlobalStatus = 0;
421  for (int biny = 2; biny <= nBinY; biny++) {
422  double flag = mL1TOccupancyMonitor->getBinContent(binx, biny);
423  if (GlobalStatus < flag) {
424  GlobalStatus = flag;
425  }
426  }
427 
428  // NOTE: Assumes mL1TSummary has same size then mL1TOccupancyMonitor
429  mL1TOccupancyMonitor->setBinContent(binx, 1, GlobalStatus);
430  mL1TSummary->setBinContent(binx, binYOccpancy, GlobalStatus);
431  }
432 }
433 
434 //____________________________________________________________________________
435 // Function: updateL1TOccupancyMonitor
436 // Description:
437 //____________________________________________________________________________
439  int nBinX = mL1TSummary->getTH2F()->GetXaxis()->GetNbins();
440  for (int binx = 1; binx <= nBinX; binx++) {
441  int GlobalStatus = 0;
442  if (mMonitorL1TRate) {
443  if (mL1TSummary->getBinContent(binx, binYRate) > GlobalStatus) {
444  GlobalStatus = mL1TSummary->getBinContent(binx, binYRate);
445  }
446  }
447  if (mMonitorL1TSync) {
448  if (mL1TSummary->getBinContent(binx, binYSync) > GlobalStatus) {
449  GlobalStatus = mL1TSummary->getBinContent(binx, binYSync);
450  }
451  }
452  if (mMonitorL1TOccupancy) {
453  if (mL1TSummary->getBinContent(binx, binYOccpancy) > GlobalStatus) {
454  GlobalStatus = mL1TSummary->getBinContent(binx, binYOccpancy);
455  }
456  }
457  mL1TSummary->setBinContent(binx, 1, GlobalStatus);
458  }
459 }
460 
461 //define this as a plug-in
LuminosityBlockID id() const
void updateL1TRateMonitor(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
T getUntrackedParameter(std::string const &, T const &) const
~L1TTestsSummary() override
const std::vector< DQMChannel > & getBadChannels() const
Definition: QReport.h:37
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
void updateL1TSummary(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
virtual void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
void updateL1TOccupancyMonitor(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
const QReport * getQReport(const std::string &qtname) const
get QReport corresponding to <qtname> (null pointer if QReport does not exist)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< std::string > getMEs()
Definition: DQMStore.cc:455
const std::string & getMessage() const
get message attached to test
Definition: QReport.h:30
int getBin(double x, std::vector< double > boundaries)
Definition: Utilities.h:455
void updateL1TSyncMonitor(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
double b
Definition: hdecay.h:118
LuminosityBlockNumber_t luminosityBlock() const
int getStatus() const
get test status (see Core/interface/QTestStatus.h)
Definition: QReport.h:24
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
L1TTestsSummary(const edm::ParameterSet &ps)
double a
Definition: hdecay.h:119
float getQTresult() const
get test result i.e. prob value
Definition: QReport.h:27
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:437
virtual TH1 * getTH1() const
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:424
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)