14 <input>CPVToolsOutput.root</input>
15 <output>test6_CPVFlavorTaggerEfficiency.root</output>
16 <contact>Yo Sato; yosato@post.kek.jp</contact>
17 <description>This file calculates the effective efficiency of the category based flavor tagger considering the two
18 standard combiners and the individual categories. Validation plots are also produced. </description>
23 from array
import array
25 ROOT.gROOT.SetBatch(
True)
27 workingFiles = [
"../CPVToolsOutput.root"]
28 treeName = str(
"B0tree")
31 workingDirectory =
'.'
39 r_subsample = array(
'd', [
48 r_size = len(r_subsample)
54 'IntermediateElectron',
58 'IntermediateKinLepton',
72 """Context handler class to quiet errors in a 'with' statement"""
75 """Class constructor"""
80 """Enter the context"""
83 ROOT.gErrorIgnoreLevel = self.
levellevel
86 """Exit the context"""
87 ROOT.gErrorIgnoreLevel = self.
oldleveloldlevel
90 tree = ROOT.TChain(treeName)
92 mcstatus = array(
'd', [-511.5, 0.0, 511.5])
93 ROOT.TH1.SetDefaultSumw2()
95 for iFile
in workingFiles:
99 for branch
in tree.GetListOfBranches():
100 totalBranches.append(branch.GetName())
102 if 'FBDT_qrCombined' in totalBranches:
103 methods.append(
"FBDT")
105 if 'FANN_qrCombined' in totalBranches:
106 methods.append(
"FANN")
109 for cat
in categories:
110 catBranch =
'qp' + cat
111 if catBranch
in totalBranches:
112 usedCategories.append(cat)
114 categoriesNtupleList = str()
115 for category
in usedCategories:
116 categoriesNtupleList = categoriesNtupleList +
"Eff_%s:" % category
120 outputFile = ROOT.TFile(
"test6_CPVFlavorTaggerEfficiency.root",
"RECREATE")
123 outputNtuple = ROOT.TNtuple(
125 "Effective efficiencies of the flavor tagger combiners as well as of the individual tagging categories.",
126 "Eff_FBDT:DeltaEff_FBDT:Eff_FANN:DeltaEff_FANN:" + categoriesNtupleList)
128 outputNtuple.SetAlias(
'Description',
"These are the effective efficiencies of the flavor tagger combiners as well as of " +
129 "the individual tagging efficiencies.")
130 outputNtuple.SetAlias(
132 "These values should not change drastically. Since the nightly reconstruction validation runs" +
133 "on the same input file (which changes only from release to release), the values between builds should be the same.")
134 outputNtuple.SetAlias(
'Contact',
"yosato@post.kek.jp")
136 efficienciesForNtuple = []
140 for method
in methods:
142 histo_avr_r = ROOT.TH1F(
'Average_r',
'Average r in each of 6 bins (B0 and B0bar)', 6,
144 histo_avr_rB0 = ROOT.TH1F(
'Average_rB0',
'Average r in each of 6 bins (B0)', 6,
146 histo_avr_rB0bar = ROOT.TH1F(
'Average_rB0bar',
'Average r in each of 6 bins (B0bar)', 6,
149 histo_entries_per_bin = ROOT.TH1F(
151 'Events binned in r_subsample according to their r-value for B0 and B0bar prob',
154 histo_entries_per_binB0 = ROOT.TH1F(
'entries_per_binB0',
'Events binned in r_subsample according '
155 'to their r-value for B0 prob', 6, r_subsample)
156 histo_entries_per_binB0bar = ROOT.TH1F(
'entries_per_binB0bar',
157 'Events binned in r_subsample according to their r-value '
158 'for B0bar prob', 6, r_subsample)
160 histo_Cnet_output_B0 = ROOT.TH1F(
'Comb_Net_Output_B0',
'Combiner network output [not equal to r] '
161 'for true B0 (binning 100)', 100, 0.0, 1.0)
163 histo_Cnet_output_B0bar = ROOT.TH1F(
'Comb_Net_Output_B0bar',
'Combiner network output [not equal to r] '
164 'for true B0bar (binning 100)', 100, 0.0, 1.0)
166 histo_belleplotB0 = ROOT.TH1F(
'qr_' + method +
'_B0',
167 'BellePlot for true B0 (binning 50)', 50,
170 histo_belleplotB0bar = ROOT.TH1F(
'qr_' + method +
'_B0Bar',
171 'BellePlot for true B0Bar (binning 50)',
175 histo_belleplotBoth = ROOT.TH1F(
'qr_' + method +
'_B0Both',
176 'qr-tagger output (binning 50)',
181 histo_calib_B0 = ROOT.TH1F(
'Calibration_' + method +
'_B0',
'CalibrationPlot for true B0', 100, -1.0, 1.0)
183 histo_calib_B0bar = ROOT.TH1F(
'Calibration_' + method +
'_B0Bar',
184 'CalibrationPlot for true B0Bar', 100, -1.0,
187 hallo12 = ROOT.TH1F(
'BellePlot_NoCut',
'BellePlot_NoCut (binning 100)',
191 diag = ROOT.TF1(
'diag',
'pol1', -1, 1)
195 histo_m0 = ROOT.TH1F(
'BellePlot_B0_m0',
196 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
197 histo_m1 = ROOT.TH1F(
'BellePlot_B0_m1',
198 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
199 histo_m2 = ROOT.TH1F(
'BellePlot_B0_m2',
200 'BellePlot_m for true B0Bar (binning 50)', 50, -1.0,
205 tree.Draw(method +
'_qrCombined>>qr_' + method +
'_B0',
'qrMC == 1')
206 tree.Draw(method +
'_qrCombined>>qr_' + method +
'_B0Bar',
'qrMC == -1')
207 tree.Draw(method +
'_qrCombined>>BellePlot_NoCut',
'abs(qrMC) == 1')
208 tree.Draw(method +
'_qrCombined>>qr_' + method +
'_B0Both',
'abs(qrMC) == 1')
210 tree.Draw(method +
'_qrCombined>>Calibration_' + method +
'_B0',
'qrMC == 1')
211 tree.Draw(method +
'_qrCombined>>Calibration_' + method +
'_B0Bar',
'qrMC == -1')
214 tree.Draw(method +
'_qrCombined>>BellePlot_B0_m0',
215 'qrMC == 1 && ' + method +
'_qrCombined>0')
216 tree.Draw(method +
'_qrCombined>>BellePlot_B0_m1',
217 'qrMC == 1 && ' + method +
'_qrCombined<0')
218 tree.Draw(method +
'_qrCombined>>BellePlot_B0_m2',
219 'qrMC == -1 && ' + method +
'_qrCombined>0 ')
224 tree.Project(
'Average_r',
'abs(' + method +
'_qrCombined)',
225 'abs(' + method +
'_qrCombined)')
226 tree.Project(
'Average_rB0',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==1)')
227 tree.Project(
'Average_rB0bar',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==-1)')
230 tree.Project(
'entries_per_bin',
'abs(' + method +
'_qrCombined)',
'abs(qrMC) == 1')
231 tree.Project(
'entries_per_binB0',
'abs(' + method +
'_qrCombined)',
'qrMC == 1')
232 tree.Project(
'entries_per_binB0bar',
'abs(' + method +
'_qrCombined)',
'qrMC == -1')
235 histo_avr_r.Divide(histo_entries_per_bin)
236 histo_avr_rB0.Divide(histo_entries_per_binB0)
237 histo_avr_rB0bar.Divide(histo_entries_per_binB0bar)
241 histo_calib_B0.Divide(hallo12)
242 histo_calib_B0bar.Divide(hallo12)
246 print(
'****************** CALIBRATION CHECK FOR COMBINER USING ' + method +
' ***************************************')
248 print(
'Fit polynomial of first order to the calibration plot. Expected value ~0.5')
250 histo_calib_B0.Fit(diag,
'TEST')
252 print(
'****************** MEASURED EFFECTIVE EFFICIENCY FOR COMBINER USING ' + method +
' ***************************')
255 total_entries = histo_entries_per_bin.GetEntries()
256 total_entries_B0 = histo_entries_per_binB0.GetEntries()
257 total_entries_B0bar = histo_entries_per_binB0bar.GetEntries()
260 event_fractionB0 = array(
'f', [0] * r_size)
261 event_fractionB0bar = array(
'f', [0] * r_size)
262 event_fractionTotal = array(
'f', [0] * r_size)
263 event_fractionDiff = array(
'f', [0] * r_size)
264 rvalueB0 = array(
'f', [0] * r_size)
265 rvalueB0bar = array(
'f', [0] * r_size)
266 rvalueB0Average = array(
'f', [0] * r_size)
267 wvalue = array(
'f', [0] * r_size)
268 wvalueB0 = array(
'f', [0] * r_size)
269 wvalueB0bar = array(
'f', [0] * r_size)
270 wvalueDiff = array(
'f', [0] * r_size)
271 entries = array(
'f', [0] * r_size)
272 entriesB0 = array(
'f', [0] * r_size)
273 entriesB0bar = array(
'f', [0] * r_size)
274 iEffEfficiency = array(
'f', [0] * r_size)
275 iDeltaEffEfficiency = array(
'f', [0] * r_size)
278 for i
in range(1, r_size):
280 rvalueB0[i] = histo_avr_rB0.GetBinContent(i)
281 rvalueB0bar[i] = histo_avr_rB0bar.GetBinContent(i)
282 rvalueB0Average[i] = (rvalueB0[i] + rvalueB0bar[i]) / 2
284 wvalue[i] = (1 - rvalueB0Average[i]) / 2
285 wvalueB0[i] = (1 - rvalueB0[i]) / 2
286 wvalueB0bar[i] = (1 - rvalueB0bar[i]) / 2
287 wvalueDiff[i] = wvalueB0[i] - wvalueB0bar[i]
288 entries[i] = histo_entries_per_bin.GetBinContent(i)
289 entriesB0[i] = histo_entries_per_binB0.GetBinContent(i)
290 entriesB0bar[i] = histo_entries_per_binB0bar.GetBinContent(i)
292 event_fractionTotal[i] = (entriesB0[i] + entriesB0bar[i]) / total_entries
293 event_fractionDiff[i] = (entriesB0[i] - entriesB0bar[i]) / total_entries
294 event_fractionB0[i] = entriesB0[i] / total_entries_B0
295 event_fractionB0bar[i] = entriesB0bar[i] / total_entries_B0bar
296 iEffEfficiency[i] = (event_fractionB0[i] * rvalueB0[i] * rvalueB0[i] +
297 event_fractionB0bar[i] * rvalueB0bar[i] * rvalueB0bar[i]) / 2
298 iDeltaEffEfficiency[i] = event_fractionB0[i] * rvalueB0[i] * \
299 rvalueB0[i] - event_fractionB0bar[i] * rvalueB0bar[i] * rvalueB0bar[i]
301 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] * rvalueB0[i]
302 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] * rvalueB0bar[i]
304 average_eff = (tot_eff_effB0 + tot_eff_effB0bar) / 2
305 diff_eff = tot_eff_effB0 - tot_eff_effB0bar
306 print(
'* ------------------------------------------------------------------------------------------------ *')
308 print(
'* __________________________________________________________________________________________ *')
310 print(
'* | TOTAL NUMBER OF TAGGED EVENTS = ' +
311 '{:<24}'.format(
"%.0f" % total_entries) +
'{:>36}'.format(
'| *'))
313 print(
'* | TOTAL AVERAGE EFFECTIVE EFFICIENCY (q=+-1)= ' +
'{:.2f}'.format(average_eff * 100) +
316 print(
'* | B0-TAGGER TOTAL EFFECTIVE EFFICIENCIES: ' +
317 '{:.2f}'.format(tot_eff_effB0 * 100) +
' % (q=+1) ' +
318 '{:.2f}'.format(tot_eff_effB0bar * 100) +
' % (q=-1) EffDiff=' +
319 '{:^5.2f}'.format(diff_eff * 100) +
' % | *')
321 print(
'* | FLAVOR PERCENTAGE (MC): ' +
322 '{:.2f}'.format(total_entries_B0 / total_entries * 100) +
' % (q=+1) ' +
323 '{:.2f}'.format(total_entries_B0bar / total_entries * 100) +
' % (q=-1) Diff=' +
324 '{:^5.2f}'.format((total_entries_B0 - total_entries_B0bar) / total_entries * 100) +
' % | *')
325 print(
'* |__________________________________________________________________________________________| *')
327 print(
'****************************************************************************************************')
330 efficienciesForNtuple.append(float(average_eff * 100))
331 efficienciesForNtuple.append(float(diff_eff * 100))
333 maxB0 = histo_belleplotB0.GetBinContent(histo_belleplotB0.GetMaximumBin())
334 maxB0bar = histo_belleplotB0bar.GetBinContent(histo_belleplotB0bar.GetMaximumBin())
335 maxB0Both = histo_belleplotBoth.GetBinContent(histo_belleplotBoth.GetMaximumBin())
337 Ymax = max(maxB0, maxB0bar, maxB0Both)
338 Ymax = Ymax + Ymax / 12
340 if YmaxForQrPlot < Ymax:
344 ROOT.gStyle.SetOptStat(0)
345 with Quiet(ROOT.kError):
346 Canvas1 = ROOT.TCanvas(
'Bla',
'Final Output', 1200, 800)
348 Canvas1.SetLeftMargin(0.13)
349 Canvas1.SetRightMargin(0.04)
350 Canvas1.SetTopMargin(0.03)
351 Canvas1.SetBottomMargin(0.14)
352 histo_belleplotB0.SetFillColorAlpha(ROOT.kBlue, 0.2)
353 histo_belleplotB0.SetFillStyle(1001)
354 histo_belleplotB0.GetXaxis().SetLabelSize(0.04)
355 histo_belleplotB0.GetYaxis().SetLabelSize(0.04)
356 histo_belleplotB0.GetYaxis().SetTitleOffset(0.9)
357 histo_belleplotB0.GetXaxis().SetTitleSize(0.06)
358 histo_belleplotB0.GetYaxis().SetTitleSize(0.06)
359 histo_belleplotB0.GetYaxis().SetLimits(0, YmaxForQrPlot)
360 histo_belleplotB0.SetLineColor(ROOT.kBlue)
361 histo_belleplotB0bar.SetFillColorAlpha(ROOT.kRed, 1.0)
362 histo_belleplotB0bar.SetFillStyle(3005)
363 histo_belleplotB0bar.SetLineColor(ROOT.kRed)
366 histo_belleplotB0.SetTitle(
'; #it{qr}_{' + method +
'} ; Events (Total = ' +
'{:<1}'.format(
"%.0f" % total_entries) +
')'
368 histo_belleplotB0.SetMinimum(0)
369 histo_belleplotB0.SetMaximum(YmaxForQrPlot)
370 histo_belleplotB0.Draw(
'hist')
371 histo_belleplotB0bar.Draw(
'hist same')
373 leg = ROOT.TLegend(0.2, 0.7, 0.9, 0.95)
377 ' #varepsilon_{eff}(B^{0}) = ' +
381 '% #frac{n_{B^{0}}}{n} = ' +
388 histo_belleplotB0bar,
389 'true #bar{B}^{0} ' +
390 ' #varepsilon_{eff}(#bar{B}^{0}) = ' +
394 '% #frac{n_{#bar{B}^{0}}}{n} = ' +
396 total_entries_B0bar /
400 leg.AddEntry(
"",
"Avrg. #bf{ #varepsilon_{eff} = " +
'{:.2f}'.format(average_eff * 100) +
401 '%} #Delta#varepsilon_{eff} = ' +
'{:^5.2f}'.format(diff_eff * 100) +
'%')
402 leg.SetTextSize(0.045)
407 with Quiet(ROOT.kError):
408 Canvas1.SaveAs(workingDirectory +
'/' +
'test6_CPVFTqr' + method +
'_both.pdf')
411 histo_belleplotBoth.GetXaxis().SetLabelSize(0.04)
412 histo_belleplotBoth.GetYaxis().SetLabelSize(0.04)
413 histo_belleplotBoth.GetYaxis().SetTitleOffset(0.7)
414 histo_belleplotBoth.GetXaxis().SetTitleOffset(0.7)
415 histo_belleplotBoth.GetXaxis().SetTitleSize(0.06)
416 histo_belleplotBoth.GetYaxis().SetTitleSize(0.06)
418 histo_belleplotBoth.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
419 histo_belleplotBoth.GetListOfFunctions().Add(ROOT.TNamed(
'Description',
'Output of the flavor tagger combiner ' + method))
420 histo_belleplotBoth.GetListOfFunctions().Add(
423 'Shape should not change drastically. E.g. Warning if the peak at 0 increases or if the peaks at +-1 decrease.'))
424 histo_belleplotBoth.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'yosato@post.kek.jp'))
426 histo_belleplotBoth.SetTitle(
427 'Flavor tagger output for combiner ' +
431 '} ; Events (Total = ' +
436 histo_belleplotBoth.SetMinimum(0)
437 histo_belleplotBoth.SetMaximum(YmaxForQrPlot)
438 histo_belleplotBoth.SetStats(
False)
439 histo_belleplotBoth.Write()
442 histo_belleplotB0.GetYaxis().SetTitleOffset(0.7)
443 histo_belleplotB0.GetXaxis().SetTitleOffset(0.7)
444 histo_belleplotB0.SetLineColor(ROOT.kBlue + 2)
445 histo_belleplotB0.SetTitle(
446 'Flavor tagger output for combiner ' +
448 ' for true B^{0}s; #it{qr}_{' +
450 '} ; Events (Total = ' +
453 histo_belleplotB0.GetEntries()) +
455 histo_belleplotB0.SetStats(
False)
457 histo_belleplotB0.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
458 histo_belleplotB0.GetListOfFunctions().Add(
459 ROOT.TNamed(
'Description',
'Output of the flavor tagger combiner ' + method +
' for true B0s'))
460 histo_belleplotB0.GetListOfFunctions().Add(
463 'Shape should not change drastically. E.g. Warning if the peak at 0 increases or if the peak at +1 decreases.'))
464 histo_belleplotB0.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'yosato@post.kek.jp'))
465 histo_belleplotB0.Write()
468 histo_belleplotB0bar.GetXaxis().SetLabelSize(0.04)
469 histo_belleplotB0bar.GetYaxis().SetLabelSize(0.04)
470 histo_belleplotB0bar.GetYaxis().SetTitleOffset(0.7)
471 histo_belleplotB0bar.GetXaxis().SetTitleOffset(0.7)
472 histo_belleplotB0bar.GetXaxis().SetTitleSize(0.06)
473 histo_belleplotB0bar.GetYaxis().SetTitleSize(0.06)
474 histo_belleplotB0bar.SetLineColor(ROOT.kBlue + 2)
475 histo_belleplotB0bar.SetTitle(
476 'Flavor tagger output for combiner ' +
478 ' for true #bar{B}^{0}s; #it{qr}_{' +
480 '} ; Events (Total = ' +
483 histo_belleplotB0bar.GetEntries()) +
485 histo_belleplotB0bar.SetMinimum(0)
486 histo_belleplotB0bar.SetMaximum(YmaxForQrPlot)
487 histo_belleplotB0bar.SetStats(
False)
489 histo_belleplotB0bar.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
490 histo_belleplotB0bar.GetListOfFunctions().Add(
493 'Output of the flavor tagger combiner ' +
496 histo_belleplotB0bar.GetListOfFunctions().Add(ROOT.TNamed(
497 'Check',
'Shape should not change drastically. E.g. Warning if the peak at 0 increases or if the peak at -1 decreases.'))
498 histo_belleplotB0bar.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'yosato@post.kek.jp'))
499 histo_belleplotB0bar.Write()
504 with Quiet(ROOT.kError):
505 Canvas2 = ROOT.TCanvas(
'Bla2',
'Calibration plot for true B0', 1200, 800)
507 Canvas2.SetLeftMargin(0.13)
508 Canvas2.SetRightMargin(0.04)
509 Canvas2.SetTopMargin(0.03)
510 Canvas2.SetBottomMargin(0.14)
511 histo_calib_B0.GetXaxis().SetLabelSize(0.04)
512 histo_calib_B0.GetYaxis().SetLabelSize(0.04)
513 histo_calib_B0.GetYaxis().SetTitleOffset(0.9)
514 histo_calib_B0.GetXaxis().SetTitleSize(0.06)
515 histo_calib_B0.GetYaxis().SetTitleSize(0.06)
516 histo_calib_B0.SetFillColorAlpha(ROOT.kBlue, 0.2)
517 histo_calib_B0.SetFillStyle(1001)
518 histo_calib_B0.GetYaxis().SetTitleOffset(0.9)
519 histo_calib_B0.SetLineColor(ROOT.kBlue)
521 histo_calib_B0.SetTitle(
'; #it{qr}_{' + method +
'} ; Calibration '
523 histo_calib_B0.Draw(
'hist')
526 leg2 = ROOT.TLegend(0.2, 0.75, 0.63, 0.93)
527 leg2.SetHeader(
" y = #it{m}#it{x} + #it{c}",
"")
528 leg2.GetListOfPrimitives().First().SetTextAlign(22)
533 diag.GetParameter(
"p1")) +
536 diag.GetParameter(
"p0")))
537 leg2.SetTextSize(0.05)
541 with Quiet(ROOT.kError):
542 Canvas2.SaveAs(workingDirectory +
'/' +
'test6_CPVFTCalibration_' + method +
'_B0.pdf')
546 histo_calib_B0.GetYaxis().SetTitleOffset(0.7)
547 histo_calib_B0.GetXaxis().SetTitleOffset(0.7)
548 histo_calib_B0.SetLineColor(ROOT.kBlue + 2)
549 histo_calib_B0.SetTitle(
'Calibration plot for the flavor tagger combiner ' +
550 method +
' ; #it{qr}_{' + method +
'} ; Calibration')
551 histo_calib_B0.SetMinimum(-0.2)
552 histo_calib_B0.SetMaximum(+1.2)
553 histo_calib_B0.SetStats(
False)
555 histo_calib_B0.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats'))
556 histo_calib_B0.GetListOfFunctions().Add(
559 'Calibration plot for the flavor tagger combiner ' +
562 histo_calib_B0.GetListOfFunctions().Add(
563 ROOT.TNamed(
'Check',
'Shape should not change drastically. E.g. warning if the shape stops being linear.'))
564 histo_calib_B0.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'yosato@post.kek.jp'))
565 histo_calib_B0.Write()
567 histo_belleplotBoth.Delete()
569 histo_avr_rB0.Delete()
570 histo_avr_rB0bar.Delete()
571 histo_entries_per_bin.Delete()
572 histo_entries_per_binB0.Delete()
573 histo_entries_per_binB0bar.Delete()
574 histo_Cnet_output_B0.Delete()
575 histo_Cnet_output_B0bar.Delete()
576 histo_belleplotB0.Delete()
577 histo_belleplotB0bar.Delete()
578 histo_calib_B0.Delete()
579 histo_calib_B0bar.Delete()
592 print(
'************************* MEASURED EFFECTIVE EFFICIENCY FOR INDIVIDUAL CATEGORIES *********************************')
597 for category
in usedCategories:
599 hist_signal = ROOT.TH1F(
'Signal_' + category,
'Input Signal (B0)' +
600 category +
' (binning 50)', 50, -1.0, 1.0)
602 hist_background = ROOT.TH1F(
'Background_' + category,
'Input Background (B0bar)' +
603 category +
' (binning 50)', 50, -1.0, 1.0)
604 hist_both = ROOT.TH1F(
'qp_' + category,
'Input Background (B0bar)' +
605 category +
' (binning 50)', 100, -1, 1)
609 hist_probB0 = ROOT.TH1F(
'ProbabilityB0_' + category,
610 'Transformed to probability (B0) (' + category +
')',
612 hist_probB0bar = ROOT.TH1F(
'ProbabilityB0bar_' + category,
613 'Transformed to probability (B0bar) (' + category +
')',
616 hist_qpB0 = ROOT.TH1F(
'QRB0_' + category,
'Transformed to qp (B0)(' +
617 category +
')', 50, -1.0, 1.0)
618 hist_qpB0bar = ROOT.TH1F(
'QRB0bar_' + category,
'Transformed to qp (B0bar) (' +
619 category +
')', 50, -1.0, 1.0)
622 hist_absqpB0 = ROOT.TH1F(
'AbsQRB0_' + category,
'Abs(qp)(B0) (' + category +
')', 6, r_subsample)
623 hist_absqpB0bar = ROOT.TH1F(
'AbsQRB0bar_' + category,
'Abs(qp) (B0bar) (' + category +
')', 6, r_subsample)
626 hist_aver_rB0 = ROOT.TH1F(
'AverageRB0_' + category,
'A good one (B0)' +
627 category, 6, r_subsample)
628 hist_aver_rB0bar = ROOT.TH1F(
'AverageRB0bar_' + category,
'A good one (B0bar)' +
629 category, 6, r_subsample)
632 hist_all = ROOT.TH1F(
'All_' + category,
'Input Signal (B0) and Background (B0Bar)' +
633 category +
' (binning 50)', 50, 0.0, 1.0)
634 tree.Draw(
'qp' + category +
'>>All_' + category,
'qrMC!=0')
635 hist_calib_B0 = ROOT.TH1F(
'Calib_B0_' + category,
'Calibration Plot for true B0' +
636 category +
' (binning 50)', 50, 0.0, 1.0)
637 tree.Draw(
'qp' + category +
'>>Calib_B0_' + category,
'qrMC == 1.0')
638 hist_calib_B0.Divide(hist_all)
641 tree.Draw(
'qp' + category +
'>>Signal_' + category,
'qrMC == 1.0')
643 tree.Draw(
'qp' + category +
'>>Background_' + category,
'qrMC == -1.0'
646 tree.Draw(
'qp' + category +
'>>qp_' + category,
'abs(qrMC) == 1.0'
652 purityB0 = array(
'd', [0] * 51)
653 dilutionB02 = array(
'd', [0] * 51)
654 purityB0bar = array(
'd', [0] * 51)
655 dilutionB0bar2 = array(
'd', [0] * 51)
656 signal = array(
'd', [0] * 51)
657 back = array(
'd', [0] * 51)
658 weight = array(
'd', [0] * 51)
660 for i
in range(1, 51):
662 signal[i] = hist_signal.GetBinContent(i)
663 back[i] = hist_background.GetBinContent(i)
665 weight[i] = signal[i] + back[i]
668 if signal[i] + back[i] == 0:
672 dilutionB0bar2[i] = 0
674 purityB0[i] = signal[i] / (signal[i] + back[i])
675 dilutionB02[i] = -1 + 2 * signal[i] / (signal[i] + back[i])
677 purityB0bar[i] = back[i] / (signal[i] + back[i])
678 dilutionB0bar2[i] = -1 + 2 * back[i] / (signal[i] + back[i])
681 hist_probB0.Fill(purityB0[i], signal[i])
682 hist_probB0bar.Fill(purityB0bar[i], back[i])
685 hist_qpB0.Fill(dilutionB02[i], signal[i])
686 hist_qpB0bar.Fill(dilutionB0bar2[i], back[i])
689 hist_absqpB0.Fill(abs(dilutionB02[i]), signal[i])
690 hist_absqpB0bar.Fill(abs(dilutionB0bar2[i]), back[i])
692 hist_aver_rB0.Fill(abs(dilutionB02[i]), abs(dilutionB02[i]) * signal[i])
693 hist_aver_rB0bar.Fill(abs(dilutionB0bar2[i]), abs(dilutionB0bar2[i]) * back[i])
696 hist_aver_rB0.Divide(hist_absqpB0)
697 hist_aver_rB0bar.Divide(hist_absqpB0bar)
703 for i
in range(1, r_size):
704 tot_entriesB0 = tot_entriesB0 + hist_absqpB0.GetBinContent(i)
705 tot_entriesB0bar = tot_entriesB0bar + hist_absqpB0bar.GetBinContent(i)
709 event_fractionB0 = array(
'f', [0] * r_size)
710 event_fractionB0bar = array(
'f', [0] * r_size)
711 rvalueB0 = array(
'f', [0] * r_size)
712 rvalueB0bar = array(
'f', [0] * r_size)
714 entriesB0 = array(
'f', [0] * r_size)
715 entriesB0bar = array(
'f', [0] * r_size)
717 for i
in range(1, r_size):
718 rvalueB0[i] = hist_aver_rB0.GetBinContent(i)
719 rvalueB0bar[i] = hist_aver_rB0bar.GetBinContent(i)
721 entriesB0[i] = hist_absqpB0.GetBinContent(i)
722 entriesB0bar[i] = hist_absqpB0bar.GetBinContent(i)
723 event_fractionB0[i] = entriesB0[i] / tot_entriesB0
724 event_fractionB0bar[i] = entriesB0bar[i] / tot_entriesB0bar
728 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] \
730 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] \
732 effDiff = tot_eff_effB0 - tot_eff_effB0bar
733 effAverage = (tot_eff_effB0 + tot_eff_effB0bar) / 2
736 '{:<25}'.format(
"* " +
749 '{: 8.2f}'.format(effAverage * 100) +
' %' +
751 '{: 8.2f}'.format(effDiff * 100) +
' % *')
755 efficienciesForNtuple.append(float(effAverage * 100))
757 maxSignal = hist_signal.GetBinContent(hist_signal.GetMaximumBin())
758 maxBackground = hist_background.GetBinContent(hist_background.GetMaximumBin())
760 Ymax = max(maxSignal, maxBackground)
761 Ymax = Ymax + Ymax / 12
763 ROOT.gStyle.SetOptStat(0)
764 with Quiet(ROOT.kError):
765 Canvas = ROOT.TCanvas(
'Bla',
'TITEL BLA', 1200, 800)
768 Canvas.SetLeftMargin(0.13)
769 Canvas.SetRightMargin(0.04)
770 Canvas.SetTopMargin(0.03)
771 Canvas.SetBottomMargin(0.14)
772 hist_signal.SetFillColorAlpha(ROOT.kBlue, 0.2)
773 hist_signal.SetFillStyle(1001)
774 hist_signal.SetTitleSize(0.1)
775 hist_signal.GetXaxis().SetLabelSize(0.04)
776 hist_signal.GetYaxis().SetLabelSize(0.04)
777 hist_signal.GetXaxis().SetTitleSize(0.06)
778 hist_signal.GetYaxis().SetTitleSize(0.06)
779 hist_signal.GetXaxis().SetLabelSize(0.04)
780 hist_signal.GetYaxis().SetLabelSize(0.04)
781 hist_signal.GetXaxis().SetTitleSize(0.05)
782 hist_signal.GetYaxis().SetTitleSize(0.05)
783 hist_signal.GetXaxis().SetTitleOffset(0.95)
784 hist_signal.GetYaxis().SetTitleOffset(1.1)
785 hist_signal.GetXaxis().SetTitleOffset(1.15)
786 hist_signal.GetYaxis().SetLimits(0, Ymax)
787 hist_signal.SetLineColor(ROOT.kBlue)
788 hist_background.SetFillColorAlpha(ROOT.kRed, 1.0)
789 hist_background.SetFillStyle(3005)
790 hist_background.GetYaxis().SetLimits(0, Ymax)
791 hist_background.SetLineColor(ROOT.kRed)
794 if category ==
'MaximumPstar':
795 catName =
'MaximumP*'
797 hist_signal.SetTitle(
'; (#it{qp})^{' + catName +
'} ; Events')
799 hist_signal.SetMaximum(Ymax)
801 hist_background.SetMaximum(Ymax)
803 hist_signal.Draw(
'hist')
804 hist_background.Draw(
'hist same')
806 l0 = ROOT.TLegend(0.13, 0.65, 0.33, 0.97)
807 l0.SetFillColorAlpha(ROOT.kWhite, 0)
808 l0.AddEntry(hist_signal,
' #varepsilon_{eff}(B^{0}) = ' +
'{:.2f}'.format(tot_eff_effB0 * 100) +
"%")
809 l0.AddEntry(hist_background,
' #varepsilon_{eff}(#bar{B}^{0}) = ' +
'{:.2f}'.format(tot_eff_effB0bar * 100) +
"%")
810 l0.AddEntry(
"",
"#bf{#varepsilon_{eff} = " +
'{:.2f}'.format(effAverage * 100) +
'%}')
811 l0.AddEntry(
"",
'#Delta#varepsilon_{eff} = ' +
'{:^5.2f}'.format(effDiff * 100) +
'%')
813 l0.SetTextSize(0.045)
816 l1 = ROOT.TLegend(0.85, 0.7, 0.96, 0.97)
817 l1.SetFillColorAlpha(ROOT.kWhite, 0.35)
818 l1.AddEntry(hist_signal,
'B^{0}_{MC}')
819 l1.AddEntry(hist_background,
'#bar{B}^{0}_{MC}')
820 l1.SetTextSize(0.045)
824 with Quiet(ROOT.kError):
825 Canvas.SaveAs(workingDirectory +
'/' +
'test6_CPVFTqp_' + category +
'_both.pdf')
828 hist_both.GetXaxis().SetLabelSize(0.04)
829 hist_both.GetYaxis().SetLabelSize(0.04)
830 hist_both.GetYaxis().SetTitleOffset(0.7)
831 hist_both.GetXaxis().SetTitleOffset(0.7)
832 hist_both.GetXaxis().SetTitleSize(0.06)
833 hist_both.GetYaxis().SetTitleSize(0.06)
835 hist_both.GetListOfFunctions().Add(ROOT.TNamed(
'MetaOptions',
'nostats, logy'))
836 hist_both.GetListOfFunctions().Add(ROOT.TNamed(
'Description',
'Output of the flavor tagger category ' + catName))
837 hist_both.GetListOfFunctions().Add(
838 ROOT.TNamed(
'Check',
'Shape should not change drastically. E.g. Warning if there is only a peak at 0.'))
839 hist_both.GetListOfFunctions().Add(ROOT.TNamed(
'Contact',
'yosato@post.kek.jp'))
842 'Flavor tagger output of the category ' +
846 '} ; Events (Total = ' +
849 hist_both.GetEntries()) +
856 outputNtuple.Fill(array(
'f', efficienciesForNtuple))
861 print(
'*******************************************************************************************************************')
oldlevel
the previously set level to be ignored
def __exit__(self, type, value, traceback)
def __init__(self, level=ROOT.kInfo+1)