Belle II Software development
qam.py
1#!/usr/bin/env python3
2
3
10
11
12from ROOT import TCanvas, TFile
13import argparse
14
15
16class QAM():
17
18 """
19 QAM class.
20 """
21
22 def __init__(self, fname='input.root'):
23 """
24 call constructor of base class, required.
25 """
26
27 super().__init__()
28
29
30 self.f = TFile(fname)
31
32 self.histHelix = {'ndf': {'all': self.f.Get('h17;1'),
33 'up': self.f.Get('h00;1'),
34 'down': self.f.Get('h01;1')},
35 'pval': {'all': self.f.Get('h18;1'),
36 'up': self.f.Get('h02;1'),
37 'down': self.f.Get('h03;1')},
38 'd0': {'all': self.f.Get('h11;1'),
39 'up': self.f.Get('h04;1'),
40 'down': self.f.Get('h05;1')},
41 'phi0': {'all': self.f.Get('h12;1'),
42 'up': self.f.Get('h06;1'),
43 'down': self.f.Get('h07;1')},
44 'omega': {'all': self.f.Get('h13;1'),
45 'up': self.f.Get('h08;1'),
46 'down': self.f.Get('h09;1')},
47 'z0': {'all': self.f.Get('h14;1'),
48 'up': self.f.Get('h0a;1'),
49 'down': self.f.Get('h0b;1')},
50 'tanl': {'all': self.f.Get('h15;1'),
51 'up': self.f.Get('h0c;1'),
52 'down': self.f.Get('h0d;1')},
53 'pt': {'all': self.f.Get('h16;1'),
54 'up': self.f.Get('h0e;1'),
55 'down': self.f.Get('h0f;1')}
56 }
57
58
59 self.histReso = {'d0': self.f.Get('h1;1'),
60 'phi0': self.f.Get('h2;1'),
61 'omega': self.f.Get('h3;1'),
62 'z0': self.f.Get('h4;1'),
63 'tanl': self.f.Get('h5;1'),
64 'pt': self.f.Get('h6;1')}
65
66
67 self.histPull = {'d0': self.f.Get('h21;1'),
68 'phi0': self.f.Get('h22;1'),
69 'omega': self.f.Get('h23;1'),
70 'z0': self.f.Get('h24;1'),
71 'tanl': self.f.Get('h25;1')}
72
73
74 self.graphPt = {'d0': self.f.Get('Graph;2'),
75 'phi0': self.f.Get('Graph;3'),
76 'omega': self.f.Get('Graph;4'),
77 'z0': self.f.Get('Graph;5'),
78 'pt': self.f.Get('Graph;1')}
79
80 self.canvas = TCanvas("canvas", "canvas", 800, 800)
81
82 self.ndiv = 1
83
84 self.index = 1
85
86 def pull(self, key='d0'):
87 '''
88 Plot pull distribution
89 '''
90 self.canvas.cd(self.index)
91 self.histPull[key].Draw()
92 self.canvas.Update()
93 self.index = self.index + 1
94
95 def getMean(self, key='pt'):
96 '''
97 Getter for mean of helix parameter.
98 '''
99 h = self.histReso[key]
100 m = h.GetMean()
101 dm = h.GetMeanError()
102 return [m, dm]
103
104 def getRms(self, key='pt'):
105 '''
106 Getter for rms of helix parameter.
107 '''
108 h = self.histReso[key]
109 s = h.GetRMS()
110 ds = h.GetRMSError()
111 return [s, ds]
112
113 def graph(self, key='pt'):
114 '''
115 Plot graph of resolution as a function of Pt.
116 '''
117 self.canvas.cd(self.index)
118 self.graphPt[key].Draw('AP')
119 self.canvas.Update()
120 self.index = self.index + 1
121
122 def reso(self, key='pt'):
123 '''
124 Plot resolution histogram.
125 '''
126 self.canvas.cd(self.index)
127 self.histReso[key].Draw()
128 self.canvas.Update()
129 self.index = self.index + 1
130
131 def draw(self, key='pt', option='all', gopt=''):
132 '''
133 Plot histogram of helix parameters etc..
134 '''
135 self.canvas.cd(self.index)
136 self.histHelix[key][option].Draw(gopt)
137 self.canvas.Update()
138 self.index = self.index + 1
139
140 def print(self, fname='test.png'):
141 """
142 Print the current plot.
143 """
144 self.canvas.Print(fname)
145
146 def div(self, i=1, j=1):
147 """
148 Divide Tcanvas by (i,j).
149 """
150 self.canvas.Clear()
151 self.canvas.Divide(i, j)
152 self.ndiv = i * j
153 self.index = 1
154
155
156if __name__ == "__main__":
157 # Make the parameters accessible form the outside.
158
159 parser = argparse.ArgumentParser()
160 parser.add_argument('input', help='Input file to be processed (unpacked CDC data).')
161 args = parser.parse_args()
162 qam = QAM(args.input)
Definition: qam.py:16
def print(self, fname='test.png')
Definition: qam.py:140
def div(self, i=1, j=1)
Definition: qam.py:146
histPull
Pull histograms.
Definition: qam.py:67
def pull(self, key='d0')
Definition: qam.py:86
histHelix
Histograms for helix parameters etc...
Definition: qam.py:32
graphPt
Graph, resolution as a function of pt.
Definition: qam.py:74
def __init__(self, fname='input.root')
Definition: qam.py:22
f
input file name
Definition: qam.py:30
index
Index of canvas position.
Definition: qam.py:84
histReso
Resolution histograms.
Definition: qam.py:59
def draw(self, key='pt', option='all', gopt='')
Definition: qam.py:131
def graph(self, key='pt')
Definition: qam.py:113
def reso(self, key='pt')
Definition: qam.py:122
def getMean(self, key='pt')
Definition: qam.py:95
def getRms(self, key='pt')
Definition: qam.py:104
ndiv
Number of division for canvas.
Definition: qam.py:82
canvas
canvas
Definition: qam.py:80