ATLAS Offline Software
dumptuple1.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 #
4 # File: D3PDMakerTest/python/dumptuple1.py
5 # Author: snyder@bnl.gov
6 # Date: Jan, 2010
7 # Purpose: Test D3PD making.
8 #
9 
10 # Always run in batch mode.
11 import os
12 if 'DISPLAY' in os.environ:
13  del os.environ['DISPLAY']
14 
15 
16 import ROOT
17 import cppyy
18 from D3PDMakerTest.Treereader import treereader
19 
20 # Touch these types early, before dictionaries are loaded,
21 # to prevent spurious error messages from ROOT.
22 # See ATLASRECTS-3486.
23 getattr(cppyy.gbl, 'vector<char>')
24 getattr(cppyy.gbl, 'vector<unsigned char>')
25 getattr(cppyy.gbl, 'vector<float>')
26 getattr(cppyy.gbl, 'vector<short>')
27 getattr(cppyy.gbl, 'map<string,string>')
28 
29 
30 from RootUtils import PyROOTFixes
31 PyROOTFixes.enable_tree_fixes()
32 
33 from PyUtils.fprint import fprintln
34 
35 def safeord(x):
36  if isinstance(x, str):
37  return ord(x)
38  if x < 0:
39  x = x + 256
40  return x
41 
42 def dump_obj1 (tr, coll = True, dodef = False):
43  for i in range (tr.n):
44  assert tr.i[i] == tr.mult_i[i]
45  print (' %1d %3d %3d %3d %3d %3d %3d %5.1f %5.1f %1d %3d %5.1f %3d %5.1f %3d %5.1f %3d %5.1f' %
46  (i,
47  safeord(tr.c[i]),
48  safeord(tr.uc[i]),
49  tr.s[i],
50  tr.us[i],
51  tr.i[i],
52  tr.ui[i],
53  tr.f[i],
54  tr.d[i],
55  tr.b[i],
56  tr.o2a_i[i],
57  tr.o2a_f[i],
58  tr.o2c_i[i],
59  tr.o2c_f[i],
60  tr.o2c_o2d_i[i],
61  tr.o2c_o2d_f[i],
62  tr.o2c_o2e_i[i],
63  tr.o2c_o2e_i[i],
64  ))
65  if dodef:
66  print (' %3d %3d' % (ord(tr.c1[i]), ord(tr.c2[i])), end='')
67  print (' %3d %3d' % (ord(tr.uc1[i]), ord(tr.uc2[i])), end='')
68  print (' %3d %3d' % (tr.s1[i], tr.s2[i]), end='')
69  print (' %3d %3d' % (tr.us1[i], tr.us2[i]), end='')
70  print (' %3d %3d' % (tr.i1[i], tr.i2[i]), end='')
71  print (' %3d %3d' % (tr.ui1[i], tr.ui2[i]), end='')
72  print (' %5.1f %5.1f' % (tr.f1[i], tr.f2[i]), end='')
73  print (' %5.1f %5.1f' % (tr.d1[i], tr.d2[i]), end='')
74  print (' %3d %3d' % (tr.b1[i], tr.b2[i]))
75  if coll:
76  for j in range (tr.o2b_n[i]):
77  assert tr.o2b_mult_i[i][j] == tr.o2b_i[i][j]
78  print (' o2b%1d %3d %5.1f' % (j,
79  tr.o2b_i[i][j],
80  tr.o2b_f[i][j]))
81  return
82 
83 
84 def dump_obj1_2 (tr):
85  for i in range (tr.n):
86  print (' %1d %3d %5.1f %3d %5.1f %3d %5.1f' %
87  (i,
88  tr.o2a_i[i],
89  tr.o2a_f[i],
90  tr.o2b_i[i],
91  tr.o2b_f[i],
92  tr.o2c_i[i],
93  tr.o2c_f[i],
94  ))
95  return
96 
97 
98 def dump_obj3 (tr):
99  for i in range (tr.n):
100  fprintln (sys.stdout, ' ', i, tr.pt[i], tr.eta[i], tr.phi[i], tr.m[i], tuple(tr.index[i]), tr.a1_index[i])
101  fprintln (sys.stdout, ' ', tr.hlv_pt[i], tr.hlv_eta[i], tr.hlv_phi[i], tr.hlv_m[i])
102  return
103 
104 
105 def dump_obj4 (tr):
106  for i in range (tr.n):
107  print (' ', i, tr.obj4[i])
108 
109 
110 def dump_obj5 (tr):
111  for i in range (tr.n):
112  print (' ', i, tr.obj5[i], tr.anInt[i], tr.aFloat[i], tr.s[i],
113  '%7.1f %6.3f %6.3f' % (tr.aFourvec[i].Pt(),
114  tr.aFourvec[i].Eta(),
115  tr.aFourvec[i].Phi()),
116  tr.dummy[i])
117 
118 
119 def dump_def (tr):
120  print (' %3d %3d' % (ord(tr.c1), ord(tr.c2)))
121  print (' %3d %3d' % (ord(tr.uc1), ord(tr.uc2)))
122  print (' %3d %3d' % (tr.s1, tr.s2))
123  print (' %3d %3d' % (tr.us1, tr.us2))
124  print (' %3d %3d' % (tr.i1, tr.i2))
125  print (' %3d %3d' % (tr.ui1, tr.ui2))
126  print (' %5.1f %5.1f' % (tr.f1, tr.f2))
127  print (' %5.1f %5.1f' % (tr.d1, tr.d2))
128  print (' %3d %3d' % (tr.b1, tr.b2))
129  return
130 
131 
132 def dump_mdt (tr):
133  for i in range (tr.n):
134  print (' ', i, tr.globalTime[i], tr.driftRadius[i],
135  tr.stepLength[i], tr.energyDeposit[i],
136  tr.particleEncoding[i], tr.kineticEnergy[i],
137  tr.MDTid[i], tr.trackNumber[i])
138  return
139 
140 
142  for i in range (tr.n):
143  fprintln (sys.stdout, ' ',
144  i, tr.barcode[i], tr.pdgId[i], tr.E[i], tr.pt[i],
145  tr.eta[i], tr.phi[i], tr.pos_x[i], tr.pos_y[i], tr.pos_z[i],
146  tr.time[i])
147  return
148 
149 
150 def dumpit (file):
151  f=ROOT.TFile(file)
152  tt=f.Get('test1')
153  tr = treereader(tt)
154  tr_o1 = tr.subreader ('o1_%s')
155  tr_o1filt = tr.subreader ('o1filt_%s')
156  tr_o12 = tr.subreader ('o12_%s')
157  tr_o3 = tr.subreader ('o3_%s')
158  tr_o4 = tr.subreader ('o4_%s')
159  tr_o5 = tr.subreader ('o5_%s')
160  tr_def = tr.subreader ('def_%s')
161  tr_mdt = tr.subreader ('mdt_hit_%s')
162  tr_trackrecord = tr.subreader ('ms_entry_truth_%s')
163  n = tt.GetEntries()
164  for i in range(n):
165  tt.GetEntry(i)
166  print ('\nEvent', i)
167  print ('-----------')
168  print ('** Obj1')
169  dump_obj1 (tr_o1, dodef = True)
170  print ('** Obj1_2')
171  dump_obj1_2 (tr_o12)
172  print ('** Obj1filt')
173  dump_obj1 (tr_o1filt, coll = False)
174  print ('** Obj3')
175  dump_obj3 (tr_o3)
176  print ('** Obj4')
177  dump_obj4 (tr_o4)
178  print ('** Obj5')
179  dump_obj5 (tr_o5)
180  print ('** Def')
181  dump_def (tr_def)
182  print ('** MDT')
183  dump_mdt (tr_mdt)
184  print ('** TrackRecord')
185  dump_trackrecord (tr_trackrecord)
186  return
187 
188 
189 if __name__ == '__main__':
190  import sys
191  file = 'test1.root'
192  if len(sys.argv) > 1:
193  file = sys.argv[1]
194  dumpit (file)
195 
python.dumptuple1.dump_obj1_2
def dump_obj1_2(tr)
Definition: dumptuple1.py:84
python.dumptuple1.dump_def
def dump_def(tr)
Definition: dumptuple1.py:119
python.dumptuple1.dump_trackrecord
def dump_trackrecord(tr)
Definition: dumptuple1.py:141
python.dumptuple1.dump_mdt
def dump_mdt(tr)
Definition: dumptuple1.py:132
python.dumptuple1.dump_obj3
def dump_obj3(tr)
Definition: dumptuple1.py:98
python.dumptuple1.safeord
def safeord(x)
Definition: dumptuple1.py:35
python.dumptuple1.dumpit
def dumpit(file)
Definition: dumptuple1.py:150
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.dumptuple1.dump_obj5
def dump_obj5(tr)
Definition: dumptuple1.py:110
python.Treereader.treereader
def treereader(tree, parent=None, subpattern=None)
Definition: Treereader.py:64
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
python.dumptuple1.dump_obj1
def dump_obj1(tr, coll=True, dodef=False)
Definition: dumptuple1.py:42
Eta
@ Eta
Definition: RPCdef.h:8
python.dumptuple1.dump_obj4
def dump_obj4(tr)
Definition: dumptuple1.py:105