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