CMS 3D CMS Logo

EffPurFromHistos.cc
Go to the documentation of this file.
4 #include "TStyle.h"
5 #include "TCanvas.h"
6 
7 #include <iostream>
8 #include <cmath>
9 
12 
13 using namespace std;
14 using namespace RecoBTag;
15 
17  TH1F* h_d,
18  TH1F* h_u,
19  TH1F* h_s,
20  TH1F* h_c,
21  TH1F* h_b,
22  TH1F* h_g,
23  TH1F* h_ni,
24  TH1F* h_dus,
25  TH1F* h_dusg,
26  TH1F* h_pu,
27  const std::string& label,
28  unsigned int mc,
29  int nBin,
30  double startO,
31  double endO)
32  : fromDiscriminatorDistr(false),
33  mcPlots_(mc),
34  doCTagPlots_(false),
35  label_(label),
36  histoExtension(ext),
37  effVersusDiscr_d(h_d),
38  effVersusDiscr_u(h_u),
39  effVersusDiscr_s(h_s),
40  effVersusDiscr_c(h_c),
41  effVersusDiscr_b(h_b),
42  effVersusDiscr_g(h_g),
43  effVersusDiscr_ni(h_ni),
44  effVersusDiscr_dus(h_dus),
45  effVersusDiscr_dusg(h_dusg),
46  effVersusDiscr_pu(h_pu),
47  nBinOutput(nBin),
48  startOutput(startO),
49  endOutput(endO) {
50  // consistency check
51  check();
52 }
53 
55  const std::string& label,
56  unsigned int mc,
57  DQMStore::IBooker& ibook,
58  int nBin,
59  double startO,
60  double endO)
61  : fromDiscriminatorDistr(true),
62  mcPlots_(mc),
63  doCTagPlots_(false),
64  label_(label),
65  nBinOutput(nBin),
66  startOutput(startO),
67  endOutput(endO) {
68  histoExtension = "_" + dDiscriminatorFC.baseNameTitle();
69 
71  std::make_unique<FlavourHistograms<double>>("totalEntries" + histoExtension,
72  "Total Entries: " + dDiscriminatorFC.baseNameDescription(),
73  dDiscriminatorFC.nBins(),
74  dDiscriminatorFC.lowerBound(),
75  dDiscriminatorFC.upperBound(),
76  false,
77  true,
78  false,
79  "b",
80  label,
81  mcPlots_,
82  ibook);
83 
84  // conditional discriminator cut for efficiency histos
85 
87  std::make_unique<FlavourHistograms<double>>("effVsDiscrCut" + histoExtension,
88  "Eff. vs Disc. Cut: " + dDiscriminatorFC.baseNameDescription(),
89  dDiscriminatorFC.nBins(),
90  dDiscriminatorFC.lowerBound(),
91  dDiscriminatorFC.upperBound(),
92  false,
93  true,
94  false,
95  "b",
96  label,
97  mcPlots_,
98  ibook);
99  discrCutEfficScan->SetMinimum(1E-4);
100  if (mcPlots_) {
101  if (mcPlots_ > 2) {
102  effVersusDiscr_d = discrCutEfficScan->histo_d();
103  effVersusDiscr_u = discrCutEfficScan->histo_u();
104  effVersusDiscr_s = discrCutEfficScan->histo_s();
105  effVersusDiscr_g = discrCutEfficScan->histo_g();
106  effVersusDiscr_dus = discrCutEfficScan->histo_dus();
107  } else {
108  effVersusDiscr_d = nullptr;
109  effVersusDiscr_u = nullptr;
110  effVersusDiscr_s = nullptr;
111  effVersusDiscr_g = nullptr;
112  effVersusDiscr_dus = nullptr;
113  }
114  effVersusDiscr_c = discrCutEfficScan->histo_c();
115  effVersusDiscr_b = discrCutEfficScan->histo_b();
116  effVersusDiscr_ni = discrCutEfficScan->histo_ni();
117  effVersusDiscr_dusg = discrCutEfficScan->histo_dusg();
118  effVersusDiscr_pu = discrCutEfficScan->histo_pu();
119 
120  if (mcPlots_ > 2) {
121  effVersusDiscr_d->SetXTitle("Discriminant");
122  effVersusDiscr_d->GetXaxis()->SetTitleOffset(0.75);
123  effVersusDiscr_u->SetXTitle("Discriminant");
124  effVersusDiscr_u->GetXaxis()->SetTitleOffset(0.75);
125  effVersusDiscr_s->SetXTitle("Discriminant");
126  effVersusDiscr_s->GetXaxis()->SetTitleOffset(0.75);
127  effVersusDiscr_g->SetXTitle("Discriminant");
128  effVersusDiscr_g->GetXaxis()->SetTitleOffset(0.75);
129  effVersusDiscr_dus->SetXTitle("Discriminant");
130  effVersusDiscr_dus->GetXaxis()->SetTitleOffset(0.75);
131  }
132  effVersusDiscr_c->SetXTitle("Discriminant");
133  effVersusDiscr_c->GetXaxis()->SetTitleOffset(0.75);
134  effVersusDiscr_b->SetXTitle("Discriminant");
135  effVersusDiscr_b->GetXaxis()->SetTitleOffset(0.75);
136  effVersusDiscr_ni->SetXTitle("Discriminant");
137  effVersusDiscr_ni->GetXaxis()->SetTitleOffset(0.75);
138  effVersusDiscr_dusg->SetXTitle("Discriminant");
139  effVersusDiscr_dusg->GetXaxis()->SetTitleOffset(0.75);
140  effVersusDiscr_pu->SetXTitle("Discriminant");
141  effVersusDiscr_pu->GetXaxis()->SetTitleOffset(0.75);
142  } else {
143  effVersusDiscr_d = nullptr;
144  effVersusDiscr_u = nullptr;
145  effVersusDiscr_s = nullptr;
146  effVersusDiscr_c = nullptr;
147  effVersusDiscr_b = nullptr;
148  effVersusDiscr_g = nullptr;
149  effVersusDiscr_ni = nullptr;
150  effVersusDiscr_dus = nullptr;
151  effVersusDiscr_dusg = nullptr;
152  effVersusDiscr_pu = nullptr;
153  }
154 
155  // discr. for computation
156  vector<TH1F*> discrCfHistos = dDiscriminatorFC.getHistoVector();
157 
158  // discr no cut
159  vector<TH1F*> discrNoCutHistos = discrNoCutEffic->getHistoVector();
160 
161  // discr no cut
162  vector<TH1F*> discrCutHistos = discrCutEfficScan->getHistoVector();
163 
164  const int& dimHistos = discrCfHistos.size(); // they all have the same size
165 
166  // DISCR-CUT LOOP:
167  // fill the histos for eff-pur computations by scanning the discriminatorFC histogram
168 
169  // better to loop over bins -> discrCut no longer needed
170  const int& nBins = dDiscriminatorFC.nBins();
171 
172  // loop over flavours
173  for (int iFlav = 0; iFlav < dimHistos; iFlav++) {
174  if (discrCfHistos[iFlav] == nullptr)
175  continue;
176  discrNoCutHistos[iFlav]->SetXTitle("Discriminant");
177  discrNoCutHistos[iFlav]->GetXaxis()->SetTitleOffset(0.75);
178 
179  // In Root histos, bin counting starts at 1 to nBins.
180  // bin 0 is the underflow, and nBins+1 is the overflow.
181  const double& nJetsFlav = discrCfHistos[iFlav]->GetEntries();
182  double sum = discrCfHistos[iFlav]->GetBinContent(nBins + 1); //+1 to get the overflow.
183 
184  for (int iDiscr = nBins; iDiscr > 0; --iDiscr) {
185  // fill all jets into NoCut histo
186  discrNoCutHistos[iFlav]->SetBinContent(iDiscr, nJetsFlav);
187  discrNoCutHistos[iFlav]->SetBinError(iDiscr, sqrt(nJetsFlav));
188  sum += discrCfHistos[iFlav]->GetBinContent(iDiscr);
189  discrCutHistos[iFlav]->SetBinContent(iDiscr, sum);
190  discrCutHistos[iFlav]->SetBinError(iDiscr, sqrt(sum));
191  }
192  }
193 
194  // divide to get efficiency vs. discriminator cut from absolute numbers
195  discrCutEfficScan->divide(*discrNoCutEffic); // does: histos including discriminator cut / flat histo
196  discrCutEfficScan->setEfficiencyFlag();
197 }
198 
200 
203  discrNoCutEffic->epsPlot(name);
204  discrCutEfficScan->epsPlot(name);
205  }
206  plot(name, ".eps");
207 }
208 
210 
212  std::string hX = "";
213  std::string Title = "";
214  if (!doCTagPlots_) {
215  hX = "FlavEffVsBEff";
216  Title = "b";
217  } else {
218  hX = "FlavEffVsCEff";
219  Title = "c";
220  }
221  TCanvas tc((hX + histoExtension).c_str(),
222  ("Flavour misidentification vs. " + Title + "-tagging efficiency " + histoExtension).c_str());
223  plot(&tc);
224  tc.Print((name + hX + histoExtension + ext).c_str());
225 }
226 
227 void EffPurFromHistos::plot(TPad* plotCanvas /* = 0 */) {
228  //fixme:
229  bool btppNI = false;
230  bool btppColour = true;
231 
232  // if ( !btppTitle ) gStyle->SetOptTitle( 0 );
233  setTDRStyle()->cd();
234 
235  if (plotCanvas)
236  plotCanvas->cd();
237 
238  gPad->UseCurrentStyle();
239  gPad->SetFillColor(0);
240  gPad->SetLogy(1);
241  gPad->SetGridx(1);
242  gPad->SetGridy(1);
243 
244  int col_c;
245  int col_g;
246  int col_dus;
247  int col_ni;
248 
249  int mStyle_c;
250  int mStyle_g;
251  int mStyle_dus;
252  int mStyle_ni;
253 
254  // marker size(same for all)
255  float mSize = gPad->GetWh() * gPad->GetHNDC() / 500.; //1.2;
256 
257  if (btppColour) {
258  col_c = 6;
259  col_g = 3; // g in green
260  col_dus = 4; // uds in blue
261  col_ni = 5; // ni in ??
262  mStyle_c = 20;
263  mStyle_g = 20;
264  mStyle_dus = 20;
265  mStyle_ni = 20;
266  } else {
267  col_c = 1;
268  col_g = 1;
269  col_dus = 1;
270  col_ni = 1;
271  mStyle_c = 22;
272  mStyle_g = 29;
273  mStyle_dus = 20;
274  mStyle_ni = 27;
275  }
276 
277  TString Title = "";
278  if (!doCTagPlots_) {
279  Title = "b";
280  } else {
281  Title = "c";
282  }
283 
284  // for the moment: plot c,dus,g
285  if (mcPlots_ > 2) {
286  EffFlavVsXEff_dus->getTH1F()->GetXaxis()->SetTitle(Title + "-jet efficiency");
287  EffFlavVsXEff_dus->getTH1F()->GetYaxis()->SetTitle("non " + Title + "-jet efficiency");
288  EffFlavVsXEff_dus->getTH1F()->GetYaxis()->SetTitleOffset(0.25);
289  EffFlavVsXEff_dus->getTH1F()->SetMaximum(1.1);
290  EffFlavVsXEff_dus->getTH1F()->SetMinimum(1.e-5);
291  EffFlavVsXEff_dus->getTH1F()->SetMarkerColor(col_dus);
292  EffFlavVsXEff_dus->getTH1F()->SetLineColor(col_dus);
293  EffFlavVsXEff_dus->getTH1F()->SetMarkerSize(mSize);
294  EffFlavVsXEff_dus->getTH1F()->SetMarkerStyle(mStyle_dus);
295  EffFlavVsXEff_dus->getTH1F()->SetStats(false);
296  EffFlavVsXEff_dus->getTH1F()->Draw("pe");
297 
298  EffFlavVsXEff_g->getTH1F()->SetMarkerColor(col_g);
299  EffFlavVsXEff_g->getTH1F()->SetLineColor(col_g);
300  EffFlavVsXEff_g->getTH1F()->SetMarkerSize(mSize);
301  EffFlavVsXEff_g->getTH1F()->SetMarkerStyle(mStyle_g);
302  EffFlavVsXEff_g->getTH1F()->SetStats(false);
303  EffFlavVsXEff_g->getTH1F()->Draw("peSame");
304  }
305  EffFlavVsXEff_c->getTH1F()->SetMarkerColor(col_c);
306  EffFlavVsXEff_c->getTH1F()->SetLineColor(col_c);
307  EffFlavVsXEff_c->getTH1F()->SetMarkerSize(mSize);
308  EffFlavVsXEff_c->getTH1F()->SetMarkerStyle(mStyle_c);
309  EffFlavVsXEff_c->getTH1F()->SetStats(false);
310  EffFlavVsXEff_c->getTH1F()->Draw("peSame");
311 
312  if (mcPlots_ > 2) {
313  EffFlavVsXEff_d->getTH1F()->SetMinimum(0.01);
314  EffFlavVsXEff_u->getTH1F()->SetMinimum(0.01);
315  EffFlavVsXEff_s->getTH1F()->SetMinimum(0.01);
316  EffFlavVsXEff_g->getTH1F()->SetMinimum(0.01);
317  EffFlavVsXEff_dus->getTH1F()->SetMinimum(0.01);
318  }
319  EffFlavVsXEff_c->getTH1F()->SetMinimum(0.01);
320  EffFlavVsXEff_b->getTH1F()->SetMinimum(0.01);
321  EffFlavVsXEff_ni->getTH1F()->SetMinimum(0.01);
322  EffFlavVsXEff_dusg->getTH1F()->SetMinimum(0.01);
323  EffFlavVsXEff_pu->getTH1F()->SetMinimum(0.01);
324 
325  // plot separately u,d and s
326  // EffFlavVsXEff_d ->GetXaxis()->SetTitle( Title + "-jet efficiency" );
327  // EffFlavVsXEff_d ->GetYaxis()->SetTitle( "non " + Title + "-jet efficiency" );
328  // EffFlavVsXEff_d ->GetYaxis()->SetTitleOffset( 1.25 );
329  // EffFlavVsXEff_d ->SetMaximum ( 1.1 );
330  // EffFlavVsXEff_d ->SetMinimum ( 1.e-5 );
331  // EffFlavVsXEff_d ->SetMarkerColor( col_dus );
332  // EffFlavVsXEff_d ->SetLineColor ( col_dus );
333  // EffFlavVsXEff_d ->SetMarkerSize ( mSize );
334  // EffFlavVsXEff_d ->SetMarkerStyle( mStyle_dus );
335  // EffFlavVsXEff_d ->SetStats ( false );
336  // EffFlavVsXEff_d ->Draw("pe");
337  //
338  // EffFlavVsXEff_u ->SetMarkerColor( col_g );
339  // EffFlavVsXEff_u ->SetLineColor ( col_g );
340  // EffFlavVsXEff_u ->SetMarkerSize ( mSize );
341  // EffFlavVsXEff_u ->SetMarkerStyle( mStyle_g );
342  // EffFlavVsXEff_u ->SetStats ( false );
343  // EffFlavVsXEff_u ->Draw("peSame");
344  //
345  // EffFlavVsXEff_s ->SetMarkerColor( col_c );
346  // EffFlavVsXEff_s ->SetLineColor ( col_c );
347  // EffFlavVsXEff_s ->SetMarkerSize ( mSize );
348  // EffFlavVsXEff_s ->SetMarkerStyle( mStyle_c );
349  // EffFlavVsXEff_s ->SetStats ( false );
350  // EffFlavVsXEff_s ->Draw("peSame");
351 
352  // only if asked: NI
353  if (btppNI) {
354  EffFlavVsXEff_ni->getTH1F()->SetMarkerColor(col_ni);
355  EffFlavVsXEff_ni->getTH1F()->SetLineColor(col_ni);
356  EffFlavVsXEff_ni->getTH1F()->SetMarkerSize(mSize);
357  EffFlavVsXEff_ni->getTH1F()->SetMarkerStyle(mStyle_ni);
358  EffFlavVsXEff_ni->getTH1F()->SetStats(false);
359  EffFlavVsXEff_ni->getTH1F()->Draw("peSame");
360  }
361 }
362 
364  // number of bins
365 
366  int nBins_d = 0;
367  int nBins_u = 0;
368  int nBins_s = 0;
369  int nBins_g = 0;
370  int nBins_dus = 0;
371  if (mcPlots_ > 2) {
372  nBins_d = effVersusDiscr_d->GetNbinsX();
373  nBins_u = effVersusDiscr_u->GetNbinsX();
374  nBins_s = effVersusDiscr_s->GetNbinsX();
375  nBins_g = effVersusDiscr_g->GetNbinsX();
376  nBins_dus = effVersusDiscr_dus->GetNbinsX();
377  }
378  const int& nBins_c = effVersusDiscr_c->GetNbinsX();
379  const int& nBins_b = effVersusDiscr_b->GetNbinsX();
380  const int& nBins_ni = effVersusDiscr_ni->GetNbinsX();
381  const int& nBins_dusg = effVersusDiscr_dusg->GetNbinsX();
382  const int& nBins_pu = effVersusDiscr_pu->GetNbinsX();
383 
384  const bool& lNBins = ((nBins_d == nBins_u && nBins_d == nBins_s && nBins_d == nBins_c && nBins_d == nBins_b &&
385  nBins_d == nBins_g && nBins_d == nBins_ni && nBins_d == nBins_dus && nBins_d == nBins_dusg) ||
386  (nBins_c == nBins_b && nBins_c == nBins_dusg && nBins_c == nBins_ni && nBins_c == nBins_pu));
387 
388  if (!lNBins) {
389  throw cms::Exception("Configuration") << "Input histograms do not all have the same number of bins!\n";
390  }
391 
392  // start
393  float sBin_d = 0;
394  float sBin_u = 0;
395  float sBin_s = 0;
396  float sBin_g = 0;
397  float sBin_dus = 0;
398  if (mcPlots_ > 2) {
399  sBin_d = effVersusDiscr_d->GetBinCenter(1);
400  sBin_u = effVersusDiscr_u->GetBinCenter(1);
401  sBin_s = effVersusDiscr_s->GetBinCenter(1);
402  sBin_g = effVersusDiscr_g->GetBinCenter(1);
403  sBin_dus = effVersusDiscr_dus->GetBinCenter(1);
404  }
405  const float& sBin_c = effVersusDiscr_c->GetBinCenter(1);
406  const float& sBin_b = effVersusDiscr_b->GetBinCenter(1);
407  const float& sBin_ni = effVersusDiscr_ni->GetBinCenter(1);
408  const float& sBin_dusg = effVersusDiscr_dusg->GetBinCenter(1);
409  const float& sBin_pu = effVersusDiscr_pu->GetBinCenter(1);
410 
411  const bool& lSBin = ((sBin_d == sBin_u && sBin_d == sBin_s && sBin_d == sBin_c && sBin_d == sBin_b &&
412  sBin_d == sBin_g && sBin_d == sBin_ni && sBin_d == sBin_dus && sBin_d == sBin_dusg) ||
413  (sBin_c == sBin_b && sBin_c == sBin_dusg && sBin_c == sBin_ni && sBin_c == sBin_pu));
414 
415  if (!lSBin) {
416  throw cms::Exception("Configuration")
417  << "EffPurFromHistos::check() : Input histograms do not all have the same start bin!\n";
418  }
419 
420  // end
421  float eBin_d = 0;
422  float eBin_u = 0;
423  float eBin_s = 0;
424  float eBin_g = 0;
425  float eBin_dus = 0;
426  if (mcPlots_ > 2) {
427  eBin_d = effVersusDiscr_d->GetBinCenter(nBins_d - 1);
428  eBin_u = effVersusDiscr_u->GetBinCenter(nBins_d - 1);
429  eBin_s = effVersusDiscr_s->GetBinCenter(nBins_d - 1);
430  eBin_g = effVersusDiscr_g->GetBinCenter(nBins_d - 1);
431  eBin_dus = effVersusDiscr_dus->GetBinCenter(nBins_d - 1);
432  }
433  const float& eBin_c = effVersusDiscr_c->GetBinCenter(nBins_d - 1);
434  const float& eBin_b = effVersusDiscr_b->GetBinCenter(nBins_d - 1);
435  const float& eBin_ni = effVersusDiscr_ni->GetBinCenter(nBins_d - 1);
436  const float& eBin_dusg = effVersusDiscr_dusg->GetBinCenter(nBins_d - 1);
437  const float& eBin_pu = effVersusDiscr_pu->GetBinCenter(nBins_d - 1);
438 
439  const bool& lEBin = ((eBin_d == eBin_u && eBin_d == eBin_s && eBin_d == eBin_c && eBin_d == eBin_b &&
440  eBin_d == eBin_g && eBin_d == eBin_ni && eBin_d == eBin_dus && eBin_d == eBin_dusg) ||
441  (eBin_c == eBin_b && eBin_c == eBin_dusg && eBin_c == eBin_ni && eBin_c == eBin_pu));
442 
443  if (!lEBin) {
444  throw cms::Exception("Configuration")
445  << "EffPurFromHistos::check() : Input histograms do not all have the same end bin!\n";
446  }
447 }
448 
450  if (!mcPlots_) {
451  EffFlavVsXEff_d = nullptr;
452  EffFlavVsXEff_u = nullptr;
453  EffFlavVsXEff_s = nullptr;
454  EffFlavVsXEff_c = nullptr;
455  EffFlavVsXEff_b = nullptr;
456  EffFlavVsXEff_g = nullptr;
457  EffFlavVsXEff_ni = nullptr;
458  EffFlavVsXEff_dus = nullptr;
459  EffFlavVsXEff_dusg = nullptr;
460  EffFlavVsXEff_pu = nullptr;
461  return;
462  }
463 
464  // to have shorter names ......
465  const std::string& hE = histoExtension;
466  std::string hX = "";
467  TString Title = "";
468  if (!doCTagPlots_) {
469  hX = "FlavEffVsBEff_";
470  Title = "b";
471  } else {
472  hX = "FlavEffVsCEff_";
473  Title = "c";
474  }
475 
476  // create histograms from base name and extension as given from user
477  // BINNING MUST BE IDENTICAL FOR ALL OF THEM!!
478  HistoProviderDQM prov("Btag", label_, ibook);
479  if (mcPlots_ > 2) {
480  EffFlavVsXEff_d = (prov.book1D(hX + "D" + hE, hX + "D" + hE, nBinOutput, startOutput, endOutput));
482  EffFlavVsXEff_u = (prov.book1D(hX + "U" + hE, hX + "U" + hE, nBinOutput, startOutput, endOutput));
484  EffFlavVsXEff_s = (prov.book1D(hX + "S" + hE, hX + "S" + hE, nBinOutput, startOutput, endOutput));
486  EffFlavVsXEff_g = (prov.book1D(hX + "G" + hE, hX + "G" + hE, nBinOutput, startOutput, endOutput));
488  EffFlavVsXEff_dus = (prov.book1D(hX + "DUS" + hE, hX + "DUS" + hE, nBinOutput, startOutput, endOutput));
490  } else {
491  EffFlavVsXEff_d = nullptr;
492  EffFlavVsXEff_u = nullptr;
493  EffFlavVsXEff_s = nullptr;
494  EffFlavVsXEff_g = nullptr;
495  EffFlavVsXEff_dus = nullptr;
496  }
497  EffFlavVsXEff_c = (prov.book1D(hX + "C" + hE, hX + "C" + hE, nBinOutput, startOutput, endOutput));
499  EffFlavVsXEff_b = (prov.book1D(hX + "B" + hE, hX + "B" + hE, nBinOutput, startOutput, endOutput));
501  EffFlavVsXEff_ni = (prov.book1D(hX + "NI" + hE, hX + "NI" + hE, nBinOutput, startOutput, endOutput));
503  EffFlavVsXEff_dusg = (prov.book1D(hX + "DUSG" + hE, hX + "DUSG" + hE, nBinOutput, startOutput, endOutput));
505  EffFlavVsXEff_pu = (prov.book1D(hX + "PU" + hE, hX + "PU" + hE, nBinOutput, startOutput, endOutput));
507 
508  if (mcPlots_ > 2) {
509  EffFlavVsXEff_d->getTH1F()->SetXTitle(Title + "-jet efficiency");
510  EffFlavVsXEff_d->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
511  EffFlavVsXEff_d->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
512  EffFlavVsXEff_d->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
513  EffFlavVsXEff_u->getTH1F()->SetXTitle(Title + "-jet efficiency");
514  EffFlavVsXEff_u->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
515  EffFlavVsXEff_u->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
516  EffFlavVsXEff_u->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
517  EffFlavVsXEff_s->getTH1F()->SetXTitle(Title + "-jet efficiency");
518  EffFlavVsXEff_s->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
519  EffFlavVsXEff_s->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
520  EffFlavVsXEff_s->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
521  EffFlavVsXEff_g->getTH1F()->SetXTitle(Title + "-jet efficiency");
522  EffFlavVsXEff_g->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
523  EffFlavVsXEff_g->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
524  EffFlavVsXEff_g->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
525  EffFlavVsXEff_dus->getTH1F()->SetXTitle(Title + "-jet efficiency");
526  EffFlavVsXEff_dus->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
527  EffFlavVsXEff_dus->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
528  EffFlavVsXEff_dus->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
529  }
530  EffFlavVsXEff_c->getTH1F()->SetXTitle(Title + "-jet efficiency");
531  EffFlavVsXEff_c->getTH1F()->SetYTitle("c-jet efficiency");
532  EffFlavVsXEff_c->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
533  EffFlavVsXEff_c->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
534  EffFlavVsXEff_b->getTH1F()->SetXTitle(Title + "-jet efficiency");
535  EffFlavVsXEff_b->getTH1F()->SetYTitle("b-jet efficiency");
536  EffFlavVsXEff_b->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
537  EffFlavVsXEff_b->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
538  EffFlavVsXEff_ni->getTH1F()->SetXTitle(Title + "-jet efficiency");
539  EffFlavVsXEff_ni->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
540  EffFlavVsXEff_ni->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
541  EffFlavVsXEff_ni->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
542  EffFlavVsXEff_dusg->getTH1F()->SetXTitle(Title + "-jet efficiency");
543  EffFlavVsXEff_dusg->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
544  EffFlavVsXEff_dusg->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
545  EffFlavVsXEff_dusg->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
546  EffFlavVsXEff_pu->getTH1F()->SetXTitle(Title + "-jet efficiency");
547  EffFlavVsXEff_pu->getTH1F()->SetYTitle("non " + Title + "-jet efficiency");
548  EffFlavVsXEff_pu->getTH1F()->GetXaxis()->SetTitleOffset(0.75);
549  EffFlavVsXEff_pu->getTH1F()->GetYaxis()->SetTitleOffset(0.75);
550 
551  // loop over eff. vs. discriminator cut b-histo and look in which bin the closest entry is;
552  // use fact that eff decreases monotonously
553 
554  // any of the histos to be created can be taken here:
555  MonitorElement* EffFlavVsXEff = EffFlavVsXEff_b;
556 
557  const int& nBinX = EffFlavVsXEff->getTH1F()->GetNbinsX();
558 
559  for (int iBinX = 1; iBinX <= nBinX; iBinX++) { // loop over the bins on the x-axis of the histograms to be filled
560 
561  const float& effXBinWidth = EffFlavVsXEff->getTH1F()->GetBinWidth(iBinX);
562  const float& effXMid = EffFlavVsXEff->getTH1F()->GetBinCenter(iBinX); // middle of b-efficiency bin
563  const float& effXLeft = effXMid - 0.5 * effXBinWidth; // left edge of bin
564  const float& effXRight = effXMid + 0.5 * effXBinWidth; // right edge of bin
565  // find the corresponding bin in the efficiency versus discriminator cut histo: closest one in efficiency
566 
567  int binClosest = -1;
568  if (!doCTagPlots_) {
569  binClosest = findBinClosestYValue(effVersusDiscr_b, effXMid, effXLeft, effXRight);
570  } else {
571  binClosest = findBinClosestYValue(effVersusDiscr_c, effXMid, effXLeft, effXRight);
572  }
573 
574  const bool& binFound = (binClosest > 0);
575  //
576  if (binFound) {
577  // fill the histos
578  if (mcPlots_ > 2) {
579  EffFlavVsXEff_d->Fill(effXMid, effVersusDiscr_d->GetBinContent(binClosest));
580  EffFlavVsXEff_u->Fill(effXMid, effVersusDiscr_u->GetBinContent(binClosest));
581  EffFlavVsXEff_s->Fill(effXMid, effVersusDiscr_s->GetBinContent(binClosest));
582  EffFlavVsXEff_g->Fill(effXMid, effVersusDiscr_g->GetBinContent(binClosest));
583  EffFlavVsXEff_dus->Fill(effXMid, effVersusDiscr_dus->GetBinContent(binClosest));
584  }
585  EffFlavVsXEff_c->Fill(effXMid, effVersusDiscr_c->GetBinContent(binClosest));
586  EffFlavVsXEff_b->Fill(effXMid, effVersusDiscr_b->GetBinContent(binClosest));
587  EffFlavVsXEff_ni->Fill(effXMid, effVersusDiscr_ni->GetBinContent(binClosest));
588  EffFlavVsXEff_dusg->Fill(effXMid, effVersusDiscr_dusg->GetBinContent(binClosest));
589  EffFlavVsXEff_pu->Fill(effXMid, effVersusDiscr_pu->GetBinContent(binClosest));
590 
591  if (mcPlots_ > 2) {
592  EffFlavVsXEff_d->getTH1F()->SetBinError(iBinX, effVersusDiscr_d->GetBinError(binClosest));
593  EffFlavVsXEff_u->getTH1F()->SetBinError(iBinX, effVersusDiscr_u->GetBinError(binClosest));
594  EffFlavVsXEff_s->getTH1F()->SetBinError(iBinX, effVersusDiscr_s->GetBinError(binClosest));
595  EffFlavVsXEff_g->getTH1F()->SetBinError(iBinX, effVersusDiscr_g->GetBinError(binClosest));
596  EffFlavVsXEff_dus->getTH1F()->SetBinError(iBinX, effVersusDiscr_dus->GetBinError(binClosest));
597  }
598  EffFlavVsXEff_c->getTH1F()->SetBinError(iBinX, effVersusDiscr_c->GetBinError(binClosest));
599  EffFlavVsXEff_b->getTH1F()->SetBinError(iBinX, effVersusDiscr_b->GetBinError(binClosest));
600  EffFlavVsXEff_ni->getTH1F()->SetBinError(iBinX, effVersusDiscr_ni->GetBinError(binClosest));
601  EffFlavVsXEff_dusg->getTH1F()->SetBinError(iBinX, effVersusDiscr_dusg->GetBinError(binClosest));
602  EffFlavVsXEff_pu->getTH1F()->SetBinError(iBinX, effVersusDiscr_pu->GetBinError(binClosest));
603  }
604  }
605 }
606 
607 #include <memory>
608 
609 #include <typeinfo>
std::unique_ptr< FlavourHistograms< double > > discrNoCutEffic
void epsPlot(const std::string &name)
void plot(TPad *theCanvas=nullptr)
MonitorElement * EffFlavVsXEff_s
void compute(DQMStore::IBooker &ibook)
std::vector< TH1F * > getHistoVector() const
std::string label_
MonitorElement * EffFlavVsXEff_u
MonitorElement * EffFlavVsXEff_g
int findBinClosestYValue(const TH1F *, const float &yVal, const float &yLow, const float &yHigh)
Definition: Tools.cc:225
double upperBound() const
MonitorElement * EffFlavVsXEff_d
MonitorElement * EffFlavVsXEff_ni
MonitorElement * EffFlavVsXEff_c
std::unique_ptr< FlavourHistograms< double > > discrCutEfficScan
double lowerBound() const
void Fill(long long x)
char const * label
MonitorElement * EffFlavVsXEff_pu
std::string baseNameTitle() const
T sqrt(T t)
Definition: SSEVec.h:19
def setTDRStyle()
Definition: plotscripts.py:89
Definition: Tools.h:22
std::string histoExtension
virtual TH1F * getTH1F() const
unsigned int mcPlots_
MonitorElement * EffFlavVsXEff_dusg
virtual MonitorElement * book1D(const std::string &name, const std::string &title, const int &nchX, const double &lowX, const double &highX)
EffPurFromHistos(const std::string &ext, TH1F *h_d, TH1F *h_u, TH1F *h_s, TH1F *h_c, TH1F *h_b, TH1F *h_g, TH1F *h_ni, TH1F *h_dus, TH1F *h_dusg, TH1F *h_pu, const std::string &label, unsigned int mc, int nBin=100, double startO=0.005, double endO=1.005)
std::string baseNameDescription() const
MonitorElement * EffFlavVsXEff_dus
Definition: memstream.h:15
void psPlot(const std::string &name)
MonitorElement * EffFlavVsXEff_b