4 This module provides ROOT IO interface for MCScore data
7 [f] loop_tree(tfile, analyze_vertex):
11 from array
import array
20 __all__ = [
'MCScoreROOTIO',
'loop_tree' ]
30 "ROOT IO interface for MCScore"
38 self.
vtree = ROOT.TTree(
'vertex',
'mc vertex')
39 self.
ptree = ROOT.TTree(
'particle',
'mc particle')
42 self.
a_x = array(
'd', [0.]); self.vtree.Branch(
'x', self.
a_x,
'x/d')
43 self.
a_y = array(
'd', [0.]); self.vtree.Branch(
'y', self.
a_y,
'y/d')
44 self.
a_z = array(
'd', [0.]); self.vtree.Branch(
'z', self.
a_z,
'z/d')
47 self.
a_np = array(
'i', [0]); self.ptree.Branch(
'np', self.
a_np,
'np/i')
51 self.ptree.Branch(
'namelist', self.
a_namelist,
'namelist/C')
54 self.ptree.Branch(
'Z', self.
a_Z,
'Z[np]/I')
57 self.ptree.Branch(
'A', self.
a_A,
'A[np]/i')
60 self.ptree.Branch(
'kE', self.
a_ke,
'kE[np]/d')
63 self.ptree.Branch(
'px', self.
a_px,
'px[np]/d')
66 self.ptree.Branch(
'py', self.
a_py,
'py[np]/d')
69 self.ptree.Branch(
'pz', self.
a_pz,
'pz[np]/d')
73 "fill vertex information to ROOT tree"
75 def push_pname(i0, pname):
81 self.
a_x[0] = vertex.x
82 self.
a_y[0] = vertex.y
83 self.
a_z[0] = vertex.z
88 *** buffer overflow in #particles/vertex.
89 *** please increment buffersize in MCScoreROOTIO(bsize).
93 self.
a_np[0] = vertex.nparticle
94 for ip
in range(vertex.nparticle):
95 particle = vertex.particle_list[ip]
96 push_pname(idx_namelist, particle.name)
97 idx_namelist += (len(particle.name)+1)
98 self.
a_Z[ip] = particle.Z
99 self.
a_A[ip] = particle.A
100 self.
a_ke[ip] = particle.kineticE
101 self.
a_px[ip] = particle.px
102 self.
a_py[ip] = particle.py
103 self.
a_pz[ip] = particle.pz
114 loop ROOT tree in a ROOT file.
115 * analyze_vertex: user function : analyze_vertex(MCVertex)
117 avtree = tfile.Get(
"vertex")
118 aptree = tfile.Get(
"particle")
121 n_vertex = avtree.GetEntries()
122 for ivtx
in xrange(n_vertex):
123 avtree.GetEntry(ivtx)
124 aptree.GetEntry(ivtx)
127 vertex = MCScore.MCVertex(avtree.x, avtree.y, avtree.z)
131 namelist = aptree.namelist
132 pname = namelist.split()
133 for ip
in xrange(nsec):
134 particle = MCScore.MCParticle(pname[ip], aptree.Z[ip], aptree.A[ip],
135 aptree.kE[ip], aptree.px[ip],
136 aptree.py[ip], aptree.pz[ip])
137 vertex.append_particle(particle)
139 analyze_vertex(vertex)
148 g = ROOT.TFile(
"reaction.root",
'recreate')
153 f =
open(
"reaction.dat")
157 vertex = MCScore.read_next_vertex(f)
162 rootio.fill_tree(vertex)
175 def my_analysis(vertex):
178 f = ROOT.TFile(
"reaction.root",
'read')
180 print "*** # of vertex= ", nv
186 if __name__ ==
"__main__":