Import Geant4 9.2.0 source tree
This commit is contained in:
@@ -1,29 +1,13 @@
|
||||
# $Id: GNUmakefile,v 1.1 2006/07/12 02:01:07 kmura Exp $
|
||||
# $Name: geant4-09-01 $
|
||||
# $Id: GNUmakefile,v 1.3 2008/12/03 07:40:49 kmura Exp $
|
||||
# $Name: geant4-09-02 $
|
||||
# ===========================================================
|
||||
# Makefile for building Geant4Py modules
|
||||
# ===========================================================
|
||||
include ../../../config/config.gmk
|
||||
|
||||
install_dir := $(Q_LIBDIR)/g4py
|
||||
|
||||
include $(G4PY_INSTALL)/config/g4py.gmk
|
||||
include $(G4PY_INSTALL)/config/sys/$(Q_SYSTEM).gmk
|
||||
|
||||
install_dir := $(Q_LIBDIR)
|
||||
|
||||
pys := $(wildcard *.py)
|
||||
pycs := $(patsubst %.py, %.pyc, $(pys))
|
||||
pyos := $(patsubst %.py, %.pyo, $(pys))
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
all: $(pycs) $(pyos)
|
||||
|
||||
|
||||
install: $(pycs) $(pyos)
|
||||
@echo ... intall "*.py" into $(install_dir)
|
||||
@if [ ! -d $(install_dir) ]; then install -d $(install_dir); fi
|
||||
@install -m 644 $(pys) $(pycs) $(pyos) $(install_dir)
|
||||
|
||||
clean:
|
||||
@-\rm -f $(pycs) $(pyos)
|
||||
include $(G4PY_INSTALL)/config/script-install.gmk
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# ==================================================================
|
||||
"""
|
||||
Python module
|
||||
|
||||
@@ -10,9 +9,14 @@ This module provides classes and functions for scoring reactions
|
||||
|
||||
Q, 2006
|
||||
"""
|
||||
# ==================================================================
|
||||
from Geant4.HEPUnit import *
|
||||
import string
|
||||
from Geant4.hepunit import *
|
||||
|
||||
# ==================================================================
|
||||
# public symbols
|
||||
# ==================================================================
|
||||
__all__ = [ 'MCParticle', 'MCVertex', 'read_next_vertex' ]
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# class definition
|
||||
@@ -24,13 +28,13 @@ import string
|
||||
class MCParticle:
|
||||
"MC particle"
|
||||
def __init__(self, aname, aZ, aA, akE, apx, apy, apz):
|
||||
self.name= aname
|
||||
self.Z= aZ
|
||||
self.A= aA
|
||||
self.kineticE= akE
|
||||
self.px= apx
|
||||
self.py= apy
|
||||
self.pz= apz
|
||||
self.name = aname
|
||||
self.Z = aZ
|
||||
self.A = aA
|
||||
self.kineticE = akE
|
||||
self.px = apx
|
||||
self.py = apy
|
||||
self.pz = apz
|
||||
|
||||
def printout(self):
|
||||
print "--- particle: %s, Z=%2d, A=%2d, kE=%g" % \
|
||||
@@ -41,13 +45,12 @@ class MCParticle:
|
||||
# ------------------------------------------------------------------
|
||||
class MCVertex :
|
||||
"MC vertex"
|
||||
|
||||
def __init__(self, ax, ay, az):
|
||||
self.x= ax
|
||||
self.y= ay
|
||||
self.z= az
|
||||
self.nparticle= 0
|
||||
self.particle_list= []
|
||||
self.x = ax
|
||||
self.y = ay
|
||||
self.z = az
|
||||
self.nparticle = 0
|
||||
self.particle_list = []
|
||||
|
||||
def append_particle(self, aparticle):
|
||||
self.particle_list.append(aparticle)
|
||||
@@ -60,73 +63,74 @@ class MCVertex :
|
||||
p.printout()
|
||||
|
||||
def dump_vertex(self, stream):
|
||||
aline= "%g %g %g %d\n" % \
|
||||
(self.x/m, self.y/m, self.z/m, self.nparticle)
|
||||
aline = "%g %g %g %d\n" % \
|
||||
(self.x/m, self.y/m, self.z/m, self.nparticle)
|
||||
stream.write(aline)
|
||||
for p in self.particle_list:
|
||||
aline= " %s %d %d %g %g %g %g\n" % \
|
||||
(p.name, p.Z, p.A, p.kineticE/MeV, p.px/MeV, p.py/MeV, p.pz/MeV)
|
||||
aline = " %s %d %d %g %g %g %g\n" % \
|
||||
(p.name, p.Z, p.A, p.kineticE/MeV, p.px/MeV, p.py/MeV, p.pz/MeV)
|
||||
stream.write(aline)
|
||||
|
||||
def __del__(self):
|
||||
np= len(self.particle_list)
|
||||
np = len(self.particle_list)
|
||||
del self.particle_list[0:np]
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# I/O interface
|
||||
# ==================================================================
|
||||
# ------------------------------------------------------------------
|
||||
def read_next_vertex(stream):
|
||||
# ------------------------------------------------------------------
|
||||
"read next vertex from a file stream"
|
||||
line= stream.readline()
|
||||
if (line == "") : # EOF
|
||||
if line == "": # EOF
|
||||
return 0
|
||||
|
||||
# reading vertex
|
||||
data= line.split()
|
||||
x= string.atof(data[0])*m
|
||||
y= string.atof(data[1])*m
|
||||
z= string.atof(data[2])*m
|
||||
nsec= string.atoi(data[3])
|
||||
data = line.split()
|
||||
x = string.atof(data[0]) * m
|
||||
y = string.atof(data[1]) * m
|
||||
z = string.atof(data[2]) * m
|
||||
nsec = string.atoi(data[3])
|
||||
|
||||
vertex= MCVertex(x,y,z)
|
||||
vertex = MCVertex(x,y,z)
|
||||
|
||||
# reading particles
|
||||
for p in range(0, nsec):
|
||||
data= stream.readline().split()
|
||||
pname= data[0]
|
||||
Z= string.atoi(data[1])
|
||||
A= string.atoi(data[2])
|
||||
kE= string.atof(data[3])*MeV
|
||||
px= string.atof(data[4])*MeV
|
||||
py= string.atof(data[5])*MeV
|
||||
pz= string.atof(data[6])*MeV
|
||||
data = stream.readline().split()
|
||||
pname = data[0]
|
||||
Z = string.atoi(data[1])
|
||||
A = string.atoi(data[2])
|
||||
kE = string.atof(data[3]) * MeV
|
||||
px = string.atof(data[4]) * MeV
|
||||
py = string.atof(data[5]) * MeV
|
||||
pz = string.atof(data[6]) * MeV
|
||||
|
||||
particle= MCParticle(pname, Z, A, kE, px, py, pz)
|
||||
particle = MCParticle(pname, Z, A, kE, px, py, pz)
|
||||
vertex.append_particle(particle)
|
||||
|
||||
return vertex
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# test
|
||||
# ==================================================================
|
||||
def test():
|
||||
f= open("reaction.dat")
|
||||
f = open("reaction.dat")
|
||||
f.seek(0)
|
||||
|
||||
while(1):
|
||||
vertex= read_next_vertex(f)
|
||||
if(vertex==0):
|
||||
vertex = read_next_vertex(f)
|
||||
if vertex == 0:
|
||||
break
|
||||
vertex.printout()
|
||||
del vertex
|
||||
f.close()
|
||||
print ">>> EOF"
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# main
|
||||
# ==================================================================
|
||||
if (__name__ == "__main__") :
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# ==================================================================
|
||||
"""
|
||||
Python module
|
||||
|
||||
@@ -9,16 +8,17 @@ This module provides ROOT IO interface for MCScore data
|
||||
|
||||
Q, 2006
|
||||
"""
|
||||
# ==================================================================
|
||||
from Geant4.HEPUnit import *
|
||||
from array import array
|
||||
import string
|
||||
import MCScore
|
||||
from Geant4.hepunit import *
|
||||
import mcscore
|
||||
import ROOT
|
||||
|
||||
# ==================================================================
|
||||
from Geant4.HEPUnit import *
|
||||
import string
|
||||
# public symbols
|
||||
# ==================================================================
|
||||
__all__ = [ 'MCScoreROOTIO', 'loop_tree' ]
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# class definition
|
||||
@@ -29,133 +29,133 @@ import string
|
||||
class MCScoreROOTIO:
|
||||
"ROOT IO interface for MCScore"
|
||||
def __init__(self, bsize=250):
|
||||
self.maxparticle= bsize # buffer size for #particles/vertex
|
||||
self.maxparticle = bsize # buffer size for #particles/vertex
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def define_tree(self):
|
||||
"define ROOT tree"
|
||||
# ------------------------------------------------------------------
|
||||
# defining tree header...
|
||||
self.vtree= ROOT.TTree('vertex', 'mc vertex')
|
||||
self.ptree= ROOT.TTree('particle', 'mc particle')
|
||||
self.vtree = ROOT.TTree('vertex', 'mc vertex')
|
||||
self.ptree = ROOT.TTree('particle', 'mc particle')
|
||||
|
||||
# vertex...
|
||||
self.a_x= array('d', [0.]); self.vtree.Branch('x', self.a_x, 'x/d')
|
||||
self.a_y= array('d', [0.]); self.vtree.Branch('y', self.a_y, 'y/d')
|
||||
self.a_z= array('d', [0.]); self.vtree.Branch('z', self.a_z, 'z/d')
|
||||
self.a_x = array('d', [0.]); self.vtree.Branch('x', self.a_x, 'x/d')
|
||||
self.a_y = array('d', [0.]); self.vtree.Branch('y', self.a_y, 'y/d')
|
||||
self.a_z = array('d', [0.]); self.vtree.Branch('z', self.a_z, 'z/d')
|
||||
|
||||
#global a_np, a_namelist, a_Z, a_A, a_ke, a_px, a_py, a_pz
|
||||
self.a_np= array('i', [0]); self.ptree.Branch('np', self.a_np, 'np/i')
|
||||
self.a_np = array('i', [0]); self.ptree.Branch('np', self.a_np, 'np/i')
|
||||
|
||||
self.a_namelist= array('c', self.maxparticle*10*['\0'])
|
||||
self.a_namelist = array('c', self.maxparticle*10*['\0'])
|
||||
# 10 characters/particle
|
||||
self.ptree.Branch('namelist', self.a_namelist, 'namelist/C')
|
||||
|
||||
self.a_Z= array('i', self.maxparticle*[0])
|
||||
self.a_Z = array('i', self.maxparticle*[0])
|
||||
self.ptree.Branch('Z', self.a_Z, 'Z[np]/I')
|
||||
|
||||
self.a_A= array('i', self.maxparticle*[0])
|
||||
self.a_A = array('i', self.maxparticle*[0])
|
||||
self.ptree.Branch('A', self.a_A, 'A[np]/i')
|
||||
|
||||
self.a_ke= array('d', self.maxparticle*[0.])
|
||||
self.a_ke = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('kE', self.a_ke, 'kE[np]/d')
|
||||
|
||||
self.a_px= array('d', self.maxparticle*[0.])
|
||||
self.a_px = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('px', self.a_px, 'px[np]/d')
|
||||
|
||||
self.a_py= array('d', self.maxparticle*[0.])
|
||||
self.a_py = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('py', self.a_py, 'py[np]/d')
|
||||
|
||||
self.a_pz= array('d', self.maxparticle*[0.])
|
||||
self.a_pz = array('d', self.maxparticle*[0.])
|
||||
self.ptree.Branch('pz', self.a_pz, 'pz[np]/d')
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def fill_tree(self, vertex):
|
||||
"fill vertex information to ROOT tree"
|
||||
# ------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------
|
||||
def push_pname(i0, pname): # local function
|
||||
n= len(pname)
|
||||
n = len(pname)
|
||||
for i in xrange(n):
|
||||
self.a_namelist[i0+i]= pname[i]
|
||||
self.a_namelist[i0+n]= ' '
|
||||
self.a_namelist[i0+i] = pname[i]
|
||||
self.a_namelist[i0+n] = ' '
|
||||
|
||||
self.a_x[0]= vertex.x
|
||||
self.a_y[0]= vertex.y
|
||||
self.a_z[0]= vertex.z
|
||||
self.a_x[0] = vertex.x
|
||||
self.a_y[0] = vertex.y
|
||||
self.a_z[0] = vertex.z
|
||||
self.vtree.Fill()
|
||||
|
||||
if(vertex.nparticle > self.maxparticle):
|
||||
if vertex.nparticle > self.maxparticle:
|
||||
raise """
|
||||
*** buffer overflow in #particles/vertex.
|
||||
*** please increment buffersize in MCScoreROOTIO(bsize).
|
||||
""", self.maxparticle
|
||||
|
||||
idx_namelist=0
|
||||
self.a_np[0]= vertex.nparticle
|
||||
idx_namelist = 0
|
||||
self.a_np[0] = vertex.nparticle
|
||||
for ip in range(vertex.nparticle):
|
||||
particle= vertex.particle_list[ip]
|
||||
particle = vertex.particle_list[ip]
|
||||
push_pname(idx_namelist, particle.name)
|
||||
idx_namelist+= (len(particle.name)+1)
|
||||
self.a_Z[ip]= particle.Z
|
||||
self.a_A[ip]= particle.A
|
||||
self.a_ke[ip]= particle.kineticE
|
||||
self.a_px[ip]= particle.px
|
||||
self.a_py[ip]= particle.py
|
||||
self.a_pz[ip]= particle.pz
|
||||
idx_namelist += (len(particle.name)+1)
|
||||
self.a_Z[ip] = particle.Z
|
||||
self.a_A[ip] = particle.A
|
||||
self.a_ke[ip] = particle.kineticE
|
||||
self.a_px[ip] = particle.px
|
||||
self.a_py[ip] = particle.py
|
||||
self.a_pz[ip] = particle.pz
|
||||
|
||||
self.a_namelist[idx_namelist]= '\0'
|
||||
self.a_namelist[idx_namelist] = '\0'
|
||||
self.ptree.Fill()
|
||||
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# functions
|
||||
# ==================================================================
|
||||
def loop_tree(tfile, analyze_vertex):
|
||||
"""
|
||||
loop ROOT tree in a ROOT file.
|
||||
* analyze_vertex: user function : analyze_vertex(MCVertex)
|
||||
"""
|
||||
# ==================================================================
|
||||
avtree= tfile.Get("vertex")
|
||||
aptree= tfile.Get("particle")
|
||||
avtree = tfile.Get("vertex")
|
||||
aptree = tfile.Get("particle")
|
||||
|
||||
# reading vertex...
|
||||
n_vertex= avtree.GetEntries()
|
||||
n_vertex = avtree.GetEntries()
|
||||
for ivtx in xrange(n_vertex):
|
||||
avtree.GetEntry(ivtx)
|
||||
aptree.GetEntry(ivtx)
|
||||
|
||||
# vertex
|
||||
vertex= MCScore.MCVertex(avtree.x, avtree.y, avtree.z)
|
||||
vertex = MCScore.MCVertex(avtree.x, avtree.y, avtree.z)
|
||||
|
||||
# reading secondary particles...
|
||||
nsec= aptree.np
|
||||
namelist= aptree.namelist
|
||||
pname= namelist.split()
|
||||
nsec = aptree.np
|
||||
namelist = aptree.namelist
|
||||
pname = namelist.split()
|
||||
for ip in xrange(nsec):
|
||||
particle= MCScore.MCParticle(pname[ip], aptree.Z[ip], aptree.A[ip],
|
||||
aptree.kE[ip], aptree.px[ip],
|
||||
aptree.py[ip], aptree.pz[ip])
|
||||
particle = MCScore.MCParticle(pname[ip], aptree.Z[ip], aptree.A[ip],
|
||||
aptree.kE[ip], aptree.px[ip],
|
||||
aptree.py[ip], aptree.pz[ip])
|
||||
vertex.append_particle(particle)
|
||||
|
||||
analyze_vertex(vertex)
|
||||
|
||||
return n_vertex
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# test
|
||||
# ==================================================================
|
||||
# ------------------------------------------------------------------
|
||||
def test_t2root():
|
||||
# ------------------------------------------------------------------
|
||||
g= ROOT.TFile("reaction.root", 'recreate')
|
||||
g = ROOT.TFile("reaction.root", 'recreate')
|
||||
|
||||
rootio= MCScoreROOTIO()
|
||||
rootio = MCScoreROOTIO()
|
||||
rootio.define_tree()
|
||||
|
||||
f= open("reaction.dat")
|
||||
f = open("reaction.dat")
|
||||
f.seek(0)
|
||||
|
||||
while(1):
|
||||
vertex= MCScore.read_next_vertex(f)
|
||||
if(vertex==0):
|
||||
vertex = MCScore.read_next_vertex(f)
|
||||
if vertex == 0:
|
||||
break
|
||||
|
||||
# filling ...
|
||||
@@ -172,19 +172,18 @@ def test_t2root():
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def test_loop():
|
||||
# ------------------------------------------------------------------
|
||||
def my_analysis(vertex):
|
||||
vertex.printout()
|
||||
|
||||
f= ROOT.TFile("reaction.root", 'read')
|
||||
nv= loop_tree(f, my_analysis)
|
||||
f = ROOT.TFile("reaction.root", 'read')
|
||||
nv = loop_tree(f, my_analysis)
|
||||
print "*** # of vertex= ", nv
|
||||
|
||||
|
||||
# ==================================================================
|
||||
# main
|
||||
# ==================================================================
|
||||
if (__name__ == "__main__") :
|
||||
if __name__ == "__main__":
|
||||
test_t2root()
|
||||
test_loop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user