23 from basf2
import B2INFO
24 import flavorTagger
as ft
25 from defaultEvaluationParameters
import categories, Quiet, r_subsample, r_size
26 from array
import array
32 ROOT.gROOT.SetBatch(
True)
34 if len(sys.argv) != 3:
35 sys.exit(
"Must provide 2 arguments: [input_sim_file] or ['input_sim_file*'] with wildcards and [treeName]"
37 workingFile = sys.argv[1]
38 workingFiles = glob.glob(str(workingFile))
39 treeName = str(sys.argv[2])
41 if len(workingFiles) < 1:
42 sys.exit(
"No file name or file names " + str(workingFile) +
" found.")
45 workingDirectory =
'.'
60 tree = ROOT.TChain(treeName)
62 mcstatus = array(
'd', [-511.5, 0.0, 511.5])
63 ROOT.TH1.SetDefaultSumw2()
65 for iFile
in workingFiles:
69 for branch
in tree.GetListOfBranches():
70 totalBranches.append(branch.GetName())
72 if 'FBDT_qrCombined' in totalBranches:
73 methods.append(
"FBDT")
75 if 'FANN_qrCombined' in totalBranches:
76 methods.append(
"FANN")
78 if 'DNN_qrCombined' in totalBranches:
82 for cat
in categories:
83 catBranch =
'qp' + cat
84 if catBranch
in totalBranches:
85 usedCategories.append(cat)
87 if len(usedCategories) > 1:
88 ft.WhichCategories(usedCategories)
94 for method
in methods:
97 histo_avr_r = ROOT.TH1F(
'Average_r',
'Average r in each of the bins (B0 and B0bar)', int(r_size - 2),
99 histo_avr_rB0 = ROOT.TH1F(
'Average_rB0',
'Average r in each of the bins (B0)', int(r_size - 2),
101 histo_avr_rB0bar = ROOT.TH1F(
'Average_rB0bar',
'Average r in each of the bins (B0bar)', int(r_size - 2),
105 histo_mc_NwB0 = ROOT.TH1F(
'mc_NwB0',
'Average r in each of the bins (B0)', int(r_size - 2),
107 histo_mc_NwB0bar = ROOT.TH1F(
'mc_NwB0bar',
'Average r in each of the bins (B0bar)', int(r_size - 2),
111 histo_ms_r = ROOT.TH1F(
'MS_r',
'Mean squared average of r in each of the bins (B0 and B0bar)', int(r_size - 2),
113 histo_ms_rB0 = ROOT.TH1F(
'MS_rB0',
'Mean squared average of r in each of the bins (B0)', int(r_size - 2),
115 histo_ms_rB0bar = ROOT.TH1F(
'MS_rB0bar',
'Mean squared average of r in each of the bins (B0bar)', int(r_size - 2),
119 histo_entries_per_bin = ROOT.TH1F(
121 'Events binned in r_subsample according to their r-value for B0 and B0bar prob',
124 histo_entries_per_binB0 = ROOT.TH1F(
'entries_per_binB0',
'Events binned in r_subsample according '
125 'to their r-value for B0 prob', int(r_size - 2), r_subsample)
126 histo_entries_per_binB0bar = ROOT.TH1F(
'entries_per_binB0bar',
127 'Events binned in r_subsample according to their r-value '
128 'for B0bar prob', int(r_size - 2), r_subsample)
130 histo_Cnet_output_B0 = ROOT.TH1F(
'Comb_Net_Output_B0',
'Combiner network output [not equal to r] '
131 'for true B0 (binning 100)', 100, 0.0, 1.0)
133 histo_Cnet_output_B0bar = ROOT.TH1F(
'Comb_Net_Output_B0bar',
'Combiner network output [not equal to r] '
134 'for true B0bar (binning 100)', 100, 0.0, 1.0)
136 histo_belleplotB0 = ROOT.TH1F(
'BellePlot_B0',
137 'BellePlot for true B0 (binning 50)', 50,
140 histo_belleplotB0bar = ROOT.TH1F(
'BellePlot_B0Bar',
141 'BellePlot for true B0Bar (binning 50)',
144 histo_notTaggedEvents = ROOT.TH1F(
'notTaggedEvents',
145 'Histogram for not tagged events',
151 histo_calib_B0 = ROOT.TH1F(
'Calibration_B0',
'CalibrationPlot for true B0', 100, -1.0, 1.0)
153 histo_calib_B0bar = ROOT.TH1F(
'Calibration_B0Bar',
154 'CalibrationPlot for true B0Bar', 100, -1.0,
157 hallo12 = ROOT.TH1F(
'BellePlot_NoCut',
'BellePlot_NoCut (binning 100)',
161 diag = ROOT.TF1(
'diag',
'pol1', -1, 1)
165 histo_m0 = ROOT.TH1F(
'BellePlot_m0',
166 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
167 histo_m1 = ROOT.TH1F(
'BellePlot_m1',
168 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
169 histo_m2 = ROOT.TH1F(
'BellePlot_m2',
170 'BellePlot_m for true B0Bar (binning 50)', 50, -1.0,
175 tree.Draw(method +
'_qrCombined>>BellePlot_B0',
'qrMC == 1')
176 tree.Draw(method +
'_qrCombined>>BellePlot_B0Bar',
'qrMC == -1')
177 tree.Draw(method +
'_qrCombined>>BellePlot_NoCut',
'abs(qrMC) == 1')
179 tree.Draw(method +
'_qrCombined>>Calibration_B0',
'qrMC == 1')
180 tree.Draw(method +
'_qrCombined>>Calibration_B0Bar',
'qrMC == -1')
182 tree.Draw(method +
'_qrCombined>>notTaggedEvents',
183 'abs(qrMC) == 0 && isSignal == 1 && ' +
184 method +
'_qrCombined < -1')
187 tree.Draw(method +
'_qrCombined>>BellePlot_m0',
188 'qrMC == 1 && ' + method +
'_qrCombined>0')
189 tree.Draw(method +
'_qrCombined>>BellePlot_m1',
190 'qrMC == 1 && ' + method +
'_qrCombined<0')
191 tree.Draw(method +
'_qrCombined>>BellePlot_m2',
192 'qrMC == -1 && ' + method +
'_qrCombined>0 ')
197 tree.Project(
'Average_r',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(abs(qrMC) == 1)')
198 tree.Project(
'Average_rB0',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==1)')
199 tree.Project(
'Average_rB0bar',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==-1)')
201 tree.Project(
'MS_r',
'abs(' + method +
'_qrCombined)',
'(' + method +
202 '_qrCombined*' + method +
'_qrCombined)*(abs(qrMC) == 1)')
203 tree.Project(
'MS_rB0',
'abs(' + method +
'_qrCombined)',
204 '(' + method +
'_qrCombined*' + method +
'_qrCombined)*(qrMC==1)')
205 tree.Project(
'MS_rB0bar',
'abs(' + method +
'_qrCombined)',
206 '(' + method +
'_qrCombined*' + method +
'_qrCombined)*(qrMC==-1)')
209 tree.Project(
'entries_per_bin',
'abs(' + method +
'_qrCombined)',
'abs(qrMC) == 1')
210 tree.Project(
'entries_per_binB0',
'abs(' + method +
'_qrCombined)',
'qrMC == 1')
211 tree.Project(
'entries_per_binB0bar',
'abs(' + method +
'_qrCombined)',
'qrMC == -1')
214 tree.Project(
'mc_NwB0',
'abs(' + method +
'_qrCombined)',
' ' + method +
'_qrCombined*qrMC < 0 && qrMC == 1')
215 tree.Project(
'mc_NwB0bar',
'abs(' + method +
'_qrCombined)',
' ' + method +
'_qrCombined*qrMC < 0 && qrMC == -1')
218 histo_avr_r.Divide(histo_entries_per_bin)
219 histo_avr_rB0.Divide(histo_entries_per_binB0)
220 histo_avr_rB0bar.Divide(histo_entries_per_binB0bar)
222 histo_ms_r.Divide(histo_entries_per_bin)
223 histo_ms_rB0.Divide(histo_entries_per_binB0)
224 histo_ms_rB0bar.Divide(histo_entries_per_binB0bar)
228 histo_calib_B0.Divide(hallo12)
229 histo_calib_B0bar.Divide(hallo12)
233 print(
'****************************** CALIBRATION CHECK FOR COMBINER USING ' +
234 method +
' ***************************************')
236 print(
'Fit ploynomial of first order to the calibration plot. Expected value ~0.5')
238 histo_calib_B0.Fit(diag,
'TEST')
240 print(
'****************************** MEASURED EFFECTIVE EFFICIENCY FOR COMBINER USING ' +
241 method +
' ***********************************')
245 total_tagged = histo_entries_per_bin.GetEntries()
246 total_tagged_B0 = histo_entries_per_binB0.GetEntries()
247 total_tagged_B0bar = histo_entries_per_binB0bar.GetEntries()
248 total_notTagged = histo_notTaggedEvents.GetEntries()
249 total_entries = (total_tagged + total_notTagged)
251 total_entriesB0 = (total_tagged_B0 + total_notTagged / 2)
252 total_entriesB0bar = (total_tagged_B0bar + total_notTagged / 2)
254 tagging_eff = total_tagged / (total_tagged + total_notTagged)
255 DeltaTagging_eff = math.sqrt(total_tagged * total_notTagged**2 + total_notTagged * total_tagged**2) / (total_entries**2)
259 uncertainty_eff_effB0 = 0
260 uncertainty_eff_effB0bar = 0
261 uncertainty_eff_effAverage = 0
262 diff_eff_Uncertainty = 0
263 event_fractionB0 = array(
'f', [0] * r_size)
264 event_fractionB0bar = array(
'f', [0] * r_size)
265 event_fractionTotal = array(
'f', [0] * r_size)
266 event_fractionTotalUncertainty = array(
'f', [0] * r_size)
267 eventsInBin_B0 = array(
'f', [0] * r_size)
268 eventsInBin_B0bar = array(
'f', [0] * r_size)
269 eventsInBin_Total = array(
'f', [0] * r_size)
270 event_fractionDiff = array(
'f', [0] * r_size)
271 event_fractionDiffUncertainty = array(
'f', [0] * r_size)
272 rvalueB0 = array(
'f', [0] * r_size)
273 rvalueB0bar = array(
'f', [0] * r_size)
274 rvalueB0Average = array(
'f', [0] * r_size)
275 rvalueStdB0 = array(
'f', [0] * r_size)
276 rvalueStdB0bar = array(
'f', [0] * r_size)
277 rvalueStdB0Average = array(
'f', [0] * r_size)
278 wvalue = array(
'f', [0] * r_size)
279 wvalueUncertainty = array(
'f', [0] * r_size)
280 wvalueB0 = array(
'f', [0] * r_size)
281 wvalueB0bar = array(
'f', [0] * r_size)
282 wvalueB0Uncertainty = array(
'f', [0] * r_size)
283 wvalueB0barUncertainty = array(
'f', [0] * r_size)
284 wvalueDiff = array(
'f', [0] * r_size)
285 wvalueDiffUncertainty = array(
'f', [0] * r_size)
286 entries = array(
'f', [0] * r_size)
287 entriesB0 = array(
'f', [0] * r_size)
288 entriesB0bar = array(
'f', [0] * r_size)
289 iEffEfficiency = array(
'f', [0] * r_size)
290 iEffEfficiencyUncertainty = array(
'f', [0] * r_size)
291 iEffEfficiencyB0Uncertainty = array(
'f', [0] * r_size)
292 iEffEfficiencyB0barUncertainty = array(
'f', [0] * r_size)
293 iEffEfficiencyB0UncertaintyFromOutput = array(
'f', [0] * r_size)
294 iEffEfficiencyB0barUncertaintyFromOutput = array(
'f', [0] * r_size)
296 iDeltaEffEfficiency = array(
'f', [0] * r_size)
297 iDeltaEffEfficiencyUncertainty = array(
'f', [0] * r_size)
298 muParam = array(
'f', [0] * r_size)
299 muParamUncertainty = array(
'f', [0] * r_size)
302 print(
'* --> DETERMINATION BASED ON MONTE CARLO ' +
306 print(
'* Note: mu = Delta_Effcy/(2*Efficiency). Needed for CP analysis ' +
307 'together with w and Delta_w *')
310 print(
'* ------------------------------------------------------------------' +
311 '-------------------------------------------------- *')
312 print(
'* r-interval <r> Efficiency Delta_Effcy ' +
314 print(
'* ------------------------------------------------------------------' +
315 '-------------------------------------------------- *')
317 for i
in range(1, r_size):
319 entries[i] = histo_entries_per_bin.GetBinContent(i)
320 entriesB0[i] = histo_entries_per_binB0.GetBinContent(i)
321 entriesB0bar[i] = histo_entries_per_binB0bar.GetBinContent(i)
324 event_fractionB0[i] = entriesB0[i] / total_entriesB0
325 event_fractionB0bar[i] = entriesB0bar[i] / total_entriesB0bar
330 event_fractionTotal[i] = (event_fractionB0[i] + event_fractionB0bar[i]) / 2
331 event_fractionDiff[i] = event_fractionB0[i] - event_fractionB0bar[i]
333 event_fractionDiffUncertainty[i] = math.sqrt(entriesB0[i] *
338 (total_entriesB0bar -
340 total_entriesB0bar**3)
342 event_fractionTotalUncertainty[i] = event_fractionDiffUncertainty[i] / 2
344 rvalueB0[i] = histo_avr_rB0.GetBinContent(i)
345 rvalueB0bar[i] = histo_avr_rB0bar.GetBinContent(i)
346 rvalueB0Average[i] = histo_avr_r.GetBinContent(i)
347 rvalueStdB0[i] = math.sqrt(histo_ms_rB0.GetBinContent(
348 i) - (histo_avr_rB0.GetBinContent(i))**2) / math.sqrt(entriesB0[i] - 1)
349 rvalueStdB0bar[i] = math.sqrt(histo_ms_rB0bar.GetBinContent(
350 i) - (histo_avr_rB0bar.GetBinContent(i))**2) / math.sqrt(entriesB0bar[i] - 1)
351 rvalueStdB0Average[i] = math.sqrt(rvalueStdB0[i]**2 + rvalueStdB0bar[i]**2) / 2
355 wvalueB0[i] = histo_mc_NwB0.GetBinContent(i) / entriesB0[i]
356 wvalueB0bar[i] = histo_mc_NwB0bar.GetBinContent(i) / entriesB0bar[i]
357 wvalueDiff[i] = wvalueB0[i] - wvalueB0bar[i]
358 wvalueB0Uncertainty[i] = math.sqrt(histo_mc_NwB0.GetBinContent(
359 i) * (entriesB0[i] - histo_mc_NwB0.GetBinContent(i)) / (entriesB0[i]**3))
360 wvalueB0barUncertainty[i] = math.sqrt(histo_mc_NwB0bar.GetBinContent(
361 i) * (entriesB0bar[i] - histo_mc_NwB0bar.GetBinContent(i)) / (entriesB0bar[i]**3))
363 wvalueDiffUncertainty[i] = math.sqrt(wvalueB0Uncertainty[i]**2 + wvalueB0barUncertainty[i]**2)
364 wvalue[i] = (wvalueB0[i] + wvalueB0bar[i]) / 2
365 wvalueUncertainty[i] = wvalueDiffUncertainty[i] / 2
372 iEffEfficiency[i] = event_fractionTotal[i] * (1 - 2 * wvalue[i])**2
374 iEffEfficiencyUncertainty[i] = (1 - 2 * wvalue[i]) * \
375 math.sqrt((2 * event_fractionTotal[i] * 2 * wvalueUncertainty[i])**2 +
376 (1 - 2 * wvalue[i])**2 * event_fractionTotalUncertainty[i]**2)
399 average_eff_eff += iEffEfficiency[i]
404 iDeltaEffEfficiency[i] = event_fractionB0[i] * (1 - 2 * wvalueB0[i])**2 - \
405 event_fractionB0bar[i] * (1 - 2 * wvalueB0bar[i])**2
407 iEffEfficiencyB0Uncertainty[i] = (1 - 2 * wvalueB0[i]) * \
408 math.sqrt((2 * total_entriesB0 * entriesB0[i] * 2 * wvalueB0Uncertainty[i])**2 +
409 (1 - 2 * wvalueB0[i])**2 * entriesB0[i] *
410 total_entriesB0 * (total_entriesB0 - entriesB0[i])) / (total_entriesB0**2)
411 iEffEfficiencyB0barUncertainty[i] = (1 - 2 * wvalueB0bar[i]) * \
412 math.sqrt((2 * total_entriesB0bar * entriesB0bar[i] * 2 * wvalueB0barUncertainty[i])**2 +
413 (1 - 2 * wvalueB0bar[i])**2 * entriesB0bar[i] *
414 total_entriesB0bar * (total_entriesB0bar - entriesB0bar[i])) / (total_entriesB0bar**2)
416 iDeltaEffEfficiencyUncertainty[i] = math.sqrt(iEffEfficiencyB0Uncertainty[i]**2 + iEffEfficiencyB0barUncertainty[i]**2)
419 diff_eff_Uncertainty = diff_eff_Uncertainty + iDeltaEffEfficiencyUncertainty[i]**2
422 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * (1 - 2 * wvalueB0[i])**2
423 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * (1 - 2 * wvalueB0bar[i])**2
424 uncertainty_eff_effAverage = uncertainty_eff_effAverage + iEffEfficiencyUncertainty[i]**2
425 uncertainty_eff_effB0 = uncertainty_eff_effB0 + iEffEfficiencyB0Uncertainty[i]**2
426 uncertainty_eff_effB0bar = uncertainty_eff_effB0bar + iEffEfficiencyB0barUncertainty[i]**2
427 muParam[i] = event_fractionDiff[i] / (2 * event_fractionTotal[i])
428 muParamUncertainty[i] = event_fractionDiffUncertainty[i] / (2 * event_fractionTotal[i]) * math.sqrt(muParam[i]**2 + 1)
431 print(
'* ' +
'{:.3f}'.format(r_subsample[i - 1]) +
' - ' +
'{:.3f}'.format(r_subsample[i]) +
' ' +
432 '{:.3f}'.format(rvalueB0Average[i]) +
' +- ' +
'{:.4f}'.format(rvalueStdB0Average[i]) +
' ' +
433 '{:.4f}'.format(event_fractionTotal[i]) +
' ' +
434 '{: .4f}'.format(event_fractionDiff[i]) +
' +- ' +
'{:.4f}'.format(event_fractionDiffUncertainty[i]) +
' ' +
435 '{: .4f}'.format(muParam[i]) +
' +- ' +
'{:.4f}'.format(muParamUncertainty[i]) +
' ' +
436 '{:.4f}'.format(wvalue[i]) +
' +- ' +
'{:.4f}'.format(wvalueUncertainty[i]) +
' ' +
437 '{: .4f}'.format(wvalueDiff[i]) +
' +- ' +
'{:.4f}'.format(wvalueDiffUncertainty[i]) +
' *')
440 uncertainty_eff_effAverage = math.sqrt(uncertainty_eff_effAverage)
441 uncertainty_eff_effB0 = math.sqrt(uncertainty_eff_effB0)
442 uncertainty_eff_effB0bar = math.sqrt(uncertainty_eff_effB0bar)
443 diff_eff = tot_eff_effB0 - tot_eff_effB0bar
444 diff_eff_Uncertainty = math.sqrt(diff_eff_Uncertainty)
445 print(
'* --------------------------------------------------------------------------------------------------' +
446 '------------------ *')
448 print(
'* __________________________________________________________________________________________ *')
450 print(
'* | TOTAL NUMBER OF TAGGED EVENTS = ' +
451 '{:<24}'.format(
"%.0f" % total_tagged) +
'{:>36}'.format(
'| *'))
454 '* | TOTAL AVERAGE EFFICIENCY (q=+-1)= ' +
465 '* | TOTAL AVERAGE EFFECTIVE EFFICIENCY (q=+-1)= ' +
471 uncertainty_eff_effAverage *
476 '* | TOTAL AVERAGE EFFECTIVE EFFICIENCY ASYMMETRY (q=+-1)= ' +
482 diff_eff_Uncertainty *
486 print(
'* | B0-TAGGER TOTAL EFFECTIVE EFFICIENCIES: ' +
487 '{:.2f}'.format(tot_eff_effB0 * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0 * 100) +
489 '{:.2f}'.format(tot_eff_effB0bar * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0bar * 100) +
490 ' % (q=-1) ' +
' | *')
492 print(
'* | FLAVOR PERCENTAGE (MC): ' +
493 '{:.2f}'.format(total_tagged_B0 / total_tagged * 100) +
' % (q=+1) ' +
494 '{:.2f}'.format(total_tagged_B0bar / total_tagged * 100) +
' % (q=-1) Diff=' +
495 '{:^5.2f}'.format((total_tagged_B0 - total_tagged_B0bar) / total_tagged * 100) +
' % | *')
496 print(
'* |__________________________________________________________________________________________| *')
498 print(
'****************************************************************************************************')
502 print(
'* --------------------------------- *')
503 print(
'* Efficiency Determination - easiest way *')
504 print(
'* --------------------------------- *')
505 total_tagged_B0 = histo_belleplotB0.GetEntries()
506 total_tagged_B0Bar = histo_belleplotB0bar.GetEntries()
507 total_tagged_wrong = histo_m1.GetEntries()
508 total_tagged_B0Bar_wrong = histo_m2.GetEntries()
509 total_tagged = total_tagged_B0 + total_tagged_B0Bar
510 total_tagged_wrong = total_tagged_wrong + total_tagged_B0Bar_wrong
512 wrong_tag_fraction_B0 = total_tagged_wrong / total_tagged_B0
513 wrong_tag_fraction_B0Bar = total_tagged_B0Bar_wrong / total_tagged_B0Bar
514 wrong_tag_fraction = total_tagged_wrong / total_tagged
515 right_tag_fraction_B0 = 1 - 2 * wrong_tag_fraction_B0
516 right_tag_fraction_B0Bar = 1 - 2 * wrong_tag_fraction_B0Bar
517 right_tag_fraction = 1 - 2 * wrong_tag_fraction
518 wrong_eff_B0 = right_tag_fraction_B0 * right_tag_fraction_B0
519 wrong_eff_B0Bar = right_tag_fraction_B0Bar * right_tag_fraction_B0Bar
520 wrong_eff = right_tag_fraction * right_tag_fraction
522 print(
'* wrong_tag_fraction for all: ' +
523 '{:.3f}'.format(wrong_tag_fraction * 100) +
525 print(
'* right_tag_fraction for all: ' +
526 '{:.3f}'.format(right_tag_fraction * 100) +
528 print(
'* wrong calculated eff all: ' +
'{:.3f}'.format(wrong_eff * 100) +
531 print(
'****************************************************************************************************')
533 print(
'Table For B2TIP')
546 maxB0 = histo_belleplotB0.GetBinContent(histo_belleplotB0.GetMaximumBin())
547 maxB0bar = histo_belleplotB0bar.GetBinContent(histo_belleplotB0bar.GetMaximumBin())
549 Ymax = max(maxB0, maxB0bar)
550 Ymax = Ymax + Ymax / 12
552 if YmaxForQrPlot < Ymax:
556 ROOT.gStyle.SetOptStat(0)
557 Canvas1 = ROOT.TCanvas(
'Bla' + method,
'Final Output', 1200, 800)
559 histo_belleplotB0.SetFillColorAlpha(ROOT.kBlue, 0.2)
560 histo_belleplotB0.SetFillStyle(1001)
561 histo_belleplotB0.GetYaxis().SetLabelSize(0.03)
562 histo_belleplotB0.GetYaxis().SetLimits(0, YmaxForQrPlot)
563 histo_belleplotB0.GetYaxis().SetTitleOffset(1.2)
564 histo_belleplotB0.SetLineColor(ROOT.kBlue)
565 histo_belleplotB0bar.SetFillColorAlpha(ROOT.kRed, 1.0)
566 histo_belleplotB0bar.SetFillStyle(3005)
567 histo_belleplotB0bar.SetLineColor(ROOT.kRed)
570 histo_belleplotB0.SetTitle(
'Final Flavor Tagger Output; #it{qr}-output ; Events'
572 histo_belleplotB0.SetMinimum(0)
573 histo_belleplotB0.SetMaximum(YmaxForQrPlot)
574 histo_belleplotB0.Draw(
'hist')
575 histo_belleplotB0bar.Draw(
'hist same')
577 leg = ROOT.TLegend(0.75, 0.8, 0.9, 0.9)
578 leg.AddEntry(histo_belleplotB0,
'true B0')
579 leg.AddEntry(histo_belleplotB0bar,
'true B0bar')
584 with Quiet(ROOT.kError):
585 Canvas1.SaveAs(workingDirectory +
'/' +
'PIC_Belleplot_both' + method +
'.pdf')
588 Canvas2 = ROOT.TCanvas(
'Bla2' + method,
'Calibration plot for true B0', 1200, 800)
590 histo_calib_B0.SetFillColorAlpha(ROOT.kBlue, 0.2)
591 histo_calib_B0.SetFillStyle(1001)
592 histo_calib_B0.GetYaxis().SetTitleOffset(1.2)
593 histo_calib_B0.SetLineColor(ROOT.kBlue)
595 histo_calib_B0.SetTitle(
'Calibration For True B0; #it{qr}-output ; Calibration '
597 histo_calib_B0.Draw(
'hist')
600 with Quiet(ROOT.kError):
601 Canvas2.SaveAs(workingDirectory +
'/' +
'PIC_Calibration_B0' + method +
'.pdf')
604 histo_avr_rB0.Delete()
605 histo_avr_rB0bar.Delete()
607 histo_ms_rB0.Delete()
608 histo_ms_rB0bar.Delete()
609 histo_mc_NwB0.Delete()
610 histo_mc_NwB0bar.Delete()
611 histo_notTaggedEvents.Delete()
612 histo_entries_per_bin.Delete()
613 histo_entries_per_binB0.Delete()
614 histo_entries_per_binB0bar.Delete()
615 histo_Cnet_output_B0.Delete()
616 histo_Cnet_output_B0bar.Delete()
617 histo_belleplotB0.Delete()
618 histo_belleplotB0bar.Delete()
619 histo_calib_B0.Delete()
620 histo_calib_B0bar.Delete()
628 print(
r'\begin{tabularx}{1\textwidth}{@{}r r r r r r r@{}}')
630 print(
r'$r$- Interval $\enskip$ & $\varepsilon_i\ $ & $\Delta\varepsilon_i\ $ & $w_i \pm \delta w_i\enskip\; $ ' +
631 r' & $\Delta w_i \pm \delta\Delta w_i $& $\varepsilon_{\text{eff}, i} \pm \delta\varepsilon_{\text{eff}, i}\enskip\, $ ' +
632 r' & $\Delta \varepsilon_{\text{eff}, i} \pm \delta\Delta \varepsilon_{\text{eff}, i}\enskip\, $\\ \hline\hline')
633 for i
in range(1, r_size):
634 print(
'$ ' +
'{:.3f}'.format(r_subsample[i - 1]) +
' - ' +
'{:.3f}'.format(r_subsample[i]) +
'$ & $'
635 '{: 6.1f}'.format(event_fractionTotal[i] * 100) +
r'$ & $' +
636 '{: 7.2f}'.format(event_fractionDiff[i] * 100) +
r'\;$ & $' +
637 '{: 7.2f}'.format(wvalue[i] * 100) +
r" \pm " +
'{:2.2f}'.format(wvalueUncertainty[i] * 100) +
r'\enskip $ & $' +
638 '{: 7.2f}'.format(wvalueDiff[i] * 100) +
r" \pm " +
639 '{:2.2f}'.format(wvalueDiffUncertainty[i] * 100) +
r'\enskip $ & $' +
640 '{: 8.4f}'.format(iEffEfficiency[i] * 100) +
641 r" \pm " +
'{:2.4f}'.format(iEffEfficiencyUncertainty[i] * 100) +
r'\, $ & $' +
642 '{: 6.4f}'.format(iDeltaEffEfficiency[i] * 100) +
643 r" \pm " +
'{:2.4f}'.format(iDeltaEffEfficiencyUncertainty[i] * 100) +
644 r'\enskip\enskip $ \\ ')
645 print(
r'\hline\hline')
646 print(
r'\multicolumn{1}{r}{Total} & & \multicolumn{5}{r}{ $\varepsilon_\text{eff} = ' +
647 r'\sum_i \varepsilon_i \cdot \langle 1-2w_i\rangle^2 = ' +
648 '{: 6.2f}'.format(average_eff_eff * 100) +
r" \pm " +
'{: 6.2f}'.format(uncertainty_eff_effAverage * 100) +
r'\enskip\, ')
649 print(
r'\Delta \varepsilon_\text{eff} = ' +
650 '{: 6.2f}'.format(diff_eff * 100) +
r" \pm " +
'{: 6.2f}'.format(diff_eff_Uncertainty * 100) +
r'\quad\ $ }' +
653 print(
r'\end{tabular}')
657 print(
'Mu-Values for Table')
660 for i
in range(1, r_size):
661 print(
'$ ' +
'{:.3f}'.format(r_subsample[i - 1]) +
' - ' +
'{:.3f}'.format(r_subsample[i]) +
'$ & $'
662 '{: 7.2f}'.format(muParam[i] * 100) +
r" \pm " +
'{:2.2f}'.format(muParamUncertainty[i] * 100) +
r' $ & ')
703 print(ft.eventLevelParticleLists)
706 print(
'******************************************* MEASURED EFFECTIVE EFFICIENCY FOR INDIVIDUAL CATEGORIES ' +
707 '**********************************************')
712 categoriesPerformance = []
713 NbinsCategories = 100
714 for (particleList, category, combinerVariable)
in ft.eventLevelParticleLists:
716 hist_both = ROOT.TH1F(
'Both_' + category,
'Input Both (B0) ' +
717 category +
' (binning)', NbinsCategories, -1.0, 1.0)
719 hist_signal = ROOT.TH1F(
'Signal_' + category,
'Input Signal (B0) ' +
720 category +
' (binning)', NbinsCategories, -1.0, 1.0)
722 hist_background = ROOT.TH1F(
'Background_' + category,
'Input Background (B0bar) ' +
723 category +
' (binning)', NbinsCategories, -1.0, 1.0)
727 hist_probB0 = ROOT.TH1F(
'Probability' + category,
728 'Transformed to probability (B0) (' + category +
')',
729 NbinsCategories, 0.0, 1.0)
730 hist_probB0bar = ROOT.TH1F(
'ProbabilityB0bar_' + category,
731 'Transformed to probability (B0bar) (' + category +
')',
732 NbinsCategories, 0.0, 1.0)
734 hist_qrB0 = ROOT.TH1F(
'QR' + category,
'Transformed to qp (B0)(' +
735 category +
')', NbinsCategories, -1.0, 1.0)
736 hist_qrB0bar = ROOT.TH1F(
'QRB0bar_' + category,
'Transformed to qp (B0bar) (' +
737 category +
')', NbinsCategories, -1.0, 1.0)
740 histo_entries_per_bin = ROOT.TH1F(
'entries_per_bin_' + category,
'Abs(qp)(B0) (' + category +
')', int(r_size - 2), r_subsample)
741 histo_entries_per_binB0 = ROOT.TH1F(
'entries_per_bin' + category,
'Abs(qp)(B0) (' +
742 category +
')', int(r_size - 2), r_subsample)
743 histo_entries_per_binB0bar = ROOT.TH1F(
'entries_per_binB0bar_' + category,
744 'Abs(qp) (B0bar) (' + category +
')', int(r_size - 2), r_subsample)
748 hist_avr_rB0 = ROOT.TH1F(
'Average_r' + category,
'Average r for B0' +
749 category, int(r_size - 2), r_subsample)
750 hist_avr_rB0bar = ROOT.TH1F(
'Average_rB0bar_' + category,
'Average r for B0bar' +
751 category, int(r_size - 2), r_subsample)
753 hist_ms_rB0 = ROOT.TH1F(
'AverageSqrdR' + category,
'Average r sqrd for B0' +
754 category, int(r_size - 2), r_subsample)
755 hist_ms_rB0bar = ROOT.TH1F(
'AverageSqrdRB0bar_' + category,
'Average r sqrd for B0bar' +
756 category, int(r_size - 2), r_subsample)
760 hist_all = ROOT.TH1F(
'All_' + category,
'Input Signal (B0) and Background (B0Bar)' +
761 category +
' (binning 50)', 50, 0.0, 1.0)
762 hist_calib_B0 = ROOT.TH1F(
'Calib_' + category,
'Calibration Plot for true B0' +
763 category +
' (binning 50)', 50, 0.0, 1.0)
766 if category !=
"KaonNotWeighted" and category !=
"LambdaNotWeighted":
768 tree.Draw(
'qp' + category +
'>>Both_' + category,
'abs(qrMC) == 1.0')
770 tree.Draw(
'qp' + category +
'>>Signal_' + category,
'qrMC == 1.0')
772 tree.Draw(
'qp' + category +
'>>Background_' + category,
'qrMC == -1.0')
773 tree.Draw(
'qp' + category +
'>>All_' + category,
'qrMC!=0')
774 tree.Draw(
'qp' + category +
'>>Calib_' + category,
'qrMC == 1.0')
784 elif category ==
"KaonNotWeighted":
785 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Both_' + category,
'abs(qrMC) == 1.0')
786 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Signal_' + category,
'qrMC == 1.0')
787 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Background_' + category,
'qrMC == -1.0')
788 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>All_' + category,
'qrMC!=0')
789 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Calib_' + category,
'qrMC == 1.0')
791 elif category ==
"LambdaNotWeighted":
792 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Both_' + category,
'abs(qrMC) == 1.0')
793 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Signal_' + category,
'qrMC == 1.0')
794 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Background_' + category,
'qrMC == -1.0')
795 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>All_' + category,
'qrMC!=0')
796 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Calib_' + category,
'qrMC == 1.0')
798 hist_calib_B0.Divide(hist_all)
801 maxSignal = hist_signal.GetBinContent(hist_signal.GetMaximumBin())
802 maxBackground = hist_background.GetBinContent(hist_background.GetMaximumBin())
804 Ymax = max(maxSignal, maxBackground)
805 Ymax = Ymax + Ymax / 12
807 ROOT.gStyle.SetOptStat(0)
808 with Quiet(ROOT.kError):
809 Canvas = ROOT.TCanvas(
'Bla',
'TITEL BLA', 1200, 800)
812 hist_signal.SetFillColorAlpha(ROOT.kBlue, 0.2)
813 hist_signal.SetFillStyle(1001)
814 hist_signal.SetTitleSize(0.1)
815 hist_signal.GetXaxis().SetLabelSize(0.04)
816 hist_signal.GetYaxis().SetLabelSize(0.04)
817 hist_signal.GetXaxis().SetTitleSize(0.05)
818 hist_signal.GetYaxis().SetTitleSize(0.05)
819 hist_signal.GetXaxis().SetTitleOffset(0.95)
820 hist_signal.GetYaxis().SetTitleOffset(1.1)
821 hist_signal.GetYaxis().SetLimits(0, Ymax)
822 hist_signal.SetLineColor(ROOT.kBlue)
823 hist_background.SetFillColorAlpha(ROOT.kRed, 1.0)
824 hist_background.SetFillStyle(3005)
825 hist_background.GetYaxis().SetLimits(0, Ymax)
826 hist_background.SetLineColor(ROOT.kRed)
828 hist_signal.SetTitle(category +
' category; #it{qp}-Output ; Events')
830 hist_signal.SetMaximum(Ymax)
832 hist_background.SetMaximum(Ymax)
834 hist_signal.Draw(
'hist')
835 hist_background.Draw(
'hist same')
837 if category ==
'MaximumPstar':
838 legend = ROOT.TLegend(0.4, 0.75, 0.6, 0.9)
840 legend = ROOT.TLegend(0.6, 0.75, 0.8, 0.9)
841 legend.AddEntry(hist_signal,
'true B0')
842 legend.AddEntry(hist_background,
'true B0bar')
843 legend.SetTextSize(0.05)
847 with Quiet(ROOT.kError):
848 Canvas.SaveAs(workingDirectory +
'/' +
'PIC_' + category +
'_Input_Combiner.pdf')
853 binCounter = int(NbinsCategories + 1)
854 dilutionB02 = array(
'd', [0] * binCounter)
855 dilutionB0bar2 = array(
'd', [0] * binCounter)
856 purityB0 = array(
'd', [0] * binCounter)
857 purityB0bar = array(
'd', [0] * binCounter)
858 signal = array(
'd', [0] * binCounter)
859 back = array(
'd', [0] * binCounter)
860 weight = array(
'd', [0] * binCounter)
862 for i
in range(1, binCounter):
864 signal[i] = hist_signal.GetBinContent(i)
865 back[i] = hist_background.GetBinContent(i)
866 weight[i] = signal[i] + back[i]
869 if signal[i] + back[i] == 0:
873 dilutionB0bar2[i] = 0
876 purityB0[i] = signal[i] / (signal[i] + back[i])
877 dilutionB02[i] = -1 + 2 * signal[i] / (signal[i] + back[i])
879 purityB0bar[i] = back[i] / (signal[i] + back[i])
880 dilutionB0bar2[i] = -1 + 2 * back[i] / (signal[i] + back[i])
883 hist_probB0.Fill(purityB0[i], signal[i])
884 hist_probB0bar.Fill(purityB0bar[i], back[i])
887 hist_qrB0.Fill(dilutionB02[i], signal[i])
888 hist_qrB0bar.Fill(dilutionB0bar2[i], back[i])
891 histo_entries_per_binB0.Fill(abs(dilutionB02[i]), signal[i])
892 histo_entries_per_binB0bar.Fill(abs(dilutionB0bar2[i]), back[i])
894 hist_avr_rB0.Fill(abs(dilutionB02[i]), abs(dilutionB02[i]) * signal[i])
895 hist_avr_rB0bar.Fill(abs(dilutionB0bar2[i]), abs(dilutionB0bar2[i]) * back[i])
897 hist_ms_rB0.Fill(abs(dilutionB02[i]), abs(dilutionB02[i] * dilutionB02[i]) * signal[i])
898 hist_ms_rB0bar.Fill(abs(dilutionB0bar2[i]), abs(dilutionB0bar2[i] * dilutionB02[i]) * back[i])
901 hist_avr_rB0.Divide(histo_entries_per_binB0)
902 hist_avr_rB0bar.Divide(histo_entries_per_binB0bar)
904 hist_ms_rB0.Divide(histo_entries_per_binB0)
905 hist_ms_rB0bar.Divide(histo_entries_per_binB0bar)
909 total_entriesB0 = total_notTagged / 2
910 total_entriesB0bar = total_notTagged / 2
911 for i
in range(1, r_size):
912 total_entriesB0 = total_entriesB0 + histo_entries_per_binB0.GetBinContent(i)
913 total_entriesB0bar = total_entriesB0bar + histo_entries_per_binB0bar.GetBinContent(i)
917 uncertainty_eff_effB0 = 0
918 uncertainty_eff_effB0bar = 0
919 uncertainty_eff_effAverage = 0
920 diff_eff_Uncertainty = 0
921 event_fractionB0 = array(
'f', [0] * r_size)
922 event_fractionB0bar = array(
'f', [0] * r_size)
923 rvalueB0 = array(
'f', [0] * r_size)
924 rvalueB0bar = array(
'f', [0] * r_size)
925 rvalueStdB0 = array(
'f', [0] * r_size)
926 rvalueStdB0bar = array(
'f', [0] * r_size)
928 entriesBoth = array(
'f', [0] * r_size)
929 entriesB0 = array(
'f', [0] * r_size)
930 entriesB0bar = array(
'f', [0] * r_size)
931 iEffEfficiencyB0Uncertainty = array(
'f', [0] * r_size)
932 iEffEfficiencyB0barUncertainty = array(
'f', [0] * r_size)
933 iDeltaEffEfficiencyUncertainty = array(
'f', [0] * r_size)
935 for i
in range(1, r_size):
937 entriesBoth[i] = entriesB0bar[i] + entriesB0[i]
938 entriesB0[i] = histo_entries_per_binB0.GetBinContent(i)
939 entriesB0bar[i] = histo_entries_per_binB0bar.GetBinContent(i)
940 event_fractionB0[i] = entriesB0[i] / total_entriesB0
941 event_fractionB0bar[i] = entriesB0bar[i] / total_entriesB0bar
946 rvalueB0[i] = hist_avr_rB0.GetBinContent(i)
947 rvalueB0bar[i] = hist_avr_rB0bar.GetBinContent(i)
950 rvalueStdB0bar[i] = 0
953 rvalueStdB0[i] = math.sqrt(abs(hist_ms_rB0.GetBinContent(
954 i) - (hist_avr_rB0.GetBinContent(i))**2)) / math.sqrt(entriesB0[i] - 1)
956 if entriesB0bar[i] > 1:
957 rvalueStdB0bar[i] = math.sqrt(abs(hist_ms_rB0bar.GetBinContent(
958 i) - (hist_avr_rB0bar.GetBinContent(i))**2)) / math.sqrt(entriesB0bar[i] - 1)
961 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] \
963 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] \
966 iEffEfficiencyB0Uncertainty[i] = rvalueB0[i] * \
967 math.sqrt((2 * total_entriesB0 * entriesB0[i] * rvalueStdB0[i])**2 +
968 rvalueB0[i]**2 * entriesB0[i] *
969 (total_entriesB0 * (total_entriesB0 - entriesB0[i]) +
970 entriesB0[i] * total_notTagged)) / (total_entriesB0**2)
971 iEffEfficiencyB0barUncertainty[i] = rvalueB0bar[i] * \
972 math.sqrt((2 * total_entriesB0bar * entriesB0bar[i] * rvalueStdB0bar[i])**2 +
973 rvalueB0bar[i]**2 * entriesB0bar[i] *
974 (total_entriesB0bar * (total_entriesB0bar - entriesB0bar[i]) +
975 entriesB0bar[i] * total_notTagged)) / (total_entriesB0bar**2)
977 iDeltaEffEfficiencyUncertainty[i] = math.sqrt(iEffEfficiencyB0Uncertainty[i]**2 + iEffEfficiencyB0barUncertainty[i]**2)
979 diff_eff_Uncertainty = diff_eff_Uncertainty + iDeltaEffEfficiencyUncertainty[i]**2
981 uncertainty_eff_effB0 = uncertainty_eff_effB0 + iEffEfficiencyB0Uncertainty[i]**2
982 uncertainty_eff_effB0bar = uncertainty_eff_effB0bar + iEffEfficiencyB0barUncertainty[i]**2
984 effDiff = tot_eff_effB0 - tot_eff_effB0bar
985 effAverage = (tot_eff_effB0 + tot_eff_effB0bar) / 2
987 uncertainty_eff_effB0 = math.sqrt(uncertainty_eff_effB0)
988 uncertainty_eff_effB0bar = math.sqrt(uncertainty_eff_effB0bar)
989 diff_eff_Uncertainty = math.sqrt(diff_eff_Uncertainty)
990 uncertainty_eff_effAverage = diff_eff_Uncertainty / 2
992 '{:<25}'.format(
"* " + category) +
' B0-Eff=' +
993 '{: 8.2f}'.format(tot_eff_effB0 * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0 * 100) +
996 '{: 8.2f}'.format(tot_eff_effB0bar * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0bar * 100) +
999 '{: 8.2f}'.format(effAverage * 100) +
" +- " +
'{:4.2f}'.format(uncertainty_eff_effAverage * 100) +
' %' +
1001 '{: 8.2f}'.format(effDiff * 100) +
" +- " +
'{:4.2f}'.format(diff_eff_Uncertainty * 100) +
' % *')
1015 categoriesPerformance.append((category, effAverage, uncertainty_eff_effAverage, effDiff, diff_eff_Uncertainty))
1016 with Quiet(ROOT.kError):
1025 print(
'**************************************************************************************************************************' +
1026 '************************')
1028 print(
'Table For B2TIP')
1030 print(
r'\begin{tabular}{ l r r }')
1032 print(
r'Categories & $\varepsilon_\text{eff} \pm \delta\varepsilon_\text{eff} $& ' +
1033 r'$\Delta\varepsilon_\text{eff} \pm \delta\Delta\varepsilon_\text{eff}$\\ \hline\hline')
1034 for (category, effAverage, uncertainty_eff_effAverage, effDiff, diff_eff_Uncertainty)
in categoriesPerformance:
1036 '{:<23}'.format(category) +
1038 '{: 6.2f}'.format(effAverage * 100) +
r" \pm " +
'{:4.2f}'.format(uncertainty_eff_effAverage * 100) +
1040 '{: 6.2f}'.format(effDiff * 100) +
r" \pm " +
'{:4.2f}'.format(diff_eff_Uncertainty * 100) +
1043 print(
r'\end{tabular}')
1044 B2INFO(
'qp Output Histograms in pdf format saved at: ' + workingDirectory)
1045 with open(
"categoriesPerformance.pkl",
"wb")
as f:
1046 pickle.dump(categoriesPerformance, f)