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