Belle II Software  release-08-01-10
test7_treeFitterFitResolution_Plot.py
1 #!/usr/bin/env python
2 
3 
10 
11 """
12 <header>
13  <input>../TreeFitted_B0ToJPsiKs.root</input>
14  <contact>Yo Sato; yosato@post.kek.jp</contact>
15  <interval>nightly</interval>
16 </header>
17 """
18 # Bto J/Psi Ks(Pi+Pi-) is fitted and the resolution of the vertex
19 # positions/E/P/pVal is plotted.
20 
21 import glob
22 
23 import ROOT
24 import sysconfig
25 ROOT.gROOT.ProcessLine(".include " + sysconfig.get_path("include")) # noqa
26 
27 workingFiles = glob.glob("../TreeFitted_B0ToJPsiKs.root")
28 
29 chain = ROOT.TChain("B0TreeFit")
30 for iFile in workingFiles:
31  chain.AddFile(iFile)
32 
33 outputFile = ROOT.TFile("test7_TreeFitterOutput.root", "RECREATE")
34 
35 RangeMicrons = 100
36 RangePull = 5
37 nBins = 50
38 
39 B0_E_pull_s = ROOT.TH1F("B0_E_pull_s", 'Pull of the B^{0} energy sig', nBins, -RangePull, RangePull)
40 B0_p_pull_s = ROOT.TH1F("B0_p_pull_s", 'Pull of the B^{0} momentum sig', nBins, -RangePull, RangePull)
41 
42 B0_vertex_pullx_s = ROOT.TH1F("B0_vertex_pullx_s", 'Pull of The B^{0} x vertex position sig', nBins, -RangePull, RangePull)
43 B0_vertex_pully_s = ROOT.TH1F("B0_vertex_pully_s", 'Pull of The B^{0} y vertex position sig', nBins, -RangePull, RangePull)
44 B0_vertex_pullz_s = ROOT.TH1F("B0_vertex_pullz_s", 'Pull of The B^{0} z vertex position sig', nBins, -RangePull, RangePull)
45 
46 B0_vertex_resolutionx_s = ROOT.TH1F("B0_vertex_resolutionx_s",
47  'meas - mc of the B^{0} x vertex sig', nBins, -RangeMicrons, RangeMicrons)
48 B0_vertex_resolutiony_s = ROOT.TH1F("B0_vertex_resolutiony_s",
49  'meas - mc of the B^{0} y vertex sig', nBins, -RangeMicrons, RangeMicrons)
50 B0_vertex_resolutionz_s = ROOT.TH1F("B0_vertex_resolutionz_s",
51  'meas - mc of the B^{0} z vertex sig', nBins, -RangeMicrons, RangeMicrons)
52 pVal_s = ROOT.TH1F("pVal_s", 'global pValue sig', nBins, -1, 1)
53 pVal_b = ROOT.TH1F("pVal_b", 'global pValue bkg', nBins, -1, 1)
54 
55 signalCut = ROOT.TCut("(isSignal>0)")
56 bkgCut = ROOT.TCut("(isSignal<1)")
57 
58 histOperationStrings = [
59  "(E - mcE) / E_uncertainty>>B0_E_pull_s",
60  "(p - mcP) / pErr>>B0_p_pull_s",
61  "(x - mcDecayVertexX) / x_uncertainty>>B0_vertex_pullx_s",
62  "(y - mcDecayVertexY) / y_uncertainty>>B0_vertex_pully_s",
63  "(z - mcDecayVertexZ) / z_uncertainty>>B0_vertex_pullz_s",
64  "(x - mcDecayVertexX)*10000>>B0_vertex_resolutionx_s",
65  "(y - mcDecayVertexY)*10000>>B0_vertex_resolutiony_s",
66  "(z - mcDecayVertexZ)*10000>>B0_vertex_resolutionz_s",
67  "chiProb>>pVal_s",
68  "chiProb>>pVal_b",
69 ]
70 
71 drawToNewHist = chain.Draw
72 for histOperation in histOperationStrings:
73  if "_s" in histOperation:
74  drawToNewHist(histOperation, signalCut)
75  else:
76  drawToNewHist(histOperation, bkgCut)
77 
78 histsAndLabels = {
79  B0_E_pull_s: "B^{0} E pull",
80  B0_p_pull_s: "B^{0} momentum pull",
81  B0_vertex_pullx_s: "pull of B^{0} vertex X ",
82  B0_vertex_pully_s: "pull of B^{0} vertex Y ",
83  B0_vertex_pullz_s: "pull of B^{0} vertex Z ",
84  B0_vertex_resolutionx_s: "meas-mc of B^{0} vertex X [#mum]",
85  B0_vertex_resolutiony_s: "meas-mc of B^{0} vertex Y [#mum]",
86  B0_vertex_resolutionz_s: "meas-mc of B^{0} vertex Z [#mum]",
87  pVal_b: "pValue",
88  pVal_s: "pValue",
89 }
90 
91 checkForGausian = "This should be a Gaussian on flat bkg and not changing."
92 metaOptions = "pvalue-warn=0.1"
93 for hist, xlabel in histsAndLabels.items():
94  hist.GetXaxis().SetTitle(xlabel)
95  hist.GetListOfFunctions().Add(ROOT.TNamed("Contact", "yosato@post.kek.jp"))
96  hist.GetListOfFunctions().Add(ROOT.TNamed("Description", xlabel))
97  hist.GetListOfFunctions().Add(ROOT.TNamed("MetaOptions", metaOptions))
98  if any(string in xlabel for string in ["pull", "meas-mc"]):
99  hist.GetListOfFunctions().Add(ROOT.TNamed("Check", checkForGausian))
100 
101 outputFile.Write()