CMS 3D CMS Logo

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