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