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