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