24 from matplotlib.colors
import colorConverter
25 from matplotlib.collections
import PolyCollection
26 from ROOT
import PyConfig
30 import matplotlib.pyplot
as plt
32 from basf2
import B2INFO
33 from defaultEvaluationParameters
import categories, Quiet, rbins
34 from array
import array
37 import matplotlib
as mpl
39 mpl.rcParams.update({
'font.size': 22})
40 mpl.rcParams[
'text.usetex'] =
True
41 mpl.rcParams[
'text.latex.preamble'] = [
r"\usepackage{amsmath}"]
43 PyConfig.IgnoreCommandLineOptions =
True
44 PyConfig.StartGuiThread =
False
46 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.WARNING)
49 def efficiencyCalculator(data, total_notTagged, SimpleOutput=False, v='notVerbose'):
53 dataB0 = data[np.where(data[:, 0] > 0)]
54 dataB0bar = data[np.where(data[:, 0] < 0)]
56 totaldataB0 = np.absolute(dataB0[:, 1])
57 totaldataB0bar = np.absolute(dataB0bar[:, 1])
59 rvalueB0 = (np.histogram(totaldataB0, rbins, weights=totaldataB0)[0] / np.histogram(totaldataB0, rbins)[0])
60 rvalueB0MeanSquared = (
70 entriesB0 = np.histogram(totaldataB0, rbins)[0]
72 rvalueB0bar = (np.histogram(totaldataB0bar, rbins, weights=totaldataB0bar)[0] / np.histogram(totaldataB0bar, rbins)[0])
73 rvalueB0barMeanSquared = (
77 weights=totaldataB0bar *
82 entriesB0bar = np.histogram(totaldataB0bar, rbins)[0]
85 if row[0] == 1
and abs(row[1]) > 1:
88 total_entries_B0 = totaldataB0.shape[0] + total_notTagged / 2
90 event_fraction_B0 = entriesB0.astype(float) / total_entries_B0
92 total_entries_B0bar = totaldataB0bar.shape[0] + total_notTagged / 2
94 event_fraction_B0bar = entriesB0bar.astype(float) / total_entries_B0bar
98 arrayShape = len(rbins) - 1
100 event_fractionTotal = np.zeros(arrayShape)
101 event_fractionB0 = np.zeros(arrayShape)
102 event_fractionB0bar = np.zeros(arrayShape)
103 event_fractionDiff = np.zeros(arrayShape)
104 event_fractionDiffUncertainty = np.zeros(arrayShape)
105 event_fractionTotalUncertainty = np.zeros(arrayShape)
107 wvalue = np.zeros(arrayShape)
108 wvalueB0 = np.zeros(arrayShape)
109 wvalueB0bar = np.zeros(arrayShape)
110 wvalueDiff = np.zeros(arrayShape)
111 wvalueDiffUncertainty = np.zeros(arrayShape)
112 wvalueUncertainty = np.zeros(arrayShape)
114 rvalueStdB0 = np.zeros(arrayShape)
115 rvalueStdB0bar = np.zeros(arrayShape)
117 muParam = np.zeros(arrayShape)
118 muParamUncertainty = np.zeros(arrayShape)
122 NwrongB0 = np.histogram(
124 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == 1))][:, 1]), rbins)[0].astype(float)
126 wvalueB0 = (NwrongB0 / entriesB0)
128 wvalueB0Uncertainty = np.sqrt(NwrongB0 * (entriesB0 - NwrongB0) / (entriesB0**3))
130 NwrongB0bar = np.histogram(
132 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == -1))][:, 1]), rbins)[0].astype(float)
134 wvalueB0bar = (NwrongB0bar / entriesB0bar)
136 wvalueB0barUncertainty = np.sqrt(NwrongB0bar * (entriesB0bar - NwrongB0bar) / (entriesB0bar**3))
138 wvalueDiff = wvalueB0 - wvalueB0bar
139 wvalueDiffUncertainty = np.sqrt(wvalueB0Uncertainty**2 + wvalueB0barUncertainty**2)
141 for i
in range(0, len(rbins) - 1):
143 event_fractionB0[i] = entriesB0[i] / total_entries_B0
144 event_fractionB0bar[i] = entriesB0bar[i] / total_entries_B0bar
146 event_fractionTotal[i] = (event_fractionB0[i] + event_fractionB0bar[i]) / 2
147 event_fractionDiff[i] = event_fractionB0[i] - event_fractionB0bar[i]
149 event_fractionDiffUncertainty[i] = math.sqrt(entriesB0[i] *
152 total_entries_B0**3 +
154 (total_entries_B0bar -
156 total_entries_B0bar**3)
158 event_fractionTotalUncertainty[i] = event_fractionDiffUncertainty[i] / 2
160 muParam[i] = event_fractionDiff[i] / (2 * event_fractionTotal[i])
161 muParamUncertainty[i] = event_fractionDiffUncertainty[i] / (2 * event_fractionTotal[i]) * math.sqrt(muParam[i]**2 + 1)
163 rvalueStdB0[i] = math.sqrt(rvalueB0MeanSquared[i] - (rvalueB0[i])**2) / math.sqrt(entriesB0[i] - 1)
164 rvalueStdB0bar[i] = math.sqrt(rvalueB0barMeanSquared[i] - (rvalueB0bar[i])**2) / math.sqrt(entriesB0bar[i] - 1)
170 wvalue[i] = (wvalueB0[i] + wvalueB0bar[i]) / 2
171 wvalueUncertainty[i] = wvalueDiffUncertainty[i] / 2
173 tot_eff_eff_B0 += event_fraction_B0[i] * (1 - 2 * wvalueB0[i])**2
174 tot_eff_eff_B0bar += event_fraction_B0bar[i] * (1 - 2 * wvalueB0bar[i])**2
176 eff = event_fractionTotal[i] * (1 - 2 * wvalue[i])**2
178 tot_eff_eff_Avg += eff
180 eff2 = (event_fraction_B0[i] * (1 - 2 * wvalueB0[i])**2 + event_fraction_B0bar[i] * (1 - 2 * wvalueB0bar[i])**2) / 2
182 rval = (rvalueB0[i] + rvalueB0bar[i]) / 2
186 "{: 6.3f}".format(rval),
188 "{: 6.3f}".format(eff),
190 "{: 6.3f}".format(eff2),
204 wvalueDiffUncertainty[i] *
209 event_fractionTotal[i] *
214 event_fractionDiff[i] *
219 event_fractionDiffUncertainty[i] *
229 muParamUncertainty[i] *
232 tot_eff_eff = (tot_eff_eff_B0 + tot_eff_eff_B0bar) / 2
233 tot_eff_diff = tot_eff_eff_B0 - tot_eff_eff_B0bar
234 efficiency = 100 * tot_eff_eff_Avg
235 efficiencyDiff = 100 * tot_eff_diff
236 efficiencyB0 = 100 * tot_eff_eff_B0
237 efficiencyB0bar = 100 * tot_eff_eff_B0bar
240 print(
"Total Efficiency from Avr. rB0 and rB0bar ",
"{: 6.3f}".format(float(100 * tot_eff_eff)))
241 print(
"Total Efficiency from Avr. wB0 and wB0bar ",
"{: 6.3f}".format(float(100 * tot_eff_eff_Avg)))
245 return efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar
249 return efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar, wvalue, wvalueB0, \
250 wvalueB0bar, wvalueDiff, wvalueDiffUncertainty, event_fractionB0, event_fractionB0bar, \
251 event_fractionDiffUncertainty, event_fractionTotalUncertainty, muParam, muParamUncertainty
254 def categoriesEfficiencyCalculator(data, v='notVerbose'):
258 r_subsample = array(
'd', [
268 hist_aver_rB0 = ROOT.TH1F(
'AverageR' + category,
'A good one (B0)' +
269 category, 6, r_subsample)
270 hist_aver_rB0bar = ROOT.TH1F(
'AverageRB0bar_' + category,
'A good one (B0bar)' +
271 category, 6, r_subsample)
273 hist_absqrB0 = ROOT.TH1F(
'AbsQR' + category,
'Abs(qr)(B0) (' + category +
')', 6, r_subsample)
274 hist_absqrB0bar = ROOT.TH1F(
'AbsQRB0bar_' + category,
'Abs(qr) (B0bar) (' + category +
')', 6, r_subsample)
276 dataB0 = data[np.where(data[:, 0] > 0)]
277 dataB0bar = data[np.where(data[:, 0] < 0)] * (-1)
280 bins = list(range(-25, 27, 1))
281 for i
in range(0, len(bins)):
282 bins[i] = float(bins[i]) / 25
285 histoB0 = np.histogram(dataB0, bins=bins)[0]
286 histoB0bar = np.histogram(dataB0bar, bins=bins)[0]
287 histoB0bar = histoB0bar[0:len(histoB0bar) - 1]
288 histoB0bar = histoB0bar[::-1]
290 dilutionB0 = np.zeros(50)
291 dilutionB0bar = np.zeros(50)
293 for i
in range(0, 50):
294 if (histoB0[i] + histoB0bar[i]) != 0:
295 dilutionB0[i] = -1 + 2 * histoB0[i] / (histoB0[i] + histoB0bar[i])
296 dilutionB0bar[i] = -1 + 2 * histoB0bar[i] / (histoB0[i] + histoB0bar[i])
297 hist_absqrB0.Fill(abs(dilutionB0[i]), histoB0[i])
298 hist_absqrB0bar.Fill(abs(dilutionB0bar[i]), histoB0bar[i])
299 hist_aver_rB0.Fill(abs(dilutionB0[i]), abs(dilutionB0[i]) * histoB0[i])
300 hist_aver_rB0bar.Fill(abs(dilutionB0bar[i]), abs(dilutionB0bar[i]) * histoB0bar[i])
302 hist_aver_rB0.Divide(hist_absqrB0)
303 hist_aver_rB0bar.Divide(hist_absqrB0bar)
305 tot_entriesB0 = dataB0[:, 1].shape[0]
306 tot_entriesB0bar = dataB0bar[:, 1].shape[0]
310 rvalueB0 = np.zeros(rbins.shape[0])
311 rvalueB0bar = np.zeros(rbins.shape[0])
312 entriesB0 = np.zeros(rbins.shape[0])
313 entriesB0bar = np.zeros(rbins.shape[0])
314 event_fractionB0 = np.zeros(rbins.shape[0])
315 event_fractionB0bar = np.zeros(rbins.shape[0])
317 for i
in range(1, rbins.shape[0]):
318 rvalueB0[i] = hist_aver_rB0.GetBinContent(i)
319 rvalueB0bar[i] = hist_aver_rB0bar.GetBinContent(i)
320 entriesB0[i] = hist_absqrB0.GetBinContent(i)
321 entriesB0bar[i] = hist_absqrB0bar.GetBinContent(i)
322 event_fractionB0[i] = entriesB0[i] / tot_entriesB0
323 event_fractionB0bar[i] = entriesB0bar[i] / tot_entriesB0bar
324 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] \
326 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] \
328 effDiff = tot_eff_effB0 - tot_eff_effB0bar
329 effAverage = (tot_eff_effB0 + tot_eff_effB0bar) / 2
331 efficiency = 100 * effAverage
332 efficiencyDiff = 100 * effDiff
333 efficiencyB0 = 100 * tot_eff_effB0
334 efficiencyB0bar = 100 * tot_eff_effB0bar
336 return efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar
339 ROOT.gROOT.SetBatch(
True)
341 if len(sys.argv) != 3:
342 sys.exit(
"Must provide 2 arguments: [input_sim_file] or ['input_sim_file*'] with wildcards and [treeName]"
344 workingFile = sys.argv[1]
345 workingFiles = glob.glob(str(workingFile))
346 treeName = str(sys.argv[2])
348 if len(workingFiles) < 1:
349 sys.exit(
"No file name or file names " + str(workingFile) +
" found.")
351 workingDirectory =
'.'
356 tree = ROOT.TChain(treeName)
358 mcstatus = array(
'd', [-511.5, 0.0, 511.5])
359 ROOT.TH1.SetDefaultSumw2()
361 for iFile
in workingFiles:
365 for branch
in tree.GetListOfBranches():
366 totalBranches.append(branch.GetName())
370 if 'FBDT_qrCombined' in totalBranches:
371 methods.append(
"FBDT")
373 if 'FANN_qrCombined' in totalBranches:
374 methods.append(
"FANN")
376 if 'DNN_qrCombined' in totalBranches:
377 methods.append(
"DNN")
379 if 'DeltaT' in totalBranches:
383 for cat
in categories:
384 catBranch =
'qp' + cat
385 if catBranch
in totalBranches:
386 usedCategories.append(cat)
389 YmaxForDeltaTPlot = 0
393 for method
in methods:
397 elif method ==
"DNN":
399 elif method ==
"FANN":
402 with Quiet(ROOT.kError):
403 qpMaximumPstar = ROOT.RooRealVar(
'qpMaximumPstar',
'qpMaximumPstar', 0, -2.1, 1.1)
404 qrCombined = ROOT.RooRealVar(
'' + method +
'_qrCombined',
'' + method +
'_qrCombined', 0, -1.1, 1.1)
405 qrMC = ROOT.RooRealVar(
'qrMC',
'qrMC', 0, -10.0, 10.0)
406 isSignal = ROOT.RooRealVar(
'isSignal',
'isSignal', 0, -10.0, 10.0)
408 DeltaT = ROOT.RooRealVar(
"DeltaT",
"DeltaT", 0., -100000., 100000.)
410 argSet = ROOT.RooArgSet(qrCombined, qrMC, isSignal, qpMaximumPstar)
416 for category
in usedCategories:
422 "ROOT.RooRealVar('hasTrueTarget' + category, 'hasTrueTarget' + category, 0, -2.1, 1.1)"))
426 exec(
"%s" %
"argSet.add(hasTrueTarget" + category +
")")
428 rooDataSet = ROOT.RooDataSet(
"data",
"data", tree, argSet,
"")
431 numberOfTrueCatagories = []
435 for i
in range(rooDataSet.numEntries()):
436 row = rooDataSet.get(i)
437 tqrCombined = row.getRealValue(
'' + method +
'_qrCombined', 0, ROOT.kTRUE)
438 tqrMC = row.getRealValue(
'qrMC', 0, ROOT.kTRUE)
439 tisSignal = row.getRealValue(
'isSignal', 0, ROOT.kTRUE)
441 if tisSignal == 1
and tqrCombined < -1
and abs(tqrMC) == 0:
449 if tqrCombined <= -1:
452 tNumberOfTrueCategories = 0
454 for category
in usedCategories:
456 if category ==
"MaximumPstar":
459 thasTrueTarget = row.getRealValue(
'hasTrueTarget' + category, 0, ROOT.kTRUE)
461 if thasTrueTarget > 0:
462 tNumberOfTrueCategories += 1
465 numberOfTrueCatagories.append(tNumberOfTrueCategories)
469 tDT = row.getRealValue(
"DeltaT", 0, ROOT.kTRUE)
470 dataAll.append([tqrMC, tqrCombined, tNumberOfTrueCategories, tDT])
472 dataAll.append([tqrMC, tqrCombined, tNumberOfTrueCategories])
475 dataAll = np.array(dataAll)
476 dataNoTrueCategory = dataAll[(np.where(dataAll[:, 2] == 0))][:, 0:4]
477 data = dataAll[:, 0:4]
478 numberOfTrueCatagories = np.array(numberOfTrueCatagories)
481 dataB0 = data[np.where(data[:, 0] > 0)]
482 dataB0bar = data[np.where(data[:, 0] < 0)]
484 efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar, wvalue, wvalueB0, wvalueB0bar, wvalueDiff, wvalueDiffUncertainty, \
485 event_fractionB0, event_fractionB0bar, event_fractionDiffUncertainty, event_fractionTotalUncertainty, muParam, \
486 muParamUncertainty = efficiencyCalculator(data, total_notTagged,
False,
'verbose')
488 efficiency =
'% .2f' % efficiency
489 efficiencyDiff =
'%.2f' % efficiencyDiff
490 efficiencyB0 =
'% .2f' % efficiencyB0
491 efficiencyB0bar =
'% .2f' % efficiencyB0bar
494 NB0 = dataB0.shape[0] / N
497 NB0bar = dataB0bar.shape[0] / N
498 NB0bar = 100 * NB0bar
499 NB0bar =
'% .2f' % NB0bar
500 NnoTrueCat = dataNoTrueCategory.shape[0]
501 FracNoFTInfo = NnoTrueCat / N
503 print(
'The total efficiency for B0: ', efficiencyB0,
'%')
504 print(
'The total efficiency for B0bar: ', efficiencyB0bar,
'%')
505 print(
'The total efficiency for method ' + method +
' is: ', efficiency,
'%')
506 print(
'The total efficiency Diff for method ' + method +
' is: ', efficiencyDiff,
'%')
509 print(
'Percentage B0/ N: ', NB0,
'%')
510 print(
'Percentage B0bar / N : ', NB0bar,
'%')
513 print(
"N without trueCats = ", NnoTrueCat)
514 print(
"Fraction Of Events without trueCats Info = ",
'{: 4.2f}'.format(float(FracNoFTInfo * 100)),
"% ")
521 DeltaTbins = list(range(-1000, 1000, 1))
522 for i
in range(0, len(DeltaTbins)):
523 DeltaTbins[i] = float(DeltaTbins[i]) / 10
526 ax = plt.axes([0.21, 0.15, 0.75, 0.8])
527 y, x, _ = ax.hist(data[:, 3], bins=DeltaTbins, facecolor=
'r', histtype=
'stepfilled', edgecolor=
'r')
530 YDTmax = YDTmax - YDTmax / 5
532 if YmaxForDeltaTPlot < YDTmax:
533 YmaxForDeltaTPlot = YDTmax
535 figTmc = plt.figure(1, figsize=(11, 8))
536 axTmc = plt.axes([0.21, 0.15, 0.76, 0.8])
538 axTmc.hist(data[np.where(data[:, 0] == -1)][:, 3], bins=DeltaTbins, histtype=
'step',
539 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0_{\rm tag}$')
541 axTmc.hist(data[np.where(data[:, 0] == 1)][:, 3], bins=DeltaTbins, histtype=
'step',
542 edgecolor=
'r', linewidth=4, alpha=0.9, label=
r'$B^0_{\rm tag}$')
544 p1, = axTmc.plot([], label=
r'$B^0_{\rm tag}$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
545 p2, = axTmc.plot([], label=
r'$\bar{B}^0_{\rm tag}$', linewidth=4.5, linestyle=
'dashed', c=
'b')
547 axTmc.set_ylabel(
r'${\rm Number\ \ of\ \ Events /\ (\, 0.1\ ps\, )}$', fontsize=35)
548 axTmc.set_xlabel(
r'$\Delta t\ /\ {\rm ps}$', fontsize=35)
550 plt.xticks([-10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10], [
r'$-10$',
r'',
r'$5$',
551 r'',
r'$0$',
r'',
r'$5$',
r'',
r'$10$'], rotation=0, size=40)
552 axTmc.tick_params(axis=
'y', labelsize=35)
553 axTmc.legend([p1, p2], [
r'$B^0_{\rm tag}$',
r'$\bar{B}^0_{\rm tag}$'], prop={
'size': 35})
555 axTmc.set_ylim(0, YmaxForDeltaTPlot)
556 axTmc.set_xlim(-10, 10)
557 plt.savefig(workingDirectory +
'/' + method +
'DeltaTMC.pdf')
560 figTft = plt.figure(2, figsize=(11, 8))
561 axTft = plt.axes([0.21, 0.15, 0.76, 0.8])
563 axTft.hist(data[np.where(data[:, 1] < 0)][:, 3], bins=DeltaTbins, histtype=
'step',
564 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0_{\rm tag}$')
566 axTft.hist(data[np.where(data[:, 1] > 0)][:, 3], bins=DeltaTbins, histtype=
'step',
567 edgecolor=
'r', linewidth=4, alpha=0.9, label=
r'$B^0_{\rm tag}$')
569 p1, = axTft.plot([], label=
r'$B^0_{\rm tag}$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
570 p2, = axTft.plot([], label=
r'$\bar{B}^0_{\rm tag}$', linewidth=4.5, linestyle=
'dashed', c=
'b')
572 axTft.set_ylabel(
r'${\rm Number\ \ of\ \ Events /\ (\, 0.1\ ps\, )}$', fontsize=35)
573 axTft.set_xlabel(
r'$\Delta t\ /\ {\rm ps}$', fontsize=35)
575 plt.xticks([-10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10], [
r'$-10$',
r'',
r'$5$',
576 r'',
r'$0$',
r'',
r'$5$',
r'',
r'$10$'], rotation=0, size=40)
577 axTft.tick_params(axis=
'y', labelsize=35)
578 axTft.legend([p1, p2], [
r'$B^0_{\rm tag}$',
r'$\bar{B}^0_{\rm tag}$'], prop={
'size': 35})
580 axTft.set_ylim(0, YmaxForDeltaTPlot)
581 axTft.set_xlim(-10, 10)
582 plt.savefig(workingDirectory +
'/' + method +
'DeltaTFT.pdf')
588 bins = list(range(-50, 51, 1))
589 for i
in range(0, len(bins)):
590 bins[i] = float(bins[i]) / 50
594 bins2 = list(range(-25, 26, 1))
595 for i
in range(0, len(bins2)):
596 bins2[i] = float(bins2[i]) / 25
599 fig1 = plt.figure(2, figsize=(11, 8))
600 ax1 = plt.axes([0.21, 0.15, 0.75, 0.8])
601 y, x, _ = ax1.hist(data[:, 1], bins=bins, facecolor=
'r', histtype=
'stepfilled', edgecolor=
'r')
604 Ymax = Ymax + Ymax / 4
606 if YmaxForQrPlot < Ymax:
609 ax1.set_ylabel(
r'${\rm Number\ \ of\ \ Events /\ (\, 0.02\, )}$', fontsize=35)
610 ax1.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
' }$', fontsize=42)
611 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
612 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=20)
613 ax1.tick_params(axis=
'y', labelsize=20)
615 ax1.set_ylim(0, YmaxForQrPlot)
616 plt.savefig(workingDirectory +
'/' + method +
'QR_Output.pdf')
621 fig2 = plt.figure(3, figsize=(11, 8))
622 ax2 = plt.axes([0.21, 0.15, 0.76, 0.8])
624 ax2.hist(data[np.where(abs(data[:, 0]) == 1)][:, 1], bins=bins, histtype=
'step', edgecolor=
'k',
625 linewidth=4, linestyle=
'dashdot', alpha=0.9, label=
r'${\rm Both}$')
627 ax2.hist(data[np.where(data[:, 0] == 1)][:, 1], bins=bins, histtype=
'step', edgecolor=
'r',
628 linewidth=4, alpha=0.9, label=
r'$B^0$')
630 ax2.hist(data[np.where(data[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
631 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
633 p3, = ax2.plot([], label=
r'${\rm Both}$', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
635 p2, = ax2.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
637 p1, = ax2.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
639 ax2.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
640 ax2.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
644 ax2.tick_params(axis=
'y', labelsize=35)
645 ax2.legend([p3, p2, p1], [
r'${\rm Both}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=9)
647 plt.xticks([-1, -0.875, -0.75, -0.625, -0.5, -0.25, -0.1, 0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
648 [
r'${-1.0}$',
r'',
r'',
r'',
r'${-0.5}$',
r'',
r'',
r'$0$',
r'',
649 r'',
r'$0.5$',
r'',
r'',
r'',
r'$1.0$'], rotation=0, size=35)
651 ax2.set_ylim(0, YmaxForQrPlot)
652 yLocs, yLabels = plt.yticks()
653 plt.savefig(workingDirectory +
'/' + method +
'QR_B0bar.pdf')
658 fig2b = plt.figure(4, figsize=(10, 8))
659 ax2b = plt.axes([0.21, 0.15, 0.76, 0.8])
660 p2b = ax2b.hist(dataNoTrueCategory[np.where(dataNoTrueCategory[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
661 edgecolor=
'b', linewidth=3.5, linestyle=
'dotted', label=
r'$\bar{B}^0$')
676 ax2b.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
677 ax2b.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
678 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
679 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=20)
680 ax2b.tick_params(axis=
'y', labelsize=20)
681 ax2b.legend([
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 20})
684 plt.savefig(workingDirectory +
'/' + method +
'QR_B0barNoTrueCategory.pdf')
699 data_entriesB0 = np.histogram(np.absolute(data[np.where(data[:, 0] == 1)][:, 1]), rbins)[0]
703 np.absolute(data[np.where(data[:, 0] == 1)][:, 1]),
705 weights=np.absolute(data[np.where(data[:, 0] == 1)][:, 1]))[0] / data_entriesB0)
708 np.absolute(data[np.where(data[:, 0] == 1)][:, 1]), rbins, weights=np.absolute(data[np.where(data[:, 0] == 1)][:, 1]) *
709 np.absolute(data[np.where(data[:, 0] == 1)][:, 1]))[0] / data_entriesB0)
710 delta_rvalueB0 = np.sqrt((delta_rvalueB0 - rvalueB0 * rvalueB0) / (data_entriesB0))
712 wrongTaggedB0 = np.histogram(
714 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == 1))][:, 1]), rbins)[0].astype(float)
716 wrong_fractionB0 = (wrongTaggedB0 / data_entriesB0)
718 delta_wrong_fractionB0 = np.sqrt(wrongTaggedB0 * (data_entriesB0 - wrongTaggedB0) / (data_entriesB0**3))
720 rmvaluesB0 = 1 - 2 * wrong_fractionB0
721 delta_rmvaluesB0 = 2 * delta_wrong_fractionB0
723 data_entriesB0bar = np.histogram(np.absolute(data[np.where(data[:, 0] == -1)][:, 1]), rbins)[0]
727 np.absolute(data[np.where(data[:, 0] == -1)][:, 1]),
729 weights=np.absolute(data[np.where(data[:, 0] == -1)][:, 1]))[0] / data_entriesB0bar)
730 delta_rvalueB0bar = (
732 np.absolute(data[np.where(data[:, 0] == -1)][:, 1]), rbins,
733 weights=np.absolute(data[np.where(data[:, 0] == -1)][:, 1]) *
734 np.absolute(data[np.where(data[:, 0] == -1)][:, 1]))[0] / data_entriesB0bar)
735 delta_rvalueB0bar = np.sqrt((delta_rvalueB0bar - rvalueB0bar * rvalueB0bar) / (data_entriesB0bar))
737 wrongTaggedB0bar = np.histogram(
739 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == -1))][:, 1]), rbins)[0].astype(float)
741 wrong_fractionB0bar = (wrongTaggedB0bar / data_entriesB0bar)
743 delta_wrong_fractionB0bar = np.sqrt(wrongTaggedB0bar * (data_entriesB0bar - wrongTaggedB0bar) / (data_entriesB0bar**3))
745 rmvaluesB0bar = 1 - 2 * wrong_fractionB0bar
746 delta_rmvaluesB0bar = 2 * delta_wrong_fractionB0bar
748 rvalue = (rvalueB0 + rvalueB0bar) / 2
749 rmvalues = (rmvaluesB0 + rmvaluesB0bar) / 2
751 delta_rvalue = np.sqrt(delta_rvalueB0**2 + delta_rvalueB0bar**2) / 2
752 delta_rmvalues = np.sqrt(delta_rmvaluesB0**2 + delta_rmvaluesB0bar**2) / 2
754 fig3a = plt.figure(5, figsize=(11, 8))
755 ax3a = plt.axes([0.21, 0.15, 0.74, 0.8])
757 line = range(0, 2, 1)
758 ax3a.plot(line, line, linewidth=4, color=
'r')
760 (p1ca, capsB0, _) = ax3a.errorbar(rvalueB0, np.absolute(rmvaluesB0), xerr=
None, yerr=
None,
762 elinewidth=4, capsize=10, ecolor=
'r', fmt=
'o', mfc=
'r',
763 mec=
'r', markersize=14)
765 (p2ca, capsB0bar, _) = ax3a.errorbar(rvalueB0bar, np.absolute(rmvaluesB0bar), xerr=
None, yerr=
None,
767 elinewidth=4, capsize=10, ecolor=
'b', fmt=
'o', mfc=
'b',
768 mec=
'b', markersize=14)
773 cap.set_markeredgewidth(4)
775 for cap
in capsB0bar:
777 cap.set_markeredgewidth(4)
779 (p3ca, caps, _) = ax3a.errorbar(rvalue, rmvalues, xerr=
None, yerr=
None,
781 elinewidth=4, capsize=10, ecolor=
'k', fmt=
'o', mfc=
'k', mec=
'k', markersize=14)
785 cap.set_markeredgewidth(4)
787 ax3a.legend([p3ca, p2ca, p1ca], [
r'${\rm Average}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=2)
789 ax3a.set_ylabel(
r'$r_{\rm \small MC} = \vert 1-2\cdot w_{\small \rm MC} \vert $', fontsize=42)
790 ax3a.set_xlabel(
r'$\langle r_{\rm ' + label +
'}$' +
r'$\rangle$', fontsize=42)
794 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
795 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
796 plt.yticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
797 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
801 ax3a.xaxis.grid(
True, linewidth=2)
802 plt.savefig(workingDirectory +
'/' + method +
'CalibrationB0B0bar.pdf')
805 fig3 = plt.figure(6, figsize=(11, 8))
806 ax3 = plt.axes([0.21, 0.15, 0.74, 0.8])
808 line = range(0, 2, 1)
809 ax3.plot(line, line, linewidth=4, color=
'r')
811 (_, caps, _) = ax3.errorbar(rvalue, rmvalues, xerr=
None, yerr=
None,
813 elinewidth=4, capsize=10, ecolor=
'b', fmt=
'o', markersize=14)
816 cap.set_markeredgewidth(4)
818 ax3.set_ylabel(
r'$r_{\rm \small MC} = 1-2\cdot w_{\small \rm MC}$', fontsize=42)
819 ax3.set_xlabel(
r'$\langle r_{\rm ' + label +
'}$' +
r'$\rangle$', fontsize=42)
823 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
824 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
825 plt.yticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
826 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
830 ax3.xaxis.grid(
True, linewidth=2)
831 plt.savefig(workingDirectory +
'/' + method +
'Calibration.pdf')
836 fig4 = plt.figure(7, figsize=(11, 8))
837 ax4 = plt.axes([0.21, 0.15, 0.76, 0.8])
838 ax4.hist(np.absolute(data[:, 1]), bins=bins, facecolor=
'r', histtype=
'stepfilled', edgecolor=
'r')
839 ax4.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
840 ax4.set_xlabel(
r'$r_{\rm ' + label +
' }$', fontsize=42)
841 ax4.tick_params(axis=
'y', labelsize=30)
850 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
851 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'$0.625$',
r'$0.75$',
r'$0.875$',
r'$1$'], rotation=0, size=30)
853 ax4.xaxis.grid(
True, linewidth=2)
854 plt.savefig(workingDirectory +
'/' + method +
'R_Output.pdf')
861 fig2a = plt.figure(8, figsize=(11, 8))
862 ax2a = plt.axes([0.21, 0.15, 0.76, 0.8])
864 ax2a.hist(data[np.where((abs(data[:, 0]) == 1) & (data[:, 1] >= 0))][:, 1], bins=bins, histtype=
'step', edgecolor=
'k',
865 linewidth=4, linestyle=
'dashdot', alpha=0.9, label=
r'$q \geq 0 $')
867 ax2a.hist(data[np.where((abs(data[:, 0]) == 1) & (data[:, 1] < 0))][:, 1] * (-1), bins=bins, histtype=
'step', edgecolor=
'g',
868 linewidth=4, linestyle=
'dashed', alpha=0.9, label=
r'$q < 0 $')
870 p3a, = ax2a.plot([], label=
r'$q \geq 0 $', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
872 p2a, = ax2a.plot([], label=
r'$q < 0 $', linewidth=4.5, linestyle=
'dashed', c=
'g')
874 ax2a.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
875 ax2a.set_xlabel(
r'$(q\cdot q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
879 ax2a.tick_params(axis=
'y', labelsize=35)
880 ax2a.legend([p3a, p2a], [
r'$q \geq 0 $',
r'$q < 0 $'], prop={
'size': 35}, loc=2)
882 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
883 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
886 ax2a.set_ylim(0, YmaxForQrPlot)
887 plt.savefig(workingDirectory +
'/' + method +
'Folded_QR_Both.pdf')
922 fig2e = plt.figure(9, figsize=(11, 11))
923 ax2e = plt.axes([0.21, 0.37, 0.76, 0.60])
925 nB0bar, nbins, patches = ax2e.hist(data[np.where(data[:, 0] == -1)][:, 1] * (-1), bins=bins, histtype=
'step',
926 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
928 nB0, nbins, patches = ax2e.hist(data[np.where(data[:, 0] == 1)][:, 1], bins=bins, histtype=
'step', edgecolor=
'r',
929 linewidth=4, alpha=0.7, label=
r'$B^0$')
931 p2c, = ax2e.plot([], label=
r'$\bar{B}^0$', linewidth=4, linestyle=
'dashed', c=
'b')
933 p1c, = ax2e.plot([], label=
r'$B^0$', linewidth=4.5, linestyle=
'solid', alpha=0.9, c=
'r')
935 ax2e.set_ylabel(
r'${\rm Events\ /\ (\, 0.02\, )}$', fontsize=35)
940 ax2e.tick_params(axis=
'y', labelsize=35)
941 ax2e.legend([p2c, p1c], [
r'$\bar{B}^0\, (q_{\rm MC} = -1)$',
r'$B^0\, (q_{\rm MC} = +1)$'], prop={
'size': 35}, loc=2)
943 plt.xticks([-1, -0.875, -0.75, -0.625, -0.5, -0.25, -0.1, 0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
944 [
r'',
r'',
r'',
r'',
r'',
r'',
r'',
r'',
r'',
945 r'',
r'',
r'',
r'',
r'',
r''], rotation=0, size=35)
947 plt.yticks(yLocs, yLabels)
948 ax2e.set_ylim(0, YmaxForQrPlot)
952 np.seterr(divide=
'ignore', invalid=
'ignore')
953 asymmetryArray = (nB0 - nB0bar) / (nB0 + nB0bar)
954 asymmetryArrayUncertainties = np.zeros(asymmetryArray.shape)
956 for i
in range(0, nB0.shape[0]):
957 denominator = nB0[i] + nB0bar[i]
959 asymmetryArrayUncertainties[i] = 2 * math.sqrt(
960 (nB0[i] * math.sqrt(nB0[i])) ** 2 +
961 (nB0bar[i] * math.sqrt(nB0bar[i]))**2) / (denominator)**2
964 nBinCenters = 0.5 * (nbins[1:] + nbins[:-1])
966 ax2eA = plt.axes([0.21, 0.15, 0.76, 0.2])
971 ax2eA.errorbar(nBinCenters, asymmetryArray, xerr=float(0.01),
972 yerr=asymmetryArrayUncertainties, elinewidth=2, mew=2, ecolor=
'k',
973 fmt=
'o', mfc=
'k', mec=
'k', markersize=3, label=
r'${\rm Data}$')
975 ax2eA.set_ylabel(
r'$\frac{N^{B^0}\; -\;\, N^{\overline{B}^0}}{N^{B^0}\; +\;\, N^{\overline{B}^0}}$', fontsize=44, labelpad=20)
976 ax2eA.yaxis.labelpad = 0
977 plt.yticks([-0.4, -0.2, 0, 0.2, 0.4],
978 [
r'',
r'$-0.2$',
r'$0.0$',
r'$0.2$',
r''], rotation=0, size=28)
980 ax2eA.set_ylim(-0.4, 0.4)
981 ax2eA.set_xlim(ax2e.get_xlim())
983 ax2eA.xaxis.grid(
True)
984 ax2eA.yaxis.grid(
True)
994 plt.xticks([-1, -0.875, -0.75, -0.625, -0.5, -0.25, -0.1, 0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
995 [
r'${-1.0}$',
r'',
r'',
r'',
r'${-0.5}$',
r'',
r'',
r'$0$',
r'',
996 r'',
r'$0.5$',
r'',
r'',
r'',
r'$1.0$'], rotation=0, size=35)
998 ax2eA.set_xlabel(
r'$q_{\rm MC}\cdot(q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
999 plt.savefig(workingDirectory +
'/' + method +
'_Folded_QR_B0barWithAsymm.pdf')
1004 fig2d = plt.figure(11, figsize=(11, 8))
1005 ax2d = plt.axes([0.21, 0.15, 0.76, 0.8])
1010 ax2d.hist(np.absolute(data[np.where(data[:, 0] == -1)][:, 1]), bins=bins, histtype=
'step',
1011 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1013 ax2d.hist(np.absolute(data[np.where(data[:, 0] == 1)][:, 1]), bins=bins, histtype=
'step', edgecolor=
'r',
1014 linewidth=4, alpha=0.9, label=
r'$B^0$')
1018 p2d, = ax2d.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1020 p1d, = ax2d.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1022 ax2d.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
1023 ax2d.set_xlabel(
r'$r_{\rm ' + label +
'}$', fontsize=42)
1027 ax2d.tick_params(axis=
'y', labelsize=35)
1028 ax2d.legend([p2d, p1d], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=2)
1030 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
1031 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
1034 ax2d.set_yscale(
'log', nonposy=
'clip')
1036 plt.savefig(workingDirectory +
'/' + method +
'_Folded_R_B0bar.pdf')
1041 fig5 = plt.figure(12, figsize=(11, 15))
1042 ax5 = plt.axes([0.21, 0.53, 0.76, 0.45])
1044 rBinCenters = 0.5 * (rbins[1:] + rbins[:-1])
1045 rBinWidths = 0.5 * (rbins[1:] - rbins[:-1])
1047 eb = ax5.errorbar(rBinCenters, 50 * (wvalueB0bar + wvalueB0), xerr=rBinWidths, yerr=50 * wvalueDiffUncertainty,
1048 label=
r'${\rm Average}$', elinewidth=4.5, ecolor=
'k', fmt=
'o', mfc=
'k', mec=
'k',
1049 mew=0, markersize=0)
1050 eb[-1][0].set_linestyle(
'dashdot')
1051 eb[-1][0].set_alpha(0.9)
1053 ebB0bar = ax5.errorbar(rBinCenters, 100 * wvalueB0, xerr=rBinWidths, yerr=50 * wvalueDiffUncertainty,
1054 label=
r'$B^0$', elinewidth=4, ecolor=
'r', fmt=
'o', mfc=
'k', mec=
'k',
1055 mew=0, markersize=0)
1056 ebB0bar[-1][0].set_alpha(0.9)
1058 ebB0bar = ax5.errorbar(rBinCenters, 100 * wvalueB0bar, xerr=rBinWidths, yerr=50 * wvalueDiffUncertainty,
1059 label=
r'$\bar{B}^0$', elinewidth=4.5, ecolor=
'b', fmt=
'o', mfc=
'k', mec=
'k',
1060 mew=0, markersize=0)
1061 ebB0bar[-1][0].set_linestyle(
'--')
1063 ax5.set_ylabel(
r'$w\ [\%]$', fontsize=45)
1064 ax5.yaxis.labelpad = 36
1067 plt.yticks([0, 10, 20, 30, 40, 50], [
r'$0$',
1068 r'$10$',
r'$20$',
r'$30$',
r'$40$',
r'$50$'], rotation=0, size=44)
1069 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1], [
r'',
r'',
1070 r'',
r'',
r'',
r'',
r'',
r''], rotation=0, size=44)
1072 p3d, = ax5.plot([], label=
r'${\rm Average}$', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
1074 p2d, = ax5.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1076 p1d, = ax5.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1078 ax5.legend([p3d, p2d, p1d], [
r'${\rm Average}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 38}, loc=1)
1083 ax5A = plt.axes([0.21, 0.08, 0.76, 0.43])
1085 ax5A.errorbar(rBinCenters, 100 * wvalueDiff, xerr=rBinWidths,
1086 yerr=100 * wvalueDiffUncertainty, elinewidth=3, mew=2, ecolor=
'k',
1087 fmt=
'o', mfc=
'k', mec=
'k', markersize=3, label=
r'${\rm Data}$')
1089 ax5A.set_ylim(-14, 14)
1091 plt.yticks([-14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14],
1092 [
r'',
r'$-12$',
r'',
r'$-8$',
r'',
r'$-4$',
r'',
r'$0$',
1093 r'',
r'$4$',
r'',
r'$8$',
r'',
r'$12$',
r''], rotation=0, size=44)
1095 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
1096 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=42)
1098 ax5A.xaxis.grid(
True)
1099 ax5A.yaxis.grid(
True)
1100 ax5A.set_ylabel(
r'$\Delta w\ [\%]$', fontsize=45)
1101 ax5A.set_xlabel(
r'$r_{\rm ' + label +
'}$', fontsize=45)
1103 plt.savefig(workingDirectory +
'/' + method +
'_WrongTagFraction.pdf')
1108 fig6 = plt.figure(13, figsize=(11, 15))
1109 ax6 = plt.axes([0.21, 0.53, 0.76, 0.45])
1111 rBinCenters = 0.5 * (rbins[1:] + rbins[:-1])
1112 rBinWidths = 0.5 * (rbins[1:] - rbins[:-1])
1114 eb = ax6.errorbar(rBinCenters, 50 * (event_fractionB0bar + event_fractionB0), xerr=rBinWidths, yerr=50 * muParamUncertainty,
1115 label=
r'${\rm Average}$', elinewidth=4.5, ecolor=
'k', fmt=
'o', mfc=
'k', mec=
'k',
1116 mew=0, markersize=0)
1117 eb[-1][0].set_linestyle(
'dashdot')
1118 eb[-1][0].set_alpha(0.9)
1120 ebB0bar = ax6.errorbar(rBinCenters, 100 * event_fractionB0bar, xerr=rBinWidths, yerr=50 * muParamUncertainty,
1121 label=
r'$B^0$', elinewidth=4, ecolor=
'r', fmt=
'o', mfc=
'k', mec=
'k',
1122 mew=0, markersize=0)
1123 ebB0bar[-1][0].set_alpha(0.9)
1125 ebB0bar = ax6.errorbar(rBinCenters, 100 * event_fractionB0, xerr=rBinWidths, yerr=50 * muParamUncertainty,
1126 label=
r'$\bar{B}^0$', elinewidth=4.5, ecolor=
'b', fmt=
'o', mfc=
'k', mec=
'k',
1127 mew=0, markersize=0)
1128 ebB0bar[-1][0].set_linestyle(
'--')
1130 ax6.set_ylabel(
r'$\varepsilon\ [\%]$', fontsize=45)
1131 ax6.yaxis.labelpad = 36
1134 plt.yticks([0, 5, 10, 15, 20, 25, 30], [
r'$0$',
r'',
1135 r'$10$',
r'',
r'$20$',
r'',
r'$30$'], rotation=0, size=45)
1136 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1], [
r'',
r'',
1137 r'',
r'',
r'',
r'',
r'',
r''], rotation=0, size=44)
1139 p3d, = ax6.plot([], label=
r'${\rm Average}$', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
1141 p2d, = ax6.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1143 p1d, = ax6.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1145 ax6.legend([p3d, p2d, p1d], [
r'${\rm Average}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 38}, loc=1)
1150 ax6A = plt.axes([0.21, 0.08, 0.76, 0.43])
1152 ax6A.errorbar(rBinCenters, 100 * muParam, xerr=rBinWidths,
1153 yerr=100 * muParamUncertainty, elinewidth=3, mew=2, ecolor=
'k',
1154 fmt=
'o', mfc=
'k', mec=
'k', markersize=3, label=
r'${\rm Data}$')
1156 ax6A.set_ylim(-4, 4)
1158 plt.yticks([-3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5],
1159 [
r'',
r'$-3$',
r'',
r'$-2$',
r'',
r'$-1$',
r'',
r'$0$',
r'',
r'$1$',
r'',
r'$2$',
r'',
r'$3$',
r''],
1160 rotation=0, size=45)
1162 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
1163 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=42)
1165 ax6A.xaxis.grid(
True)
1166 ax6A.yaxis.grid(
True)
1167 ax6A.set_ylabel(
r'$\mu\ [\%]$', fontsize=45)
1168 ax6A.set_xlabel(
r'$r_{\rm ' + label +
'}$', fontsize=45)
1170 ax6A.yaxis.labelpad = 25
1172 plt.savefig(workingDirectory +
'/' + method +
'_EfficiencyAndMu.pdf')
1177 fig7 = plt.figure(14, figsize=(11, 8))
1178 ax7 = plt.axes([0.21, 0.15, 0.76, 0.8])
1179 weights = np.ones_like(numberOfTrueCatagories) * 100 / float(len(numberOfTrueCatagories))
1180 hi5, w, _ = ax4.hist(numberOfTrueCatagories, weights=weights, bins=list(
1181 range(0, 14, 1)), facecolor=
'r', histtype=
'stepfilled', edgecolor=
'k')
1183 ax7.bar(np.array(range(0, 13, 1)) + 0.1, hi5, 0.8, color=
'r', ecolor=
'k')
1184 ax7.set_ylabel(
r'${\rm Percentage\ of\ Events\ /\ (\, 0.02\, )}$', fontsize=25)
1185 ax7.set_xlabel(
r'${\rm True\ Categories}$', fontsize=25)
1186 plt.xticks([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5],
1187 [
r'$0$',
r'$1$',
r'$2$',
r'$3$',
r'$4$',
r'$5$',
r'$6$',
r'$7$',
r'$8$'],
1188 rotation=0, horizontalalignment=
'center', size=25)
1189 ax7.tick_params(axis=
'y', labelsize=25)
1193 plt.savefig(workingDirectory +
'/' + method +
'TrueCategories.pdf')
1196 fig = plt.figure(figsize=(8, 8))
1197 ax = fig.add_subplot(111, projection=
'3d')
1200 bins2 = list(range(-51, 51, 1))
1201 for i
in range(0, len(bins2)):
1202 bins2[i] = float(bins2[i]) / 50
1204 bins2 = np.array(bins2)
1208 return colorConverter.to_rgba(arg, alpha=0.5)
1214 zs = list(range(0, 7, 1))
1220 for z
in range(0, 7, 1):
1221 dataTrueCats = dataAll[(np.where(dataAll[:, 2] == z))][:, 0:2]
1222 weightsa = np.ones_like(dataTrueCats[np.where(dataTrueCats[:, 0] == -1)][:, 1]) * \
1223 (hi5[z] * dataAll.shape[0] / 100) / float(len(dataTrueCats[:, 1]))
1224 weightsb = np.ones_like(dataTrueCats[np.where(dataTrueCats[:, 0] == 1)][:, 1]) * \
1225 (hi5[z] * dataAll.shape[0] / 100) / float(len(dataTrueCats[:, 1]))
1226 ya, wa, _ = ax2.hist(dataTrueCats[np.where(dataTrueCats[:, 0] == -1)][:, 1], weights=weightsa, bins=bins, histtype=
'step',
1227 edgecolor=
'b', linewidth=3.5, linestyle=
'dotted', label=
r'$\bar{B}^0$')
1228 yb, wb, _ = ax2.hist(dataTrueCats[np.where(dataTrueCats[:, 0] == 1)][:, 1], weights=weightsb, bins=bins, histtype=
'step',
1229 edgecolor=
'r', linewidth=2, label=
r'$B^0$')
1230 ya = np.insert(ya, ya.shape[0], 0)
1231 ya = np.insert(ya, 0, 0)
1232 yb = np.insert(yb, yb.shape[0], 0)
1233 yb = np.insert(yb, 0, 0)
1238 colorsa.append(cc(
'b'))
1239 colorsb.append(cc(
'r'))
1240 vertsa.append(list(zip(bins2, ya)))
1241 vertsb.append(list(zip(bins2, yb)))
1243 iEfficiency, iEfficiencyDiff, iEfficiencyB0, iEfficiencyB0bar = efficiencyCalculator(dataTrueCats, total_notTagged,
True)
1245 iEfficiencies.append([iEfficiencyB0, iEfficiencyB0bar])
1247 polya = PolyCollection(vertsa, facecolors=colorsa)
1248 polyb = PolyCollection(vertsb, facecolors=colorsb)
1249 polya.set_alpha(0.5)
1250 polyb.set_alpha(0.5)
1251 ax.add_collection3d(polya, zs=zs, zdir=
'y')
1252 ax.add_collection3d(polyb, zs=zs, zdir=
'y')
1260 ax.set_xlim3d(-1, 1)
1261 ax.set_ylim3d(-0.5, 7)
1262 ax.set_yticks([0, 1, 2, 3, 4, 5, 6])
1263 ax.xaxis.labelpad = 18
1264 ax.yaxis.labelpad = 16
1265 ax.zaxis.labelpad = 22
1267 ax.set_yticklabels(sorted({
r'$0$',
r'$1$',
r'$2$',
r'$3$',
r'$4$',
r'$5$',
r'$6$'}),
1268 verticalalignment=
'baseline',
1269 horizontalalignment=
'left')
1271 ax.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
' }$')
1272 ax.set_ylabel(
r'${\rm True\ Categories}$')
1273 ax.set_zlabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', rotation=-90)
1274 Zmax = Zmax + Zmax / 5
1275 ax.set_zlim3d(0, Zmax)
1276 p1 = plt.Rectangle((0, 0), 1, 1, fc=
"b", alpha=0.5)
1277 p2 = plt.Rectangle((0, 0), 1, 1, fc=
"r", alpha=0.5)
1278 ax.legend([p1, p2], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 20}, loc=(0.523, 0.687))
1279 plt.savefig(workingDirectory +
'/3DTrueCategorieQR' + method +
'.pdf')
1282 iEfficiencies = np.array(iEfficiencies)
1284 fig = plt.figure(15, figsize=(12, 8))
1285 ax = plt.axes([0.18, 0.15, 0.8, 0.8])
1288 p1 = ax.bar(np.array(range(0, 7, 1)) + width / 4, iEfficiencies[:, 1], width, color=
'b', ecolor=
'k', label=
r'$\bar{B}^0$')
1289 p2 = ax.bar(np.array(range(0, 7, 1)) + width + width / 4, iEfficiencies[:, 0], width, color=
'r', ecolor=
'k', label=
r'$B^0$')
1290 ax.set_ylabel(
r'$ \varepsilon_{\rm eff}/\ \% $', fontsize=35)
1291 ax.set_xlabel(
r'${\rm True\ Categories}$', fontsize=35)
1292 plt.xticks([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5],
1293 [
r'$0$',
r'$1$',
r'$2$',
r'$3$',
r'$4$',
r'$5$',
r'$6$',
r'$7$',
r'$8$'],
1294 rotation=0, horizontalalignment=
'center', size=35)
1295 ax.tick_params(axis=
'y', labelsize=35)
1298 ax.legend([
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35})
1300 plt.savefig(workingDirectory +
'/EfficienciesTrueCats' + method +
'.pdf')
1304 NoTargetEfficiencies = []
1307 categoryLabelsDict = {
'Electron':
r'${\rm Electron}$',
1308 'IntermediateElectron':
r'${\rm Int. Electron}$',
1309 'Muon':
r'${\rm Muon}$',
1310 'IntermediateMuon':
r'${\rm Int. Muon}$',
1311 'KinLepton':
r'${\rm KinLepton}$',
1312 'IntermediateKinLepton':
r'${\rm Int. KinLepton}$',
1313 'Kaon':
r'${\rm Kaon}$',
1314 'SlowPion':
r'${\rm Slow Pion}$',
1315 'FastHadron':
r'${\rm Fast Hadron}$',
1316 'Lambda':
r'${\rm Lambda}$',
1317 'FSC':
r'${\rm FSC}$',
1318 'MaximumPstar':
r'${\rm MaximumPstar}$',
1319 'KaonPion':
r'${\rm Kaon-Pion}$'}
1354 qrMC = ROOT.RooRealVar(
'qrMC',
'qrMC', 0, -1.0, 1.0)
1355 argSet = ROOT.RooArgSet(qrMC)
1357 for iCategory
in usedCategories:
1359 with Quiet(ROOT.kError):
1364 "ROOT.RooRealVar('hasTrueTarget' + iCategory, 'hasTrueTarget' + iCategory, 0, -2.1, 1.1)"))
1369 "ROOT.RooRealVar('qp' + iCategory, 'hasTrueTarget' + iCategory, 0, -2.1, 1.1)"))
1373 exec(
"%s" %
"argSet.add(hasTrueTarget" + iCategory +
")")
1374 exec(
"%s" %
"argSet.add(qp" + iCategory +
")")
1375 rooDataSet = ROOT.RooDataSet(
"data",
"data", tree, argSet,
"")
1377 for category
in usedCategories:
1388 for i
in range(rooDataSet.numEntries()):
1389 row = rooDataSet.get(i)
1390 tqp = row.getRealValue(
'qp' + category, 0, ROOT.kTRUE)
1391 thasTrueTarget = row.getRealValue(
'hasTrueTarget' + category, 0, ROOT.kTRUE)
1392 tqrMC = row.getRealValue(
'qrMC', 0, ROOT.kTRUE)
1394 tNumberOfTrueCategories = 0
1395 noMCAssociated =
False
1397 for iCategory
in usedCategories:
1399 if iCategory ==
"MaximumPstar":
1401 ihasTrueTarget = row.getRealValue(
'hasTrueTarget' + iCategory, 0, ROOT.kTRUE)
1404 if ihasTrueTarget > 0:
1405 tNumberOfTrueCategories += 1
1406 if ihasTrueTarget < 0:
1407 noMCAssociated =
True
1417 data.append([tqrMC, tqp])
1418 if thasTrueTarget > 0:
1419 dataTruth.append([tqrMC, tqp])
1420 if tNumberOfTrueCategories < 1
and not noMCAssociated:
1422 if category ==
"Lambda" and tqp == 0:
1425 dataNoTarget.append([tqrMC, tqp])
1427 data = np.array(data)
1428 dataTruth = np.array(dataTruth)
1429 dataNoTarget = np.array(dataNoTarget)
1433 noTargetEfficiency, noTargetEfficiencyDiff, noTargetEfficiencyB0, noTargetEfficiencyB0bar = categoriesEfficiencyCalculator(data)
1434 print(
"Efficiencies for B0, B0bar = ",
'{: 6.2f}'.format(noTargetEfficiencyB0),
1435 " %, ",
'{: 6.2f}'.format(noTargetEfficiencyB0bar),
" %")
1437 noTargetEfficiency, noTargetEfficiencyDiff, noTargetEfficiencyB0, noTargetEfficiencyB0bar = categoriesEfficiencyCalculator(
1439 print(
"Efficiencies for B0, B0bar If Not Target = ",
'{: 6.2f}'.format(
1440 noTargetEfficiencyB0),
" %, ",
'{: 6.2f}'.format(noTargetEfficiencyB0bar),
" %")
1442 NoTargetEfficiencies.append([noTargetEfficiencyB0, noTargetEfficiencyB0bar])
1443 categoryLabel.append(categoryLabelsDict[category])
1445 trueTargetEfficiency, trueTargetEfficiencyDiff, trueTargetEfficiencyB0, \
1446 trueTargetEfficiencyB0bar = categoriesEfficiencyCalculator(dataTruth)
1447 print(
"Efficiencies for B0, B0bar If True Target= ",
'{: 6.2f}'.format(
1448 trueTargetEfficiencyB0),
" %, ",
'{: 6.2f}'.format(trueTargetEfficiencyB0bar),
" %")
1454 bins = list(range(-50, 51, 1))
1455 for i
in range(0, len(bins)):
1456 bins[i] = float(bins[i]) / 50
1461 if category !=
'Lambda' and category !=
'MaximumPstar' and category !=
'Kaon':
1462 title =
r'$q_{\rm cand}\cdot y_{\rm ' + category +
'}$'
1463 elif category ==
'MaximumPstar':
1464 title =
r'$q_{\rm cand}\cdot y_{{\rm Maximum}\, p^*}$'
1466 elif category ==
'Kaon':
1468 title =
r'$(q_{\rm cand}\cdot y_{\rm Kaon})_{\rm eff}$'
1469 elif category ==
'Lambda':
1470 title =
r'$(q_{\rm \Lambda}\cdot y_{\rm Lambda})_{\rm eff}$'
1472 if category ==
'IntermediateKinLepton':
1474 title =
r'$q_{\rm cand}\cdot y_{\rm Int.\, Kin.\, Lepton}$'
1475 elif category ==
'KinLepton':
1476 title =
r'$q_{\rm cand}\cdot y_{\rm Kin.\, Lepton}$'
1477 elif category ==
'IntermediateMuon':
1478 title =
r'$q_{\rm cand}\cdot y_{\rm Int.\, Muon}$'
1479 elif category ==
'IntermediateElectron':
1480 title =
r'$q_{\rm cand}\cdot y_{\rm Int.\, Electron}$'
1481 elif category ==
'KaonPion':
1482 title =
r'$q_{\rm cand}\cdot y_{\rm Kaon-Pion}$'
1483 elif category ==
'FastHadron':
1485 title =
r'$q_{\rm cand}\cdot y_{\rm Fast\, Hadron}$'
1486 elif category ==
'SlowPion':
1487 title =
r'$q_{\rm cand}\cdot y_{\rm Slow\, Pion}$'
1489 fig2 = plt.figure(2, figsize=(11, 8))
1490 ax2 = plt.axes([0.21, 0.16, 0.75, 0.81])
1491 ax2.hist(data[np.where(data[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
1492 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1494 data[np.where(data[:, 0] == 1)][:, 1],
1502 p2, = ax2.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1503 p1, = ax2.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1505 ax2.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=37)
1506 ax2.set_xlabel(title, fontsize=48)
1507 ax2.set_yscale(
'log', nonposy=
'clip')
1508 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
1509 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=37)
1510 ax2.tick_params(axis=
'y', labelsize=37)
1511 ax2.legend([p2, p1], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=location)
1513 plt.savefig(workingDirectory +
'/' +
'pyPIC_' + category +
'_Input_Combiner.pdf')
1516 fig2b = plt.figure(2, figsize=(11, 8))
1517 ax2b = plt.axes([0.21, 0.16, 0.75, 0.81])
1518 ax2b.hist(dataTruth[np.where(dataTruth[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
1519 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1521 dataTruth[np.where(dataTruth[:, 0] == 1)][:, 1],
1529 p2, = ax2b.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1530 p1, = ax2b.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1532 ax2b.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=37)
1533 ax2b.set_xlabel(title, fontsize=48)
1534 ax2b.set_yscale(
'log', nonposy=
'clip')
1535 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
1536 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=37)
1537 ax2b.tick_params(axis=
'y', labelsize=37)
1538 ax2b.legend([p2, p1], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=location)
1540 plt.savefig(workingDirectory +
'/' +
'pyPIC_' + category +
'_Input_CombinerTruth.pdf')
1543 fig2c = plt.figure(2, figsize=(11, 8))
1544 ax2c = plt.axes([0.21, 0.16, 0.75, 0.81])
1545 ax2c.hist(dataNoTarget[np.where(dataNoTarget[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
1546 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1548 dataNoTarget[np.where(dataNoTarget[:, 0] == 1)][:, 1],
1556 p2, = ax2c.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1557 p1, = ax2c.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1559 ax2c.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=37)
1560 ax2c.set_xlabel(title, fontsize=48)
1561 ax2c.set_yscale(
'log', nonposy=
'clip')
1562 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
1563 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=37)
1564 ax2c.tick_params(axis=
'y', labelsize=37)
1565 ax2c.legend([p2, p1], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=location)
1567 plt.savefig(workingDirectory +
'/' +
'pyPIC_' + category +
'_Input_CombinerNoTarget.pdf')
1570 percentageCategory = dataTruth.shape[0] / data.shape[0] * 100
1571 percentageCategory =
'% .2f' % percentageCategory
1573 print(
"Percentage of Category " + category +
" is = " + percentageCategory +
" %")
1577 NoTargetEfficiencies = np.array(NoTargetEfficiencies)
1578 fig = plt.figure(5, figsize=(29, 18))
1579 ax = plt.axes([0.15, 0.3, 0.81, 0.67])
1582 p1 = ax.bar(np.array(range(0, 13, 1)) + width / 4, NoTargetEfficiencies[:, 1], width, color=
'b', ecolor=
'k', label=
r'$\bar{B}^0$')
1583 p2 = ax.bar(np.array(range(0, 13, 1)) + width + width / 4, NoTargetEfficiencies[:, 0], width, color=
'r', ecolor=
'k', label=
r'$B^0$')
1584 ax.set_ylabel(
r'$ \varepsilon_{\rm eff}/\ \% $', fontsize=30)
1585 plt.xticks([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5, 11.5, 12.5],
1586 categoryLabel, rotation=50, horizontalalignment=
'right', size=30)
1587 plt.yticks([5, 10, 15, 20, 25, 50, 100], [
r"$5$",
r"",
r"$15$",
r"",
r"$25$",
r"$50$",
r"$100$"], size=30)
1590 ax.legend([
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 25})
1592 plt.savefig(workingDirectory +
'/EfficienciesNoTarget.pdf')
1596 print(
'*******************************************************************************************************************')
1597 B2INFO(
'qr Output Histograms in pdf format saved at: ' + workingDirectory)