22 from basf2
import B2INFO
23 import flavorTagger
as ft
24 from defaultEvaluationParameters
import categories, Quiet, r_subsample, r_size
25 from array
import array
31 ROOT.gROOT.SetBatch(
True)
33 if len(sys.argv) != 3:
34 sys.exit(
"Must provide 2 arguments: [input_sim_file] or ['input_sim_file*'] with wildcards and [treeName]"
36 workingFile = sys.argv[1]
37 workingFiles = glob.glob(str(workingFile))
38 treeName = str(sys.argv[2])
40 if len(workingFiles) < 1:
41 sys.exit(
"No file name or file names " + str(workingFile) +
" found.")
44 workingDirectory =
'.'
59 tree = ROOT.TChain(treeName)
61 mcstatus = array(
'd', [-511.5, 0.0, 511.5])
62 ROOT.TH1.SetDefaultSumw2()
64 for iFile
in workingFiles:
68 for branch
in tree.GetListOfBranches():
69 totalBranches.append(branch.GetName())
71 if 'FBDT_qrCombined' in totalBranches:
72 methods.append(
"FBDT")
74 if 'FANN_qrCombined' in totalBranches:
75 methods.append(
"FANN")
77 if 'DNN_qrCombined' in totalBranches:
81 for cat
in categories:
82 catBranch =
'qp' + cat
83 if catBranch
in totalBranches:
84 usedCategories.append(cat)
90 for method
in methods:
93 histo_avr_r = ROOT.TH1F(
'Average_r',
'Average r in each of the bins (B0 and B0bar)', int(r_size - 2),
95 histo_avr_rB0 = ROOT.TH1F(
'Average_rB0',
'Average r in each of the bins (B0)', int(r_size - 2),
97 histo_avr_rB0bar = ROOT.TH1F(
'Average_rB0bar',
'Average r in each of the bins (B0bar)', int(r_size - 2),
101 histo_mc_NwB0 = ROOT.TH1F(
'mc_NwB0',
'Average r in each of the bins (B0)', int(r_size - 2),
103 histo_mc_NwB0bar = ROOT.TH1F(
'mc_NwB0bar',
'Average r in each of the bins (B0bar)', int(r_size - 2),
107 histo_ms_r = ROOT.TH1F(
'MS_r',
'Mean squared average of r in each of the bins (B0 and B0bar)', int(r_size - 2),
109 histo_ms_rB0 = ROOT.TH1F(
'MS_rB0',
'Mean squared average of r in each of the bins (B0)', int(r_size - 2),
111 histo_ms_rB0bar = ROOT.TH1F(
'MS_rB0bar',
'Mean squared average of r in each of the bins (B0bar)', int(r_size - 2),
115 histo_entries_per_bin = ROOT.TH1F(
117 'Events binned in r_subsample according to their r-value for B0 and B0bar prob',
120 histo_entries_per_binB0 = ROOT.TH1F(
'entries_per_binB0',
'Events binned in r_subsample according '
121 'to their r-value for B0 prob', int(r_size - 2), r_subsample)
122 histo_entries_per_binB0bar = ROOT.TH1F(
'entries_per_binB0bar',
123 'Events binned in r_subsample according to their r-value '
124 'for B0bar prob', int(r_size - 2), r_subsample)
126 histo_Cnet_output_B0 = ROOT.TH1F(
'Comb_Net_Output_B0',
'Combiner network output [not equal to r] '
127 'for true B0 (binning 100)', 100, 0.0, 1.0)
129 histo_Cnet_output_B0bar = ROOT.TH1F(
'Comb_Net_Output_B0bar',
'Combiner network output [not equal to r] '
130 'for true B0bar (binning 100)', 100, 0.0, 1.0)
132 histo_belleplotB0 = ROOT.TH1F(
'BellePlot_B0',
133 'BellePlot for true B0 (binning 50)', 50,
136 histo_belleplotB0bar = ROOT.TH1F(
'BellePlot_B0Bar',
137 'BellePlot for true B0Bar (binning 50)',
140 histo_notTaggedEvents = ROOT.TH1F(
'notTaggedEvents',
141 'Histogram for not tagged events',
147 histo_calib_B0 = ROOT.TH1F(
'Calibration_B0',
'CalibrationPlot for true B0', 100, -1.0, 1.0)
149 histo_calib_B0bar = ROOT.TH1F(
'Calibration_B0Bar',
150 'CalibrationPlot for true B0Bar', 100, -1.0,
153 hallo12 = ROOT.TH1F(
'BellePlot_NoCut',
'BellePlot_NoCut (binning 100)',
157 diag = ROOT.TF1(
'diag',
'pol1', -1, 1)
161 histo_m0 = ROOT.TH1F(
'BellePlot_m0',
162 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
163 histo_m1 = ROOT.TH1F(
'BellePlot_m1',
164 'BellePlot_m for true B0 (binning 50)', 50, -1.0, 1.0)
165 histo_m2 = ROOT.TH1F(
'BellePlot_m2',
166 'BellePlot_m for true B0Bar (binning 50)', 50, -1.0,
171 tree.Draw(method +
'_qrCombined>>BellePlot_B0',
'qrMC == 1')
172 tree.Draw(method +
'_qrCombined>>BellePlot_B0Bar',
'qrMC == -1')
173 tree.Draw(method +
'_qrCombined>>BellePlot_NoCut',
'abs(qrMC) == 1')
175 tree.Draw(method +
'_qrCombined>>Calibration_B0',
'qrMC == 1')
176 tree.Draw(method +
'_qrCombined>>Calibration_B0Bar',
'qrMC == -1')
178 tree.Draw(method +
'_qrCombined>>notTaggedEvents',
179 'abs(qrMC) == 0 && isSignal == 1 && ' +
180 method +
'_qrCombined < -1')
183 tree.Draw(method +
'_qrCombined>>BellePlot_m0',
184 'qrMC == 1 && ' + method +
'_qrCombined>0')
185 tree.Draw(method +
'_qrCombined>>BellePlot_m1',
186 'qrMC == 1 && ' + method +
'_qrCombined<0')
187 tree.Draw(method +
'_qrCombined>>BellePlot_m2',
188 'qrMC == -1 && ' + method +
'_qrCombined>0 ')
193 tree.Project(
'Average_r',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(abs(qrMC) == 1)')
194 tree.Project(
'Average_rB0',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==1)')
195 tree.Project(
'Average_rB0bar',
'abs(' + method +
'_qrCombined)',
'abs(' + method +
'_qrCombined)*(qrMC==-1)')
197 tree.Project(
'MS_r',
'abs(' + method +
'_qrCombined)',
'(' + method +
198 '_qrCombined*' + method +
'_qrCombined)*(abs(qrMC) == 1)')
199 tree.Project(
'MS_rB0',
'abs(' + method +
'_qrCombined)',
200 '(' + method +
'_qrCombined*' + method +
'_qrCombined)*(qrMC==1)')
201 tree.Project(
'MS_rB0bar',
'abs(' + method +
'_qrCombined)',
202 '(' + method +
'_qrCombined*' + method +
'_qrCombined)*(qrMC==-1)')
205 tree.Project(
'entries_per_bin',
'abs(' + method +
'_qrCombined)',
'abs(qrMC) == 1')
206 tree.Project(
'entries_per_binB0',
'abs(' + method +
'_qrCombined)',
'qrMC == 1')
207 tree.Project(
'entries_per_binB0bar',
'abs(' + method +
'_qrCombined)',
'qrMC == -1')
210 tree.Project(
'mc_NwB0',
'abs(' + method +
'_qrCombined)',
' ' + method +
'_qrCombined*qrMC < 0 && qrMC == 1')
211 tree.Project(
'mc_NwB0bar',
'abs(' + method +
'_qrCombined)',
' ' + method +
'_qrCombined*qrMC < 0 && qrMC == -1')
214 histo_avr_r.Divide(histo_entries_per_bin)
215 histo_avr_rB0.Divide(histo_entries_per_binB0)
216 histo_avr_rB0bar.Divide(histo_entries_per_binB0bar)
218 histo_ms_r.Divide(histo_entries_per_bin)
219 histo_ms_rB0.Divide(histo_entries_per_binB0)
220 histo_ms_rB0bar.Divide(histo_entries_per_binB0bar)
224 histo_calib_B0.Divide(hallo12)
225 histo_calib_B0bar.Divide(hallo12)
229 print(
'****************************** CALIBRATION CHECK FOR COMBINER USING ' +
230 method +
' ***************************************')
232 print(
'Fit ploynomial of first order to the calibration plot. Expected value ~0.5')
234 histo_calib_B0.Fit(diag,
'TEST')
236 print(
'****************************** MEASURED EFFECTIVE EFFICIENCY FOR COMBINER USING ' +
237 method +
' ***********************************')
241 total_tagged = histo_entries_per_bin.GetEntries()
242 total_tagged_B0 = histo_entries_per_binB0.GetEntries()
243 total_tagged_B0bar = histo_entries_per_binB0bar.GetEntries()
244 total_notTagged = histo_notTaggedEvents.GetEntries()
245 total_entries = (total_tagged + total_notTagged)
247 total_entriesB0 = (total_tagged_B0 + total_notTagged / 2)
248 total_entriesB0bar = (total_tagged_B0bar + total_notTagged / 2)
250 tagging_eff = total_tagged / (total_tagged + total_notTagged)
251 DeltaTagging_eff = math.sqrt(total_tagged * total_notTagged**2 + total_notTagged * total_tagged**2) / (total_entries**2)
255 uncertainty_eff_effB0 = 0
256 uncertainty_eff_effB0bar = 0
257 uncertainty_eff_effAverage = 0
258 diff_eff_Uncertainty = 0
259 event_fractionB0 = array(
'f', [0] * r_size)
260 event_fractionB0bar = array(
'f', [0] * r_size)
261 event_fractionTotal = array(
'f', [0] * r_size)
262 event_fractionTotalUncertainty = array(
'f', [0] * r_size)
263 eventsInBin_B0 = array(
'f', [0] * r_size)
264 eventsInBin_B0bar = array(
'f', [0] * r_size)
265 eventsInBin_Total = array(
'f', [0] * r_size)
266 event_fractionDiff = array(
'f', [0] * r_size)
267 event_fractionDiffUncertainty = array(
'f', [0] * r_size)
268 rvalueB0 = array(
'f', [0] * r_size)
269 rvalueB0bar = array(
'f', [0] * r_size)
270 rvalueB0Average = array(
'f', [0] * r_size)
271 rvalueStdB0 = array(
'f', [0] * r_size)
272 rvalueStdB0bar = array(
'f', [0] * r_size)
273 rvalueStdB0Average = array(
'f', [0] * r_size)
274 wvalue = array(
'f', [0] * r_size)
275 wvalueUncertainty = array(
'f', [0] * r_size)
276 wvalueB0 = array(
'f', [0] * r_size)
277 wvalueB0bar = array(
'f', [0] * r_size)
278 wvalueB0Uncertainty = array(
'f', [0] * r_size)
279 wvalueB0barUncertainty = array(
'f', [0] * r_size)
280 wvalueDiff = array(
'f', [0] * r_size)
281 wvalueDiffUncertainty = array(
'f', [0] * r_size)
282 entries = array(
'f', [0] * r_size)
283 entriesB0 = array(
'f', [0] * r_size)
284 entriesB0bar = array(
'f', [0] * r_size)
285 iEffEfficiency = array(
'f', [0] * r_size)
286 iEffEfficiencyUncertainty = array(
'f', [0] * r_size)
287 iEffEfficiencyB0Uncertainty = array(
'f', [0] * r_size)
288 iEffEfficiencyB0barUncertainty = array(
'f', [0] * r_size)
289 iEffEfficiencyB0UncertaintyFromOutput = array(
'f', [0] * r_size)
290 iEffEfficiencyB0barUncertaintyFromOutput = array(
'f', [0] * r_size)
292 iDeltaEffEfficiency = array(
'f', [0] * r_size)
293 iDeltaEffEfficiencyUncertainty = array(
'f', [0] * r_size)
294 muParam = array(
'f', [0] * r_size)
295 muParamUncertainty = array(
'f', [0] * r_size)
298 print(
'* --> DETERMINATION BASED ON MONTE CARLO ' +
302 print(
'* Note: mu = Delta_Effcy/(2*Efficiency). Needed for CP analysis ' +
303 'together with w and Delta_w *')
306 print(
'* ------------------------------------------------------------------' +
307 '-------------------------------------------------- *')
308 print(
'* r-interval <r> Efficiency Delta_Effcy ' +
310 print(
'* ------------------------------------------------------------------' +
311 '-------------------------------------------------- *')
313 for i
in range(1, r_size):
315 entries[i] = histo_entries_per_bin.GetBinContent(i)
316 entriesB0[i] = histo_entries_per_binB0.GetBinContent(i)
317 entriesB0bar[i] = histo_entries_per_binB0bar.GetBinContent(i)
320 event_fractionB0[i] = entriesB0[i] / total_entriesB0
321 event_fractionB0bar[i] = entriesB0bar[i] / total_entriesB0bar
326 event_fractionTotal[i] = (event_fractionB0[i] + event_fractionB0bar[i]) / 2
327 event_fractionDiff[i] = event_fractionB0[i] - event_fractionB0bar[i]
329 event_fractionDiffUncertainty[i] = math.sqrt(entriesB0[i] *
334 (total_entriesB0bar -
336 total_entriesB0bar**3)
338 event_fractionTotalUncertainty[i] = event_fractionDiffUncertainty[i] / 2
340 rvalueB0[i] = histo_avr_rB0.GetBinContent(i)
341 rvalueB0bar[i] = histo_avr_rB0bar.GetBinContent(i)
342 rvalueB0Average[i] = histo_avr_r.GetBinContent(i)
343 rvalueStdB0[i] = math.sqrt(histo_ms_rB0.GetBinContent(
344 i) - (histo_avr_rB0.GetBinContent(i))**2) / math.sqrt(entriesB0[i] - 1)
345 rvalueStdB0bar[i] = math.sqrt(histo_ms_rB0bar.GetBinContent(
346 i) - (histo_avr_rB0bar.GetBinContent(i))**2) / math.sqrt(entriesB0bar[i] - 1)
347 rvalueStdB0Average[i] = math.sqrt(rvalueStdB0[i]**2 + rvalueStdB0bar[i]**2) / 2
351 wvalueB0[i] = histo_mc_NwB0.GetBinContent(i) / entriesB0[i]
352 wvalueB0bar[i] = histo_mc_NwB0bar.GetBinContent(i) / entriesB0bar[i]
353 wvalueDiff[i] = wvalueB0[i] - wvalueB0bar[i]
354 wvalueB0Uncertainty[i] = math.sqrt(histo_mc_NwB0.GetBinContent(
355 i) * (entriesB0[i] - histo_mc_NwB0.GetBinContent(i)) / (entriesB0[i]**3))
356 wvalueB0barUncertainty[i] = math.sqrt(histo_mc_NwB0bar.GetBinContent(
357 i) * (entriesB0bar[i] - histo_mc_NwB0bar.GetBinContent(i)) / (entriesB0bar[i]**3))
359 wvalueDiffUncertainty[i] = math.sqrt(wvalueB0Uncertainty[i]**2 + wvalueB0barUncertainty[i]**2)
360 wvalue[i] = (wvalueB0[i] + wvalueB0bar[i]) / 2
361 wvalueUncertainty[i] = wvalueDiffUncertainty[i] / 2
368 iEffEfficiency[i] = event_fractionTotal[i] * (1 - 2 * wvalue[i])**2
370 iEffEfficiencyUncertainty[i] = (1 - 2 * wvalue[i]) * \
371 math.sqrt((2 * event_fractionTotal[i] * 2 * wvalueUncertainty[i])**2 +
372 (1 - 2 * wvalue[i])**2 * event_fractionTotalUncertainty[i]**2)
395 average_eff_eff += iEffEfficiency[i]
400 iDeltaEffEfficiency[i] = event_fractionB0[i] * (1 - 2 * wvalueB0[i])**2 - \
401 event_fractionB0bar[i] * (1 - 2 * wvalueB0bar[i])**2
403 iEffEfficiencyB0Uncertainty[i] = (1 - 2 * wvalueB0[i]) * \
404 math.sqrt((2 * total_entriesB0 * entriesB0[i] * 2 * wvalueB0Uncertainty[i])**2 +
405 (1 - 2 * wvalueB0[i])**2 * entriesB0[i] *
406 total_entriesB0 * (total_entriesB0 - entriesB0[i])) / (total_entriesB0**2)
407 iEffEfficiencyB0barUncertainty[i] = (1 - 2 * wvalueB0bar[i]) * \
408 math.sqrt((2 * total_entriesB0bar * entriesB0bar[i] * 2 * wvalueB0barUncertainty[i])**2 +
409 (1 - 2 * wvalueB0bar[i])**2 * entriesB0bar[i] *
410 total_entriesB0bar * (total_entriesB0bar - entriesB0bar[i])) / (total_entriesB0bar**2)
412 iDeltaEffEfficiencyUncertainty[i] = math.sqrt(iEffEfficiencyB0Uncertainty[i]**2 + iEffEfficiencyB0barUncertainty[i]**2)
415 diff_eff_Uncertainty = diff_eff_Uncertainty + iDeltaEffEfficiencyUncertainty[i]**2
418 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * (1 - 2 * wvalueB0[i])**2
419 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * (1 - 2 * wvalueB0bar[i])**2
420 uncertainty_eff_effAverage = uncertainty_eff_effAverage + iEffEfficiencyUncertainty[i]**2
421 uncertainty_eff_effB0 = uncertainty_eff_effB0 + iEffEfficiencyB0Uncertainty[i]**2
422 uncertainty_eff_effB0bar = uncertainty_eff_effB0bar + iEffEfficiencyB0barUncertainty[i]**2
423 muParam[i] = event_fractionDiff[i] / (2 * event_fractionTotal[i])
424 muParamUncertainty[i] = event_fractionDiffUncertainty[i] / (2 * event_fractionTotal[i]) * math.sqrt(muParam[i]**2 + 1)
427 print(
'* ' +
'{:.3f}'.format(r_subsample[i - 1]) +
' - ' +
'{:.3f}'.format(r_subsample[i]) +
' ' +
428 '{:.3f}'.format(rvalueB0Average[i]) +
' +- ' +
'{:.4f}'.format(rvalueStdB0Average[i]) +
' ' +
429 '{:.4f}'.format(event_fractionTotal[i]) +
' ' +
430 '{: .4f}'.format(event_fractionDiff[i]) +
' +- ' +
'{:.4f}'.format(event_fractionDiffUncertainty[i]) +
' ' +
431 '{: .4f}'.format(muParam[i]) +
' +- ' +
'{:.4f}'.format(muParamUncertainty[i]) +
' ' +
432 '{:.4f}'.format(wvalue[i]) +
' +- ' +
'{:.4f}'.format(wvalueUncertainty[i]) +
' ' +
433 '{: .4f}'.format(wvalueDiff[i]) +
' +- ' +
'{:.4f}'.format(wvalueDiffUncertainty[i]) +
' *')
436 uncertainty_eff_effAverage = math.sqrt(uncertainty_eff_effAverage)
437 uncertainty_eff_effB0 = math.sqrt(uncertainty_eff_effB0)
438 uncertainty_eff_effB0bar = math.sqrt(uncertainty_eff_effB0bar)
439 diff_eff = tot_eff_effB0 - tot_eff_effB0bar
440 diff_eff_Uncertainty = math.sqrt(diff_eff_Uncertainty)
441 print(
'* --------------------------------------------------------------------------------------------------' +
442 '------------------ *')
444 print(
'* __________________________________________________________________________________________ *')
446 print(
'* | TOTAL NUMBER OF TAGGED EVENTS = ' +
447 '{:<24}'.format(
"%.0f" % total_tagged) +
'{:>36}'.format(
'| *'))
450 '* | TOTAL AVERAGE EFFICIENCY (q=+-1)= ' +
461 '* | TOTAL AVERAGE EFFECTIVE EFFICIENCY (q=+-1)= ' +
467 uncertainty_eff_effAverage *
472 '* | TOTAL AVERAGE EFFECTIVE EFFICIENCY ASYMMETRY (q=+-1)= ' +
478 diff_eff_Uncertainty *
482 print(
'* | B0-TAGGER TOTAL EFFECTIVE EFFICIENCIES: ' +
483 '{:.2f}'.format(tot_eff_effB0 * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0 * 100) +
485 '{:.2f}'.format(tot_eff_effB0bar * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0bar * 100) +
486 ' % (q=-1) ' +
' | *')
488 print(
'* | FLAVOR PERCENTAGE (MC): ' +
489 '{:.2f}'.format(total_tagged_B0 / total_tagged * 100) +
' % (q=+1) ' +
490 '{:.2f}'.format(total_tagged_B0bar / total_tagged * 100) +
' % (q=-1) Diff=' +
491 '{:^5.2f}'.format((total_tagged_B0 - total_tagged_B0bar) / total_tagged * 100) +
' % | *')
492 print(
'* |__________________________________________________________________________________________| *')
494 print(
'****************************************************************************************************')
498 print(
'* --------------------------------- *')
499 print(
'* Efficiency Determination - easiest way *')
500 print(
'* --------------------------------- *')
501 total_tagged_B0 = histo_belleplotB0.GetEntries()
502 total_tagged_B0Bar = histo_belleplotB0bar.GetEntries()
503 total_tagged_wrong = histo_m1.GetEntries()
504 total_tagged_B0Bar_wrong = histo_m2.GetEntries()
505 total_tagged = total_tagged_B0 + total_tagged_B0Bar
506 total_tagged_wrong = total_tagged_wrong + total_tagged_B0Bar_wrong
508 wrong_tag_fraction_B0 = total_tagged_wrong / total_tagged_B0
509 wrong_tag_fraction_B0Bar = total_tagged_B0Bar_wrong / total_tagged_B0Bar
510 wrong_tag_fraction = total_tagged_wrong / total_tagged
511 right_tag_fraction_B0 = 1 - 2 * wrong_tag_fraction_B0
512 right_tag_fraction_B0Bar = 1 - 2 * wrong_tag_fraction_B0Bar
513 right_tag_fraction = 1 - 2 * wrong_tag_fraction
514 wrong_eff_B0 = right_tag_fraction_B0 * right_tag_fraction_B0
515 wrong_eff_B0Bar = right_tag_fraction_B0Bar * right_tag_fraction_B0Bar
516 wrong_eff = right_tag_fraction * right_tag_fraction
518 print(
'* wrong_tag_fraction for all: ' +
519 '{:.3f}'.format(wrong_tag_fraction * 100) +
521 print(
'* right_tag_fraction for all: ' +
522 '{:.3f}'.format(right_tag_fraction * 100) +
524 print(
'* wrong calculated eff all: ' +
'{:.3f}'.format(wrong_eff * 100) +
527 print(
'****************************************************************************************************')
529 print(
'Table For B2TIP')
542 maxB0 = histo_belleplotB0.GetBinContent(histo_belleplotB0.GetMaximumBin())
543 maxB0bar = histo_belleplotB0bar.GetBinContent(histo_belleplotB0bar.GetMaximumBin())
545 Ymax = max(maxB0, maxB0bar)
546 Ymax = Ymax + Ymax / 12
548 if YmaxForQrPlot < Ymax:
552 ROOT.gStyle.SetOptStat(0)
553 Canvas1 = ROOT.TCanvas(
'Bla' + method,
'Final Output', 1200, 800)
555 histo_belleplotB0.SetFillColorAlpha(ROOT.kBlue, 0.2)
556 histo_belleplotB0.SetFillStyle(1001)
557 histo_belleplotB0.GetYaxis().SetLabelSize(0.03)
558 histo_belleplotB0.GetYaxis().SetLimits(0, YmaxForQrPlot)
559 histo_belleplotB0.GetYaxis().SetTitleOffset(1.2)
560 histo_belleplotB0.SetLineColor(ROOT.kBlue)
561 histo_belleplotB0bar.SetFillColorAlpha(ROOT.kRed, 1.0)
562 histo_belleplotB0bar.SetFillStyle(3005)
563 histo_belleplotB0bar.SetLineColor(ROOT.kRed)
566 histo_belleplotB0.SetTitle(
'Final Flavor Tagger Output; #it{qr}-output ; Events'
568 histo_belleplotB0.SetMinimum(0)
569 histo_belleplotB0.SetMaximum(YmaxForQrPlot)
570 histo_belleplotB0.Draw(
'hist')
571 histo_belleplotB0bar.Draw(
'hist same')
573 leg = ROOT.TLegend(0.75, 0.8, 0.9, 0.9)
574 leg.AddEntry(histo_belleplotB0,
'true B0')
575 leg.AddEntry(histo_belleplotB0bar,
'true B0bar')
580 with Quiet(ROOT.kError):
581 Canvas1.SaveAs(workingDirectory +
'/' +
'PIC_Belleplot_both' + method +
'.pdf')
584 Canvas2 = ROOT.TCanvas(
'Bla2' + method,
'Calibration plot for true B0', 1200, 800)
586 histo_calib_B0.SetFillColorAlpha(ROOT.kBlue, 0.2)
587 histo_calib_B0.SetFillStyle(1001)
588 histo_calib_B0.GetYaxis().SetTitleOffset(1.2)
589 histo_calib_B0.SetLineColor(ROOT.kBlue)
591 histo_calib_B0.SetTitle(
'Calibration For True B0; #it{qr}-output ; Calibration '
593 histo_calib_B0.Draw(
'hist')
596 with Quiet(ROOT.kError):
597 Canvas2.SaveAs(workingDirectory +
'/' +
'PIC_Calibration_B0' + method +
'.pdf')
600 histo_avr_rB0.Delete()
601 histo_avr_rB0bar.Delete()
603 histo_ms_rB0.Delete()
604 histo_ms_rB0bar.Delete()
605 histo_mc_NwB0.Delete()
606 histo_mc_NwB0bar.Delete()
607 histo_notTaggedEvents.Delete()
608 histo_entries_per_bin.Delete()
609 histo_entries_per_binB0.Delete()
610 histo_entries_per_binB0bar.Delete()
611 histo_Cnet_output_B0.Delete()
612 histo_Cnet_output_B0bar.Delete()
613 histo_belleplotB0.Delete()
614 histo_belleplotB0bar.Delete()
615 histo_calib_B0.Delete()
616 histo_calib_B0bar.Delete()
624 print(
r'\begin{tabularx}{1\textwidth}{@{}r r r r r r r@{}}')
626 print(
r'$r$- Interval $\enskip$ & $\varepsilon_i\ $ & $\Delta\varepsilon_i\ $ & $w_i \pm \delta w_i\enskip\; $ ' +
627 r' & $\Delta w_i \pm \delta\Delta w_i $& $\varepsilon_{\text{eff}, i} \pm \delta\varepsilon_{\text{eff}, i}\enskip\, $ ' +
628 r' & $\Delta \varepsilon_{\text{eff}, i} \pm \delta\Delta \varepsilon_{\text{eff}, i}\enskip\, $\\ \hline\hline')
629 for i
in range(1, r_size):
630 print(
'$ ' +
'{:.3f}'.format(r_subsample[i - 1]) +
' - ' +
'{:.3f}'.format(r_subsample[i]) +
'$ & $'
631 '{: 6.1f}'.format(event_fractionTotal[i] * 100) +
r'$ & $' +
632 '{: 7.2f}'.format(event_fractionDiff[i] * 100) +
r'\;$ & $' +
633 '{: 7.2f}'.format(wvalue[i] * 100) +
r" \pm " +
'{:2.2f}'.format(wvalueUncertainty[i] * 100) +
r'\enskip $ & $' +
634 '{: 7.2f}'.format(wvalueDiff[i] * 100) +
r" \pm " +
635 '{:2.2f}'.format(wvalueDiffUncertainty[i] * 100) +
r'\enskip $ & $' +
636 '{: 8.4f}'.format(iEffEfficiency[i] * 100) +
637 r" \pm " +
'{:2.4f}'.format(iEffEfficiencyUncertainty[i] * 100) +
r'\, $ & $' +
638 '{: 6.4f}'.format(iDeltaEffEfficiency[i] * 100) +
639 r" \pm " +
'{:2.4f}'.format(iDeltaEffEfficiencyUncertainty[i] * 100) +
640 r'\enskip\enskip $ \\ ')
641 print(
r'\hline\hline')
642 print(
r'\multicolumn{1}{r}{Total} & & \multicolumn{5}{r}{ $\varepsilon_\text{eff} = ' +
643 r'\sum_i \varepsilon_i \cdot \langle 1-2w_i\rangle^2 = ' +
644 '{: 6.2f}'.format(average_eff_eff * 100) +
r" \pm " +
'{: 6.2f}'.format(uncertainty_eff_effAverage * 100) +
r'\enskip\, ')
645 print(
r'\Delta \varepsilon_\text{eff} = ' +
646 '{: 6.2f}'.format(diff_eff * 100) +
r" \pm " +
'{: 6.2f}'.format(diff_eff_Uncertainty * 100) +
r'\quad\ $ }' +
649 print(
r'\end{tabular}')
653 print(
'Mu-Values for Table')
656 for i
in range(1, r_size):
657 print(
'$ ' +
'{:.3f}'.format(r_subsample[i - 1]) +
' - ' +
'{:.3f}'.format(r_subsample[i]) +
'$ & $'
658 '{: 7.2f}'.format(muParam[i] * 100) +
r" \pm " +
'{:2.2f}'.format(muParamUncertainty[i] * 100) +
r' $ & ')
667 print(ft.getEventLevelParticleLists(usedCategories))
670 print(
'******************************************* MEASURED EFFECTIVE EFFICIENCY FOR INDIVIDUAL CATEGORIES ' +
671 '**********************************************')
676 categoriesPerformance = []
677 NbinsCategories = 100
678 for category
in usedCategories:
680 hist_both = ROOT.TH1F(
'Both_' + category,
'Input Both (B0) ' +
681 category +
' (binning)', NbinsCategories, -1.0, 1.0)
683 hist_signal = ROOT.TH1F(
'Signal_' + category,
'Input Signal (B0) ' +
684 category +
' (binning)', NbinsCategories, -1.0, 1.0)
686 hist_background = ROOT.TH1F(
'Background_' + category,
'Input Background (B0bar) ' +
687 category +
' (binning)', NbinsCategories, -1.0, 1.0)
691 hist_probB0 = ROOT.TH1F(
'Probability' + category,
692 'Transformed to probability (B0) (' + category +
')',
693 NbinsCategories, 0.0, 1.0)
694 hist_probB0bar = ROOT.TH1F(
'ProbabilityB0bar_' + category,
695 'Transformed to probability (B0bar) (' + category +
')',
696 NbinsCategories, 0.0, 1.0)
698 hist_qrB0 = ROOT.TH1F(
'QR' + category,
'Transformed to qp (B0)(' +
699 category +
')', NbinsCategories, -1.0, 1.0)
700 hist_qrB0bar = ROOT.TH1F(
'QRB0bar_' + category,
'Transformed to qp (B0bar) (' +
701 category +
')', NbinsCategories, -1.0, 1.0)
704 histo_entries_per_bin = ROOT.TH1F(
'entries_per_bin_' + category,
'Abs(qp)(B0) (' + category +
')', int(r_size - 2), r_subsample)
705 histo_entries_per_binB0 = ROOT.TH1F(
'entries_per_bin' + category,
'Abs(qp)(B0) (' +
706 category +
')', int(r_size - 2), r_subsample)
707 histo_entries_per_binB0bar = ROOT.TH1F(
'entries_per_binB0bar_' + category,
708 'Abs(qp) (B0bar) (' + category +
')', int(r_size - 2), r_subsample)
712 hist_avr_rB0 = ROOT.TH1F(
'Average_r' + category,
'Average r for B0' +
713 category, int(r_size - 2), r_subsample)
714 hist_avr_rB0bar = ROOT.TH1F(
'Average_rB0bar_' + category,
'Average r for B0bar' +
715 category, int(r_size - 2), r_subsample)
717 hist_ms_rB0 = ROOT.TH1F(
'AverageSqrdR' + category,
'Average r sqrd for B0' +
718 category, int(r_size - 2), r_subsample)
719 hist_ms_rB0bar = ROOT.TH1F(
'AverageSqrdRB0bar_' + category,
'Average r sqrd for B0bar' +
720 category, int(r_size - 2), r_subsample)
724 hist_all = ROOT.TH1F(
'All_' + category,
'Input Signal (B0) and Background (B0Bar)' +
725 category +
' (binning 50)', 50, 0.0, 1.0)
726 hist_calib_B0 = ROOT.TH1F(
'Calib_' + category,
'Calibration Plot for true B0' +
727 category +
' (binning 50)', 50, 0.0, 1.0)
730 if category !=
"KaonNotWeighted" and category !=
"LambdaNotWeighted":
732 tree.Draw(
'qp' + category +
'>>Both_' + category,
'abs(qrMC) == 1.0')
734 tree.Draw(
'qp' + category +
'>>Signal_' + category,
'qrMC == 1.0')
736 tree.Draw(
'qp' + category +
'>>Background_' + category,
'qrMC == -1.0')
737 tree.Draw(
'qp' + category +
'>>All_' + category,
'qrMC!=0')
738 tree.Draw(
'qp' + category +
'>>Calib_' + category,
'qrMC == 1.0')
748 elif category ==
"KaonNotWeighted":
749 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Both_' + category,
'abs(qrMC) == 1.0')
750 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Signal_' + category,
'qrMC == 1.0')
751 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Background_' + category,
'qrMC == -1.0')
752 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>All_' + category,
'qrMC!=0')
753 tree.Draw(
'extraInfo__boQpOfKaon__bc' +
'>>Calib_' + category,
'qrMC == 1.0')
755 elif category ==
"LambdaNotWeighted":
756 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Both_' + category,
'abs(qrMC) == 1.0')
757 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Signal_' + category,
'qrMC == 1.0')
758 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Background_' + category,
'qrMC == -1.0')
759 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>All_' + category,
'qrMC!=0')
760 tree.Draw(
'extraInfo__boQpOfLambda__bc' +
'>>Calib_' + category,
'qrMC == 1.0')
762 hist_calib_B0.Divide(hist_all)
765 maxSignal = hist_signal.GetBinContent(hist_signal.GetMaximumBin())
766 maxBackground = hist_background.GetBinContent(hist_background.GetMaximumBin())
768 Ymax = max(maxSignal, maxBackground)
769 Ymax = Ymax + Ymax / 12
771 ROOT.gStyle.SetOptStat(0)
772 with Quiet(ROOT.kError):
773 Canvas = ROOT.TCanvas(
'Bla',
'TITEL BLA', 1200, 800)
776 hist_signal.SetFillColorAlpha(ROOT.kBlue, 0.2)
777 hist_signal.SetFillStyle(1001)
778 hist_signal.SetTitleSize(0.1)
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.GetYaxis().SetLimits(0, Ymax)
786 hist_signal.SetLineColor(ROOT.kBlue)
787 hist_background.SetFillColorAlpha(ROOT.kRed, 1.0)
788 hist_background.SetFillStyle(3005)
789 hist_background.GetYaxis().SetLimits(0, Ymax)
790 hist_background.SetLineColor(ROOT.kRed)
792 hist_signal.SetTitle(category +
' category; #it{qp}-Output ; Events')
794 hist_signal.SetMaximum(Ymax)
796 hist_background.SetMaximum(Ymax)
798 hist_signal.Draw(
'hist')
799 hist_background.Draw(
'hist same')
801 if category ==
'MaximumPstar':
802 legend = ROOT.TLegend(0.4, 0.75, 0.6, 0.9)
804 legend = ROOT.TLegend(0.6, 0.75, 0.8, 0.9)
805 legend.AddEntry(hist_signal,
'true B0')
806 legend.AddEntry(hist_background,
'true B0bar')
807 legend.SetTextSize(0.05)
811 with Quiet(ROOT.kError):
812 Canvas.SaveAs(workingDirectory +
'/' +
'PIC_' + category +
'_Input_Combiner.pdf')
817 binCounter = int(NbinsCategories + 1)
818 dilutionB02 = array(
'd', [0] * binCounter)
819 dilutionB0bar2 = array(
'd', [0] * binCounter)
820 purityB0 = array(
'd', [0] * binCounter)
821 purityB0bar = array(
'd', [0] * binCounter)
822 signal = array(
'd', [0] * binCounter)
823 back = array(
'd', [0] * binCounter)
824 weight = array(
'd', [0] * binCounter)
826 for i
in range(1, binCounter):
828 signal[i] = hist_signal.GetBinContent(i)
829 back[i] = hist_background.GetBinContent(i)
830 weight[i] = signal[i] + back[i]
833 if signal[i] + back[i] == 0:
837 dilutionB0bar2[i] = 0
840 purityB0[i] = signal[i] / (signal[i] + back[i])
841 dilutionB02[i] = -1 + 2 * signal[i] / (signal[i] + back[i])
843 purityB0bar[i] = back[i] / (signal[i] + back[i])
844 dilutionB0bar2[i] = -1 + 2 * back[i] / (signal[i] + back[i])
847 hist_probB0.Fill(purityB0[i], signal[i])
848 hist_probB0bar.Fill(purityB0bar[i], back[i])
851 hist_qrB0.Fill(dilutionB02[i], signal[i])
852 hist_qrB0bar.Fill(dilutionB0bar2[i], back[i])
855 histo_entries_per_binB0.Fill(abs(dilutionB02[i]), signal[i])
856 histo_entries_per_binB0bar.Fill(abs(dilutionB0bar2[i]), back[i])
858 hist_avr_rB0.Fill(abs(dilutionB02[i]), abs(dilutionB02[i]) * signal[i])
859 hist_avr_rB0bar.Fill(abs(dilutionB0bar2[i]), abs(dilutionB0bar2[i]) * back[i])
861 hist_ms_rB0.Fill(abs(dilutionB02[i]), abs(dilutionB02[i] * dilutionB02[i]) * signal[i])
862 hist_ms_rB0bar.Fill(abs(dilutionB0bar2[i]), abs(dilutionB0bar2[i] * dilutionB02[i]) * back[i])
865 hist_avr_rB0.Divide(histo_entries_per_binB0)
866 hist_avr_rB0bar.Divide(histo_entries_per_binB0bar)
868 hist_ms_rB0.Divide(histo_entries_per_binB0)
869 hist_ms_rB0bar.Divide(histo_entries_per_binB0bar)
873 total_entriesB0 = total_notTagged / 2
874 total_entriesB0bar = total_notTagged / 2
875 for i
in range(1, r_size):
876 total_entriesB0 = total_entriesB0 + histo_entries_per_binB0.GetBinContent(i)
877 total_entriesB0bar = total_entriesB0bar + histo_entries_per_binB0bar.GetBinContent(i)
881 uncertainty_eff_effB0 = 0
882 uncertainty_eff_effB0bar = 0
883 uncertainty_eff_effAverage = 0
884 diff_eff_Uncertainty = 0
885 event_fractionB0 = array(
'f', [0] * r_size)
886 event_fractionB0bar = array(
'f', [0] * r_size)
887 rvalueB0 = array(
'f', [0] * r_size)
888 rvalueB0bar = array(
'f', [0] * r_size)
889 rvalueStdB0 = array(
'f', [0] * r_size)
890 rvalueStdB0bar = array(
'f', [0] * r_size)
892 entriesBoth = array(
'f', [0] * r_size)
893 entriesB0 = array(
'f', [0] * r_size)
894 entriesB0bar = array(
'f', [0] * r_size)
895 iEffEfficiencyB0Uncertainty = array(
'f', [0] * r_size)
896 iEffEfficiencyB0barUncertainty = array(
'f', [0] * r_size)
897 iDeltaEffEfficiencyUncertainty = array(
'f', [0] * r_size)
899 for i
in range(1, r_size):
901 entriesBoth[i] = entriesB0bar[i] + entriesB0[i]
902 entriesB0[i] = histo_entries_per_binB0.GetBinContent(i)
903 entriesB0bar[i] = histo_entries_per_binB0bar.GetBinContent(i)
904 event_fractionB0[i] = entriesB0[i] / total_entriesB0
905 event_fractionB0bar[i] = entriesB0bar[i] / total_entriesB0bar
910 rvalueB0[i] = hist_avr_rB0.GetBinContent(i)
911 rvalueB0bar[i] = hist_avr_rB0bar.GetBinContent(i)
914 rvalueStdB0bar[i] = 0
917 rvalueStdB0[i] = math.sqrt(abs(hist_ms_rB0.GetBinContent(
918 i) - (hist_avr_rB0.GetBinContent(i))**2)) / math.sqrt(entriesB0[i] - 1)
920 if entriesB0bar[i] > 1:
921 rvalueStdB0bar[i] = math.sqrt(abs(hist_ms_rB0bar.GetBinContent(
922 i) - (hist_avr_rB0bar.GetBinContent(i))**2)) / math.sqrt(entriesB0bar[i] - 1)
925 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] \
927 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] \
930 iEffEfficiencyB0Uncertainty[i] = rvalueB0[i] * \
931 math.sqrt((2 * total_entriesB0 * entriesB0[i] * rvalueStdB0[i])**2 +
932 rvalueB0[i]**2 * entriesB0[i] *
933 (total_entriesB0 * (total_entriesB0 - entriesB0[i]) +
934 entriesB0[i] * total_notTagged)) / (total_entriesB0**2)
935 iEffEfficiencyB0barUncertainty[i] = rvalueB0bar[i] * \
936 math.sqrt((2 * total_entriesB0bar * entriesB0bar[i] * rvalueStdB0bar[i])**2 +
937 rvalueB0bar[i]**2 * entriesB0bar[i] *
938 (total_entriesB0bar * (total_entriesB0bar - entriesB0bar[i]) +
939 entriesB0bar[i] * total_notTagged)) / (total_entriesB0bar**2)
941 iDeltaEffEfficiencyUncertainty[i] = math.sqrt(iEffEfficiencyB0Uncertainty[i]**2 + iEffEfficiencyB0barUncertainty[i]**2)
943 diff_eff_Uncertainty = diff_eff_Uncertainty + iDeltaEffEfficiencyUncertainty[i]**2
945 uncertainty_eff_effB0 = uncertainty_eff_effB0 + iEffEfficiencyB0Uncertainty[i]**2
946 uncertainty_eff_effB0bar = uncertainty_eff_effB0bar + iEffEfficiencyB0barUncertainty[i]**2
948 effDiff = tot_eff_effB0 - tot_eff_effB0bar
949 effAverage = (tot_eff_effB0 + tot_eff_effB0bar) / 2
951 uncertainty_eff_effB0 = math.sqrt(uncertainty_eff_effB0)
952 uncertainty_eff_effB0bar = math.sqrt(uncertainty_eff_effB0bar)
953 diff_eff_Uncertainty = math.sqrt(diff_eff_Uncertainty)
954 uncertainty_eff_effAverage = diff_eff_Uncertainty / 2
956 '{:<25}'.format(
"* " + category) +
' B0-Eff=' +
957 '{: 8.2f}'.format(tot_eff_effB0 * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0 * 100) +
960 '{: 8.2f}'.format(tot_eff_effB0bar * 100) +
" +-" +
'{: 4.2f}'.format(uncertainty_eff_effB0bar * 100) +
963 '{: 8.2f}'.format(effAverage * 100) +
" +- " +
'{:4.2f}'.format(uncertainty_eff_effAverage * 100) +
' %' +
965 '{: 8.2f}'.format(effDiff * 100) +
" +- " +
'{:4.2f}'.format(diff_eff_Uncertainty * 100) +
' % *')
979 categoriesPerformance.append((category, effAverage, uncertainty_eff_effAverage, effDiff, diff_eff_Uncertainty))
980 with Quiet(ROOT.kError):
989 print(
'**************************************************************************************************************************' +
990 '************************')
992 print(
'Table For B2TIP')
994 print(
r'\begin{tabular}{ l r r }')
996 print(
r'Categories & $\varepsilon_\text{eff} \pm \delta\varepsilon_\text{eff} $& ' +
997 r'$\Delta\varepsilon_\text{eff} \pm \delta\Delta\varepsilon_\text{eff}$\\ \hline\hline')
998 for (category, effAverage, uncertainty_eff_effAverage, effDiff, diff_eff_Uncertainty)
in categoriesPerformance:
1000 '{:<23}'.format(category) +
1002 '{: 6.2f}'.format(effAverage * 100) +
r" \pm " +
'{:4.2f}'.format(uncertainty_eff_effAverage * 100) +
1004 '{: 6.2f}'.format(effDiff * 100) +
r" \pm " +
'{:4.2f}'.format(diff_eff_Uncertainty * 100) +
1007 print(
r'\end{tabular}')
1008 B2INFO(
'qp Output Histograms in pdf format saved at: ' + workingDirectory)
1009 with open(
"categoriesPerformance.pkl",
"wb")
as f:
1010 pickle.dump(categoriesPerformance, f)