CMS 3D CMS Logo

L1TOccupancyClient.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: L1TOccupancyClient
24 // Description: This is the constructor, basic variable initialization
25 // Inputs:
26 // * const edm::ParameterSet& ps = Parameter for this analyzer
27 //____________________________________________________________________________
29  // Get parameters
30  parameters_ = ps;
31  verbose_ = ps.getParameter<bool>("verbose");
32  tests_ = ps.getParameter<std::vector<ParameterSet> >("testParams");
33 
34  if (verbose_) {
35  cout << "[L1TOccupancyClient:] Called constructor" << endl;
36  }
37 }
38 
39 //____________________________________________________________________________
40 // Function: ~L1TOccupancyClient
41 // Description: This is the destructor, basic variable deletion
42 //____________________________________________________________________________
44  if (verbose_) {
45  cout << "[L1TOccupancyClient:] Called destructor" << endl;
46  }
47 }
48 
49 //____________________________________________________________________________
50 // Function: beginRun
51 // Description: This is will be run at the begining of each run
52 // Inputs:
53 // * const Run& r = Run information
54 // * const EventSetup& context = Event Setup information
55 //____________________________________________________________________________
57  hservice_ = new L1TOccupancyClientHistogramService(parameters_, ibooker, verbose_);
58 
59  if (verbose_) {
60  cout << "[L1TOccupancyClient:] Called beginRun" << endl;
61 
62  // In verbose mode we will produce an extra output file with several tests
63  file_ = TFile::Open("DQM_L1TOccupancyClient_Snapshots_LS.root", "RECREATE");
64  }
65 
66  ibooker.setCurrentFolder("L1T/L1TOccupancy/");
67  //dbe_->setCurrentFolder("L1T/L1TOccupancy/Results");
68  //dbe_->setCurrentFolder("L1T/L1TOccupancy/BadCellValues");
69  //dbe_->setCurrentFolder("L1T/L1TOccupancy/Certification");
70 
71  // Loop over all tests in defined
72  for (vector<ParameterSet>::iterator it = tests_.begin(); it != tests_.end(); it++) {
73  // If the test algorithm is XYSymmetry we create the necessary histograms
74  if ((*it).getUntrackedParameter<string>("algoName", "XYSymmetry") == "XYSymmetry") {
75  // Getting Parameters for the test
76  string testName = (*it).getParameter<string>("testName");
77  ParameterSet algoParameters = (*it).getParameter<ParameterSet>("algoParams");
78  string histPath = algoParameters.getParameter<string>("histPath");
79 
80  if (verbose_) {
81  cout << "[L1TOccupancyClient:] Monitored histogram path: " << histPath << endl;
82 
83  // Creating verbose file directory structure
84  // test_name/test_name_Results,
85  // test_name/test_name_Histos
86  // TDirectory *td = file_->mkdir(testName.c_str() ,testName.c_str());
87  //FIXME: sub never used gcc361 warning
88  //TDirectory *sub = td ->mkdir((testName+"_Results").c_str(),string("_Results").c_str());
89 
90  //sub = td->mkdir((testName+"_Histos").c_str() ,(testName+"_Histos").c_str());
91  //sub = td->mkdir((testName+"_Histos_AllLS").c_str(),(testName+"_Histos_AllLS").c_str());
92  }
93 
94  // Load histograms in service instance
95  if (hservice_->loadHisto(igetter, testName, histPath)) {
96  // Mask channels specified in python file
97  hservice_->setMaskedBins(testName, algoParameters.getParameter<vector<ParameterSet> >("maskedAreas"));
98 
99  // Book MonitorElements
100  // * Test results
101  ibooker.setCurrentFolder("L1T/L1TOccupancy/Results");
102  string title = testName;
103  MonitorElement* m = ibooker.book2D(title.c_str(), hservice_->getDifferentialHistogram(testName));
104  m->setTitle(title);
105  m->Reset();
106  meResults[title] = m;
107 
108  // * Which cells are masked as bad
109  ibooker.setCurrentFolder("L1T/L1TOccupancy/HistogramDiff");
110  title = testName;
111  m = ibooker.book2D(title.c_str(), hservice_->getDifferentialHistogram(testName));
112  m->Reset();
113  m->setTitle(title);
114  meDifferential[title] = m;
115 
116  // * Fraction of bad cells
117  ibooker.setCurrentFolder("L1T/L1TOccupancy/Certification");
118  title = testName;
119  m = ibooker.book1D(title.c_str(), title.c_str(), 2500, -.5, 2500. - .5);
120  m->setTitle(title);
121  meCertification[title] = m;
122 
123  mValidTests.push_back(&(*it));
124  }
125  }
126  }
127 }
128 
129 //____________________________________________________________________________
130 // Function: endRun
131 // Description: This is will be run at the end of each run
132 // Inputs:
133 // * const Run& r = Run information
134 // * const EventSetup& context = Event Setup information
135 //____________________________________________________________________________
137  book(ibooker, igetter);
138 
139  if (verbose_) {
140  cout << "[L1TOccupancyClient:] Called endRun()" << endl;
141  }
142 
143  // Loop over every test in python
144  for (std::vector<ParameterSet*>::iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
145  ParameterSet& test = (**it);
146  string algo_name = test.getUntrackedParameter<string>("algoName", "XYSymmetry");
147  string test_name = test.getParameter<string>("testName");
148 
149  if (verbose_) {
150  cout << "[L1TOccupancyClient:] Starting calculations for: " << algo_name << " on: " << test_name << endl;
151  }
152 
153  if (algo_name == "XYSymmetry") {
154  ParameterSet ps = (**it).getParameter<ParameterSet>("algoParams");
155  string histPath = ps.getParameter<string>("histPath");
156 
157  vector<pair<int, double> > deadChannels;
158  vector<pair<int, double> > statDev;
159  bool enoughStats = false;
160 
161  // Make final block
162  hservice_->updateHistogramEndRun(test_name);
163 
164  // Perform the test
165  double dead = xySymmetry(ps, test_name, deadChannels, statDev, enoughStats);
166  stringstream str;
167  str << test_name << "_cumu_LS_EndRun";
168 
169  if (verbose_) {
170  TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
171 
172  cumulative_save->SetTitle(str.str().c_str());
173 
174  TDirectory* td = file_->GetDirectory(test_name.c_str());
175 
176  td->cd(string(test_name + "_Histos_AllLS").c_str());
177 
178  cumulative_save->Write();
179  }
180  // If we have enough statistics, we can write test result
181  if (enoughStats) {
182  // Make the result histogram
183  printDeadChannels(deadChannels, meResults[test_name]->getTH2F(), statDev, test_name);
184 
185  if (verbose_) {
186  TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
187  cumulative_save->SetTitle(str.str().c_str());
188  TDirectory* td = file_->GetDirectory(("DQM_L1TOccupancyClient_Snapshots_LS.root:/" + test_name).c_str());
189  td->cd(string(test_name + "_Histos").c_str());
190  cumulative_save->Write();
191 
192  // save the result histo
193  TH2F* h2f = meResults[test_name]->getTH2F();
194  stringstream str2;
195  str2 << test_name << "_result_LS_EndRun";
196  TH2F* dead_save = (TH2F*)h2f->Clone(str2.str().c_str());
197 
198  td->cd(string(test_name + "_Results").c_str());
199  dead_save->SetTitle(str2.str().c_str());
200  dead_save->Write();
201  }
202 
203  // Updating test results
204  meDifferential[test_name]->Reset();
205  meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
206 
207  vector<int> lsCertification = hservice_->getLSCertification(test_name);
208 
209  // Fill fraction of dead channels
210  for (unsigned int i = 0; i < lsCertification.size(); i++) {
211  int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
212  meCertification[test_name]->getTH1()->SetBinContent(bin, 1 - dead);
213  }
214 
215  // Reset differential histo
216  hservice_->resetHisto(test_name);
217 
218  if (verbose_) {
219  cout << "Now we have enough statstics for " << test_name << endl;
220  }
221 
222  } else {
223  if (verbose_) {
224  cout << "we don't have enough statstics for " << test_name << endl;
225  }
226 
227  // Getting LS which this test monitored
228  vector<int> lsCertification = hservice_->getLSCertification(test_name);
229 
230  // Fill fraction of dead channels
231  for (unsigned int i = 0; i < lsCertification.size(); i++) {
232  int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
233  meCertification[test_name]->getTH1()->SetBinContent(bin, -1);
234  }
235  }
236  } else {
237  if (verbose_) {
238  cout << "No valid algorithm" << std::endl;
239  }
240  }
241  }
242 
243  if (verbose_) {
244  file_->Close();
245  }
246 
247  delete hservice_;
248 }
249 
250 //____________________________________________________________________________
251 // Function: beginLuminosityBlock
252 // Description: This is will be run at the begining of each luminosity block
253 // Inputs:
254 // * const LuminosityBlock& lumiSeg = Luminosity Block information
255 // * const EventSetup& context = Event Setup information
256 //____________________________________________________________________________
257 
258 //____________________________________________________________________________
259 // Function: endLuminosityBlock
260 // Description: This is will be run at the end of each luminosity block
261 // Inputs:
262 // * const LuminosityBlock& lumiSeg = Luminosity Block information
263 // * const EventSetup& context = Event Setup information
264 //____________________________________________________________________________
266  DQMStore::IGetter& igetter,
267  const edm::LuminosityBlock& lumiSeg,
268  const edm::EventSetup& c) {
269  book(ibooker, igetter);
270 
271  int eventLS = lumiSeg.id().luminosityBlock();
272 
273  if (verbose_) {
274  cout << "[L1TOccupancyClient:] Called endLuminosityBlock()" << endl;
275  cout << "[L1TOccupancyClient:] Lumisection: " << eventLS << endl;
276  }
277 
278  // Loop over every test in python
279  for (std::vector<ParameterSet*>::const_iterator it = mValidTests.begin(); it != mValidTests.end(); it++) {
280  ParameterSet& test = (**it);
281  string algo_name = test.getUntrackedParameter<string>("algoName", "XYSymmetry");
282  string test_name = test.getParameter<string>("testName");
283 
284  if (verbose_) {
285  cout << "[L1TOccupancyClient:] Starting calculations for " << algo_name << " on:" << test_name << endl;
286  }
287 
288  if (algo_name == "XYSymmetry") {
289  ParameterSet ps = (**it).getParameter<ParameterSet>("algoParams");
290  string histPath = ps.getParameter<string>("histPath");
291 
292  vector<pair<int, double> > deadChannels;
293  vector<pair<int, double> > statDev;
294  bool enoughStats = false;
295 
296  // Update histo's data with data of this LS
297  hservice_->updateHistogramEndLS(igetter, test_name, histPath, eventLS);
298 
299  // Perform the test
300  double dead = xySymmetry(ps, test_name, deadChannels, statDev, enoughStats);
301  stringstream str;
302  str << test_name << "_cumu_LS_" << eventLS;
303 
304  if (verbose_) {
305  TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
306  cumulative_save->SetTitle(str.str().c_str());
307  TDirectory* td = file_->GetDirectory(test_name.c_str());
308  td->cd(string(test_name + "_Histos_AllLS").c_str());
309  cumulative_save->Write();
310  }
311 
312  // If we have enough statistics, we can write test result
313  if (enoughStats) {
314  // Make the result histogram
315  printDeadChannels(deadChannels, meResults[test_name]->getTH2F(), statDev, test_name);
316 
317  if (verbose_) {
318  TH2F* cumulative_save = (TH2F*)hservice_->getDifferentialHistogram(test_name)->Clone(str.str().c_str());
319  cumulative_save->SetTitle(str.str().c_str());
320  TDirectory* td = file_->GetDirectory(("DQM_L1TOccupancyClient_Snapshots_LS.root:/" + test_name).c_str());
321  td->cd(string(test_name + "_Histos").c_str());
322  cumulative_save->Write();
323 
324  // save the result histo
325  TH2F* h2f = meResults[test_name]->getTH2F();
326  stringstream str2;
327  str2 << test_name << "_result_LS_" << eventLS;
328  TH2F* dead_save = (TH2F*)h2f->Clone(str2.str().c_str());
329 
330  td->cd(string(test_name + "_Results").c_str());
331  dead_save->SetTitle(str2.str().c_str());
332  dead_save->Write();
333  }
334 
335  // Updating test results
336  meDifferential[test_name]->Reset();
337  meDifferential[test_name]->getTH2F()->Add(hservice_->getDifferentialHistogram(test_name));
338 
339  vector<int> lsCertification = hservice_->getLSCertification(test_name);
340 
341  // Fill fraction of dead channels
342  for (unsigned int i = 0; i < lsCertification.size(); i++) {
343  int bin = meCertification[test_name]->getTH1()->FindBin(lsCertification[i]);
344  meCertification[test_name]->getTH1()->SetBinContent(bin, 1 - dead);
345  }
346 
347  // Reset differential histo
348  hservice_->resetHisto(test_name);
349 
350  if (verbose_) {
351  cout << "Now we have enough statstics for " << test_name << endl;
352  }
353 
354  } else {
355  if (verbose_) {
356  cout << "we don't have enough statstics for " << test_name << endl;
357  }
358  }
359  } else {
360  if (verbose_) {
361  cout << "No valid algorithm" << std::endl;
362  }
363  }
364  }
365 }
366 
367 //____________________________________________________________________________
368 // Function: analyze
369 // Description: This is will be run for every event
370 // Inputs:
371 // * const Event& e = Event information
372 // * const EventSetup& context = Event Setup information
373 //____________________________________________________________________________
374 //void L1TOccupancyClient::analyze(const Event& e, const EventSetup& context){}
375 
376 //____________________________________________________________________________
377 // Function: xySymmetry
378 // Description: This method preforms the XY Symmetry test
379 // Inputs:
380 // * ParameterSet ps = Parameters for the test
381 // * std::string test_name = Test name of the test to be executed
382 // * std::vector< pair<int,double> >& deadChannels = Vector of
383 // * std::vector< pair<int,double> >& statDev =
384 // * bool& enoughStats =
385 // Outputs:
386 // * double = fraction of bins that failed test, DeadChannels in vector, in: ParameterSet of test parameters
387 //____________________________________________________________________________
389  string iTestName,
390  vector<pair<int, double> >& deadChannels,
391  vector<pair<int, double> >& statDev,
392  bool& enoughStats) {
393  // Getting differential histogram for this this thes
394  TH2F* diffHist = hservice_->getDifferentialHistogram(iTestName);
395 
396  int pAxis = ps.getUntrackedParameter<int>("axis", 1);
397  int pAverageMode = ps.getUntrackedParameter<int>("averageMode", 2); // 1=arith. mean, 2=median
398  int nBinsX = diffHist->GetNbinsX(); // actual number of bins x
399  int nBinsY = diffHist->GetNbinsY(); // actual number of bins y
400 
401  // Axis==1 : Means symmetry axis is vertical
402  if (pAxis == 1) {
403  int maxBinStrip, centralBinStrip; // x-coordinate of strips
404 
405  maxBinStrip = nBinsX;
406 
407  // If takeCenter=true determine central bin of the pAxis
408  // If takeCenter=false determine the bin to use based user input
409  if (ps.getUntrackedParameter<bool>("takeCenter", true)) {
410  centralBinStrip = nBinsX / 2 + 1;
411  } else {
412  double pAxisSymmetryValue = ps.getParameter<double>("axisSymmetryValue");
413  getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 1);
414  }
415 
416  // Assuming odd number of strips --> first comparison is middle strip to itself
417  int upBinStrip = centralBinStrip;
418  int lowBinStrip = centralBinStrip;
419 
420  // If even number decrease lowBinstrip by one
421  if (nBinsX % 2 == 0) {
422  lowBinStrip--;
423  }
424 
425  // Do we have enough statistics? Min(Max(strip_i,strip_j))>threshold
426  std::unique_ptr<double[]> maxAvgs(new double[maxBinStrip - upBinStrip + 1]);
427 
428  int nActualStrips = 0; //number of strips that are not fully masked
429  for (int i = 0, j = upBinStrip, k = lowBinStrip; j <= maxBinStrip; i++, j++, k--) {
430  double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsY, j, pAverageMode);
431  double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsY, k, pAverageMode);
432 
433  // Protection for when both strips are masked
434  if (!hservice_->isStripMasked(iTestName, j, pAxis) && !hservice_->isStripMasked(iTestName, k, pAxis)) {
435  maxAvgs[i] = TMath::Max(avg1, avg2);
436  nActualStrips++;
437  }
438  }
439 
440  vector<double> defaultMu0up;
441  defaultMu0up.push_back(13.7655);
442  defaultMu0up.push_back(184.742);
443  defaultMu0up.push_back(50735.3);
444  defaultMu0up.push_back(-97.6793);
445 
446  TF1 tf("myFunc", "[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
447  vector<double> params = ps.getUntrackedParameter<vector<double> >("params_mu0_up", defaultMu0up);
448  for (unsigned int i = 0; i < params.size(); i++) {
449  tf.SetParameter(i, params[i]);
450  }
451  int statsup = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
452 
453  vector<double> defaultMu0low;
454  defaultMu0low.push_back(2.19664);
455  defaultMu0low.push_back(1.94546);
456  defaultMu0low.push_back(-99.3263);
457  defaultMu0low.push_back(19.388);
458 
459  params = ps.getUntrackedParameter<vector<double> >("params_mu0_low", defaultMu0low);
460  for (unsigned int i = 0; i < params.size(); i++) {
461  tf.SetParameter(i, params[i]);
462  }
463  int statslow = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
464 
465  if (verbose_) {
466  cout << "nbins: " << hservice_->getNBinsHistogram(iTestName) << endl;
467  cout << "statsup= " << statsup << ", statslow= " << statslow << endl;
468  }
469 
470  enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) > TMath::Max(statsup, statslow);
471  if (verbose_) {
472  cout << "stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
473  << ", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
474  << ", threshold: " << TMath::Max(statsup, statslow) << endl;
475  }
476 
477  //if enough statistics
478  //make the test
479  if (enoughStats) {
480  for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
481  double avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, upBinStrip, pAverageMode);
482  compareWithStrip(
483  diffHist, iTestName, lowBinStrip, nBinsY, pAxis, avg, ps, deadChannels); //compare with lower side
484 
485  avg = getAvrg(diffHist, iTestName, pAxis, nBinsY, lowBinStrip, pAverageMode);
486  compareWithStrip(
487  diffHist, iTestName, upBinStrip, nBinsY, pAxis, avg, ps, deadChannels); //compare with upper side
488  }
489  }
490  }
491 
492  // pAxis==2 : Means symetry pAxis is horizontal
493  else if (pAxis == 2) {
494  int maxBinStrip, centralBinStrip; //x-coordinate of strips
495 
496  maxBinStrip = nBinsY;
497 
498  // Determine center of diagram: either with set pAxis or middle of diagram
499  if (ps.getUntrackedParameter<bool>("takeCenter", true)) {
500  centralBinStrip = nBinsY / 2 + 1;
501  } else {
502  double pAxisSymmetryValue = ps.getParameter<double>("axisSymmetryValue");
503  getBinCoordinateOnAxisWithValue(diffHist, pAxisSymmetryValue, centralBinStrip, 2);
504  }
505 
506  //assuming odd number of strips --> first comparison is middle strip to itself
507  int lowBinStrip = centralBinStrip, upBinStrip = centralBinStrip;
508 
509  //if even number
510  if (nBinsX % 2 == 0) {
511  //decrease lowBinstrip by one
512  lowBinStrip--;
513  }
514 
515  //do we have enough statistics? Min(Max(strip_i,strip_j))>threshold
516  std::unique_ptr<double[]> maxAvgs(new double[maxBinStrip - upBinStrip + 1]);
517  int nActualStrips = 0;
518  for (int i = 0, j = upBinStrip, k = lowBinStrip; j <= maxBinStrip; i++, j++, k--) {
519  double avg1 = getAvrg(diffHist, iTestName, pAxis, nBinsX, j, pAverageMode);
520  double avg2 = getAvrg(diffHist, iTestName, pAxis, nBinsX, k, pAverageMode);
521  if (!hservice_->isStripMasked(iTestName, j, pAxis) && !hservice_->isStripMasked(iTestName, k, pAxis)) {
522  maxAvgs[i] = TMath::Max(avg1, avg2);
523  nActualStrips++;
524  }
525  }
526 
527  vector<double> defaultMu0up;
528  defaultMu0up.push_back(13.7655);
529  defaultMu0up.push_back(184.742);
530  defaultMu0up.push_back(50735.3);
531  defaultMu0up.push_back(-97.6793);
532 
533  vector<double> params = ps.getUntrackedParameter<std::vector<double> >("params_mu0_up", defaultMu0up);
534  TF1 tf("myFunc", "[0]*(TMath::Log(x*[1]+[2]))+[3]", 10., 11000.);
535  for (unsigned int i = 0; i < params.size(); i++) {
536  tf.SetParameter(i, params[i]);
537  }
538  int statsup = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
539 
540  vector<double> defaultMu0low;
541  defaultMu0low.push_back(2.19664);
542  defaultMu0low.push_back(1.94546);
543  defaultMu0low.push_back(-99.3263);
544  defaultMu0low.push_back(19.388);
545 
546  params = ps.getUntrackedParameter<std::vector<double> >("params_mu0_low", defaultMu0low);
547  for (unsigned int i = 0; i < params.size(); i++) {
548  tf.SetParameter(i, params[i]);
549  }
550  int statslow = (int)tf.Eval(hservice_->getNBinsHistogram(iTestName));
551  if (verbose_) {
552  cout << "statsup= " << statsup << ", statslow= " << statslow << endl;
553  }
554  enoughStats = TMath::MinElement(nActualStrips, maxAvgs.get()) > TMath::Max(statsup, statslow);
555  if (verbose_) {
556  cout << "stats: " << TMath::MinElement(nActualStrips, maxAvgs.get())
557  << ", statsAvg: " << diffHist->GetEntries() / hservice_->getNBinsHistogram(iTestName)
558  << ", threshold: " << TMath::Max(statsup, statslow) << endl;
559  }
560 
561  //if we have enough statistics
562  //make the test
563  if (enoughStats) {
564  for (; upBinStrip <= maxBinStrip; upBinStrip++, lowBinStrip--) {
565  double avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, upBinStrip, pAverageMode);
566  compareWithStrip(
567  diffHist, iTestName, lowBinStrip, nBinsX, pAxis, avg, ps, deadChannels); //compare with lower side
568 
569  avg = getAvrg(diffHist, iTestName, pAxis, nBinsX, lowBinStrip, pAverageMode);
570  compareWithStrip(
571  diffHist, iTestName, upBinStrip, nBinsX, pAxis, avg, ps, deadChannels); //compare with upper side
572  }
573  }
574  } else {
575  if (verbose_) {
576  cout << "Invalid axis" << endl;
577  }
578  }
579 
580  return (deadChannels.size() - hservice_->getNBinsMasked(iTestName)) * 1.0 / hservice_->getNBinsHistogram(iTestName);
581 }
582 
583 //____________________________________________________________________________
584 // Function: getAvrg
585 // Description: Calculate strip average with method iAvgMode, where strip is
586 // prependicular to iAxis at bin iBinStrip of histogram iHist
587 // Inputs:
588 // * TH2F* iHist = Histogram to be tested
589 // * string iTestName = Name of the test
590 // * int iAxis = Axis prependicular to plot symmetry
591 // * int iNBins = Number of bins in the strip
592 // * int iBinStrip = Bin corresponding to the strip in iAxis
593 // * int iAvgMode = Type of average mode 1) Average 2) Median
594 // Outputs:
595 // * double = Average of input strip
596 //____________________________________________________________________________
597 double L1TOccupancyClient::getAvrg(TH2F* iHist, string iTestName, int iAxis, int iNBins, int iBinStrip, int iAvgMode) {
598  double avg = 0.0;
599  TH1D* proj = nullptr;
600  TH2F* histo = new TH2F(*iHist);
601 
602  std::vector<double> values;
603  int marked;
604 
605  if (iAxis == 1) {
606  switch (iAvgMode) {
607  // arithmetic average
608  case 1:
609  marked = hservice_->maskBins(iTestName, histo, iBinStrip, iAxis);
610  proj = histo->ProjectionX();
611  avg = proj->GetBinContent(iBinStrip) / (iNBins - marked);
612  break;
613 
614  // median
615  case 2:
616  marked = hservice_->maskBins(iTestName, histo, iBinStrip, iAxis);
617  proj = histo->ProjectionY("_py", iBinStrip, iBinStrip);
618  for (int i = 0; i < iNBins; i++) {
619  values.push_back(proj->GetBinContent(i + 1));
620  }
621  avg = TMath::Median(iNBins, &values[0]);
622  break;
623  default:
624  if (verbose_) {
625  cout << "Invalid averaging mode!" << endl;
626  }
627  break;
628  }
629  } else if (iAxis == 2) {
630  switch (iAvgMode) {
631  // arithmetic average
632  case 1:
633  marked = hservice_->maskBins(iTestName, histo, iBinStrip, iAxis);
634  proj = histo->ProjectionY();
635  avg = proj->GetBinContent(iBinStrip) / (iNBins - marked);
636  break;
637  // median
638  case 2:
639  marked = hservice_->maskBins(iTestName, histo, iBinStrip, iAxis);
640  proj = histo->ProjectionX("_px", iBinStrip, iBinStrip);
641  for (int i = 0; i < iNBins; i++) {
642  values.push_back(proj->GetBinContent(i + 1));
643  }
644 
645  avg = TMath::Median(iNBins, &values[0]);
646  break;
647  default:
648  if (verbose_) {
649  cout << "invalid averaging mode!" << endl;
650  }
651  break;
652  }
653  } else {
654  if (verbose_) {
655  cout << "invalid axis" << endl;
656  }
657  }
658  delete proj;
659  delete histo;
660  return avg;
661 }
662 
663 //____________________________________________________________________________
664 // Function: printDeadChannels
665 // Description:
666 // Inputs:
667 // * vector< pair<int,double> > iDeadChannels = List of bin that are masked of failed tthe test
668 // * TH2F* oHistDeadChannels = Histogram where test results should be printed
669 // * vector< pair<int,double> > statDev = ???
670 // * string iTestName = Name of the test
671 //____________________________________________________________________________
672 void L1TOccupancyClient::printDeadChannels(const vector<pair<int, double> >& iDeadChannels,
673  TH2F* oHistDeadChannels,
674  const vector<std::pair<int, double> >& statDev,
675  string iTestName) {
676  // Reset the dead channels histogram
677  oHistDeadChannels->Reset();
678  if (verbose_) {
679  cout << "suspect or masked channels of " << iTestName << ": ";
680  }
681 
682  int x, y, z;
683  float chi2 = 0.0;
684 
685  // put all bad (value=1) and masked (value=-1) cells in histo
686  for (std::vector<pair<int, double> >::const_iterator it = iDeadChannels.begin(); it != iDeadChannels.end(); it++) {
687  int bin = (*it).first;
688  oHistDeadChannels->GetBinXYZ(bin, x, y, z);
689 
690  if (hservice_->isMasked(iTestName, x, y)) {
691  oHistDeadChannels->SetBinContent(bin, -1);
692  if (verbose_) {
693  printf("(%4i,%4i) Masked\n", x, y);
694  }
695  } else {
696  oHistDeadChannels->SetBinContent(bin, 1);
697  if (verbose_) {
698  printf("(%4i,%4i) Failed test\n", x, y);
699  }
700  }
701  }
702 
703  // FIXME: Is this needed?
704  for (std::vector<pair<int, double> >::const_iterator it = statDev.begin(); it != statDev.end(); it++) {
705  double dev = (*it).second;
706  chi2 += dev;
707  }
708  //put total chi2 in float
709 
710  if (verbose_) {
711  cout << "total number of suspect channels: " << (iDeadChannels.size() - (hservice_->getNBinsMasked(iTestName)))
712  << endl;
713  }
714 }
715 
716 //____________________________________________________________________________
717 // Function: compareWithStrip
718 // Description: Evaluates statistical compatibility of a strip (cell by cell) against a given average
719 // Inputs:
720 // * TH2F* iHist = Histogram to be tested
721 // * string iTestName = Which test to apply
722 // * int iBinStrip = Bin Coordinate (in bin units) of the stripo
723 // * int iNBins = Number of Bins in the strip
724 // * int iAxis = Which Axis is prependicular to the plot symmetry.
725 // * double iAvg = Average of the strip
726 // * ParameterSet iPS = Parameters for the test
727 // * vector<pair<int,double> >& oChannels = Output of bin that are masked or failed the test
728 // Outputs:
729 // * int = Number of dead channels
730 //____________________________________________________________________________
732  string iTestName,
733  int iBinStrip,
734  int iNBins,
735  int iAxis,
736  double iAvg,
737  const ParameterSet& iPS,
738  vector<pair<int, double> >& oChannels) {
739  int dead = 0;
740 
741  //
742  if (iAxis == 1) {
743  // Get and set parameters for working curves
744  TF1* fmuup = new TF1("fmuup", "TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
745  TF1* fmulow = new TF1("fmulow", "TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
746  fmuup->SetParameter(0, iAvg * iPS.getUntrackedParameter<double>("factorup", 2.0));
747  fmuup->SetParameter(1, iAvg);
748  fmulow->SetParameter(0, iAvg * iPS.getUntrackedParameter<double>("factorlow", 0.1));
749  fmulow->SetParameter(1, iAvg);
750 
751  TF1* fchi = new TF1("fchi", "[0]*x**2+[1]*x+[2]", 0., 1500.);
752 
753  // Evaluate sigma up
754  vector<double> defaultChi2up;
755  defaultChi2up.push_back(5.45058e-05);
756  defaultChi2up.push_back(0.268756);
757  defaultChi2up.push_back(-11.7515);
758 
759  vector<double> params = iPS.getUntrackedParameter<vector<double> >("params_chi2_up", defaultChi2up);
760  for (unsigned int i = 0; i < params.size(); i++) {
761  fchi->SetParameter(i, params[i]);
762  }
763  double sigma_up = fchi->Eval(iAvg);
764 
765  // Evaluate sigma low
766  vector<double> defaultChi2low;
767  defaultChi2low.push_back(4.11095e-05);
768  defaultChi2low.push_back(0.577451);
769  defaultChi2low.push_back(-10.378);
770 
771  params = iPS.getUntrackedParameter<vector<double> >("params_chi2_low", defaultChi2low);
772  for (unsigned int i = 0; i < params.size(); i++) {
773  fchi->SetParameter(i, params[i]);
774  }
775  double sigma_low = fchi->Eval(iAvg);
776 
777  if (verbose_) {
778  cout << "binstrip= " << iBinStrip << ", sigmaup= " << sigma_up << ", sigmalow= " << sigma_low << endl;
779  }
780 
781  for (int i = 1; i <= iNBins; i++) {
782  if (verbose_) {
783  cout << " " << i << " binContent: up:" << fmuup->Eval(iHist->GetBinContent(iBinStrip, i))
784  << " low: " << fmulow->Eval(iHist->GetBinContent(iBinStrip, i)) << endl;
785  }
786 
787  // Evaluate chi2 for cells
788  double muup = fmuup->Eval(iHist->GetBinContent(iBinStrip, i));
789  double mulow = fmulow->Eval(iHist->GetBinContent(iBinStrip, i));
790 
791  // If channel is masked -> set it to value -1
792  if (hservice_->isMasked(iTestName, iBinStrip, i)) {
793  oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip, i), -1.0));
794  }
795  //else perform test
796  else if (muup > sigma_up || mulow > sigma_low ||
797  ((fabs(muup) == std::numeric_limits<double>::infinity()) &&
798  (fabs(mulow) == std::numeric_limits<double>::infinity()))) {
799  dead++;
800  oChannels.push_back(
801  pair<int, double>(iHist->GetBin(iBinStrip, i), abs(iHist->GetBinContent(iBinStrip, i) - iAvg) / iAvg));
802  }
803  }
804  }
805  //
806  else if (iAxis == 2) {
807  //get and set parameters for working curves
808  TF1* fmuup = new TF1("fmuup", "TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
809  TF1* fmulow = new TF1("fmulow", "TMath::Log(TMath::PoissonI(x,[0])/TMath::PoissonI(x,[1]))", -10000., 10000.);
810  fmuup->SetParameter(0, iAvg * iPS.getUntrackedParameter<double>("factorup", 2.0));
811  fmuup->SetParameter(1, iAvg);
812  fmulow->SetParameter(0, iAvg * iPS.getUntrackedParameter<double>("factorlow", 0.1));
813  fmulow->SetParameter(1, iAvg);
814 
815  TF1* fchi = new TF1("fchi", "[0]*x**2+[1]*x+[2]", 0., 1500.);
816 
817  // Evaluate sigma up
818  vector<double> defaultChi2up;
819  defaultChi2up.push_back(5.45058e-05);
820  defaultChi2up.push_back(0.268756);
821  defaultChi2up.push_back(-11.7515);
822 
823  vector<double> params = iPS.getUntrackedParameter<vector<double> >("params_chi2_up", defaultChi2up);
824  for (unsigned int i = 0; i < params.size(); i++) {
825  fchi->SetParameter(i, params[i]);
826  }
827  double sigma_up = fchi->Eval(iAvg);
828 
829  // Evaluate sigma low
830  vector<double> defaultChi2low;
831  defaultChi2low.push_back(4.11095e-05);
832  defaultChi2low.push_back(0.577451);
833  defaultChi2low.push_back(-10.378);
834 
835  params = iPS.getUntrackedParameter<vector<double> >("params_chi2_low", defaultChi2low);
836  for (unsigned int i = 0; i < params.size(); i++) {
837  fchi->SetParameter(i, params[i]);
838  }
839  double sigma_low = fchi->Eval(iAvg);
840 
841  if (verbose_) {
842  cout << "binstrip= " << iBinStrip << ", sigmaup= " << sigma_up << ", sigmalow= " << sigma_low << endl;
843  }
844 
845  for (int i = 1; i <= iNBins; i++) {
846  if (verbose_) {
847  cout << " " << i << " binContent: up:" << fmuup->Eval(iHist->GetBinContent(i, iBinStrip))
848  << " low: " << fmulow->Eval(iHist->GetBinContent(i, iBinStrip)) << endl;
849  }
850 
851  //evaluate chi2 for cells
852  double muup = fmuup->Eval(iHist->GetBinContent(i, iBinStrip));
853  double mulow = fmulow->Eval(iHist->GetBinContent(i, iBinStrip));
854 
855  //if channel is masked -> set it to value -1
856  if (hservice_->isMasked(iTestName, i, iBinStrip)) {
857  oChannels.push_back(pair<int, double>(iHist->GetBin(iBinStrip, i), -1.0));
858  }
859  //else perform test
860  else if (muup > sigma_up || mulow > sigma_low ||
861  ((fabs(muup) == std::numeric_limits<double>::infinity()) &&
862  (fabs(mulow) == std::numeric_limits<double>::infinity()))) {
863  dead++;
864  oChannels.push_back(
865  pair<int, double>(iHist->GetBin(i, iBinStrip), abs(iHist->GetBinContent(i, iBinStrip) - iAvg) / iAvg));
866  }
867  }
868  } else {
869  if (verbose_) {
870  cout << "invalid axis" << endl;
871  }
872  }
873 
874  return dead;
875 }
876 
877 //____________________________________________________________________________
878 // Function: getBinCoordinateOnAxisWithValue
879 // Description: Returns the bin global bin number with the iValue in the iAxis
880 // Inputs:
881 // * TH2F* iHist = Histogram to be tested
882 // * double iValue = Value to be evaluated in the histogram iHist
883 // * int& oBinCoordinate = (output) bin number (X or Y) for iValue
884 // * int iAxis = Axis to be used
885 //____________________________________________________________________________
886 void L1TOccupancyClient::getBinCoordinateOnAxisWithValue(TH2F* iHist, double iValue, int& oBinCoordinate, int iAxis) {
887  int nBinsX = iHist->GetNbinsX(); //actual number of bins x
888  int nBinsY = iHist->GetNbinsY(); //actual number of bins y
889 
890  if (iAxis == 1) {
891  int global = iHist->GetXaxis()->FindFixBin(iValue);
892 
893  // If parameter exceeds axis' value: set to maximum number of bins in x-axis
894  if (global > nBinsX * nBinsY) {
895  global = iHist->GetXaxis()->GetLast();
896  }
897 
898  // Get coordinates of bin
899  int y, z;
900  iHist->GetBinXYZ(global, oBinCoordinate, y, z);
901  } else if (iAxis == 2) {
902  int global = iHist->GetYaxis()->FindFixBin(iValue);
903 
904  // If parameter exceeds axis' value: set to maximum number of bins in x-axis
905  if (global > nBinsX * nBinsY) {
906  global = iHist->GetYaxis()->GetLast();
907  }
908 
909  // Get coordinates of bin
910  int x, z;
911  iHist->GetBinXYZ(global, x, oBinCoordinate, z);
912  }
913 }
914 
915 //define this as a plug-in
runGCPTkAlMap.title
string title
Definition: runGCPTkAlMap.py:94
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
ESHandle.h
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm
HLT enums.
Definition: AlignableModifier.h:19
gather_cfg.cout
cout
Definition: gather_cfg.py:144
dqm::implementation::NavigatorBase::setCurrentFolder
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
DQMStore.h
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
infinity
const double infinity
Definition: CSCChamberFitter.cc:10
L1TOccupancyClient
Definition: L1TOccupancyClient.h:30
tools.TF1
TF1
Definition: tools.py:23
L1TOccupancyClientHistogramService
Definition: L1TOccupancyClientHistogramService.h:22
test
Definition: SmallWORMDict.h:13
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
str
#define str(s)
Definition: TestProcessor.cc:51
L1TBPTX_cfi.testName
testName
Definition: L1TBPTX_cfi.py:24
dqmdumpme.k
k
Definition: dqmdumpme.py:60
L1TOccupancyClient::~L1TOccupancyClient
~L1TOccupancyClient() override
Destructor.
Definition: L1TOccupancyClient.cc:43
amptDefault_cfi.proj
proj
Definition: amptDefault_cfi.py:13
edm::ParameterSet
Definition: ParameterSet.h:47
L1TOccupancyClient.h
L1TOccupancyClient::printDeadChannels
void printDeadChannels(const std::vector< std::pair< int, double > > &deadChannels, TH2F *h2f, const std::vector< std::pair< int, double > > &statDev, std::string test_name)
Definition: L1TOccupancyClient.cc:672
createfilelist.int
int
Definition: createfilelist.py:10
edm::LuminosityBlockID::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockID.h:42
edm::LuminosityBlockBase::id
LuminosityBlockID id() const
Definition: LuminosityBlockBase.h:44
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
Max
T Max(T a, T b)
Definition: MathUtil.h:44
edm::EventSetup
Definition: EventSetup.h:57
L1TOccupancyClient::book
void book(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter)
Definition: L1TOccupancyClient.cc:56
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
L1TOccupancyClient::dqmEndLuminosityBlock
void dqmEndLuminosityBlock(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter, const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c) override
Definition: L1TOccupancyClient.cc:265
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
std
Definition: JetResolutionObject.h:76
HLT_FULL_cff.algo_name
algo_name
Definition: HLT_FULL_cff.py:9255
dqm::implementation::IGetter
Definition: DQMStore.h:484
dqm::implementation::IBooker::book2D
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:177
L1TOccupancyClient::dqmEndJob
void dqmEndJob(DQMStore::IBooker &ibooker, DQMStore::IGetter &igetter) override
Definition: L1TOccupancyClient.cc:136
L1TOccupancyClient::xySymmetry
double xySymmetry(const edm::ParameterSet &ps, std::string test_name, std::vector< std::pair< int, double > > &deadChannels, std::vector< std::pair< int, double > > &statDev, bool &enoughStats)
Definition: L1TOccupancyClient.cc:388
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm::implementation::IBooker
Definition: DQMStore.h:43
L1TOccupancyClient_cfi.histPath
histPath
Definition: L1TOccupancyClient_cfi.py:41
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
L1TOccupancyClient::L1TOccupancyClient
L1TOccupancyClient(const edm::ParameterSet &ps)
Constructor.
Definition: L1TOccupancyClient.cc:28
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
L1TOccupancyClient::compareWithStrip
int compareWithStrip(TH2F *histo, std::string test, int binStrip, int nBins, int axis, double avg, const edm::ParameterSet &ps, std::vector< std::pair< int, double > > &deadChannels)
Definition: L1TOccupancyClient.cc:731
L1TOccupancyClient::getAvrg
double getAvrg(TH2F *h2f, std::string test, int axis, int nBins, int binStrip, int avrgMode)
Definition: L1TOccupancyClient.cc:597
dqm::implementation::IBooker::book1D
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
L1TOccupancyClient::getBinCoordinateOnAxisWithValue
void getBinCoordinateOnAxisWithValue(TH2F *h2f, double content, int &coord, int axis)
Definition: L1TOccupancyClient.cc:886