6 <input>CPVToolsOutput.root</input>
7 <output>test6_CPVFlavorTaggerEfficiency.root</output>
8 <contact>Fernando Abudinen; abudinen@mpp.mpg.de</contact>
9 <description>This file calculates the effective efficiency of the category based flavor tagger considering the two
10 standard combiners and the individual categories. Validation plots are also pruduced. </description>
15 from basf2
import B2INFO, B2FATAL
16 import flavorTagger
as ft
18 from ROOT
import Belle2
19 from array
import array
21 ROOT.gROOT.SetBatch(
True)
23 workingFiles = [
"../CPVToolsOutput.root"]
24 treeName = str(
"B0tree")
27 workingDirectory =
'.'
35 r_subsample = array(
'd', [
44 r_size = len(r_subsample)
55 'IntermediateElectron',
59 'IntermediateKinLepton',
73 """Context handler class to quiet errors in a 'with' statement"""
76 """Class constructor"""
81 """Enter the context"""
84 ROOT.gErrorIgnoreLevel = self.
level
87 """Exit the context"""
88 ROOT.gErrorIgnoreLevel = self.
oldlevel
91 tree = ROOT.TChain(treeName)
93 mcstatus = array(
'd', [-511.5, 0.0, 511.5])
94 ROOT.TH1.SetDefaultSumw2()
96 for iFile
in workingFiles:
101 for branch
in tree.GetListOfBranches():
102 totalBranches.append(branch.GetName())
104 if 'FBDT_qrCombined' in totalBranches:
105 methods.append(
"FBDT")
107 if 'FANN_qrCombined' in totalBranches:
108 methods.append(
"FANN")
111 for cat
in categories:
112 catBranch =
'qp' + cat
113 if catBranch
in totalBranches:
114 usedCategories.append(cat)
116 if len(usedCategories) > 1:
117 ft.WhichCategories(usedCategories)
119 categoriesNtupleList = str()
120 for (particleList, category, combinerVariable)
in ft.eventLevelParticleLists:
121 categoriesNtupleList = categoriesNtupleList +
"Eff_%s:" % category
125 outputFile = ROOT.TFile(
"test6_CPVFlavorTaggerEfficiency.root",
"RECREATE")
128 outputNtuple = ROOT.TNtuple(
130 "Effective efficiencies of the flavor tagger combiners as well as of the individual tagging categories.",
131 "Eff_FBDT:DeltaEff_FBDT:Eff_FANN:DeltaEff_FANN:" + categoriesNtupleList)
133 outputNtuple.SetAlias(
'Description',
"These are the effective efficiencies of the flavor tagger combiners as well as of " +
134 "the individual tagging efficiencies.")
135 outputNtuple.SetAlias(
137 "These values should not change drastically. Since the nightly reconstruction validation runs" +
138 "on the same input file (which changes only from release to release), the values between builds should be the same.")
139 outputNtuple.SetAlias(
'Contact',
"abudinen@mpp.mpg.de")
141 efficienciesForNtuple = []
145 for method
in methods:
147 histo_avr_r = ROOT.TH1F(
'Average_r',
'Average r in each of 6 bins (B0 and B0bar)', 6,
149 histo_avr_rB0 = ROOT.TH1F(
'Average_rB0',
'Average r in each of 6 bins (B0)', 6,
151 histo_avr_rB0bar = ROOT.TH1F(
'Average_rB0bar',
'Average r in each of 6 bins (B0bar)', 6,
154 histo_entries_per_bin = ROOT.TH1F(
156 'Events binned in r_subsample according to their r-value for B0 and B0bar prob',
159 histo_entries_per_binB0 = ROOT.TH1F(
'entries_per_binB0',
'Events binned in r_subsample according '
160 'to their r-value for B0 prob', 6, r_subsample)
161 histo_entries_per_binB0bar = ROOT.TH1F(
'entries_per_binB0bar',
162 'Events binned in r_subsample according to their r-value '
163 'for B0bar prob', 6, r_subsample)
165 histo_Cnet_output_B0 = ROOT.TH1F(
'Comb_Net_Output_B0',
'Combiner network output [not equal to r] '
166 'for true B0 (binning 100)', 100, 0.0, 1.0)
168 histo_Cnet_output_B0bar = ROOT.TH1F(
'Comb_Net_Output_B0bar',
'Combiner network output [not equal to r] '
169 'for true B0bar (binning 100)', 100, 0.0, 1.0)
171 histo_belleplotB0 = ROOT.TH1F(
'qr_' + method +
'_B0',
172 'BellePlot for true B0 (binning 50)', 50,
175 histo_belleplotB0bar = ROOT.TH1F(
'qr_' + method +
'_B0Bar',
176 'BellePlot for true B0Bar (binning 50)',
180 histo_belleplotBoth = ROOT.TH1F(
'qr_' + method +
'_B0Both',
181 'qr-tagger output (binning 50)',
186 histo_calib_B0 = ROOT.TH1F(
'Calibration_' + method +
'_B0',
'CalibrationPlot for true B0', 100, -1.0, 1.0)
188 histo_calib_B0bar = ROOT.TH1F(
'Calibration_' + method +
'_B0Bar',
189 'CalibrationPlot for true B0Bar', 100, -1.0,
192 hallo12 = ROOT.TH1F(
'BellePlot_NoCut',
'BellePlot_NoCut (binning 100)',
196 diag = ROOT.TF1(
'diag',
'pol1', -1, 1)
200 histo_m0 = ROOT.TH1F(
'BellePlot_B0_m0',
201 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
202 histo_m1 = ROOT.TH1F(
'BellePlot_B0_m1',
203 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
204 histo_m2 = ROOT.TH1F(
'BellePlot_B0_m2',
205 'BellePlot_m for true B0Bar (binning 50)', 50, -1.0,
210 tree.Draw(method +
'_qrCombined>>qr_' + method +
'_B0',
'qrMC == 1')
211 tree.Draw(method +
'_qrCombined>>qr_' + method +
'_B0Bar',
'qrMC == -1')
212 tree.Draw(method +
'_qrCombined>>BellePlot_NoCut',
'abs(qrMC) == 1')
213 tree.Draw(method +
'_qrCombined>>qr_' + method +
'_B0Both',
'abs(qrMC) == 1')
215 tree.Draw(method +
'_qrCombined>>Calibration_' + method +
'_B0',
'qrMC == 1')
216 tree.Draw(method +
'_qrCombined>>Calibration_' + method +
'_B0Bar',
'qrMC == -1')
219 tree.Draw(method +
'_qrCombined>>BellePlot_B0_m0',
220 'qrMC == 1 && ' + method +
'_qrCombined>0')
221 tree.Draw(method +
'_qrCombined>>BellePlot_B0_m1',
222 'qrMC == 1 && ' + method +
'_qrCombined<0')
223 tree.Draw(method +
'_qrCombined>>BellePlot_B0_m2',
224 'qrMC == -1 && ' + method +
'_qrCombined>0 ')
229 tree.Project(
'Average_r',
'abs(' + method +
'_qrCombined)',
230 'abs(' + method +
'_qrCombined)')
231 tree.Project(
'Average_rB0',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==1)')
232 tree.Project(
'Average_rB0bar',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==-1)')
235 tree.Project(
'entries_per_bin',
'abs(' + method +
'_qrCombined)',
'abs(qrMC) == 1')
236 tree.Project(
'entries_per_binB0',
'abs(' + method +
'_qrCombined)',
'qrMC == 1')
237 tree.Project(
'entries_per_binB0bar',
'abs(' + method +
'_qrCombined)',
'qrMC == -1')
240 histo_avr_r.Divide(histo_entries_per_bin)
241 histo_avr_rB0.Divide(histo_entries_per_binB0)
242 histo_avr_rB0bar.Divide(histo_entries_per_binB0bar)
246 histo_calib_B0.Divide(hallo12)
247 histo_calib_B0bar.Divide(hallo12)
251 print(
'****************** CALIBRATION CHECK FOR COMBINER USING ' + method +
' ***************************************')
253 print(
'Fit ploynomial of first order to the calibration plot. Expected value ~0.5')
255 histo_calib_B0.Fit(diag,
'TEST')
257 print(
'****************** MEASURED EFFECTIVE EFFICIENCY FOR COMBINER USING ' + method +
' ***************************')
260 total_entries = histo_entries_per_bin.GetEntries()
261 total_entries_B0 = histo_entries_per_binB0.GetEntries()
262 total_entries_B0bar = histo_entries_per_binB0bar.GetEntries()
265 event_fractionB0 = array(
'f', [0] * r_size)
266 event_fractionB0bar = array(
'f', [0] * r_size)
267 event_fractionTotal = array(
'f', [0] * r_size)
268 event_fractionDiff = array(
'f', [0] * r_size)
269 rvalueB0 = array(
'f', [0] * r_size)
270 rvalueB0bar = array(
'f', [0] * r_size)
271 rvalueB0Average = array(
'f', [0] * r_size)
272 wvalue = array(
'f', [0] * r_size)
273 wvalueB0 = array(
'f', [0] * r_size)
274 wvalueB0bar = array(
'f', [0] * r_size)
275 wvalueDiff = array(
'f', [0] * r_size)
276 entries = array(
'f', [0] * r_size)
277 entriesB0 = array(
'f', [0] * r_size)
278 entriesB0bar = array(
'f', [0] * r_size)
279 iEffEfficiency = array(
'f', [0] * r_size)
280 iDeltaEffEfficiency = array(
'f', [0] * r_size)
283 for i
in range(1, r_size):
285 rvalueB0[i] = histo_avr_rB0.GetBinContent(i)
286 rvalueB0bar[i] = histo_avr_rB0bar.GetBinContent(i)
287 rvalueB0Average[i] = (rvalueB0[i] + rvalueB0bar[i]) / 2
289 wvalue[i] = (1 - rvalueB0Average[i]) / 2
290 wvalueB0[i] = (1 - rvalueB0[i]) / 2
291 wvalueB0bar[i] = (1 - rvalueB0bar[i]) / 2
292 wvalueDiff[i] = wvalueB0[i] - wvalueB0bar[i]
293 entries[i] = histo_entries_per_bin.GetBinContent(i)
294 entriesB0[i] = histo_entries_per_binB0.GetBinContent(i)
295 entriesB0bar[i] = histo_entries_per_binB0bar.GetBinContent(i)
297 event_fractionTotal[i] = (entriesB0[i] + entriesB0bar[i]) / total_entries
298 event_fractionDiff[i] = (entriesB0[i] - entriesB0bar[i]) / total_entries
299 event_fractionB0[i] = entriesB0[i] / total_entries_B0
300 event_fractionB0bar[i] = entriesB0bar[i] / total_entries_B0bar
301 iEffEfficiency[i] = (event_fractionB0[i] * rvalueB0[i] * rvalueB0[i] +
302 event_fractionB0bar[i] * rvalueB0bar[i] * rvalueB0bar[i]) / 2
303 iDeltaEffEfficiency[i] = event_fractionB0[i] * rvalueB0[i] * \
304 rvalueB0[i] - event_fractionB0bar[i] * rvalueB0bar[i] * rvalueB0bar[i]
306 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] * rvalueB0[i]
307 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] * rvalueB0bar[i]
309 average_eff = (tot_eff_effB0 + tot_eff_effB0bar) / 2
310 diff_eff = tot_eff_effB0 - tot_eff_effB0bar
311 print(
'* ------------------------------------------------------------------------------------------------ *')
313 print(
'* __________________________________________________________________________________________ *')
315 print(
'* | TOTAL NUMBER OF TAGGED EVENTS = ' +
316 '{:<24}'.format(
"%.0f" % total_entries) +
'{:>36}'.format(
'| *'))
318 print(
'* | TOTAL AVERAGE EFFECTIVE EFFICIENCY (q=+-1)= ' +
'{:.2f}'.format(average_eff * 100) +
321 print(
'* | B0-TAGGER TOTAL EFFECTIVE EFFICIENCIES: ' +
322 '{:.2f}'.format(tot_eff_effB0 * 100) +
' % (q=+1) ' +
323 '{:.2f}'.format(tot_eff_effB0bar * 100) +
' % (q=-1) EffDiff=' +
324 '{:^5.2f}'.format(diff_eff * 100) +
' % | *')
326 print(
'* | FLAVOR PERCENTAGE (MC): ' +
327 '{:.2f}'.format(total_entries_B0 / total_entries * 100) +
' % (q=+1) ' +
328 '{:.2f}'.format(total_entries_B0bar / total_entries * 100) +
' % (q=-1) Diff=' +
329 '{:^5.2f}'.format((total_entries_B0 - total_entries_B0bar) / total_entries * 100) +
' % | *')
330 print(
'* |__________________________________________________________________________________________| *')
332 print(
'****************************************************************************************************')
335 efficienciesForNtuple.append(float(average_eff * 100))
336 efficienciesForNtuple.append(float(diff_eff * 100))
338 maxB0 = histo_belleplotB0.GetBinContent(histo_belleplotB0.GetMaximumBin())
339 maxB0bar = histo_belleplotB0bar.GetBinContent(histo_belleplotB0bar.GetMaximumBin())
340 maxB0Both = histo_belleplotBoth.GetBinContent(histo_belleplotBoth.GetMaximumBin())
342 Ymax = max(maxB0, maxB0bar, maxB0Both)
343 Ymax = Ymax + Ymax / 12
345 if YmaxForQrPlot < Ymax:
349 ROOT.gStyle.SetOptStat(0)
350 with Quiet(ROOT.kError):
351 Canvas1 = ROOT.TCanvas(
'Bla',
'Final Output', 1200, 800)
353 Canvas1.SetLeftMargin(0.13)
354 Canvas1.SetRightMargin(0.04)
355 Canvas1.SetTopMargin(0.03)
356 Canvas1.SetBottomMargin(0.14)
357 histo_belleplotB0.SetFillColorAlpha(ROOT.kBlue, 0.2)
358 histo_belleplotB0.SetFillStyle(1001)
359 histo_belleplotB0.GetXaxis().SetLabelSize(0.04)
360 histo_belleplotB0.GetYaxis().SetLabelSize(0.04)
361 histo_belleplotB0.GetYaxis().SetTitleOffset(0.9)
362 histo_belleplotB0.GetXaxis().SetTitleSize(0.06)
363 histo_belleplotB0.GetYaxis().SetTitleSize(0.06)
364 histo_belleplotB0.GetYaxis().SetLimits(0, YmaxForQrPlot)
365 histo_belleplotB0.SetLineColor(ROOT.kBlue)
366 histo_belleplotB0bar.SetFillColorAlpha(ROOT.kRed, 1.0)
367 histo_belleplotB0bar.SetFillStyle(3005)
368 histo_belleplotB0bar.SetLineColor(ROOT.kRed)
371 histo_belleplotB0.SetTitle(
'; #it{qr}_{' + method +
'} ; Events (Total = ' +
'{:<1}'.format(
"%.0f" % total_entries) +
')'
373 histo_belleplotB0.SetMinimum(0)
374 histo_belleplotB0.SetMaximum(YmaxForQrPlot)
375 histo_belleplotB0.Draw(
'hist')
376 histo_belleplotB0bar.Draw(
'hist same')
378 leg = ROOT.TLegend(0.2, 0.7, 0.9, 0.95)
382 ' #varepsilon_{eff}(B^{0}) = ' +
386 '% #frac{n_{B^{0}}}{n} = ' +
393 histo_belleplotB0bar,
394 'true #bar{B}^{0} ' +
395 ' #varepsilon_{eff}(#bar{B}^{0}) = ' +
399 '% #frac{n_{#bar{B}^{0}}}{n} = ' +
401 total_entries_B0bar /
405 leg.AddEntry(
"",
"Avrg. #bf{ #varepsilon_{eff} = " +
'{:.2f}'.format(average_eff * 100) +
406 '%} #Delta#varepsilon_{eff} = ' +
'{:^5.2f}'.format(diff_eff * 100) +
'%')
407 leg.SetTextSize(0.045)
412 with Quiet(ROOT.kError):
413 Canvas1.SaveAs(workingDirectory +
'/' +
'test6_CPVFTqr' + method +
'_both.pdf')
416 histo_belleplotBoth.GetXaxis().SetLabelSize(0.04)
417 histo_belleplotBoth.GetYaxis().SetLabelSize(0.04)
418 histo_belleplotBoth.GetYaxis().SetTitleOffset(0.7)
419 histo_belleplotBoth.GetXaxis().SetTitleOffset(0.7)
420 histo_belleplotBoth.GetXaxis().SetTitleSize(0.06)
421 histo_belleplotBoth.GetYaxis().SetTitleSize(0.06)
423 histo_belleplotBoth.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
424 histo_belleplotBoth.GetListOfFunctions().Add(ROOT.TNamed(
'Description',
'Output of the flavor tagger combiner ' + method))
425 histo_belleplotBoth.GetListOfFunctions().Add(
428 'Shape should not change drastically. E.g. Warning if the peak at 0 increases or if the peaks at +-1 decrease.'))
429 histo_belleplotBoth.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'abudinen@mpp.mpg.de'))
431 histo_belleplotBoth.SetTitle(
432 'Flavor tagger output for combiner ' +
436 '} ; Events (Total = ' +
441 histo_belleplotBoth.SetMinimum(0)
442 histo_belleplotBoth.SetMaximum(YmaxForQrPlot)
443 histo_belleplotBoth.SetStats(
False)
444 histo_belleplotBoth.Write()
447 histo_belleplotB0.GetYaxis().SetTitleOffset(0.7)
448 histo_belleplotB0.GetXaxis().SetTitleOffset(0.7)
449 histo_belleplotB0.SetLineColor(ROOT.kBlue + 2)
450 histo_belleplotB0.SetTitle(
451 'Flavor tagger output for combiner ' +
453 ' for true B^{0}s; #it{qr}_{' +
455 '} ; Events (Total = ' +
458 histo_belleplotB0.GetEntries()) +
460 histo_belleplotB0.SetStats(
False)
462 histo_belleplotB0.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
463 histo_belleplotB0.GetListOfFunctions().Add(
464 ROOT.TNamed(
'Description',
'Output of the flavor tagger combiner ' + method +
' for true B0s'))
465 histo_belleplotB0.GetListOfFunctions().Add(
468 'Shape should not change drastically. E.g. Warning if the peak at 0 increases or if the peak at +1 decreases.'))
469 histo_belleplotB0.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'abudinen@mpp.mpg.de'))
470 histo_belleplotB0.Write()
473 histo_belleplotB0bar.GetXaxis().SetLabelSize(0.04)
474 histo_belleplotB0bar.GetYaxis().SetLabelSize(0.04)
475 histo_belleplotB0bar.GetYaxis().SetTitleOffset(0.7)
476 histo_belleplotB0bar.GetXaxis().SetTitleOffset(0.7)
477 histo_belleplotB0bar.GetXaxis().SetTitleSize(0.06)
478 histo_belleplotB0bar.GetYaxis().SetTitleSize(0.06)
479 histo_belleplotB0bar.SetLineColor(ROOT.kBlue + 2)
480 histo_belleplotB0bar.SetTitle(
481 'Flavor tagger output for combiner ' +
483 ' for true #bar{B}^{0}s; #it{qr}_{' +
485 '} ; Events (Total = ' +
488 histo_belleplotB0bar.GetEntries()) +
490 histo_belleplotB0bar.SetMinimum(0)
491 histo_belleplotB0bar.SetMaximum(YmaxForQrPlot)
492 histo_belleplotB0bar.SetStats(
False)
494 histo_belleplotB0bar.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
495 histo_belleplotB0bar.GetListOfFunctions().Add(
498 'Output of the flavor tagger combiner ' +
501 histo_belleplotB0bar.GetListOfFunctions().Add(ROOT.TNamed(
502 'Check',
'Shape should not change drastically. E.g. Warning if the peak at 0 increases or if the peak at -1 decreases.'))
503 histo_belleplotB0bar.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'abudinen@mpp.mpg.de'))
504 histo_belleplotB0bar.Write()
509 with Quiet(ROOT.kError):
510 Canvas2 = ROOT.TCanvas(
'Bla2',
'Calibration plot for true B0', 1200, 800)
512 Canvas2.SetLeftMargin(0.13)
513 Canvas2.SetRightMargin(0.04)
514 Canvas2.SetTopMargin(0.03)
515 Canvas2.SetBottomMargin(0.14)
516 histo_calib_B0.GetXaxis().SetLabelSize(0.04)
517 histo_calib_B0.GetYaxis().SetLabelSize(0.04)
518 histo_calib_B0.GetYaxis().SetTitleOffset(0.9)
519 histo_calib_B0.GetXaxis().SetTitleSize(0.06)
520 histo_calib_B0.GetYaxis().SetTitleSize(0.06)
521 histo_calib_B0.SetFillColorAlpha(ROOT.kBlue, 0.2)
522 histo_calib_B0.SetFillStyle(1001)
523 histo_calib_B0.GetYaxis().SetTitleOffset(0.9)
524 histo_calib_B0.SetLineColor(ROOT.kBlue)
526 histo_calib_B0.SetTitle(
'; #it{qr}_{' + method +
'} ; Calibration '
528 histo_calib_B0.Draw(
'hist')
531 leg2 = ROOT.TLegend(0.2, 0.75, 0.63, 0.93)
532 leg2.SetHeader(
" y = #it{m}#it{x} + #it{c}",
"")
533 leg2.GetListOfPrimitives().First().SetTextAlign(22)
538 diag.GetParameter(
"p1")) +
541 diag.GetParameter(
"p0")))
542 leg2.SetTextSize(0.05)
546 with Quiet(ROOT.kError):
547 Canvas2.SaveAs(workingDirectory +
'/' +
'test6_CPVFTCalibration_' + method +
'_B0.pdf')
551 histo_calib_B0.GetYaxis().SetTitleOffset(0.7)
552 histo_calib_B0.GetXaxis().SetTitleOffset(0.7)
553 histo_calib_B0.SetLineColor(ROOT.kBlue + 2)
554 histo_calib_B0.SetTitle(
'Calibration plot for the flavor tagger combiner ' +
555 method +
' ; #it{qr}_{' + method +
'} ; Calibration')
556 histo_calib_B0.SetMinimum(-0.2)
557 histo_calib_B0.SetMaximum(+1.2)
558 histo_calib_B0.SetStats(
False)
560 histo_calib_B0.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
561 histo_calib_B0.GetListOfFunctions().Add(
564 'Calibration plot for the flavor tagger combiner ' +
567 histo_calib_B0.GetListOfFunctions().Add(
568 ROOT.TNamed(
'Check',
'Shape should not change drastically. E.g. warning if the shape stops beeing linear.'))
569 histo_calib_B0.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'abudinen@mpp.mpg.de'))
570 histo_calib_B0.Write()
572 histo_belleplotBoth.Delete()
574 histo_avr_rB0.Delete()
575 histo_avr_rB0bar.Delete()
576 histo_entries_per_bin.Delete()
577 histo_entries_per_binB0.Delete()
578 histo_entries_per_binB0bar.Delete()
579 histo_Cnet_output_B0.Delete()
580 histo_Cnet_output_B0bar.Delete()
581 histo_belleplotB0.Delete()
582 histo_belleplotB0bar.Delete()
583 histo_calib_B0.Delete()
584 histo_calib_B0bar.Delete()
597 print(
'************************* MEASURED EFFECTIVE EFFICIENCY FOR INDIVIDUAL CATEGORIES *********************************')
602 for (particleList, category, combinerVariable)
in ft.eventLevelParticleLists:
604 hist_signal = ROOT.TH1F(
'Signal_' + category,
'Input Signal (B0)' +
605 category +
' (binning 50)', 50, -1.0, 1.0)
607 hist_background = ROOT.TH1F(
'Background_' + category,
'Input Background (B0bar)' +
608 category +
' (binning 50)', 50, -1.0, 1.0)
609 hist_both = ROOT.TH1F(
'qp_' + category,
'Input Background (B0bar)' +
610 category +
' (binning 50)', 100, -1, 1)
614 hist_probB0 = ROOT.TH1F(
'ProbabilityB0_' + category,
615 'Transformed to probability (B0) (' + category +
')',
617 hist_probB0bar = ROOT.TH1F(
'ProbabilityB0bar_' + category,
618 'Transformed to probability (B0bar) (' + category +
')',
621 hist_qpB0 = ROOT.TH1F(
'QRB0_' + category,
'Transformed to qp (B0)(' +
622 category +
')', 50, -1.0, 1.0)
623 hist_qpB0bar = ROOT.TH1F(
'QRB0bar_' + category,
'Transformed to qp (B0bar) (' +
624 category +
')', 50, -1.0, 1.0)
627 hist_absqpB0 = ROOT.TH1F(
'AbsQRB0_' + category,
'Abs(qp)(B0) (' + category +
')', 6, r_subsample)
628 hist_absqpB0bar = ROOT.TH1F(
'AbsQRB0bar_' + category,
'Abs(qp) (B0bar) (' + category +
')', 6, r_subsample)
631 hist_aver_rB0 = ROOT.TH1F(
'AverageRB0_' + category,
'A good one (B0)' +
632 category, 6, r_subsample)
633 hist_aver_rB0bar = ROOT.TH1F(
'AverageRB0bar_' + category,
'A good one (B0bar)' +
634 category, 6, r_subsample)
637 hist_all = ROOT.TH1F(
'All_' + category,
'Input Signal (B0) and Background (B0Bar)' +
638 category +
' (binning 50)', 50, 0.0, 1.0)
639 tree.Draw(
'qp' + category +
'>>All_' + category,
'qrMC!=0')
640 hist_calib_B0 = ROOT.TH1F(
'Calib_B0_' + category,
'Calibration Plot for true B0' +
641 category +
' (binning 50)', 50, 0.0, 1.0)
642 tree.Draw(
'qp' + category +
'>>Calib_B0_' + category,
'qrMC == 1.0')
643 hist_calib_B0.Divide(hist_all)
646 tree.Draw(
'qp' + category +
'>>Signal_' + category,
'qrMC == 1.0')
648 tree.Draw(
'qp' + category +
'>>Background_' + category,
'qrMC == -1.0'
651 tree.Draw(
'qp' + category +
'>>qp_' + category,
'abs(qrMC) == 1.0'
657 purityB0 = array(
'd', [0] * 51)
658 dilutionB02 = array(
'd', [0] * 51)
659 purityB0bar = array(
'd', [0] * 51)
660 dilutionB0bar2 = array(
'd', [0] * 51)
661 signal = array(
'd', [0] * 51)
662 back = array(
'd', [0] * 51)
663 weight = array(
'd', [0] * 51)
665 for i
in range(1, 51):
667 signal[i] = hist_signal.GetBinContent(i)
668 back[i] = hist_background.GetBinContent(i)
670 weight[i] = signal[i] + back[i]
673 if signal[i] + back[i] == 0:
677 dilutionB0bar2[i] = 0
679 purityB0[i] = signal[i] / (signal[i] + back[i])
680 dilutionB02[i] = -1 + 2 * signal[i] / (signal[i] + back[i])
682 purityB0bar[i] = back[i] / (signal[i] + back[i])
683 dilutionB0bar2[i] = -1 + 2 * back[i] / (signal[i] + back[i])
686 hist_probB0.Fill(purityB0[i], signal[i])
687 hist_probB0bar.Fill(purityB0bar[i], back[i])
690 hist_qpB0.Fill(dilutionB02[i], signal[i])
691 hist_qpB0bar.Fill(dilutionB0bar2[i], back[i])
694 hist_absqpB0.Fill(abs(dilutionB02[i]), signal[i])
695 hist_absqpB0bar.Fill(abs(dilutionB0bar2[i]), back[i])
697 hist_aver_rB0.Fill(abs(dilutionB02[i]), abs(dilutionB02[i]) * signal[i])
698 hist_aver_rB0bar.Fill(abs(dilutionB0bar2[i]), abs(dilutionB0bar2[i]) * back[i])
701 hist_aver_rB0.Divide(hist_absqpB0)
702 hist_aver_rB0bar.Divide(hist_absqpB0bar)
708 for i
in range(1, r_size):
709 tot_entriesB0 = tot_entriesB0 + hist_absqpB0.GetBinContent(i)
710 tot_entriesB0bar = tot_entriesB0bar + hist_absqpB0bar.GetBinContent(i)
714 event_fractionB0 = array(
'f', [0] * r_size)
715 event_fractionB0bar = array(
'f', [0] * r_size)
716 rvalueB0 = array(
'f', [0] * r_size)
717 rvalueB0bar = array(
'f', [0] * r_size)
719 entriesB0 = array(
'f', [0] * r_size)
720 entriesB0bar = array(
'f', [0] * r_size)
722 for i
in range(1, r_size):
723 rvalueB0[i] = hist_aver_rB0.GetBinContent(i)
724 rvalueB0bar[i] = hist_aver_rB0bar.GetBinContent(i)
726 entriesB0[i] = hist_absqpB0.GetBinContent(i)
727 entriesB0bar[i] = hist_absqpB0bar.GetBinContent(i)
728 event_fractionB0[i] = entriesB0[i] / tot_entriesB0
729 event_fractionB0bar[i] = entriesB0bar[i] / tot_entriesB0bar
733 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] \
735 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] \
737 effDiff = tot_eff_effB0 - tot_eff_effB0bar
738 effAverage = (tot_eff_effB0 + tot_eff_effB0bar) / 2
741 '{:<25}'.format(
"* " +
754 '{: 8.2f}'.format(effAverage * 100) +
' %' +
756 '{: 8.2f}'.format(effDiff * 100) +
' % *')
760 efficienciesForNtuple.append(float(effAverage * 100))
762 maxSignal = hist_signal.GetBinContent(hist_signal.GetMaximumBin())
763 maxBackground = hist_background.GetBinContent(hist_background.GetMaximumBin())
765 Ymax = max(maxSignal, maxBackground)
766 Ymax = Ymax + Ymax / 12
768 ROOT.gStyle.SetOptStat(0)
769 with Quiet(ROOT.kError):
770 Canvas = ROOT.TCanvas(
'Bla',
'TITEL BLA', 1200, 800)
773 Canvas.SetLeftMargin(0.13)
774 Canvas.SetRightMargin(0.04)
775 Canvas.SetTopMargin(0.03)
776 Canvas.SetBottomMargin(0.14)
777 hist_signal.SetFillColorAlpha(ROOT.kBlue, 0.2)
778 hist_signal.SetFillStyle(1001)
779 hist_signal.SetTitleSize(0.1)
780 hist_signal.GetXaxis().SetLabelSize(0.04)
781 hist_signal.GetYaxis().SetLabelSize(0.04)
782 hist_signal.GetXaxis().SetTitleSize(0.06)
783 hist_signal.GetYaxis().SetTitleSize(0.06)
784 hist_signal.GetXaxis().SetLabelSize(0.04)
785 hist_signal.GetYaxis().SetLabelSize(0.04)
786 hist_signal.GetXaxis().SetTitleSize(0.05)
787 hist_signal.GetYaxis().SetTitleSize(0.05)
788 hist_signal.GetXaxis().SetTitleOffset(0.95)
789 hist_signal.GetYaxis().SetTitleOffset(1.1)
790 hist_signal.GetXaxis().SetTitleOffset(1.15)
791 hist_signal.GetYaxis().SetLimits(0, Ymax)
792 hist_signal.SetLineColor(ROOT.kBlue)
793 hist_background.SetFillColorAlpha(ROOT.kRed, 1.0)
794 hist_background.SetFillStyle(3005)
795 hist_background.GetYaxis().SetLimits(0, Ymax)
796 hist_background.SetLineColor(ROOT.kRed)
799 if category ==
'MaximumPstar':
800 catName =
'MaximumP*'
802 hist_signal.SetTitle(
'; (#it{qp})^{' + catName +
'} ; Events')
804 hist_signal.SetMaximum(Ymax)
806 hist_background.SetMaximum(Ymax)
808 hist_signal.Draw(
'hist')
809 hist_background.Draw(
'hist same')
811 l0 = ROOT.TLegend(0.13, 0.65, 0.33, 0.97)
812 l0.SetFillColorAlpha(ROOT.kWhite, 0)
813 l0.AddEntry(hist_signal,
' #varepsilon_{eff}(B^{0}) = ' +
'{:.2f}'.format(tot_eff_effB0 * 100) +
"%")
814 l0.AddEntry(hist_background,
' #varepsilon_{eff}(#bar{B}^{0}) = ' +
'{:.2f}'.format(tot_eff_effB0bar * 100) +
"%")
815 l0.AddEntry(
"",
"#bf{#varepsilon_{eff} = " +
'{:.2f}'.format(effAverage * 100) +
'%}')
816 l0.AddEntry(
"",
'#Delta#varepsilon_{eff} = ' +
'{:^5.2f}'.format(effDiff * 100) +
'%')
818 l0.SetTextSize(0.045)
821 l1 = ROOT.TLegend(0.85, 0.7, 0.96, 0.97)
822 l1.SetFillColorAlpha(ROOT.kWhite, 0.35)
823 l1.AddEntry(hist_signal,
'B^{0}_{MC}')
824 l1.AddEntry(hist_background,
'#bar{B}^{0}_{MC}')
825 l1.SetTextSize(0.045)
829 with Quiet(ROOT.kError):
830 Canvas.SaveAs(workingDirectory +
'/' +
'test6_CPVFTqp_' + category +
'_both.pdf')
833 hist_both.GetXaxis().SetLabelSize(0.04)
834 hist_both.GetYaxis().SetLabelSize(0.04)
835 hist_both.GetYaxis().SetTitleOffset(0.7)
836 hist_both.GetXaxis().SetTitleOffset(0.7)
837 hist_both.GetXaxis().SetTitleSize(0.06)
838 hist_both.GetYaxis().SetTitleSize(0.06)
840 hist_both.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats, logy'))
841 hist_both.GetListOfFunctions().Add(ROOT.TNamed(
'Description',
'Output of the flavor tagger category ' + catName))
842 hist_both.GetListOfFunctions().Add(
843 ROOT.TNamed(
'Check',
'Shape should not change drastically. E.g. Warning if there is only a peak at 0.'))
844 hist_both.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'abudinen@mpp.mpg.de'))
847 'Flavor tagger output of the category ' +
851 '} ; Events (Total = ' +
854 hist_both.GetEntries()) +
861 outputNtuple.Fill(array(
'f', efficienciesForNtuple))
866 print(
'*******************************************************************************************************************')