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 import flavorTagger
as ft
34 from defaultEvaluationParameters
import categories, Quiet, rbins
35 from array
import array
38 import matplotlib
as mpl
40 mpl.rcParams.update({
'font.size': 22})
41 mpl.rcParams[
'text.usetex'] =
True
42 mpl.rcParams[
'text.latex.preamble'] = [
r"\usepackage{amsmath}"]
44 PyConfig.IgnoreCommandLineOptions =
True
45 PyConfig.StartGuiThread =
False
47 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.WARNING)
50 def efficiencyCalculator(data, total_notTagged, SimpleOutput=False, v='notVerbose'):
54 dataB0 = data[np.where(data[:, 0] > 0)]
55 dataB0bar = data[np.where(data[:, 0] < 0)]
57 totaldataB0 = np.absolute(dataB0[:, 1])
58 totaldataB0bar = np.absolute(dataB0bar[:, 1])
60 rvalueB0 = (np.histogram(totaldataB0, rbins, weights=totaldataB0)[0] / np.histogram(totaldataB0, rbins)[0])
61 rvalueB0MeanSquared = (
71 entriesB0 = np.histogram(totaldataB0, rbins)[0]
73 rvalueB0bar = (np.histogram(totaldataB0bar, rbins, weights=totaldataB0bar)[0] / np.histogram(totaldataB0bar, rbins)[0])
74 rvalueB0barMeanSquared = (
78 weights=totaldataB0bar *
83 entriesB0bar = np.histogram(totaldataB0bar, rbins)[0]
86 if row[0] == 1
and abs(row[1]) > 1:
89 total_entries_B0 = totaldataB0.shape[0] + total_notTagged / 2
91 event_fraction_B0 = entriesB0.astype(float) / total_entries_B0
93 total_entries_B0bar = totaldataB0bar.shape[0] + total_notTagged / 2
95 event_fraction_B0bar = entriesB0bar.astype(float) / total_entries_B0bar
99 arrayShape = len(rbins) - 1
101 event_fractionTotal = np.zeros(arrayShape)
102 event_fractionB0 = np.zeros(arrayShape)
103 event_fractionB0bar = np.zeros(arrayShape)
104 event_fractionDiff = np.zeros(arrayShape)
105 event_fractionDiffUncertainty = np.zeros(arrayShape)
106 event_fractionTotalUncertainty = np.zeros(arrayShape)
108 wvalue = np.zeros(arrayShape)
109 wvalueB0 = np.zeros(arrayShape)
110 wvalueB0bar = np.zeros(arrayShape)
111 wvalueDiff = np.zeros(arrayShape)
112 wvalueDiffUncertainty = np.zeros(arrayShape)
113 wvalueUncertainty = np.zeros(arrayShape)
115 rvalueStdB0 = np.zeros(arrayShape)
116 rvalueStdB0bar = np.zeros(arrayShape)
118 muParam = np.zeros(arrayShape)
119 muParamUncertainty = np.zeros(arrayShape)
123 NwrongB0 = np.histogram(
125 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == 1))][:, 1]), rbins)[0].astype(float)
127 wvalueB0 = (NwrongB0 / entriesB0)
129 wvalueB0Uncertainty = np.sqrt(NwrongB0 * (entriesB0 - NwrongB0) / (entriesB0**3))
131 NwrongB0bar = np.histogram(
133 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == -1))][:, 1]), rbins)[0].astype(float)
135 wvalueB0bar = (NwrongB0bar / entriesB0bar)
137 wvalueB0barUncertainty = np.sqrt(NwrongB0bar * (entriesB0bar - NwrongB0bar) / (entriesB0bar**3))
139 wvalueDiff = wvalueB0 - wvalueB0bar
140 wvalueDiffUncertainty = np.sqrt(wvalueB0Uncertainty**2 + wvalueB0barUncertainty**2)
142 for i
in range(0, len(rbins) - 1):
144 event_fractionB0[i] = entriesB0[i] / total_entries_B0
145 event_fractionB0bar[i] = entriesB0bar[i] / total_entries_B0bar
147 event_fractionTotal[i] = (event_fractionB0[i] + event_fractionB0bar[i]) / 2
148 event_fractionDiff[i] = event_fractionB0[i] - event_fractionB0bar[i]
150 event_fractionDiffUncertainty[i] = math.sqrt(entriesB0[i] *
153 total_entries_B0**3 +
155 (total_entries_B0bar -
157 total_entries_B0bar**3)
159 event_fractionTotalUncertainty[i] = event_fractionDiffUncertainty[i] / 2
161 muParam[i] = event_fractionDiff[i] / (2 * event_fractionTotal[i])
162 muParamUncertainty[i] = event_fractionDiffUncertainty[i] / (2 * event_fractionTotal[i]) * math.sqrt(muParam[i]**2 + 1)
164 rvalueStdB0[i] = math.sqrt(rvalueB0MeanSquared[i] - (rvalueB0[i])**2) / math.sqrt(entriesB0[i] - 1)
165 rvalueStdB0bar[i] = math.sqrt(rvalueB0barMeanSquared[i] - (rvalueB0bar[i])**2) / math.sqrt(entriesB0bar[i] - 1)
171 wvalue[i] = (wvalueB0[i] + wvalueB0bar[i]) / 2
172 wvalueUncertainty[i] = wvalueDiffUncertainty[i] / 2
174 tot_eff_eff_B0 += event_fraction_B0[i] * (1 - 2 * wvalueB0[i])**2
175 tot_eff_eff_B0bar += event_fraction_B0bar[i] * (1 - 2 * wvalueB0bar[i])**2
177 eff = event_fractionTotal[i] * (1 - 2 * wvalue[i])**2
179 tot_eff_eff_Avg += eff
181 eff2 = (event_fraction_B0[i] * (1 - 2 * wvalueB0[i])**2 + event_fraction_B0bar[i] * (1 - 2 * wvalueB0bar[i])**2) / 2
183 rval = (rvalueB0[i] + rvalueB0bar[i]) / 2
187 "{: 6.3f}".format(rval),
189 "{: 6.3f}".format(eff),
191 "{: 6.3f}".format(eff2),
205 wvalueDiffUncertainty[i] *
210 event_fractionTotal[i] *
215 event_fractionDiff[i] *
220 event_fractionDiffUncertainty[i] *
230 muParamUncertainty[i] *
233 tot_eff_eff = (tot_eff_eff_B0 + tot_eff_eff_B0bar) / 2
234 tot_eff_diff = tot_eff_eff_B0 - tot_eff_eff_B0bar
235 efficiency = 100 * tot_eff_eff_Avg
236 efficiencyDiff = 100 * tot_eff_diff
237 efficiencyB0 = 100 * tot_eff_eff_B0
238 efficiencyB0bar = 100 * tot_eff_eff_B0bar
241 print(
"Total Efficiency from Avr. rB0 and rB0bar ",
"{: 6.3f}".format(float(100 * tot_eff_eff)))
242 print(
"Total Efficiency from Avr. wB0 and wB0bar ",
"{: 6.3f}".format(float(100 * tot_eff_eff_Avg)))
246 return efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar
250 return efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar, wvalue, wvalueB0, \
251 wvalueB0bar, wvalueDiff, wvalueDiffUncertainty, event_fractionB0, event_fractionB0bar, \
252 event_fractionDiffUncertainty, event_fractionTotalUncertainty, muParam, muParamUncertainty
255 def categoriesEfficiencyCalculator(data, v='notVerbose'):
259 r_subsample = array(
'd', [
269 hist_aver_rB0 = ROOT.TH1F(
'AverageR' + category,
'A good one (B0)' +
270 category, 6, r_subsample)
271 hist_aver_rB0bar = ROOT.TH1F(
'AverageRB0bar_' + category,
'A good one (B0bar)' +
272 category, 6, r_subsample)
274 hist_absqrB0 = ROOT.TH1F(
'AbsQR' + category,
'Abs(qr)(B0) (' + category +
')', 6, r_subsample)
275 hist_absqrB0bar = ROOT.TH1F(
'AbsQRB0bar_' + category,
'Abs(qr) (B0bar) (' + category +
')', 6, r_subsample)
277 dataB0 = data[np.where(data[:, 0] > 0)]
278 dataB0bar = data[np.where(data[:, 0] < 0)] * (-1)
281 bins = list(range(-25, 27, 1))
282 for i
in range(0, len(bins)):
283 bins[i] = float(bins[i]) / 25
286 histoB0 = np.histogram(dataB0, bins=bins)[0]
287 histoB0bar = np.histogram(dataB0bar, bins=bins)[0]
288 histoB0bar = histoB0bar[0:len(histoB0bar) - 1]
289 histoB0bar = histoB0bar[::-1]
291 dilutionB0 = np.zeros(50)
292 dilutionB0bar = np.zeros(50)
294 for i
in range(0, 50):
295 if (histoB0[i] + histoB0bar[i]) != 0:
296 dilutionB0[i] = -1 + 2 * histoB0[i] / (histoB0[i] + histoB0bar[i])
297 dilutionB0bar[i] = -1 + 2 * histoB0bar[i] / (histoB0[i] + histoB0bar[i])
298 hist_absqrB0.Fill(abs(dilutionB0[i]), histoB0[i])
299 hist_absqrB0bar.Fill(abs(dilutionB0bar[i]), histoB0bar[i])
300 hist_aver_rB0.Fill(abs(dilutionB0[i]), abs(dilutionB0[i]) * histoB0[i])
301 hist_aver_rB0bar.Fill(abs(dilutionB0bar[i]), abs(dilutionB0bar[i]) * histoB0bar[i])
303 hist_aver_rB0.Divide(hist_absqrB0)
304 hist_aver_rB0bar.Divide(hist_absqrB0bar)
306 tot_entriesB0 = dataB0[:, 1].shape[0]
307 tot_entriesB0bar = dataB0bar[:, 1].shape[0]
311 rvalueB0 = np.zeros(rbins.shape[0])
312 rvalueB0bar = np.zeros(rbins.shape[0])
313 entriesB0 = np.zeros(rbins.shape[0])
314 entriesB0bar = np.zeros(rbins.shape[0])
315 event_fractionB0 = np.zeros(rbins.shape[0])
316 event_fractionB0bar = np.zeros(rbins.shape[0])
318 for i
in range(1, rbins.shape[0]):
319 rvalueB0[i] = hist_aver_rB0.GetBinContent(i)
320 rvalueB0bar[i] = hist_aver_rB0bar.GetBinContent(i)
321 entriesB0[i] = hist_absqrB0.GetBinContent(i)
322 entriesB0bar[i] = hist_absqrB0bar.GetBinContent(i)
323 event_fractionB0[i] = entriesB0[i] / tot_entriesB0
324 event_fractionB0bar[i] = entriesB0bar[i] / tot_entriesB0bar
325 tot_eff_effB0 = tot_eff_effB0 + event_fractionB0[i] * rvalueB0[i] \
327 tot_eff_effB0bar = tot_eff_effB0bar + event_fractionB0bar[i] * rvalueB0bar[i] \
329 effDiff = tot_eff_effB0 - tot_eff_effB0bar
330 effAverage = (tot_eff_effB0 + tot_eff_effB0bar) / 2
332 efficiency = 100 * effAverage
333 efficiencyDiff = 100 * effDiff
334 efficiencyB0 = 100 * tot_eff_effB0
335 efficiencyB0bar = 100 * tot_eff_effB0bar
337 return efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar
340 ROOT.gROOT.SetBatch(
True)
342 if len(sys.argv) != 3:
343 sys.exit(
"Must provide 2 arguments: [input_sim_file] or ['input_sim_file*'] with wildcards and [treeName]"
345 workingFile = sys.argv[1]
346 workingFiles = glob.glob(str(workingFile))
347 treeName = str(sys.argv[2])
349 if len(workingFiles) < 1:
350 sys.exit(
"No file name or file names " + str(workingFile) +
" found.")
352 workingDirectory =
'.'
357 tree = ROOT.TChain(treeName)
359 mcstatus = array(
'd', [-511.5, 0.0, 511.5])
360 ROOT.TH1.SetDefaultSumw2()
362 for iFile
in workingFiles:
366 for branch
in tree.GetListOfBranches():
367 totalBranches.append(branch.GetName())
371 if 'FBDT_qrCombined' in totalBranches:
372 methods.append(
"FBDT")
374 if 'FANN_qrCombined' in totalBranches:
375 methods.append(
"FANN")
377 if 'DNN_qrCombined' in totalBranches:
378 methods.append(
"DNN")
380 if 'DeltaT' in totalBranches:
384 for cat
in categories:
385 catBranch =
'qp' + cat
386 if catBranch
in totalBranches:
387 usedCategories.append(cat)
389 if len(usedCategories) > 1:
390 ft.WhichCategories(usedCategories)
393 YmaxForDeltaTPlot = 0
397 for method
in methods:
401 elif method ==
"DNN":
403 elif method ==
"FANN":
406 with Quiet(ROOT.kError):
407 qpMaximumPstar = ROOT.RooRealVar(
'qpMaximumPstar',
'qpMaximumPstar', 0, -2.1, 1.1)
408 qrCombined = ROOT.RooRealVar(
'' + method +
'_qrCombined',
'' + method +
'_qrCombined', 0, -1.1, 1.1)
409 qrMC = ROOT.RooRealVar(
'qrMC',
'qrMC', 0, -10.0, 10.0)
410 isSignal = ROOT.RooRealVar(
'isSignal',
'isSignal', 0, -10.0, 10.0)
412 DeltaT = ROOT.RooRealVar(
"DeltaT",
"DeltaT", 0., -100000., 100000.)
414 argSet = ROOT.RooArgSet(qrCombined, qrMC, isSignal, qpMaximumPstar)
420 for (particleList, category, combinerVariable)
in ft.eventLevelParticleLists:
426 "ROOT.RooRealVar('hasTrueTarget' + category, 'hasTrueTarget' + category, 0, -2.1, 1.1)"))
430 exec(
"%s" %
"argSet.add(hasTrueTarget" + category +
")")
432 rooDataSet = ROOT.RooDataSet(
"data",
"data", tree, argSet,
"")
435 numberOfTrueCatagories = []
439 for i
in range(rooDataSet.numEntries()):
440 row = rooDataSet.get(i)
441 tqrCombined = row.getRealValue(
'' + method +
'_qrCombined', 0, ROOT.kTRUE)
442 tqrMC = row.getRealValue(
'qrMC', 0, ROOT.kTRUE)
443 tisSignal = row.getRealValue(
'isSignal', 0, ROOT.kTRUE)
445 if tisSignal == 1
and tqrCombined < -1
and abs(tqrMC) == 0:
453 if tqrCombined <= -1:
456 tNumberOfTrueCategories = 0
458 for (particleList, category, combinerVariable)
in ft.eventLevelParticleLists:
460 if category ==
"MaximumPstar":
463 thasTrueTarget = row.getRealValue(
'hasTrueTarget' + category, 0, ROOT.kTRUE)
465 if thasTrueTarget > 0:
466 tNumberOfTrueCategories += 1
469 numberOfTrueCatagories.append(tNumberOfTrueCategories)
473 tDT = row.getRealValue(
"DeltaT", 0, ROOT.kTRUE)
474 dataAll.append([tqrMC, tqrCombined, tNumberOfTrueCategories, tDT])
476 dataAll.append([tqrMC, tqrCombined, tNumberOfTrueCategories])
479 dataAll = np.array(dataAll)
480 dataNoTrueCategory = dataAll[(np.where(dataAll[:, 2] == 0))][:, 0:4]
481 data = dataAll[:, 0:4]
482 numberOfTrueCatagories = np.array(numberOfTrueCatagories)
485 dataB0 = data[np.where(data[:, 0] > 0)]
486 dataB0bar = data[np.where(data[:, 0] < 0)]
488 efficiency, efficiencyDiff, efficiencyB0, efficiencyB0bar, wvalue, wvalueB0, wvalueB0bar, wvalueDiff, wvalueDiffUncertainty, \
489 event_fractionB0, event_fractionB0bar, event_fractionDiffUncertainty, event_fractionTotalUncertainty, muParam, \
490 muParamUncertainty = efficiencyCalculator(data, total_notTagged,
False,
'verbose')
492 efficiency =
'% .2f' % efficiency
493 efficiencyDiff =
'%.2f' % efficiencyDiff
494 efficiencyB0 =
'% .2f' % efficiencyB0
495 efficiencyB0bar =
'% .2f' % efficiencyB0bar
498 NB0 = dataB0.shape[0] / N
501 NB0bar = dataB0bar.shape[0] / N
502 NB0bar = 100 * NB0bar
503 NB0bar =
'% .2f' % NB0bar
504 NnoTrueCat = dataNoTrueCategory.shape[0]
505 FracNoFTInfo = NnoTrueCat / N
507 print(
'The total efficiency for B0: ', efficiencyB0,
'%')
508 print(
'The total efficiency for B0bar: ', efficiencyB0bar,
'%')
509 print(
'The total efficiency for method ' + method +
' is: ', efficiency,
'%')
510 print(
'The total efficiency Diff for method ' + method +
' is: ', efficiencyDiff,
'%')
513 print(
'Percentage B0/ N: ', NB0,
'%')
514 print(
'Percentage B0bar / N : ', NB0bar,
'%')
517 print(
"N without trueCats = ", NnoTrueCat)
518 print(
"Fraction Of Events without trueCats Info = ",
'{: 4.2f}'.format(float(FracNoFTInfo * 100)),
"% ")
525 DeltaTbins = list(range(-1000, 1000, 1))
526 for i
in range(0, len(DeltaTbins)):
527 DeltaTbins[i] = float(DeltaTbins[i]) / 10
530 ax = plt.axes([0.21, 0.15, 0.75, 0.8])
531 y, x, _ = ax.hist(data[:, 3], bins=DeltaTbins, facecolor=
'r', histtype=
'stepfilled', edgecolor=
'r')
534 YDTmax = YDTmax - YDTmax / 5
536 if YmaxForDeltaTPlot < YDTmax:
537 YmaxForDeltaTPlot = YDTmax
539 figTmc = plt.figure(1, figsize=(11, 8))
540 axTmc = plt.axes([0.21, 0.15, 0.76, 0.8])
542 axTmc.hist(data[np.where(data[:, 0] == -1)][:, 3], bins=DeltaTbins, histtype=
'step',
543 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0_{\rm tag}$')
545 axTmc.hist(data[np.where(data[:, 0] == 1)][:, 3], bins=DeltaTbins, histtype=
'step',
546 edgecolor=
'r', linewidth=4, alpha=0.9, label=
r'$B^0_{\rm tag}$')
548 p1, = axTmc.plot([], label=
r'$B^0_{\rm tag}$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
549 p2, = axTmc.plot([], label=
r'$\bar{B}^0_{\rm tag}$', linewidth=4.5, linestyle=
'dashed', c=
'b')
551 axTmc.set_ylabel(
r'${\rm Number\ \ of\ \ Events /\ (\, 0.1\ ps\, )}$', fontsize=35)
552 axTmc.set_xlabel(
r'$\Delta t\ /\ {\rm ps}$', fontsize=35)
554 plt.xticks([-10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10], [
r'$-10$',
r'',
r'$5$',
555 r'',
r'$0$',
r'',
r'$5$',
r'',
r'$10$'], rotation=0, size=40)
556 axTmc.tick_params(axis=
'y', labelsize=35)
557 axTmc.legend([p1, p2], [
r'$B^0_{\rm tag}$',
r'$\bar{B}^0_{\rm tag}$'], prop={
'size': 35})
559 axTmc.set_ylim(0, YmaxForDeltaTPlot)
560 axTmc.set_xlim(-10, 10)
561 plt.savefig(workingDirectory +
'/' + method +
'DeltaTMC.pdf')
564 figTft = plt.figure(2, figsize=(11, 8))
565 axTft = plt.axes([0.21, 0.15, 0.76, 0.8])
567 axTft.hist(data[np.where(data[:, 1] < 0)][:, 3], bins=DeltaTbins, histtype=
'step',
568 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0_{\rm tag}$')
570 axTft.hist(data[np.where(data[:, 1] > 0)][:, 3], bins=DeltaTbins, histtype=
'step',
571 edgecolor=
'r', linewidth=4, alpha=0.9, label=
r'$B^0_{\rm tag}$')
573 p1, = axTft.plot([], label=
r'$B^0_{\rm tag}$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
574 p2, = axTft.plot([], label=
r'$\bar{B}^0_{\rm tag}$', linewidth=4.5, linestyle=
'dashed', c=
'b')
576 axTft.set_ylabel(
r'${\rm Number\ \ of\ \ Events /\ (\, 0.1\ ps\, )}$', fontsize=35)
577 axTft.set_xlabel(
r'$\Delta t\ /\ {\rm ps}$', fontsize=35)
579 plt.xticks([-10, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10], [
r'$-10$',
r'',
r'$5$',
580 r'',
r'$0$',
r'',
r'$5$',
r'',
r'$10$'], rotation=0, size=40)
581 axTft.tick_params(axis=
'y', labelsize=35)
582 axTft.legend([p1, p2], [
r'$B^0_{\rm tag}$',
r'$\bar{B}^0_{\rm tag}$'], prop={
'size': 35})
584 axTft.set_ylim(0, YmaxForDeltaTPlot)
585 axTft.set_xlim(-10, 10)
586 plt.savefig(workingDirectory +
'/' + method +
'DeltaTFT.pdf')
592 bins = list(range(-50, 51, 1))
593 for i
in range(0, len(bins)):
594 bins[i] = float(bins[i]) / 50
598 bins2 = list(range(-25, 26, 1))
599 for i
in range(0, len(bins2)):
600 bins2[i] = float(bins2[i]) / 25
603 fig1 = plt.figure(2, figsize=(11, 8))
604 ax1 = plt.axes([0.21, 0.15, 0.75, 0.8])
605 y, x, _ = ax1.hist(data[:, 1], bins=bins, facecolor=
'r', histtype=
'stepfilled', edgecolor=
'r')
608 Ymax = Ymax + Ymax / 4
610 if YmaxForQrPlot < Ymax:
613 ax1.set_ylabel(
r'${\rm Number\ \ of\ \ Events /\ (\, 0.02\, )}$', fontsize=35)
614 ax1.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
' }$', fontsize=42)
615 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
616 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=20)
617 ax1.tick_params(axis=
'y', labelsize=20)
619 ax1.set_ylim(0, YmaxForQrPlot)
620 plt.savefig(workingDirectory +
'/' + method +
'QR_Output.pdf')
625 fig2 = plt.figure(3, figsize=(11, 8))
626 ax2 = plt.axes([0.21, 0.15, 0.76, 0.8])
628 ax2.hist(data[np.where(abs(data[:, 0]) == 1)][:, 1], bins=bins, histtype=
'step', edgecolor=
'k',
629 linewidth=4, linestyle=
'dashdot', alpha=0.9, label=
r'${\rm Both}$')
631 ax2.hist(data[np.where(data[:, 0] == 1)][:, 1], bins=bins, histtype=
'step', edgecolor=
'r',
632 linewidth=4, alpha=0.9, label=
r'$B^0$')
634 ax2.hist(data[np.where(data[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
635 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
637 p3, = ax2.plot([], label=
r'${\rm Both}$', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
639 p2, = ax2.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
641 p1, = ax2.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
643 ax2.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
644 ax2.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
648 ax2.tick_params(axis=
'y', labelsize=35)
649 ax2.legend([p3, p2, p1], [
r'${\rm Both}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=9)
651 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],
652 [
r'${-1.0}$',
r'',
r'',
r'',
r'${-0.5}$',
r'',
r'',
r'$0$',
r'',
653 r'',
r'$0.5$',
r'',
r'',
r'',
r'$1.0$'], rotation=0, size=35)
655 ax2.set_ylim(0, YmaxForQrPlot)
656 yLocs, yLabels = plt.yticks()
657 plt.savefig(workingDirectory +
'/' + method +
'QR_B0bar.pdf')
662 fig2b = plt.figure(4, figsize=(10, 8))
663 ax2b = plt.axes([0.21, 0.15, 0.76, 0.8])
664 p2b = ax2b.hist(dataNoTrueCategory[np.where(dataNoTrueCategory[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
665 edgecolor=
'b', linewidth=3.5, linestyle=
'dotted', label=
r'$\bar{B}^0$')
680 ax2b.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
681 ax2b.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
682 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
683 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=20)
684 ax2b.tick_params(axis=
'y', labelsize=20)
685 ax2b.legend([
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 20})
688 plt.savefig(workingDirectory +
'/' + method +
'QR_B0barNoTrueCategory.pdf')
703 data_entriesB0 = np.histogram(np.absolute(data[np.where(data[:, 0] == 1)][:, 1]), rbins)[0]
707 np.absolute(data[np.where(data[:, 0] == 1)][:, 1]),
709 weights=np.absolute(data[np.where(data[:, 0] == 1)][:, 1]))[0] / data_entriesB0)
712 np.absolute(data[np.where(data[:, 0] == 1)][:, 1]), rbins, weights=np.absolute(data[np.where(data[:, 0] == 1)][:, 1]) *
713 np.absolute(data[np.where(data[:, 0] == 1)][:, 1]))[0] / data_entriesB0)
714 delta_rvalueB0 = np.sqrt((delta_rvalueB0 - rvalueB0 * rvalueB0) / (data_entriesB0))
716 wrongTaggedB0 = np.histogram(
718 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == 1))][:, 1]), rbins)[0].astype(float)
720 wrong_fractionB0 = (wrongTaggedB0 / data_entriesB0)
722 delta_wrong_fractionB0 = np.sqrt(wrongTaggedB0 * (data_entriesB0 - wrongTaggedB0) / (data_entriesB0**3))
724 rmvaluesB0 = 1 - 2 * wrong_fractionB0
725 delta_rmvaluesB0 = 2 * delta_wrong_fractionB0
727 data_entriesB0bar = np.histogram(np.absolute(data[np.where(data[:, 0] == -1)][:, 1]), rbins)[0]
731 np.absolute(data[np.where(data[:, 0] == -1)][:, 1]),
733 weights=np.absolute(data[np.where(data[:, 0] == -1)][:, 1]))[0] / data_entriesB0bar)
734 delta_rvalueB0bar = (
736 np.absolute(data[np.where(data[:, 0] == -1)][:, 1]), rbins,
737 weights=np.absolute(data[np.where(data[:, 0] == -1)][:, 1]) *
738 np.absolute(data[np.where(data[:, 0] == -1)][:, 1]))[0] / data_entriesB0bar)
739 delta_rvalueB0bar = np.sqrt((delta_rvalueB0bar - rvalueB0bar * rvalueB0bar) / (data_entriesB0bar))
741 wrongTaggedB0bar = np.histogram(
743 data[np.where((np.sign(data[:, 0]) != np.sign(data[:, 1])) & (data[:, 0] == -1))][:, 1]), rbins)[0].astype(float)
745 wrong_fractionB0bar = (wrongTaggedB0bar / data_entriesB0bar)
747 delta_wrong_fractionB0bar = np.sqrt(wrongTaggedB0bar * (data_entriesB0bar - wrongTaggedB0bar) / (data_entriesB0bar**3))
749 rmvaluesB0bar = 1 - 2 * wrong_fractionB0bar
750 delta_rmvaluesB0bar = 2 * delta_wrong_fractionB0bar
752 rvalue = (rvalueB0 + rvalueB0bar) / 2
753 rmvalues = (rmvaluesB0 + rmvaluesB0bar) / 2
755 delta_rvalue = np.sqrt(delta_rvalueB0**2 + delta_rvalueB0bar**2) / 2
756 delta_rmvalues = np.sqrt(delta_rmvaluesB0**2 + delta_rmvaluesB0bar**2) / 2
758 fig3a = plt.figure(5, figsize=(11, 8))
759 ax3a = plt.axes([0.21, 0.15, 0.74, 0.8])
761 line = range(0, 2, 1)
762 ax3a.plot(line, line, linewidth=4, color=
'r')
764 (p1ca, capsB0, _) = ax3a.errorbar(rvalueB0, np.absolute(rmvaluesB0), xerr=
None, yerr=
None,
766 elinewidth=4, capsize=10, ecolor=
'r', fmt=
'o', mfc=
'r',
767 mec=
'r', markersize=14)
769 (p2ca, capsB0bar, _) = ax3a.errorbar(rvalueB0bar, np.absolute(rmvaluesB0bar), xerr=
None, yerr=
None,
771 elinewidth=4, capsize=10, ecolor=
'b', fmt=
'o', mfc=
'b',
772 mec=
'b', markersize=14)
777 cap.set_markeredgewidth(4)
779 for cap
in capsB0bar:
781 cap.set_markeredgewidth(4)
783 (p3ca, caps, _) = ax3a.errorbar(rvalue, rmvalues, xerr=
None, yerr=
None,
785 elinewidth=4, capsize=10, ecolor=
'k', fmt=
'o', mfc=
'k', mec=
'k', markersize=14)
789 cap.set_markeredgewidth(4)
791 ax3a.legend([p3ca, p2ca, p1ca], [
r'${\rm Average}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=2)
793 ax3a.set_ylabel(
r'$r_{\rm \small MC} = \vert 1-2\cdot w_{\small \rm MC} \vert $', fontsize=42)
794 ax3a.set_xlabel(
r'$\langle r_{\rm ' + label +
'}$' +
r'$\rangle$', fontsize=42)
798 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
799 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
800 plt.yticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
801 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
805 ax3a.xaxis.grid(
True, linewidth=2)
806 plt.savefig(workingDirectory +
'/' + method +
'CalibrationB0B0bar.pdf')
809 fig3 = plt.figure(6, figsize=(11, 8))
810 ax3 = plt.axes([0.21, 0.15, 0.74, 0.8])
812 line = range(0, 2, 1)
813 ax3.plot(line, line, linewidth=4, color=
'r')
815 (_, caps, _) = ax3.errorbar(rvalue, rmvalues, xerr=
None, yerr=
None,
817 elinewidth=4, capsize=10, ecolor=
'b', fmt=
'o', markersize=14)
820 cap.set_markeredgewidth(4)
822 ax3.set_ylabel(
r'$r_{\rm \small MC} = 1-2\cdot w_{\small \rm MC}$', fontsize=42)
823 ax3.set_xlabel(
r'$\langle r_{\rm ' + label +
'}$' +
r'$\rangle$', fontsize=42)
827 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
828 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
829 plt.yticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
830 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
834 ax3.xaxis.grid(
True, linewidth=2)
835 plt.savefig(workingDirectory +
'/' + method +
'Calibration.pdf')
840 fig4 = plt.figure(7, figsize=(11, 8))
841 ax4 = plt.axes([0.21, 0.15, 0.76, 0.8])
842 ax4.hist(np.absolute(data[:, 1]), bins=bins, facecolor=
'r', histtype=
'stepfilled', edgecolor=
'r')
843 ax4.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
844 ax4.set_xlabel(
r'$r_{\rm ' + label +
' }$', fontsize=42)
845 ax4.tick_params(axis=
'y', labelsize=30)
854 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
855 [
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)
857 ax4.xaxis.grid(
True, linewidth=2)
858 plt.savefig(workingDirectory +
'/' + method +
'R_Output.pdf')
865 fig2a = plt.figure(8, figsize=(11, 8))
866 ax2a = plt.axes([0.21, 0.15, 0.76, 0.8])
868 ax2a.hist(data[np.where((abs(data[:, 0]) == 1) & (data[:, 1] >= 0))][:, 1], bins=bins, histtype=
'step', edgecolor=
'k',
869 linewidth=4, linestyle=
'dashdot', alpha=0.9, label=
r'$q \geq 0 $')
871 ax2a.hist(data[np.where((abs(data[:, 0]) == 1) & (data[:, 1] < 0))][:, 1] * (-1), bins=bins, histtype=
'step', edgecolor=
'g',
872 linewidth=4, linestyle=
'dashed', alpha=0.9, label=
r'$q < 0 $')
874 p3a, = ax2a.plot([], label=
r'$q \geq 0 $', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
876 p2a, = ax2a.plot([], label=
r'$q < 0 $', linewidth=4.5, linestyle=
'dashed', c=
'g')
878 ax2a.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
879 ax2a.set_xlabel(
r'$(q\cdot q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
883 ax2a.tick_params(axis=
'y', labelsize=35)
884 ax2a.legend([p3a, p2a], [
r'$q \geq 0 $',
r'$q < 0 $'], prop={
'size': 35}, loc=2)
886 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
887 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
890 ax2a.set_ylim(0, YmaxForQrPlot)
891 plt.savefig(workingDirectory +
'/' + method +
'Folded_QR_Both.pdf')
926 fig2e = plt.figure(9, figsize=(11, 11))
927 ax2e = plt.axes([0.21, 0.37, 0.76, 0.60])
929 nB0bar, nbins, patches = ax2e.hist(data[np.where(data[:, 0] == -1)][:, 1] * (-1), bins=bins, histtype=
'step',
930 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
932 nB0, nbins, patches = ax2e.hist(data[np.where(data[:, 0] == 1)][:, 1], bins=bins, histtype=
'step', edgecolor=
'r',
933 linewidth=4, alpha=0.7, label=
r'$B^0$')
935 p2c, = ax2e.plot([], label=
r'$\bar{B}^0$', linewidth=4, linestyle=
'dashed', c=
'b')
937 p1c, = ax2e.plot([], label=
r'$B^0$', linewidth=4.5, linestyle=
'solid', alpha=0.9, c=
'r')
939 ax2e.set_ylabel(
r'${\rm Events\ /\ (\, 0.02\, )}$', fontsize=35)
944 ax2e.tick_params(axis=
'y', labelsize=35)
945 ax2e.legend([p2c, p1c], [
r'$\bar{B}^0\, (q_{\rm MC} = -1)$',
r'$B^0\, (q_{\rm MC} = +1)$'], prop={
'size': 35}, loc=2)
947 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],
948 [
r'',
r'',
r'',
r'',
r'',
r'',
r'',
r'',
r'',
949 r'',
r'',
r'',
r'',
r'',
r''], rotation=0, size=35)
951 plt.yticks(yLocs, yLabels)
952 ax2e.set_ylim(0, YmaxForQrPlot)
956 np.seterr(divide=
'ignore', invalid=
'ignore')
957 asymmetryArray = (nB0 - nB0bar) / (nB0 + nB0bar)
958 asymmetryArrayUncertainties = np.zeros(asymmetryArray.shape)
960 for i
in range(0, nB0.shape[0]):
961 denominator = nB0[i] + nB0bar[i]
963 asymmetryArrayUncertainties[i] = 2 * math.sqrt(
964 (nB0[i] * math.sqrt(nB0[i])) ** 2 +
965 (nB0bar[i] * math.sqrt(nB0bar[i]))**2) / (denominator)**2
968 nBinCenters = 0.5 * (nbins[1:] + nbins[:-1])
970 ax2eA = plt.axes([0.21, 0.15, 0.76, 0.2])
975 ax2eA.errorbar(nBinCenters, asymmetryArray, xerr=float(0.01),
976 yerr=asymmetryArrayUncertainties, elinewidth=2, mew=2, ecolor=
'k',
977 fmt=
'o', mfc=
'k', mec=
'k', markersize=3, label=
r'${\rm Data}$')
979 ax2eA.set_ylabel(
r'$\frac{N^{B^0}\; -\;\, N^{\overline{B}^0}}{N^{B^0}\; +\;\, N^{\overline{B}^0}}$', fontsize=44, labelpad=20)
980 ax2eA.yaxis.labelpad = 0
981 plt.yticks([-0.4, -0.2, 0, 0.2, 0.4],
982 [
r'',
r'$-0.2$',
r'$0.0$',
r'$0.2$',
r''], rotation=0, size=28)
984 ax2eA.set_ylim(-0.4, 0.4)
985 ax2eA.set_xlim(ax2e.get_xlim())
987 ax2eA.xaxis.grid(
True)
988 ax2eA.yaxis.grid(
True)
998 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],
999 [
r'${-1.0}$',
r'',
r'',
r'',
r'${-0.5}$',
r'',
r'',
r'$0$',
r'',
1000 r'',
r'$0.5$',
r'',
r'',
r'',
r'$1.0$'], rotation=0, size=35)
1002 ax2eA.set_xlabel(
r'$q_{\rm MC}\cdot(q\cdot r)_{\rm ' + label +
'}$', fontsize=42)
1003 plt.savefig(workingDirectory +
'/' + method +
'_Folded_QR_B0barWithAsymm.pdf')
1008 fig2d = plt.figure(11, figsize=(11, 8))
1009 ax2d = plt.axes([0.21, 0.15, 0.76, 0.8])
1014 ax2d.hist(np.absolute(data[np.where(data[:, 0] == -1)][:, 1]), bins=bins, histtype=
'step',
1015 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1017 ax2d.hist(np.absolute(data[np.where(data[:, 0] == 1)][:, 1]), bins=bins, histtype=
'step', edgecolor=
'r',
1018 linewidth=4, alpha=0.9, label=
r'$B^0$')
1022 p2d, = ax2d.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1024 p1d, = ax2d.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1026 ax2d.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=35)
1027 ax2d.set_xlabel(
r'$r_{\rm ' + label +
'}$', fontsize=42)
1031 ax2d.tick_params(axis=
'y', labelsize=35)
1032 ax2d.legend([p2d, p1d], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=2)
1034 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
1035 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=35)
1038 ax2d.set_yscale(
'log', nonposy=
'clip')
1040 plt.savefig(workingDirectory +
'/' + method +
'_Folded_R_B0bar.pdf')
1045 fig5 = plt.figure(12, figsize=(11, 15))
1046 ax5 = plt.axes([0.21, 0.53, 0.76, 0.45])
1048 rBinCenters = 0.5 * (rbins[1:] + rbins[:-1])
1049 rBinWidths = 0.5 * (rbins[1:] - rbins[:-1])
1051 eb = ax5.errorbar(rBinCenters, 50 * (wvalueB0bar + wvalueB0), xerr=rBinWidths, yerr=50 * wvalueDiffUncertainty,
1052 label=
r'${\rm Average}$', elinewidth=4.5, ecolor=
'k', fmt=
'o', mfc=
'k', mec=
'k',
1053 mew=0, markersize=0)
1054 eb[-1][0].set_linestyle(
'dashdot')
1055 eb[-1][0].set_alpha(0.9)
1057 ebB0bar = ax5.errorbar(rBinCenters, 100 * wvalueB0, xerr=rBinWidths, yerr=50 * wvalueDiffUncertainty,
1058 label=
r'$B^0$', elinewidth=4, ecolor=
'r', fmt=
'o', mfc=
'k', mec=
'k',
1059 mew=0, markersize=0)
1060 ebB0bar[-1][0].set_alpha(0.9)
1062 ebB0bar = ax5.errorbar(rBinCenters, 100 * wvalueB0bar, xerr=rBinWidths, yerr=50 * wvalueDiffUncertainty,
1063 label=
r'$\bar{B}^0$', elinewidth=4.5, ecolor=
'b', fmt=
'o', mfc=
'k', mec=
'k',
1064 mew=0, markersize=0)
1065 ebB0bar[-1][0].set_linestyle(
'--')
1067 ax5.set_ylabel(
r'$w\ [\%]$', fontsize=45)
1068 ax5.yaxis.labelpad = 36
1071 plt.yticks([0, 10, 20, 30, 40, 50], [
r'$0$',
1072 r'$10$',
r'$20$',
r'$30$',
r'$40$',
r'$50$'], rotation=0, size=44)
1073 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1], [
r'',
r'',
1074 r'',
r'',
r'',
r'',
r'',
r''], rotation=0, size=44)
1076 p3d, = ax5.plot([], label=
r'${\rm Average}$', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
1078 p2d, = ax5.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1080 p1d, = ax5.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1082 ax5.legend([p3d, p2d, p1d], [
r'${\rm Average}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 38}, loc=1)
1087 ax5A = plt.axes([0.21, 0.08, 0.76, 0.43])
1089 ax5A.errorbar(rBinCenters, 100 * wvalueDiff, xerr=rBinWidths,
1090 yerr=100 * wvalueDiffUncertainty, elinewidth=3, mew=2, ecolor=
'k',
1091 fmt=
'o', mfc=
'k', mec=
'k', markersize=3, label=
r'${\rm Data}$')
1093 ax5A.set_ylim(-14, 14)
1095 plt.yticks([-14, -12, -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 12, 14],
1096 [
r'',
r'$-12$',
r'',
r'$-8$',
r'',
r'$-4$',
r'',
r'$0$',
1097 r'',
r'$4$',
r'',
r'$8$',
r'',
r'$12$',
r''], rotation=0, size=44)
1099 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
1100 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=42)
1102 ax5A.xaxis.grid(
True)
1103 ax5A.yaxis.grid(
True)
1104 ax5A.set_ylabel(
r'$\Delta w\ [\%]$', fontsize=45)
1105 ax5A.set_xlabel(
r'$r_{\rm ' + label +
'}$', fontsize=45)
1107 plt.savefig(workingDirectory +
'/' + method +
'_WrongTagFraction.pdf')
1112 fig6 = plt.figure(13, figsize=(11, 15))
1113 ax6 = plt.axes([0.21, 0.53, 0.76, 0.45])
1115 rBinCenters = 0.5 * (rbins[1:] + rbins[:-1])
1116 rBinWidths = 0.5 * (rbins[1:] - rbins[:-1])
1118 eb = ax6.errorbar(rBinCenters, 50 * (event_fractionB0bar + event_fractionB0), xerr=rBinWidths, yerr=50 * muParamUncertainty,
1119 label=
r'${\rm Average}$', elinewidth=4.5, ecolor=
'k', fmt=
'o', mfc=
'k', mec=
'k',
1120 mew=0, markersize=0)
1121 eb[-1][0].set_linestyle(
'dashdot')
1122 eb[-1][0].set_alpha(0.9)
1124 ebB0bar = ax6.errorbar(rBinCenters, 100 * event_fractionB0bar, xerr=rBinWidths, yerr=50 * muParamUncertainty,
1125 label=
r'$B^0$', elinewidth=4, ecolor=
'r', fmt=
'o', mfc=
'k', mec=
'k',
1126 mew=0, markersize=0)
1127 ebB0bar[-1][0].set_alpha(0.9)
1129 ebB0bar = ax6.errorbar(rBinCenters, 100 * event_fractionB0, xerr=rBinWidths, yerr=50 * muParamUncertainty,
1130 label=
r'$\bar{B}^0$', elinewidth=4.5, ecolor=
'b', fmt=
'o', mfc=
'k', mec=
'k',
1131 mew=0, markersize=0)
1132 ebB0bar[-1][0].set_linestyle(
'--')
1134 ax6.set_ylabel(
r'$\varepsilon\ [\%]$', fontsize=45)
1135 ax6.yaxis.labelpad = 36
1138 plt.yticks([0, 5, 10, 15, 20, 25, 30], [
r'$0$',
r'',
1139 r'$10$',
r'',
r'$20$',
r'',
r'$30$'], rotation=0, size=45)
1140 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1], [
r'',
r'',
1141 r'',
r'',
r'',
r'',
r'',
r''], rotation=0, size=44)
1143 p3d, = ax6.plot([], label=
r'${\rm Average}$', linewidth=4, linestyle=
'dashdot', alpha=0.9, c=
'k')
1145 p2d, = ax6.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1147 p1d, = ax6.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1149 ax6.legend([p3d, p2d, p1d], [
r'${\rm Average}$',
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 38}, loc=1)
1154 ax6A = plt.axes([0.21, 0.08, 0.76, 0.43])
1156 ax6A.errorbar(rBinCenters, 100 * muParam, xerr=rBinWidths,
1157 yerr=100 * muParamUncertainty, elinewidth=3, mew=2, ecolor=
'k',
1158 fmt=
'o', mfc=
'k', mec=
'k', markersize=3, label=
r'${\rm Data}$')
1160 ax6A.set_ylim(-4, 4)
1162 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],
1163 [
r'',
r'$-3$',
r'',
r'$-2$',
r'',
r'$-1$',
r'',
r'$0$',
r'',
r'$1$',
r'',
r'$2$',
r'',
r'$3$',
r''],
1164 rotation=0, size=45)
1166 plt.xticks([0, 0.1, 0.25, 0.5, 0.625, 0.75, 0.875, 1],
1167 [
r'$0$',
r'$0.1$',
r'$0.25$',
r'$0.5$',
r'',
r'$0.75$',
r'',
r'$1.0$'], rotation=0, size=42)
1169 ax6A.xaxis.grid(
True)
1170 ax6A.yaxis.grid(
True)
1171 ax6A.set_ylabel(
r'$\mu\ [\%]$', fontsize=45)
1172 ax6A.set_xlabel(
r'$r_{\rm ' + label +
'}$', fontsize=45)
1174 ax6A.yaxis.labelpad = 25
1176 plt.savefig(workingDirectory +
'/' + method +
'_EfficiencyAndMu.pdf')
1181 fig7 = plt.figure(14, figsize=(11, 8))
1182 ax7 = plt.axes([0.21, 0.15, 0.76, 0.8])
1183 weights = np.ones_like(numberOfTrueCatagories) * 100 / float(len(numberOfTrueCatagories))
1184 hi5, w, _ = ax4.hist(numberOfTrueCatagories, weights=weights, bins=list(
1185 range(0, 14, 1)), facecolor=
'r', histtype=
'stepfilled', edgecolor=
'k')
1187 ax7.bar(np.array(range(0, 13, 1)) + 0.1, hi5, 0.8, color=
'r', ecolor=
'k')
1188 ax7.set_ylabel(
r'${\rm Percentage\ of\ Events\ /\ (\, 0.02\, )}$', fontsize=25)
1189 ax7.set_xlabel(
r'${\rm True\ Categories}$', fontsize=25)
1190 plt.xticks([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5],
1191 [
r'$0$',
r'$1$',
r'$2$',
r'$3$',
r'$4$',
r'$5$',
r'$6$',
r'$7$',
r'$8$'],
1192 rotation=0, horizontalalignment=
'center', size=25)
1193 ax7.tick_params(axis=
'y', labelsize=25)
1197 plt.savefig(workingDirectory +
'/' + method +
'TrueCategories.pdf')
1200 fig = plt.figure(figsize=(8, 8))
1201 ax = fig.add_subplot(111, projection=
'3d')
1204 bins2 = list(range(-51, 51, 1))
1205 for i
in range(0, len(bins2)):
1206 bins2[i] = float(bins2[i]) / 50
1208 bins2 = np.array(bins2)
1212 return colorConverter.to_rgba(arg, alpha=0.5)
1218 zs = list(range(0, 7, 1))
1224 for z
in range(0, 7, 1):
1225 dataTrueCats = dataAll[(np.where(dataAll[:, 2] == z))][:, 0:2]
1226 weightsa = np.ones_like(dataTrueCats[np.where(dataTrueCats[:, 0] == -1)][:, 1]) * \
1227 (hi5[z] * dataAll.shape[0] / 100) / float(len(dataTrueCats[:, 1]))
1228 weightsb = np.ones_like(dataTrueCats[np.where(dataTrueCats[:, 0] == 1)][:, 1]) * \
1229 (hi5[z] * dataAll.shape[0] / 100) / float(len(dataTrueCats[:, 1]))
1230 ya, wa, _ = ax2.hist(dataTrueCats[np.where(dataTrueCats[:, 0] == -1)][:, 1], weights=weightsa, bins=bins, histtype=
'step',
1231 edgecolor=
'b', linewidth=3.5, linestyle=
'dotted', label=
r'$\bar{B}^0$')
1232 yb, wb, _ = ax2.hist(dataTrueCats[np.where(dataTrueCats[:, 0] == 1)][:, 1], weights=weightsb, bins=bins, histtype=
'step',
1233 edgecolor=
'r', linewidth=2, label=
r'$B^0$')
1234 ya = np.insert(ya, ya.shape[0], 0)
1235 ya = np.insert(ya, 0, 0)
1236 yb = np.insert(yb, yb.shape[0], 0)
1237 yb = np.insert(yb, 0, 0)
1242 colorsa.append(cc(
'b'))
1243 colorsb.append(cc(
'r'))
1244 vertsa.append(list(zip(bins2, ya)))
1245 vertsb.append(list(zip(bins2, yb)))
1247 iEfficiency, iEfficiencyDiff, iEfficiencyB0, iEfficiencyB0bar = efficiencyCalculator(dataTrueCats, total_notTagged,
True)
1249 iEfficiencies.append([iEfficiencyB0, iEfficiencyB0bar])
1251 polya = PolyCollection(vertsa, facecolors=colorsa)
1252 polyb = PolyCollection(vertsb, facecolors=colorsb)
1253 polya.set_alpha(0.5)
1254 polyb.set_alpha(0.5)
1255 ax.add_collection3d(polya, zs=zs, zdir=
'y')
1256 ax.add_collection3d(polyb, zs=zs, zdir=
'y')
1264 ax.set_xlim3d(-1, 1)
1265 ax.set_ylim3d(-0.5, 7)
1266 ax.set_yticks([0, 1, 2, 3, 4, 5, 6])
1267 ax.xaxis.labelpad = 18
1268 ax.yaxis.labelpad = 16
1269 ax.zaxis.labelpad = 22
1271 ax.set_yticklabels(sorted({
r'$0$',
r'$1$',
r'$2$',
r'$3$',
r'$4$',
r'$5$',
r'$6$'}),
1272 verticalalignment=
'baseline',
1273 horizontalalignment=
'left')
1275 ax.set_xlabel(
r'$(q\cdot r)_{\rm ' + label +
' }$')
1276 ax.set_ylabel(
r'${\rm True\ Categories}$')
1277 ax.set_zlabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', rotation=-90)
1278 Zmax = Zmax + Zmax / 5
1279 ax.set_zlim3d(0, Zmax)
1280 p1 = plt.Rectangle((0, 0), 1, 1, fc=
"b", alpha=0.5)
1281 p2 = plt.Rectangle((0, 0), 1, 1, fc=
"r", alpha=0.5)
1282 ax.legend([p1, p2], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 20}, loc=(0.523, 0.687))
1283 plt.savefig(workingDirectory +
'/3DTrueCategorieQR' + method +
'.pdf')
1286 iEfficiencies = np.array(iEfficiencies)
1288 fig = plt.figure(15, figsize=(12, 8))
1289 ax = plt.axes([0.18, 0.15, 0.8, 0.8])
1292 p1 = ax.bar(np.array(range(0, 7, 1)) + width / 4, iEfficiencies[:, 1], width, color=
'b', ecolor=
'k', label=
r'$\bar{B}^0$')
1293 p2 = ax.bar(np.array(range(0, 7, 1)) + width + width / 4, iEfficiencies[:, 0], width, color=
'r', ecolor=
'k', label=
r'$B^0$')
1294 ax.set_ylabel(
r'$ \varepsilon_{\rm eff}/\ \% $', fontsize=35)
1295 ax.set_xlabel(
r'${\rm True\ Categories}$', fontsize=35)
1296 plt.xticks([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5],
1297 [
r'$0$',
r'$1$',
r'$2$',
r'$3$',
r'$4$',
r'$5$',
r'$6$',
r'$7$',
r'$8$'],
1298 rotation=0, horizontalalignment=
'center', size=35)
1299 ax.tick_params(axis=
'y', labelsize=35)
1302 ax.legend([
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35})
1304 plt.savefig(workingDirectory +
'/EfficienciesTrueCats' + method +
'.pdf')
1308 NoTargetEfficiencies = []
1311 categoryLabelsDict = {
'Electron':
r'${\rm Electron}$',
1312 'IntermediateElectron':
r'${\rm Int. Electron}$',
1313 'Muon':
r'${\rm Muon}$',
1314 'IntermediateMuon':
r'${\rm Int. Muon}$',
1315 'KinLepton':
r'${\rm KinLepton}$',
1316 'IntermediateKinLepton':
r'${\rm Int. KinLepton}$',
1317 'Kaon':
r'${\rm Kaon}$',
1318 'SlowPion':
r'${\rm Slow Pion}$',
1319 'FastHadron':
r'${\rm Fast Hadron}$',
1320 'Lambda':
r'${\rm Lambda}$',
1321 'FSC':
r'${\rm FSC}$',
1322 'MaximumPstar':
r'${\rm MaximumPstar}$',
1323 'KaonPion':
r'${\rm Kaon-Pion}$'}
1358 qrMC = ROOT.RooRealVar(
'qrMC',
'qrMC', 0, -1.0, 1.0)
1359 argSet = ROOT.RooArgSet(qrMC)
1361 for (particleList, iCategory, combinerVariable)
in ft.eventLevelParticleLists:
1363 with Quiet(ROOT.kError):
1368 "ROOT.RooRealVar('hasTrueTarget' + iCategory, 'hasTrueTarget' + iCategory, 0, -2.1, 1.1)"))
1373 "ROOT.RooRealVar('qp' + iCategory, 'hasTrueTarget' + iCategory, 0, -2.1, 1.1)"))
1377 exec(
"%s" %
"argSet.add(hasTrueTarget" + iCategory +
")")
1378 exec(
"%s" %
"argSet.add(qp" + iCategory +
")")
1379 rooDataSet = ROOT.RooDataSet(
"data",
"data", tree, argSet,
"")
1382 for (particleList, category, combinerVariable)
in ft.eventLevelParticleLists:
1393 for i
in range(rooDataSet.numEntries()):
1394 row = rooDataSet.get(i)
1395 tqp = row.getRealValue(
'qp' + category, 0, ROOT.kTRUE)
1396 thasTrueTarget = row.getRealValue(
'hasTrueTarget' + category, 0, ROOT.kTRUE)
1397 tqrMC = row.getRealValue(
'qrMC', 0, ROOT.kTRUE)
1399 tNumberOfTrueCategories = 0
1400 noMCAssociated =
False
1402 for (particleList, iCategory, combinerVariable)
in ft.eventLevelParticleLists:
1404 if iCategory ==
"MaximumPstar":
1406 ihasTrueTarget = row.getRealValue(
'hasTrueTarget' + iCategory, 0, ROOT.kTRUE)
1409 if ihasTrueTarget > 0:
1410 tNumberOfTrueCategories += 1
1411 if ihasTrueTarget < 0:
1412 noMCAssociated =
True
1422 data.append([tqrMC, tqp])
1423 if thasTrueTarget > 0:
1424 dataTruth.append([tqrMC, tqp])
1425 if tNumberOfTrueCategories < 1
and not noMCAssociated:
1427 if category ==
"Lambda" and tqp == 0:
1430 dataNoTarget.append([tqrMC, tqp])
1432 data = np.array(data)
1433 dataTruth = np.array(dataTruth)
1434 dataNoTarget = np.array(dataNoTarget)
1438 noTargetEfficiency, noTargetEfficiencyDiff, noTargetEfficiencyB0, noTargetEfficiencyB0bar = categoriesEfficiencyCalculator(data)
1439 print(
"Efficiencies for B0, B0bar = ",
'{: 6.2f}'.format(noTargetEfficiencyB0),
1440 " %, ",
'{: 6.2f}'.format(noTargetEfficiencyB0bar),
" %")
1442 noTargetEfficiency, noTargetEfficiencyDiff, noTargetEfficiencyB0, noTargetEfficiencyB0bar = categoriesEfficiencyCalculator(
1444 print(
"Efficiencies for B0, B0bar If Not Target = ",
'{: 6.2f}'.format(
1445 noTargetEfficiencyB0),
" %, ",
'{: 6.2f}'.format(noTargetEfficiencyB0bar),
" %")
1447 NoTargetEfficiencies.append([noTargetEfficiencyB0, noTargetEfficiencyB0bar])
1448 categoryLabel.append(categoryLabelsDict[category])
1450 trueTargetEfficiency, trueTargetEfficiencyDiff, trueTargetEfficiencyB0, \
1451 trueTargetEfficiencyB0bar = categoriesEfficiencyCalculator(dataTruth)
1452 print(
"Efficiencies for B0, B0bar If True Target= ",
'{: 6.2f}'.format(
1453 trueTargetEfficiencyB0),
" %, ",
'{: 6.2f}'.format(trueTargetEfficiencyB0bar),
" %")
1459 bins = list(range(-50, 51, 1))
1460 for i
in range(0, len(bins)):
1461 bins[i] = float(bins[i]) / 50
1466 if category !=
'Lambda' and category !=
'MaximumPstar' and category !=
'Kaon':
1467 title =
r'$q_{\rm cand}\cdot y_{\rm ' + category +
'}$'
1468 elif category ==
'MaximumPstar':
1469 title =
r'$q_{\rm cand}\cdot y_{{\rm Maximum}\, p^*}$'
1471 elif category ==
'Kaon':
1473 title =
r'$(q_{\rm cand}\cdot y_{\rm Kaon})_{\rm eff}$'
1474 elif category ==
'Lambda':
1475 title =
r'$(q_{\rm \Lambda}\cdot y_{\rm Lambda})_{\rm eff}$'
1477 if category ==
'IntermediateKinLepton':
1479 title =
r'$q_{\rm cand}\cdot y_{\rm Int.\, Kin.\, Lepton}$'
1480 elif category ==
'KinLepton':
1481 title =
r'$q_{\rm cand}\cdot y_{\rm Kin.\, Lepton}$'
1482 elif category ==
'IntermediateMuon':
1483 title =
r'$q_{\rm cand}\cdot y_{\rm Int.\, Muon}$'
1484 elif category ==
'IntermediateElectron':
1485 title =
r'$q_{\rm cand}\cdot y_{\rm Int.\, Electron}$'
1486 elif category ==
'KaonPion':
1487 title =
r'$q_{\rm cand}\cdot y_{\rm Kaon-Pion}$'
1488 elif category ==
'FastHadron':
1490 title =
r'$q_{\rm cand}\cdot y_{\rm Fast\, Hadron}$'
1491 elif category ==
'SlowPion':
1492 title =
r'$q_{\rm cand}\cdot y_{\rm Slow\, Pion}$'
1494 fig2 = plt.figure(2, figsize=(11, 8))
1495 ax2 = plt.axes([0.21, 0.16, 0.75, 0.81])
1496 ax2.hist(data[np.where(data[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
1497 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1499 data[np.where(data[:, 0] == 1)][:, 1],
1507 p2, = ax2.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1508 p1, = ax2.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1510 ax2.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=37)
1511 ax2.set_xlabel(title, fontsize=48)
1512 ax2.set_yscale(
'log', nonposy=
'clip')
1513 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
1514 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=37)
1515 ax2.tick_params(axis=
'y', labelsize=37)
1516 ax2.legend([p2, p1], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=location)
1518 plt.savefig(workingDirectory +
'/' +
'pyPIC_' + category +
'_Input_Combiner.pdf')
1521 fig2b = plt.figure(2, figsize=(11, 8))
1522 ax2b = plt.axes([0.21, 0.16, 0.75, 0.81])
1523 ax2b.hist(dataTruth[np.where(dataTruth[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
1524 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1526 dataTruth[np.where(dataTruth[:, 0] == 1)][:, 1],
1534 p2, = ax2b.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1535 p1, = ax2b.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1537 ax2b.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=37)
1538 ax2b.set_xlabel(title, fontsize=48)
1539 ax2b.set_yscale(
'log', nonposy=
'clip')
1540 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
1541 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=37)
1542 ax2b.tick_params(axis=
'y', labelsize=37)
1543 ax2b.legend([p2, p1], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=location)
1545 plt.savefig(workingDirectory +
'/' +
'pyPIC_' + category +
'_Input_CombinerTruth.pdf')
1548 fig2c = plt.figure(2, figsize=(11, 8))
1549 ax2c = plt.axes([0.21, 0.16, 0.75, 0.81])
1550 ax2c.hist(dataNoTarget[np.where(dataNoTarget[:, 0] == -1)][:, 1], bins=bins, histtype=
'step',
1551 edgecolor=
'b', linewidth=4.5, linestyle=
'dashed', label=
r'$\bar{B}^0$')
1553 dataNoTarget[np.where(dataNoTarget[:, 0] == 1)][:, 1],
1561 p2, = ax2c.plot([], label=
r'$\bar{B}^0$', linewidth=4.5, linestyle=
'dashed', c=
'b')
1562 p1, = ax2c.plot([], label=
r'$B^0$', linewidth=4, linestyle=
'solid', alpha=0.9, c=
'r')
1564 ax2c.set_ylabel(
r'${\rm Number\ \ of\ \ Events\ /\ (\, 0.02\, )}$', fontsize=37)
1565 ax2c.set_xlabel(title, fontsize=48)
1566 ax2c.set_yscale(
'log', nonposy=
'clip')
1567 plt.xticks([-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1],
1568 [
r'$-1$',
r'',
r'$-0.5$',
r'',
r'$0$',
r'',
r'$0.5$',
r'',
r'$1$'], rotation=0, size=37)
1569 ax2c.tick_params(axis=
'y', labelsize=37)
1570 ax2c.legend([p2, p1], [
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 35}, loc=location)
1572 plt.savefig(workingDirectory +
'/' +
'pyPIC_' + category +
'_Input_CombinerNoTarget.pdf')
1575 percentageCategory = dataTruth.shape[0] / data.shape[0] * 100
1576 percentageCategory =
'% .2f' % percentageCategory
1578 print(
"Percentage of Category " + category +
" is = " + percentageCategory +
" %")
1582 NoTargetEfficiencies = np.array(NoTargetEfficiencies)
1583 fig = plt.figure(5, figsize=(29, 18))
1584 ax = plt.axes([0.15, 0.3, 0.81, 0.67])
1587 p1 = ax.bar(np.array(range(0, 13, 1)) + width / 4, NoTargetEfficiencies[:, 1], width, color=
'b', ecolor=
'k', label=
r'$\bar{B}^0$')
1588 p2 = ax.bar(np.array(range(0, 13, 1)) + width + width / 4, NoTargetEfficiencies[:, 0], width, color=
'r', ecolor=
'k', label=
r'$B^0$')
1589 ax.set_ylabel(
r'$ \varepsilon_{\rm eff}/\ \% $', fontsize=30)
1590 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],
1591 categoryLabel, rotation=50, horizontalalignment=
'right', size=30)
1592 plt.yticks([5, 10, 15, 20, 25, 50, 100], [
r"$5$",
r"",
r"$15$",
r"",
r"$25$",
r"$50$",
r"$100$"], size=30)
1595 ax.legend([
r'$\bar{B}^0$',
r'$B^0$'], prop={
'size': 25})
1597 plt.savefig(workingDirectory +
'/EfficienciesNoTarget.pdf')
1601 print(
'*******************************************************************************************************************')
1602 B2INFO(
'qr Output Histograms in pdf format saved at: ' + workingDirectory)