CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TTestsSummary.cc
Go to the documentation of this file.
2 
13 #include <stdio.h>
14 #include <sstream>
15 #include <math.h>
16 #include <vector>
17 #include <TMath.h>
18 #include <limits.h>
19 #include <TFile.h>
20 #include <TDirectory.h>
21 #include <TProfile.h>
22 
23 using namespace std;
24 using namespace edm;
25 
26 //____________________________________________________________________________
27 // Function: L1TTestsSummary
28 // Description: This is the constructor, basic variable initialization
29 // Inputs:
30 // * const edm::ParameterSet& ps = Parameter for this analyzer
31 //____________________________________________________________________________
33 
34  if(mVerbose){cout << "[L1TTestsSummary:] Called constructor" << endl;}
35 
36  // Get parameters
37  mParameters = ps;
38  mVerbose = ps.getUntrackedParameter<bool>("verbose" ,true);
39  mMonitorL1TRate = ps.getUntrackedParameter<bool>("MonitorL1TRate" ,true);
40  mMonitorL1TSync = ps.getUntrackedParameter<bool>("MonitorL1TSync" ,true);
41  mMonitorL1TOccupancy = ps.getUntrackedParameter<bool>("MonitorL1TOccupancy",true);
42 
43  mL1TRatePath = ps.getUntrackedParameter<string>("L1TRatePath" ,"L1T/L1TRate/Certification/");
44  mL1TSyncPath = ps.getUntrackedParameter<string>("L1TSyncPath" ,"L1T/L1TSync/Certification/");
45  mL1TOccupancyPath = ps.getUntrackedParameter<string>("L1TOccupancyPath","L1T/L1TOccupancy/Certification/");
46 
47  // Get back-end interface
48  mDBE = Service<DQMStore>().operator->();
49 
50 }
51 
52 //____________________________________________________________________________
53 // Function: ~L1TTestsSummary
54 // Description: This is the destructor, basic variable deletion
55 //____________________________________________________________________________
57  if(mVerbose){cout << "[L1TTestsSummary:] Called destructor" << endl;}
58 }
59 
60 //____________________________________________________________________________
61 // Function: beginJob
62 // Description: This will be run at the beginning of each job
63 //____________________________________________________________________________
65 
66  if(mVerbose){cout << "[L1TTestsSummary:] Called BeginJob" << endl;}
67 
68  // get backend interface
69  mDBE = Service<DQMStore>().operator->();
70 
71  if (mDBE) {
72  mDBE->setCurrentFolder("L1T/L1TOccupancy");
73  mDBE->rmdir("L1T/L1TOccupancy");
74  }
75 }
76 
77 //____________________________________________________________________________
78 // Function: endJob
79 // Description: This will be run at the end of each job
80 //____________________________________________________________________________
82  if(mVerbose){cout << "[L1TTestsSummary:] Called endJob" << endl;}
83 }
84 
85 //____________________________________________________________________________
86 // Function: beginRun
87 // Description: This is will be run at the begining of each run
88 // Inputs:
89 // * const Run& r = Run information
90 // * const EventSetup& context = Event Setup information
91 //____________________________________________________________________________
92 void L1TTestsSummary::beginRun(const Run& r, const EventSetup& context){
93 
94  if(mVerbose){cout << "[L1TTestsSummary:] Called beginRun" << endl;}
95 
96  int maxLS = 2500;
97 
98  if(mMonitorL1TRate){
99 
100  if(mVerbose){cout << "[L1TTestsSummary:] Initializing L1TRate Module Monitoring" << endl;}
101 
102  mDBE->setCurrentFolder(mL1TRatePath);
103  vector<string> histToMonitor = mDBE->getMEs();
104  int histLines = histToMonitor.size()+1;
105 
106  mDBE->setCurrentFolder("L1T/L1TTestsSummary/");
107  mL1TRateMonitor = mDBE->book2D("RateQualitySummary","L1T Rates Monitor Summary",maxLS,+0.5,double(maxLS)+0.5,histLines,0,histLines);
108  mL1TRateMonitor->setAxisTitle("Lumi Section" ,1);
109 
110  mL1TRateMonitor->setBinLabel(1,"Summary",2);
111  for(unsigned int i=0 ; i<histToMonitor.size() ; i++){
112  string name = mDBE->get(mL1TRatePath+histToMonitor[i])->getTH1()->GetName();
113  mL1TRateMonitor->setBinLabel(i+2,name,2);
114  }
115  }
116  if(mMonitorL1TSync){
117 
118  if(mVerbose){cout << "[L1TTestsSummary:] Initializing L1TSync Module Monitoring" << endl;}
119 
120  mDBE->setCurrentFolder(mL1TSyncPath);
121  vector<string> histToMonitor = mDBE->getMEs();
122  int histLines = histToMonitor.size()+1;
123 
124  mDBE->setCurrentFolder("L1T/L1TTestsSummary/");
125  mL1TSyncMonitor = mDBE->book2D("SyncQualitySummary","L1T Synchronization Monitor Summary",maxLS,0.5,double(maxLS)+0.5,histLines,0,histLines);
126  mL1TSyncMonitor->setAxisTitle("Lumi Section" ,1);
127 
128  mL1TSyncMonitor->setBinLabel(1,"Summary",2);
129  for(unsigned int i=0 ; i<histToMonitor.size() ; i++){
130  string name = mDBE->get(mL1TSyncPath+histToMonitor[i])->getTH1()->GetName();
131  mL1TSyncMonitor->setBinLabel(i+2,name,2);
132  }
133 
134  }
135  if(mMonitorL1TOccupancy){
136 
137  if(mVerbose){cout << "[L1TTestsSummary:] Initializing L1TOccupancy Module Monitoring" << endl;}
138 
139  mDBE->setCurrentFolder(mL1TOccupancyPath);
140  vector<string> histToMonitor = mDBE->getMEs();
141  int histLines = histToMonitor.size()+1;
142 
143  mDBE->setCurrentFolder("L1T/L1TTestsSummary/");
144  mL1TOccupancyMonitor = mDBE->book2D("OccupancySummary","L1T Occupancy Monitor Summary",maxLS,+0.5,double(maxLS)+0.5,histLines,0,histLines);
145  mL1TOccupancyMonitor->setAxisTitle("Lumi Section" ,1);
146 
147  mL1TOccupancyMonitor->setBinLabel(1,"Summary",2);
148  for(unsigned int i=0 ; i<histToMonitor.size() ; i++){
149  string name = mDBE->get(mL1TOccupancyPath+histToMonitor[i])->getTH1()->GetName();
150  mL1TOccupancyMonitor->setBinLabel(i+2,name,2);
151  }
152  }
153 
154  //-> Making the summary of summaries
155  int testsToMonitor=1;
156  if(mMonitorL1TRate) {testsToMonitor++;}
157  if(mMonitorL1TSync) {testsToMonitor++;}
158  if(mMonitorL1TOccupancy){testsToMonitor++;}
159 
160  // Creating
161  mDBE->setCurrentFolder("L1T/L1TTestsSummary/");
162  mL1TSummary = mDBE->book2D("L1TQualitySummary","L1 Tests Summary",maxLS,+0.5,double(maxLS)+0.5,testsToMonitor,0,testsToMonitor);
163  mL1TSummary->setAxisTitle("Lumi Section" ,1);
164  mL1TSummary->setBinLabel(1,"L1T Summary",2);
165 
166  int it=2;
167  if(mMonitorL1TRate) {mL1TSummary->setBinLabel(it,"Rates" ,2); binYRate =it; it++;}
168  if(mMonitorL1TSync) {mL1TSummary->setBinLabel(it,"Synchronization",2); binYSync =it; it++;}
169  if(mMonitorL1TOccupancy){mL1TSummary->setBinLabel(it,"Occupancy" ,2); binYOccpancy=it;}
170 
171 }
172 
173 //____________________________________________________________________________
174 // Function: endRun
175 // Description: This is will be run at the end of each run
176 // Inputs:
177 // * const Run& r = Run information
178 // * const EventSetup& context = Event Setup information
179 //____________________________________________________________________________
180 void L1TTestsSummary::endRun(const Run& r, const EventSetup& context){
181 
182  if(mVerbose){cout << "[L1TTestsSummary:] Called endRun()" << endl;}
183 
184  if(mMonitorL1TRate) {updateL1TRateMonitor();}
185  if(mMonitorL1TSync) {updateL1TSyncMonitor();}
186  if(mMonitorL1TOccupancy){updateL1TOccupancyMonitor();}
187  updateL1TSummary();
188 
189 }
190 
191 //____________________________________________________________________________
192 // Function: beginLuminosityBlock
193 // Description: This is will be run at the begining of each luminosity block
194 // Inputs:
195 // * const LuminosityBlock& lumiSeg = Luminosity Block information
196 // * const EventSetup& context = Event Setup information
197 //____________________________________________________________________________
199  if(mVerbose){cout << "[L1TTestsSummary:] Called beginLuminosityBlock()" << endl;}
200 }
201 
202 //____________________________________________________________________________
203 // Function: endLuminosityBlock
204 // Description: This is will be run at the end of each luminosity block
205 // Inputs:
206 // * const LuminosityBlock& lumiSeg = Luminosity Block information
207 // * const EventSetup& context = Event Setup information
208 //____________________________________________________________________________
210 
211  int eventLS = lumiSeg.id().luminosityBlock();
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) {updateL1TRateMonitor();}
221  if(mMonitorL1TSync) {updateL1TSyncMonitor();}
222  if(mMonitorL1TOccupancy){updateL1TOccupancyMonitor();}
223  updateL1TSummary();
224 
225 }
226 
227 //____________________________________________________________________________
228 // Function: analyze
229 // Description: This is will be run for every event
230 // Inputs:
231 // * const Event& e = Event information
232 // * const EventSetup& context = Event Setup information
233 //____________________________________________________________________________
234 void L1TTestsSummary::analyze(const Event& e, const EventSetup& context){}
235 
236 //____________________________________________________________________________
237 // Function: updateL1TRateMonitor
238 // Description:
239 //____________________________________________________________________________
241 
242  mDBE->setCurrentFolder(mL1TRatePath);
243  vector<string> histToMonitor = mDBE->getMEs();
244 
245  for(unsigned int i=0 ; i<histToMonitor.size() ; i++){
246 
247  MonitorElement* me = mDBE->get(mL1TRatePath+histToMonitor[i]);
248  if(mVerbose) {cout << "[L1TTestsSummary:] Found ME: " << me->getTH1()->GetName() << endl;}
249 
250  const QReport * myQReport = me->getQReport("L1TRateTest"); //get QReport associated to your ME
251  if(myQReport) {
252  float qtresult = myQReport->getQTresult(); // get QT result value
253  int qtstatus = myQReport->getStatus(); // get QT status value (see table below)
254  string qtmessage = myQReport->getMessage() ; // get the whole QT result message
255  vector<DQMChannel> qtBadChannels = myQReport->getBadChannels();
256 
257  if(mVerbose) {
258  cout << "[L1TTestsSummary:] Found QReport for ME: " << me->getTH1()->GetName() << endl;
259  cout << "[L1TTestsSummary:] Result=" << qtresult << " status=" << qtstatus << " message=" << qtmessage << endl;
260  cout << "[L1TTestsSummary:] Bad Channels size=" << qtBadChannels.size() << endl;
261  }
262 
263  for(unsigned int i=0 ; i<mProcessedLS.size()-1 ; i++){
264  int binx = mL1TRateMonitor->getTH2F()->GetXaxis()->FindBin(mProcessedLS[i]);
265  int biny = mL1TRateMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
266  mL1TRateMonitor->setBinContent(binx,biny,100);
267  }
268 
269  for(unsigned int a=0 ; a<qtBadChannels.size() ; a++){
270  for(unsigned int b=0 ; b<mProcessedLS.size()-1 ; b++){
271 
272  // Converting bin to value
273  double valueBinBad = me->getTH1()->GetBinCenter(qtBadChannels[a].getBin());
274 
275  if(valueBinBad==(mProcessedLS[b])){
276  int binx = mL1TRateMonitor->getTH2F()->GetXaxis()->FindBin(valueBinBad);
277  int biny = mL1TRateMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
278  mL1TRateMonitor->setBinContent(binx,biny,300);
279  }
280  }
281  }
282  }
283  }
284 
285  //-> Filling the summaries
286  int nBinX = mL1TRateMonitor->getTH2F()->GetXaxis()->GetNbins();
287  int nBinY = mL1TRateMonitor->getTH2F()->GetYaxis()->GetNbins();
288  for(int binx=1; binx<=nBinX ; binx++){
289  int GlobalStatus=0;
290  for(int biny=2; biny<=nBinY ; biny++){
291  double flag = mL1TRateMonitor->getBinContent(binx,biny);
292  if(GlobalStatus<flag){GlobalStatus=flag;}
293  }
294 
295  // NOTE: Assumes mL1TSummary has same size then mL1TRateMonitor
296  mL1TRateMonitor->setBinContent(binx, 1,GlobalStatus);
297  mL1TSummary ->setBinContent(binx,binYRate,GlobalStatus);
298  }
299 }
300 
301 //____________________________________________________________________________
302 // Function: updateL1TSyncMonitor
303 // Description:
304 // Note: Values certified by L1TRates are always about currentLS-1 since we
305 // use rate averages from the previous LS from GT
306 //____________________________________________________________________________
308 
309  mDBE->setCurrentFolder(mL1TSyncPath);
310  vector<string> histToMonitor = mDBE->getMEs();
311 
312  for(unsigned int i=0 ; i<histToMonitor.size() ; i++){
313 
314  MonitorElement* me = mDBE->get(mL1TSyncPath+histToMonitor[i]);
315  if(mVerbose) {cout << "[L1TTestsSummary:] Found ME: " << me->getTH1()->GetName() << endl;}
316 
317  const QReport * myQReport = me->getQReport("L1TSyncTest"); //get QReport associated to your ME
318  if(myQReport) {
319  float qtresult = myQReport->getQTresult(); // get QT result value
320  int qtstatus = myQReport->getStatus(); // get QT status value (see table below)
321  string qtmessage = myQReport->getMessage() ; // get the whole QT result message
322  vector<DQMChannel> qtBadChannels = myQReport->getBadChannels();
323 
324  if(mVerbose) {
325  cout << "[L1TTestsSummary:] Found QReport for ME: " << me->getTH1()->GetName() << endl;
326  cout << "[L1TTestsSummary:] Result=" << qtresult << " status=" << qtstatus << " message=" << qtmessage << endl;
327  cout << "[L1TTestsSummary:] Bad Channels size=" << qtBadChannels.size() << endl;
328  }
329 
330  for(unsigned int i=0 ; i<mProcessedLS.size() ; i++){
331  int binx = mL1TSyncMonitor->getTH2F()->GetXaxis()->FindBin(mProcessedLS[i]);
332  int biny = mL1TSyncMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
333  mL1TSyncMonitor->setBinContent(binx,biny,100);
334  }
335 
336  for(unsigned int a=0 ; a<qtBadChannels.size() ; a++){
337  for(unsigned int b=0 ; b<mProcessedLS.size() ; b++){
338 
339  // Converting bin to value
340  double valueBinBad = me->getTH1()->GetBinCenter(qtBadChannels[a].getBin());
341 
342  if(valueBinBad==mProcessedLS[b]){
343  int binx = mL1TSyncMonitor->getTH2F()->GetXaxis()->FindBin(valueBinBad);
344  int biny = mL1TSyncMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
345  mL1TSyncMonitor->setBinContent(binx,biny,300);
346  }
347  }
348  }
349  }
350  }
351 
352  //-> Filling the summaries
353  int nBinX = mL1TSyncMonitor->getTH2F()->GetXaxis()->GetNbins();
354  int nBinY = mL1TSyncMonitor->getTH2F()->GetYaxis()->GetNbins();
355  for(int binx=1; binx<=nBinX ; binx++){
356  int GlobalStatus=0;
357  for(int biny=2; biny<=nBinY ; biny++){
358  double flag = mL1TSyncMonitor->getBinContent(binx,biny);
359  if(GlobalStatus<flag){GlobalStatus=flag;}
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 
374  mDBE->setCurrentFolder(mL1TOccupancyPath);
375  vector<string> histToMonitor = mDBE->getMEs();
376 
377  for(unsigned int i=0 ; i<histToMonitor.size() ; i++){
378 
379  MonitorElement* me = mDBE->get(mL1TOccupancyPath+histToMonitor[i]);
380  if(mVerbose) {cout << "[L1TTestsSummary:] Found ME: " << me->getTH1()->GetName() << endl;}
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  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 
404  // Converting bin to value
405  double valueBinBad = me->getTH1()->GetBinCenter(qtBadChannels[a].getBin());
406 
407  if(valueBinBad==mProcessedLS[b]){
408  int binx = mL1TOccupancyMonitor->getTH2F()->GetXaxis()->FindBin(valueBinBad);
409  int biny = mL1TOccupancyMonitor->getTH2F()->GetYaxis()->FindBin(me->getTH1()->GetName());
410  mL1TOccupancyMonitor->setBinContent(binx,biny,300);
411  }
412  }
413  }
414  }
415  }
416 
417  //-> Filling the summaries
418  int nBinX = mL1TOccupancyMonitor->getTH2F()->GetXaxis()->GetNbins();
419  int nBinY = mL1TOccupancyMonitor->getTH2F()->GetYaxis()->GetNbins();
420  for(int binx=1; binx<=nBinX ; binx++){
421  int GlobalStatus=0;
422  for(int biny=2; biny<=nBinY ; biny++){
423  double flag = mL1TOccupancyMonitor->getBinContent(binx,biny);
424  if(GlobalStatus<flag){GlobalStatus=flag;}
425  }
426 
427  // NOTE: Assumes mL1TSummary has same size then mL1TOccupancyMonitor
428  mL1TOccupancyMonitor->setBinContent(binx, 1,GlobalStatus);
429  mL1TSummary ->setBinContent(binx,binYOccpancy,GlobalStatus);
430  }
431 }
432 
433 //____________________________________________________________________________
434 // Function: updateL1TOccupancyMonitor
435 // Description:
436 //____________________________________________________________________________
438 
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
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
const QReport * getQReport(const std::string &qtname) const
get QReport corresponding to &lt;qtname&gt; (null pointer if QReport does not exist)
long int flag
Definition: mlp_lapack.h:47
void beginRun(const edm::Run &r, const edm::EventSetup &c)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginJob(void)
const std::string & getMessage(void) const
get message attached to test
Definition: QReport.h:24
void analyze(const edm::Event &e, const edm::EventSetup &c)
int getStatus(void) const
get test status (see Core/interface/QTestStatus.h)
Definition: QReport.h:16
TH1 * getTH1(void) const
int getBin(double x, std::vector< double > boundaries)
Definition: Utilities.h:512
const std::vector< DQMChannel > & getBadChannels(void) const
Definition: QReport.h:33
double b
Definition: hdecay.h:120
LuminosityBlockNumber_t luminosityBlock() const
void endRun(const edm::Run &r, const edm::EventSetup &c)
float getQTresult(void) const
get test result i.e. prob value
Definition: QReport.h:20
L1TTestsSummary(const edm::ParameterSet &ps)
double a
Definition: hdecay.h:121
virtual ~L1TTestsSummary()
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context)
void updateL1TOccupancyMonitor()
tuple cout
Definition: gather_cfg.py:121
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
Definition: Run.h:33