Import Geant4 10.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-12-09 12:35:28 +01:00
parent 4ec577e5c4
commit a3452e42ac
3514 changed files with 210500 additions and 89628 deletions
+11 -1
View File
@@ -1,4 +1,4 @@
$Id: History 94509 2015-11-20 10:14:44Z gcosmo $
$Id: History 101892 2016-12-07 08:07:30Z gcosmo $
-------------------------------------------------------------------
=========================================================
@@ -18,6 +18,16 @@ committal in the CVS repository !
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
envs-V10-02-02 / 7 Dec. 2016 K.Murakami
- remove G4VisAttributes::Invisible as deprecated
envs-V10-02-01 / 21 Nov. 2016 K.Murakami
- fixed version strings in __init_.py
envs-V10-02-00 / 18 Nov. 2016 K.Murakami
- update for 10.3 release
- CMake modified for unit/integration tests with CTest
envs-V10-01-01 / 20 Nov. 2015 K. Murakami
- update CMakeLists.txt, change minimum version requirement to 3.3
- add exported methods requested by enhansment-id 1613
+3 -1
View File
@@ -11,6 +11,8 @@ set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
# debug mode
set(DEBUG FALSE CACHE BOOL "Debug Mode (Debug On)")
enable_testing()
#------------------------------------------------------------------------------
# Do not edit below
#------------------------------------------------------------------------------
@@ -66,4 +68,4 @@ add_subdirectory(site-modules)
add_subdirectory(examples)
# tests
add_subdirectory(tests EXCLUDE_FROM_ALL)
add_subdirectory(tests)
+12
View File
@@ -11,6 +11,18 @@ Geant4Py is a Geant4-Python bridge.
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
7 Dec. 2016 K. Murakami
- remove G4VisAttributes::Invisible as deprecated
21 Nov. 2016 K. Murakami
- fix version strings in __init__.py
18 Nov. 2016 K. Murakami
- update for 10.3 release
- CMake modified for unit/integration tests with CTest
- remove ExN03 physics list
19 Nov. 2015 K. Murakami
- update CMakeLists.txt, change minimum version requirement to 3.3
- add exported methods requested by enhansment-id 1613
File diff suppressed because one or more lines are too long
+14 -12
View File
@@ -24,8 +24,8 @@ ROOT for histogramming/analysis
### Tested Platforms
* CentOS6 (RH6 clones)
* OSX Yosemite
* CentOS7 (RH7 clones)
* OSX (Sierra)
How to Install
@@ -34,8 +34,8 @@ Before building library, *GEANT4_INSTALL* environment variable should be set.
# export GEANT4_INSTALL=<Geant4 install path> (zsh, bash)
# setenv GEANT4_INSTALL <Geant4 install path> (csh)
(G4 install path is the path specified by "CMAKE_INSTALL_PREFIX" when building Geant4)
(G4 install path is the path specified by "CMAKE_INSTALL_PREFIX" when building Geant4)
then
# mkdir build
@@ -44,13 +44,16 @@ then
# make
# make install
If you want to run the testing component,
# cd build/tests
# make; make install
By default, g4py is installed in \<g4py\>/lib(64) directory.
Before doing tests with CTest, you have to set environment variables
for Geant4 data.
# make
# make install
# ctest
performs automatic unit/integration tests with CTest.
How to Use:
-----------
@@ -61,8 +64,8 @@ Some environment variables are required at run time.
Python module search directories, given by a colon-separated list of directories, like
# export PYTHONPATH=<g4py>/lib64:<g4py>/examples:<g4py>/tests (zsh, bash)
# setenv PYTHONPATH <g4py>/lib64:<g4py>/examples:<g4py>/tests (csh)
# export PYTHONPATH=<g4py>/lib64:<g4py>/lib64/examples:<g4py>/lib64/tests (zsh, bash)
# setenv PYTHONPATH <g4py>/lib64:<g4py>/lib64/examples:<g4py>/lib64/tests (csh)
@@ -70,4 +73,3 @@ Python module search directories, given by a colon-separated list of directories
You can import Geant4Py modules in Python just like
>>> import Geant4
@@ -8,7 +8,8 @@
from Geant4 import *
import g4py.Qmaterials, g4py.NISTmaterials
import g4py.ExN03geom
import g4py.ExN03pl
#import g4py.ExN03pl
import g4py.EMSTDpl
import g4py.ParticleGun, g4py.MedicalBeam
import sys
from time import *
@@ -37,7 +38,6 @@ HepRandom.setTheSeed(20050830L)
# ------------------------------------------------------------------
# normal way for constructing user geometry
exN03geom= g4py.ExN03geom.ExN03DetectorConstruction()
gRunManager.SetUserInitialization(exN03geom)
@@ -53,7 +53,7 @@ gRunManager.SetUserInitialization(exN03geom)
# setup for physics list
# ------------------------------------------------------------------
# normal way for constructing user physics list
exN03PL= g4py.ExN03pl.PhysicsList()
exN03PL= g4py.EMSTDpl.PhysicsListEMstd()
gRunManager.SetUserInitialization(exN03PL)
# 2nd way, short-cut way
@@ -97,7 +97,7 @@ gRunManager.Initialize()
#gProcessTable.SetProcessActivation("annihil", 0)
# visualization
# visualization
# OGLSX, VRML and HEPREP sceneHandlers are all created with names
gApplyUICommand("/vis/sceneHandler/create OGLSX OGLSX")
gApplyUICommand("/vis/sceneHandler/create VRML2FILE VRML")
@@ -141,7 +141,7 @@ from Tkinter import *
class App(Frame):
g4pipe = 0
def init(self):
#title and header row=0, 1
@@ -149,7 +149,7 @@ class App(Frame):
title.grid(row=0, column=1, columnspan=3)
header = Label(self, text="empowered by \n Geant4Py")
header.grid(row=1, column=1, columnspan=3)
# number of layers
# number of layers
layerLabel = Label(self, bg="green", text="No of layers")
self.layerVar=IntVar()
self.layerVar.set(10)
@@ -228,7 +228,7 @@ class App(Frame):
energyLabel.grid(row=9, column=0, sticky=W)
energy.grid(row=9, column=1, columnspan=5, sticky=W)
#number of event row=10
#number of event row=10
eventLabel = Label(self, bg="green", text="Events")
self.eventVar=IntVar()
self.eventVar.set(3)
@@ -259,7 +259,7 @@ class App(Frame):
processLabel=Label(self, text="Process on/off", bg="green")
processLabel.grid(row=11, column=0, sticky=W)
procTab = {}
self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annihil","muIoni", "muBrems", "hIoni"]
pos=1
self.processVar = {}
@@ -319,11 +319,11 @@ class App(Frame):
commandEntry.grid(row=17, column=1, columnspan=3, sticky=E+W)
comBut.grid(row=17, column=5)
#exit row = 0
#exit row = 0
exitBut = Button(self, bg="red", text="End all", command=sys.exit)
exitBut.grid(row=0, column=5, sticky=W)
#on Run butto do...
#on Run butto do...
def cmd_beamOn(self):
exN03geom.SetNbOfLayers(self.layerVar.get())
exN03geom.SetAbsorberMaterial(self.absorbermaterialVar.get())
@@ -353,7 +353,7 @@ class App(Frame):
gRunManager.BeamOn(1)
sleep(0.01)
gApplyUICommand("/vis/viewer/update")
def cmd_setProcess(self):
for i in self.processList:
if self.processVar[i].get() == 0:
@@ -362,10 +362,10 @@ class App(Frame):
else:
gProcessTable.SetProcessActivation(i, 1)
print "Process " + i + " activated"
def cmd_g4command(self):
gApplyUICommand(self.g4commandVar.get())
def cmd_particle(self, particle):
gApplyUICommand("/gun/particle " + particle)
@@ -402,7 +402,7 @@ class App(Frame):
if self.g4pipe == 0:
Popen(heprepViewer + " -file " + heprepDir + "/" + heprepName +".heprep", shell=True)
self.g4pipe = 1
def cmd_expand(self):
gApplyUICommand("/vis/viewer/zoom 1.2")
@@ -415,12 +415,12 @@ class App(Frame):
gApplyUICommand("/vis/viewer/zoom 0.8")
def __init__(self, master=None):
Frame.__init__(self, master)
self.init()
self.grid()
app = App()
app.mainloop()
@@ -53,7 +53,7 @@ gRunManager.SetUserInitialization(exN03geom)
# setup for physics list
# ------------------------------------------------------------------
# normal way for constructing user physics list
exN03PL= g4py.ExN03pl.PhysicsList()
exN03PL= g4py.EMSTDpl.PhysicsListEMstd()
gRunManager.SetUserInitialization(exN03PL)
# 2nd way, short-cut way
@@ -97,7 +97,7 @@ gRunManager.Initialize()
#gProcessTable.SetProcessActivation("annihil", 0)
# visualization
# visualization
# OGLSX, VRML and HEPREP sceneHandlers are all created with names
gApplyUICommand("/vis/sceneHandler/create OGLSX OGLSX")
gApplyUICommand("/vis/sceneHandler/create VRML2FILE VRML")
@@ -141,7 +141,7 @@ from tkinter import *
class App(Frame):
g4pipe = 0
def init(self):
#title and header row=0, 1
@@ -149,7 +149,7 @@ class App(Frame):
title.grid(row=0, column=1, columnspan=3)
header = Label(self, text="empowered by \n Geant4Py")
header.grid(row=1, column=1, columnspan=3)
# number of layers
# number of layers
layerLabel = Label(self, bg="green", text="No of layers")
self.layerVar=IntVar()
self.layerVar.set(10)
@@ -228,7 +228,7 @@ class App(Frame):
energyLabel.grid(row=9, column=0, sticky=W)
energy.grid(row=9, column=1, columnspan=5, sticky=W)
#number of event row=10
#number of event row=10
eventLabel = Label(self, bg="green", text="Events")
self.eventVar=IntVar()
self.eventVar.set(3)
@@ -259,7 +259,7 @@ class App(Frame):
processLabel=Label(self, text="Process on/off", bg="green")
processLabel.grid(row=11, column=0, sticky=W)
procTab = {}
self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annihil","muIoni", "muBrems", "hIoni"]
pos=1
self.processVar = {}
@@ -319,11 +319,11 @@ class App(Frame):
commandEntry.grid(row=17, column=1, columnspan=3, sticky=E+W)
comBut.grid(row=17, column=5)
#exit row = 0
#exit row = 0
exitBut = Button(self, bg="red", text="End all", command=sys.exit)
exitBut.grid(row=0, column=5, sticky=W)
#on Run butto do...
#on Run butto do...
def cmd_beamOn(self):
exN03geom.SetNbOfLayers(self.layerVar.get())
exN03geom.SetAbsorberMaterial(self.absorbermaterialVar.get())
@@ -353,7 +353,7 @@ class App(Frame):
gRunManager.BeamOn(1)
sleep(0.01)
gApplyUICommand("/vis/viewer/update")
def cmd_setProcess(self):
for i in self.processList:
if self.processVar[i].get() == 0:
@@ -362,10 +362,10 @@ class App(Frame):
else:
gProcessTable.SetProcessActivation(i, 1)
print("Process " + i + " activated")
def cmd_g4command(self):
gApplyUICommand(self.g4commandVar.get())
def cmd_particle(self, particle):
gApplyUICommand("/gun/particle " + particle)
@@ -402,7 +402,7 @@ class App(Frame):
if self.g4pipe == 0:
Popen(heprepViewer + " -file " + heprepDir + "/" + heprepName +".heprep", shell=True)
self.g4pipe = 1
def cmd_expand(self):
gApplyUICommand("/vis/viewer/zoom 1.2")
@@ -415,12 +415,12 @@ class App(Frame):
gApplyUICommand("/vis/viewer/zoom 0.8")
def __init__(self, master=None):
Frame.__init__(self, master)
self.init()
self.grid()
app = App()
app.mainloop()
@@ -7,7 +7,7 @@
# Koichi Murakami (KEK/CRC)
# ==================================================================
from Geant4 import *
import g4py.ExN03pl
import g4py.EMSTDpl
import g4py.emcalculator
import EmPlot
import ROOT
@@ -19,7 +19,7 @@ from cStringIO import StringIO
# ==================================================================
def g4_configure() :
EmPlot.Configure()
g4py.ExN03pl.Construct()
g4py.EMSTDpl.Construct()
# -------------------------------------------------------------------
# plot for chaged particles
@@ -24,7 +24,7 @@
// ********************************************************************
//
//
// $Id: ExN03DetectorConstruction.cc 66892 2013-01-17 10:57:59Z gunter $
// $Id: ExN03DetectorConstruction.cc 101905 2016-12-07 11:34:39Z gunter $
//
//
@@ -344,7 +344,7 @@ G4VPhysicalVolume* ExN03DetectorConstruction::ConstructCalorimeter()
//
// Visualization attributes
//
logicWorld->SetVisAttributes (G4VisAttributes::Invisible);
logicWorld->SetVisAttributes (G4VisAttributes::GetInvisible());
G4VisAttributes* simpleBoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
simpleBoxVisAtt->SetVisibility(true);
@@ -2,4 +2,3 @@
add_subdirectory(EMSTDpl)
add_subdirectory(ExN01pl)
add_subdirectory(ExN03pl)
@@ -0,0 +1,136 @@
"""
Python module
This module provides classes and functions for scoring reactions
[C] MCVertex:
[C] MCParticle:
[f] read_next_vertex(stream):
Q, 2006
"""
import string
from Geant4.hepunit import *
# ==================================================================
# public symbols
# ==================================================================
__all__ = [ 'MCParticle', 'MCVertex', 'read_next_vertex' ]
# ==================================================================
# class definition
# ==================================================================
# ------------------------------------------------------------------
# MCParticle
# ------------------------------------------------------------------
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
def printout(self):
print "--- particle: %s, Z=%2d, A=%2d, kE=%g" % \
(self.name, self.Z, self.A, self.kineticE/MeV)
# ------------------------------------------------------------------
# MCVertex
# ------------------------------------------------------------------
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 = []
def append_particle(self, aparticle):
self.particle_list.append(aparticle)
self.nparticle= self.nparticle+1
def printout(self):
print "@@@ vertex: x=(%g,%g,%g) Nsec=%3d" % \
(self.x/cm, self.y/cm, self.z/cm, self.nparticle)
for p in self.particle_list:
p.printout()
def dump_vertex(self, stream):
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)
stream.write(aline)
def __del__(self):
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
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])
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
particle = MCParticle(pname, Z, A, kE, px, py, pz)
vertex.append_particle(particle)
return vertex
# ==================================================================
# test
# ==================================================================
def test():
f = open("reaction.dat")
f.seek(0)
while(1):
vertex = read_next_vertex(f)
if vertex == 0:
break
vertex.printout()
del vertex
f.close()
print ">>> EOF"
# ==================================================================
# main
# ==================================================================
if __name__ == "__main__":
test()
@@ -0,0 +1,189 @@
"""
Python module
This module provides ROOT IO interface for MCScore data
[C] MCScoreROOTIO
[f] loop_tree(tfile, analyze_vertex):
Q, 2006
"""
from array import array
import string
from Geant4.hepunit import *
import mcscore
import ROOT
# ==================================================================
# public symbols
# ==================================================================
__all__ = [ 'MCScoreROOTIO', 'loop_tree' ]
# ==================================================================
# class definition
# ==================================================================
# ------------------------------------------------------------------
# MCScoreROOTIO
# ------------------------------------------------------------------
class MCScoreROOTIO:
"ROOT IO interface for MCScore"
def __init__(self, bsize=250):
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')
# 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')
#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_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.ptree.Branch('Z', self.a_Z, 'Z[np]/I')
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.ptree.Branch('kE', self.a_ke, 'kE[np]/d')
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.ptree.Branch('py', self.a_py, 'py[np]/d')
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)
for i in xrange(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.vtree.Fill()
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
for ip in range(vertex.nparticle):
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
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")
# reading vertex...
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)
# reading secondary particles...
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])
vertex.append_particle(particle)
analyze_vertex(vertex)
return n_vertex
# ==================================================================
# test
# ==================================================================
def test_t2root():
g = ROOT.TFile("reaction.root", 'recreate')
rootio = MCScoreROOTIO()
rootio.define_tree()
f = open("reaction.dat")
f.seek(0)
while(1):
vertex = MCScore.read_next_vertex(f)
if vertex == 0:
break
# filling ...
rootio.fill_tree(vertex)
del vertex
print ">>> EOF"
f.close()
# closing ROOT file
g.Write()
g.Close()
# ------------------------------------------------------------------
def test_loop():
def my_analysis(vertex):
vertex.printout()
f = ROOT.TFile("reaction.root", 'read')
nv = loop_tree(f, my_analysis)
print "*** # of vertex= ", nv
# ==================================================================
# main
# ==================================================================
if __name__ == "__main__":
test_t2root()
test_loop()
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pyG4VisAttributes.cc 76884 2013-11-18 12:54:03Z gcosmo $
// $Id: pyG4VisAttributes.cc 101892 2016-12-07 08:07:30Z gcosmo $
// ====================================================================
// pyG4VisAttributes.cc
//
@@ -75,7 +75,6 @@ void export_G4VisAttributes()
.def(init<const G4Colour&>())
.def(init<G4bool, const G4Colour&>())
// ---
.def_readonly("Invisible", &G4VisAttributes::Invisible)
.def("GetInvisible", &G4VisAttributes::GetInvisible,
return_value_policy<reference_existing_object>())
.staticmethod("GetInvisible")
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pyG4AtomicShells.cc 66892 2013-01-17 10:57:59Z gunter $
// $Id: pyG4AtomicShells.cc 101514 2016-11-18 15:30:57Z gcosmo $
// ====================================================================
// pyG4AtomicShells.cc
//
@@ -40,7 +40,7 @@ using namespace boost::python;
void export_G4AtomicShells()
{
class_<G4AtomicShells, boost::noncopyable>
("G4AtomicShells", "Atomic subshell binding energy table")
("G4AtomicShells", "Atomic subshell binding energy table", no_init)
.def("GetNumberOfShells", &G4AtomicShells::GetNumberOfShells)
.staticmethod("GetNumberOfShells")
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pyG4Element.cc 76884 2013-11-18 12:54:03Z gcosmo $
// $Id: pyG4Element.cc 101514 2016-11-18 15:30:57Z gcosmo $
// ====================================================================
// pyG4Element.cc
//
@@ -105,8 +105,5 @@ void export_G4Element()
return_internal_reference<>())
// ---
.def("Print", Print)
.def(self == self)
.def(self != self)
;
}
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pyG4NistManager.cc 76884 2013-11-18 12:54:03Z gcosmo $
// $Id: pyG4NistManager.cc 101514 2016-11-18 15:30:57Z gcosmo $
// ====================================================================
// pyG4NistManager.cc
//
@@ -52,9 +52,9 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_FindOrBuildElement,
FindOrBuildElement, 1, 2)
// PrintElement
void(G4NistManager::*f1_PrintElement)(const G4String&)
void(G4NistManager::*f1_PrintElement)(const G4String&) const
= &G4NistManager::PrintElement;
void(G4NistManager::*f2_PrintElement)(G4int)
void(G4NistManager::*f2_PrintElement)(G4int) const
= &G4NistManager::PrintElement;
// FindOrBuildMaterial
@@ -148,4 +148,3 @@ void export_G4NistManager()
;
#endif
}
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pyPhysicsLists.cc 76884 2013-11-18 12:54:03Z gcosmo $
// $Id: pyPhysicsLists.cc 101514 2016-11-18 15:30:57Z gcosmo $
// ====================================================================
// pyPhysicsLists.cc
//
@@ -32,24 +32,28 @@
#include <boost/python.hpp>
#include <vector>
#include <algorithm>
#include "FTF_BIC.hh"
#include "FTFP_BERT.hh"
#include "FTFP_BERT_ATL.hh"
#include "FTFP_BERT_HP.hh"
#include "FTFP_BERT_TRV.hh"
#include "FTFP_INCLXX.hh"
#include "FTFP_INCLXX_HP.hh"
#include "FTF_BIC.hh"
#include "LBE.hh"
#include "NuBeam.hh"
#include "QBBC.hh"
#include "QGS_BIC.hh"
#include "QGSP_BERT.hh"
#include "QGSP_BERT_HP.hh"
#include "QGSP_BIC.hh"
#include "QGSP_BIC_AllHP.hh"
#include "QGSP_BIC_HP.hh"
#include "QGSP_FTFP_BERT.hh"
#include "QGSP_INCLXX.hh"
#include "QGSP_INCLXX_HP.hh"
#include "QGS_BIC.hh"
#include "Shielding.hh"
// macro for adding physics lists
#define ADD_PHYSICS_LIST(plname) \
class_<plname, plname*, bases<G4VUserPhysicsList>, boost::noncopyable> \
@@ -87,22 +91,25 @@ void export_PhysicsLists()
{
def("ListPhysicsList", ListPhysicsList);
ADD_PHYSICS_LIST(FTF_BIC);
ADD_PHYSICS_LIST(FTFP_BERT);
ADD_PHYSICS_LIST(FTFP_BERT_ATL);
ADD_PHYSICS_LIST(FTFP_BERT_HP);
ADD_PHYSICS_LIST(FTFP_BERT_TRV);
ADD_PHYSICS_LIST(FTFP_INCLXX);
ADD_PHYSICS_LIST(FTFP_INCLXX_HP);
ADD_PHYSICS_LIST(FTF_BIC);
ADD_PHYSICS_LIST(LBE);
ADD_PHYSICS_LIST(NuBeam);
ADD_PHYSICS_LIST(QBBC);
ADD_PHYSICS_LIST(QGS_BIC);
ADD_PHYSICS_LIST(QGSP_BERT);
ADD_PHYSICS_LIST(QGSP_BERT_HP);
ADD_PHYSICS_LIST(QGSP_BIC);
ADD_PHYSICS_LIST(QGSP_BIC_AllHP);
ADD_PHYSICS_LIST(QGSP_BIC_HP);
ADD_PHYSICS_LIST(QGSP_FTFP_BERT);
ADD_PHYSICS_LIST(QGSP_INCLXX);
ADD_PHYSICS_LIST(QGSP_INCLXX_HP);
ADD_PHYSICS_LIST(QGS_BIC);
ADD_PHYSICS_LIST(Shielding);
// sort PL vector
@@ -6,7 +6,6 @@ add_library(
${_TARGET} SHARED
pyG4CrossSectionHandler.cc
pyG4EmCalculator.cc
pyG4LossTableManager.cc
pyG4ProcVector.cc
pyG4ProcessManager.cc
pyG4ProcessTable.cc
@@ -23,7 +23,7 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: pymodG4processes.cc 66892 2013-01-17 10:57:59Z gunter $
// $Id: pymodG4processes.cc 101514 2016-11-18 15:30:57Z gcosmo $
// ====================================================================
// pymodG4processes.cc
//
@@ -42,7 +42,6 @@ void export_G4VProcess();
void export_G4ProcVector();
void export_G4ProcessType();
void export_G4EmCalculator();
void export_G4LossTableManager();
void export_G4ProductionCutsTable();
void export_G4VCrossSectionHandler();
void export_G4CrossSectionHandler();
@@ -55,7 +54,6 @@ BOOST_PYTHON_MODULE(G4processes)
export_G4ProcVector();
export_G4ProcessType();
export_G4EmCalculator();
export_G4LossTableManager();
export_G4ProductionCutsTable();
export_G4VCrossSectionHandler();
export_G4CrossSectionHandler();
+5 -10
View File
@@ -7,9 +7,9 @@
# This package contains a set of Python interface with Geant4.
# ==================================================================
"""
# $Id: __init__.py 94382 2015-11-13 10:18:01Z gcosmo $
__version__ ='10.2'
__date__ = 'November/2015'
# $Id: __init__.py 101648 2016-11-21 08:42:14Z gcosmo $
__version__ ='10.3'
__date__ = 'November/2016'
__author__ = 'K.Murakami (Koichi.Murakami@kek.jp)'
# import submodules
@@ -35,7 +35,7 @@ from colortable import *
def print_version():
print """=============================================================
Welcome to Geant4Py (A Geant4-Python Bridge)
Version : %s
Date : %s
Contact : %s
@@ -87,9 +87,6 @@ gParticleIterator = PyG4ParticleList()
# gProcessTable
gProcessTable = G4ProcessTable.GetProcessTable()
# gLossTableManager
gLossTableManager = G4LossTableManager.Instance()
# gProductionCutsTable
gProductionCutsTable = G4ProductionCutsTable.GetProductionCutsTable()
@@ -153,7 +150,7 @@ if G4VisManager.GetConcreteInstance() == None:
gVisManager.RegisterGraphicsSystem(_heprep_file)
gVisManager.RegisterGraphicsSystem(_atree)
gVisManager.RegisterGraphicsSystem(_raytracer)
gVisManager.Initialize()
# version information
@@ -243,5 +240,3 @@ def _run_abort(signum, frame):
if (threading.activeCount() == 1):
signal.signal(signal.SIGINT, _run_abort)
+308
View File
@@ -0,0 +1,308 @@
"""
# ==================================================================
# Python module
#
# This module defines physical units and constants used in HEP,
# which are imported from CLHEP library.
#
# Q, 2005
# ==================================================================
"""
#$Id: hepunit.py 66892 2013-01-17 10:57:59Z gunter $
# ==================================================================
# imported from "SystemOfUnits.h"
# ==================================================================
millimeter = 1.
millimeter2 = millimeter*millimeter
millimeter3 = millimeter*millimeter*millimeter
centimeter = 10.*millimeter
centimeter2 = centimeter*centimeter
centimeter3 = centimeter*centimeter*centimeter
meter = 1000.*millimeter
meter2 = meter*meter
meter3 = meter*meter*meter
kilometer = 1000.*meter
kilometer2 = kilometer*kilometer
kilometer3 = kilometer*kilometer*kilometer
parsec = 3.0856775807e+16*meter
micrometer = 1.e-6 *meter
nanometer = 1.e-9 *meter
angstrom = 1.e-10*meter
fermi = 1.e-15*meter
barn = 1.e-28*meter2
millibarn = 1.e-3 *barn
microbarn = 1.e-6 *barn
nanobarn = 1.e-9 *barn
picobarn = 1.e-12*barn
# symbols
mm = millimeter
mm2 = millimeter2
mm3 = millimeter3
cm = centimeter
cm2 = centimeter2
cm3 = centimeter3
m = meter
m2 = meter2
m3 = meter3
km = kilometer
km2 = kilometer2
km3 = kilometer3
pc = parsec
#
# Angle
#
radian = 1.
milliradian = 1.e-3*radian
degree = (3.14159265358979323846/180.0)*radian
steradian = 1.
# symbols
rad = radian
mrad = milliradian
sr = steradian
deg = degree
#
# Time [T]
#
nanosecond = 1.
second = 1.e+9 *nanosecond
millisecond = 1.e-3 *second
microsecond = 1.e-6 *second
picosecond = 1.e-12*second
hertz = 1./second
kilohertz = 1.e+3*hertz
megahertz = 1.e+6*hertz
# symbols
ns = nanosecond
s = second
ms = millisecond
#
# Electric charge [Q]
#
eplus = 1. # positron charge
e_SI = 1.60217733e-19 # positron charge in coulomb
coulomb = eplus/e_SI # coulomb = 6.24150 e+18 * eplus
#
# Energy [E]
#
megaelectronvolt = 1.
electronvolt = 1.e-6*megaelectronvolt
kiloelectronvolt = 1.e-3*megaelectronvolt
gigaelectronvolt = 1.e+3*megaelectronvolt
teraelectronvolt = 1.e+6*megaelectronvolt
petaelectronvolt = 1.e+9*megaelectronvolt
joule = electronvolt/e_SI # joule = 6.24150 e+12 * MeV
# symbols
MeV = megaelectronvolt
eV = electronvolt
keV = kiloelectronvolt
GeV = gigaelectronvolt
TeV = teraelectronvolt
PeV = petaelectronvolt
#
# Mass [E][T^2][L^-2]
#
kilogram = joule*second*second/(meter*meter)
gram = 1.e-3*kilogram
milligram = 1.e-3*gram
# symbols
kg = kilogram
g = gram
mg = milligram
#
# Power [E][T^-1]
#
watt = joule/second # watt = 6.24150 e+3 * MeV/ns
#
# Force [E][L^-1]
#
newton = joule/meter # newton = 6.24150 e+9 * MeV/mm
#
# Pressure [E][L^-3]
#
pascal = newton/m2 # pascal = 6.24150 e+3 * MeV/mm3
bar = 100000*pascal # bar = 6.24150 e+8 * MeV/mm3
atmosphere = 101325*pascal # atm = 6.32420 e+8 * MeV/mm3
#
# Electric current [Q][T^-1]
#
ampere = coulomb/second # ampere = 6.24150 e+9 * eplus/ns
milliampere = 1.e-3*ampere
microampere = 1.e-6*ampere
nanoampere = 1.e-9*ampere
#
# Electric potential [E][Q^-1]
#
megavolt = megaelectronvolt/eplus
kilovolt = 1.e-3*megavolt
volt = 1.e-6*megavolt
#
# Electric resistance [E][T][Q^-2]
#
ohm = volt/ampere # ohm = 1.60217e-16*(MeV/eplus)/(eplus/ns)
#
# Electric capacitance [Q^2][E^-1]
#
farad = coulomb/volt # farad = 6.24150e+24 * eplus/Megavolt
millifarad = 1.e-3*farad
microfarad = 1.e-6*farad
nanofarad = 1.e-9*farad
picofarad = 1.e-12*farad
#
# Magnetic Flux [T][E][Q^-1]
#
weber = volt*second # weber = 1000*megavolt*ns
#
# Magnetic Field [T][E][Q^-1][L^-2]
#
tesla = volt*second/meter2 # tesla =0.001*megavolt*ns/mm2
gauss = 1.e-4*tesla
kilogauss = 1.e-1*tesla
#
# Inductance [T^2][E][Q^-2]
#
henry = weber/ampere # henry = 1.60217e-7*MeV*(ns/eplus)**2
#
# Temperature
#
kelvin = 1.
#
# Amount of substance
#
mole = 1.
#
# Activity [T^-1]
#
becquerel = 1./second
curie = 3.7e+10 * becquerel
#
# Absorbed dose [L^2][T^-2]
#
gray = joule/kilogram
#
# Luminous intensity [I]
#
candela = 1.
#
# Luminous flux [I]
#
lumen = candela*steradian
#
# Illuminance [I][L^-2]
#
lux = lumen/meter2
#
# Miscellaneous
#
perCent = 0.01
perThousand = 0.001
perMillion = 0.000001
# ==================================================================
# imported from "PhysicalConstants.h"
# ==================================================================
pi = 3.14159265358979323846
twopi = 2.*pi
halfpi = pi/2.
pi2 = pi*pi
#
Avogadro = 6.0221367e+23/mole
# c = 299.792458 mm/ns
# c^2 = 898.7404 (mm/ns)^2
c_light = 2.99792458e+8 * m/s
c_squared = c_light * c_light
# h = 4.13566e-12 MeV*ns
# hbar = 6.58212e-13 MeV*ns
# hbarc = 197.32705e-12 MeV*mm
h_Planck = 6.6260755e-34 * joule*s
hbar_Planck = h_Planck/twopi
hbarc = hbar_Planck * c_light
hbarc_squared = hbarc * hbarc
#
electron_charge = - eplus # see SystemOfUnits.h
e_squared = eplus * eplus
# amu_c2 - atomic equivalent mass unit
# amu - atomic mass unit
electron_mass_c2 = 0.51099906 * MeV
proton_mass_c2 = 938.27231 * MeV
neutron_mass_c2 = 939.56563 * MeV
amu_c2 = 931.49432 * MeV
amu = amu_c2/c_squared
# permeability of free space mu0 = 2.01334e-16 Mev*(ns*eplus)^2/mm
# permittivity of free space epsil0 = 5.52636e+10 eplus^2/(MeV*mm)
mu0 = 4*pi*1.e-7 * henry/m
epsilon0 = 1./(c_squared*mu0)
# electromagnetic coupling = 1.43996e-12 MeV*mm/(eplus^2)
elm_coupling = e_squared/(4*pi*epsilon0)
fine_structure_const = elm_coupling/hbarc
classic_electr_radius = elm_coupling/electron_mass_c2
electron_Compton_length = hbarc/electron_mass_c2
Bohr_radius = electron_Compton_length/fine_structure_const
alpha_rcl2 = fine_structure_const * classic_electr_radius \
* classic_electr_radius
twopi_mc2_rcl2 = twopi * electron_mass_c2 \
* classic_electr_radius \
* classic_electr_radius
#
k_Boltzmann = 8.617385e-11 * MeV/kelvin
#
STP_Temperature = 273.15*kelvin
STP_Pressure = 1.*atmosphere
kGasThreshold = 10.*mg/cm3
#
universe_mean_density = 1.e-25*g/cm3
+5 -5
View File
@@ -7,9 +7,9 @@
# This package contains a set of Python interface with Geant4.
# ==================================================================
"""
# $Id: __init__.py 94382 2015-11-13 10:18:01Z gcosmo $
__version__ ='10.2.0'
__date__ = 'November/2015'
# $Id: __init__.py 101648 2016-11-21 08:42:14Z gcosmo $
__version__ ='10.3'
__date__ = 'November/2016'
__author__ = 'K.Murakami (Koichi.Murakami@kek.jp)'
# import submodules
@@ -35,7 +35,7 @@ from .colortable import *
def print_version():
print("""=============================================================
Welcome to Geant4Py (A Geant4-Python Bridge)
Version : %s
Date : %s
Contact : %s
@@ -153,7 +153,7 @@ if G4VisManager.GetConcreteInstance() == None:
gVisManager.RegisterGraphicsSystem(_heprep_file)
gVisManager.RegisterGraphicsSystem(_atree)
gVisManager.RegisterGraphicsSystem(_raytracer)
gVisManager.Initialize()
# version information
+25 -1
View File
@@ -6,7 +6,7 @@ set(TEST_MODULES_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/tests)
add_subdirectory(test00/module)
add_subdirectory(test01/module)
add_subdirectory(test02/module)
#add_subdirectory(test03/module EXCLUDE_FROM_ALL)
add_subdirectory(test03/module EXCLUDE_FROM_ALL)
add_subdirectory(test04/module)
add_subdirectory(test05/module)
add_subdirectory(test06/module)
@@ -20,3 +20,27 @@ add_subdirectory(test13/module)
# tests for g4py
add_subdirectory(gtest01/module)
# testing
add_subdirectory(test00)
add_subdirectory(test01)
add_subdirectory(test02)
add_subdirectory(test03)
add_subdirectory(test04)
add_subdirectory(test05)
add_subdirectory(test06)
add_subdirectory(test07)
add_subdirectory(test08)
add_subdirectory(test09)
add_subdirectory(test10)
add_subdirectory(test11)
add_subdirectory(test12)
add_subdirectory(test13)
#
add_subdirectory(gtest01)
add_subdirectory(gtest02)
add_subdirectory(gtest03)
add_subdirectory(gtest04)
add_subdirectory(gtest05)
add_subdirectory(gtest06)
add_subdirectory(gtest07)
File diff suppressed because one or more lines are too long
@@ -0,0 +1,8 @@
# add teting
add_test(gtest01 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest01
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest01
# - check basic control flow
# ==================================================================
from Geant4 import *
import gtest01
import random
#import thread
# ==================================================================
# user actions in python
# ==================================================================
class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction):
"My Primary Generator Action"
def __init__(self):
G4VUserPrimaryGeneratorAction.__init__(self)
self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event):
#dx= random.gauss(0., 0.1)
dx=0.
self.particleGun.SetParticleMomentumDirection(G4ThreeVector(dx, 0., 1.))
self.particleGun.GeneratePrimaryVertex(event)
# ------------------------------------------------------------------
class MyRunAction(G4UserRunAction):
"My Run Action"
def BeginOfRunAction(self, run):
print "*** #event to be processed (BRA)=",
run.GetNumberOfEventToBeProcessed()
def EndOfRunAction(self, run):
print "*** run end run(ERA)=", run.GetRunID()
# ------------------------------------------------------------------
class MyEventAction(G4UserEventAction):
"My Event Action"
#def BeginOfEventAction(self, event):
#print "*** current event (BEA)=", event.GetEventID()
# pass
#def EndOfEventAction(self, event):
# print "*** current event (EEA)=", event.GetEventID()
# ------------------------------------------------------------------
class MySteppingAction(G4UserSteppingAction):
"My Stepping Action"
def UserSteppingAction(self, step):
#print "*** dE/dx in current step=", step.GetTotalEnergyDeposit()
track= step.GetTrack()
touchable= track.GetTouchable()
pv= touchable.GetVolume()
#print pv.GetCopyNo()
#print touchable.GetReplicaNumber(0)
# ------------------------------------------------------------------
class MyField(G4MagneticField):
"My Magnetic Field"
def GetFieldValue(self, pos, time):
bfield= G4ThreeVector()
bfield.x= 0.
bfield.y= 5.*tesla
bfield.z= 0.
return bfield
# ==================================================================
# main
# ==================================================================
qMaterials= gtest01.QMaterials()
qMaterials.Construct()
qDC= gtest01.QDetectorConstruction()
gRunManager.SetUserInitialization(qDC)
qPL= gtest01.QPhysicsList()
gRunManager.SetUserInitialization(qPL)
# set user actions...
#qPGA= gtest01.QPrimaryGeneratorAction()
myPGA= MyPrimaryGeneratorAction()
gRunManager.SetUserAction(myPGA)
#myRA= MyRunAction()
#gRunManager.SetUserAction(myRA)
myEA= MyEventAction()
gRunManager.SetUserAction(myEA)
mySA= MySteppingAction()
gRunManager.SetUserAction(mySA)
# set particle gun
#ApplyUICommand("/control/execute gun.mac")
#pg= qPGA.GetParticleGun()
pg= myPGA.particleGun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(200.*MeV)
pg.SetParticlePosition(G4ThreeVector(0.,0.,-14.9)*cm)
# magnetic field
fieldMgr= gTransportationManager.GetFieldManager()
myField= G4UniformMagField(G4ThreeVector(0.,10.*tesla,0.))
#myField= MyField()
fieldMgr.SetDetectorField(myField)
fieldMgr.CreateChordFinder(myField)
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
gRunManager.BeamOn(10)
#thread.start_new_thread(gRunManager.BeamOn, (100000))
+2 -8
View File
@@ -8,7 +8,6 @@
from Geant4 import *
import gtest01
import random
#import thread
# ==================================================================
# user actions in python
@@ -70,7 +69,7 @@ class MyField(G4MagneticField):
bfield.y= 5.*tesla
bfield.z= 0.
return bfield
# ==================================================================
# main
# ==================================================================
@@ -90,7 +89,7 @@ gRunManager.SetUserAction(myPGA)
#myRA= MyRunAction()
#gRunManager.SetUserAction(myRA)
myEA= MyEventAction()
gRunManager.SetUserAction(myEA)
@@ -114,10 +113,5 @@ fieldMgr.CreateChordFinder(myField)
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
gRunManager.BeamOn(10)
#thread.start_new_thread(gRunManager.BeamOn, (100000))
@@ -0,0 +1,8 @@
# add teting
add_test(gtest02 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest02
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
+133
View File
@@ -0,0 +1,133 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4py.Qmaterials, g4py.NISTmaterials
import g4py.Qgeom, g4py.ExN01geom, g4py.ExN03geom
import g4py.ExN01pl, g4py.EMSTDpl
import g4py.ParticleGun, g4py.MedicalBeam
# ==================================================================
# user setup
# ==================================================================
# ------------------------------------------------------------------
# Setup-0 (Q)
# ------------------------------------------------------------------
def Setup0():
# simple materials for Qgeom
g4py.Qmaterials.Construct()
# NIST materials
#g4py.NISTmaterials.Construct()
# normal way for constructing user geometry
#qDC= g4py.Qgeom.QDetectorConstruction()
#gRunManager.SetUserInitialization(qDC)
# 2nd way, short-cut way
g4py.Qgeom.Construct()
# primary
global primary_position, primary_direction
primary_position= G4ThreeVector(0.,0., -14.9*cm)
primary_direction= G4ThreeVector(0.2, 0., 1.)
# ------------------------------------------------------------------
# Setup-1 (ExampleN01)
# ------------------------------------------------------------------
def Setup1():
g4py.ExN01geom.Construct()
global primary_position, primary_direction
primary_position= G4ThreeVector(-2.5*m, 0., 0.)
primary_direction= G4ThreeVector(1., 0., 0.)
# ------------------------------------------------------------------
# Setup-3 (ExampleN03)
# ------------------------------------------------------------------
def Setup3():
#exN03geom= g4py.ExN03geom.ExN03DetectorConstruction()
#gRunManager.SetUserInitialization(exN03geom)
g4py.ExN03geom.Construct()
global primary_position, primary_direction
primary_position= G4ThreeVector(-1.*m, 0., 0.)
primary_direction= G4ThreeVector(1., 0., 0.)
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# ------------------------------------------------------------------
# user setup
# ------------------------------------------------------------------
Setup0()
#Setup1()
#Setup3()
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
# normal way for constructing user physics list
#exN01PL= ExN01PhysicsList.ExN01PhysicsList()
#gRunManager.SetUserInitialization(exN01PL)
# 2nd way, short-cut way
# geantino + transportation
#g4py.ExN01pl.Construct()
# electron/gamma standard EM
g4py.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
# ------------
# Particle Gun
# ------------
# normal way for constructing user physics list
#pgPGA= g4py.ParticleGun.ParticleGunAction()
#gRunManager.SetUserAction(pgPGA)
#pg= pgPGA.GetParticleGun()
# 2nd way, short-cut way
pg= g4py.ParticleGun.Construct()
# set parameters of particle gun
pg.SetParticleByName("e-")
pg.SetParticleEnergy(300.*MeV)
pg.SetParticlePosition(primary_position)
pg.SetParticleMomentumDirection(primary_direction)
# ------------
# Medical Beam
# ------------
#beam= g4py.MedicalBeam.Construct()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gApplyUICommand("/control/execute vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+2 -6
View File
@@ -24,7 +24,7 @@ def Setup0():
# NIST materials
#g4py.NISTmaterials.Construct()
# normal way for constructing user geometry
#qDC= g4py.Qgeom.QDetectorConstruction()
#gRunManager.SetUserInitialization(qDC)
@@ -125,9 +125,5 @@ pg.SetParticleMomentumDirection(primary_direction)
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gApplyUICommand("/control/execute vis.mac")
# beamOn
#gRunManager.BeamOn(3)
gRunManager.BeamOn(10)
@@ -0,0 +1,8 @@
# add teting
add_test(gtest03 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest03
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/python
# ==================================================================
# python script for Geant4Py test
#
# gtest02
# - test for using site-module packages
# ==================================================================
from Geant4 import *
import g4py.NISTmaterials
import g4py.ezgeom
from g4py.ezgeom import G4EzVolume
import g4py.EMSTDpl
import g4py.ParticleGun
# ==================================================================
# intialize
# ==================================================================
def Configure():
# ------------------------------------------------------------------
# setup for materials
# ------------------------------------------------------------------
# simple materials for Qgeom
g4py.NISTmaterials.Construct()
# ------------------------------------------------------------------
# setup for geometry
# ------------------------------------------------------------------
#g4py.Qgeom.Construct()
g4py.ezgeom.Construct() # initialize
# ------------------------------------------------------------------
# setup for physics list
# ------------------------------------------------------------------
g4py.EMSTDpl.Construct()
# ------------------------------------------------------------------
# setup for primary generator action
# ------------------------------------------------------------------
g4py.ParticleGun.Construct()
gControlExecute("gun.mac")
# ==================================================================
# constructing geometry
# ==================================================================
def ConstructGeom():
print "* Constructing geometry..."
# reset world material
air= G4Material.GetMaterial("G4_AIR")
g4py.ezgeom.SetWorldMaterial(air)
# target
global target
target= G4EzVolume("Target")
au= G4Material.GetMaterial("G4_Au")
target.CreateTubeVolume(au, 0., 1.*cm, 1.*mm)
target.PlaceIt(G4ThreeVector(0.,0.,-10.*cm))
# dummy box
global detector_box, detector_box_pv
detector_box= G4EzVolume("DetectorBox")
detector_box.CreateBoxVolume(air, 20.*cm, 20.*cm, 40.*cm)
detector_box_pv= detector_box.PlaceIt(G4ThreeVector(0.,0.,20.*cm))
# calorimeter
global cal
cal= G4EzVolume("Calorimeter")
nai= G4Material.GetMaterial("G4_SODIUM_IODIDE")
cal.CreateBoxVolume(nai, 5.*cm, 5.*cm, 30.*cm)
dd= 5.*cm
for ical in range(-1, 2):
calPos= G4ThreeVector(dd*ical, 0., 0.)
print calPos
cal.PlaceIt(calPos, ical+1, detector_box)
# ==================================================================
# main
# ==================================================================
# ------------------------------------------------------------------
# randum number
# ------------------------------------------------------------------
rand_engine= Ranlux64Engine()
HepRandom.setTheEngine(rand_engine)
HepRandom.setTheSeed(20050830L)
# setup...
Configure()
ConstructGeom()
# ------------------------------------------------------------------
# go...
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
#gRunManager.BeamOn(3)
+1 -5
View File
@@ -92,9 +92,5 @@ ConstructGeom()
# ------------------------------------------------------------------
gRunManager.Initialize()
# visualization
gControlExecute("vis.mac")
# beamOn
#gRunManager.BeamOn(3)
gRunManager.BeamOn(10)
@@ -0,0 +1,8 @@
# add teting
add_test(gtest04 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest04
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
@@ -0,0 +1,8 @@
# add teting
add_test(gtest05 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest05
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
@@ -0,0 +1,8 @@
# add teting
add_test(gtest06 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest06
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
@@ -0,0 +1,8 @@
# add teting
add_test(gtest07 python test.py)
configure_file(test.py test.py)
set_property(TEST gtest07
PROPERTY ENVIRONMENT
PYTHONPATH=./module:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
)
@@ -0,0 +1,5 @@
# add teting
add_test(test00 python test.py)
configure_file(test.py test.py)
set_property(TEST test00 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test01 python test.py)
configure_file(test.py test.py)
set_property(TEST test01 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test02 python test.py)
configure_file(test.py test.py)
set_property(TEST test02 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,3 @@
# add teting
add_test(test03 echo ok)
@@ -0,0 +1,9 @@
# add teting
add_test(test04-1 python test1.py)
configure_file(test1.py test1.py)
set_property(TEST test04-1 PROPERTY ENVIRONMENT PYTHONPATH=./module)
#
add_test(test04-2 python test2.py)
configure_file(test2.py test2.py)
set_property(TEST test04-2 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test05 python test.py)
configure_file(test.py test.py)
set_property(TEST test05 PROPERTY ENVIRONMENT PYTHONPATH=./module)
+4 -6
View File
@@ -33,9 +33,7 @@ print "CMethod(1,10.)=", a.CMethod(1,10.)
print "CMethod(1,10.,100.)=", a.CMethod(1,10.,100.)
print ""
print "*** ERRORS!! ***"
a.AMethod(1,2,3) # error
try:
a.AMethod(1,2,3) # error
except:
print "*** ERRORS!! ***"
@@ -0,0 +1,5 @@
# add teting
add_test(test06 python test.py)
configure_file(test.py test.py)
set_property(TEST test06 PROPERTY ENVIRONMENT PYTHONPATH=./module)
+5 -5
View File
@@ -48,8 +48,8 @@ print myx.PVMethod()
print ""
x= test06.XBase()
print "*** Runtime ERROR will occur!" \
" because pure virtual function is called."
x.PVMethod()
try:
x.PVMethod()
except:
print "*** Runtime ERROR occured!" \
" because pure virtual function is called."
@@ -0,0 +1,5 @@
# add teting
add_test(test07 python test.py)
configure_file(test.py test.py)
set_property(TEST test07 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test08 python test.py)
configure_file(test.py test.py)
set_property(TEST test08 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test09 python test.py)
configure_file(test.py test.py)
set_property(TEST test09 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test10 python test.py)
configure_file(test.py test.py)
set_property(TEST test10 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test11 python test.py)
configure_file(test.py test.py)
set_property(TEST test11 PROPERTY ENVIRONMENT PYTHONPATH=./module)
+4 -1
View File
@@ -7,5 +7,8 @@
import test11
a= test11.AClass(1)
b= test11.AClass()
try:
b = test11.AClass()
except:
print "AClass default constructor is not allowed."
@@ -0,0 +1,5 @@
# add teting
add_test(test12 python test.py)
configure_file(test.py test.py)
set_property(TEST test12 PROPERTY ENVIRONMENT PYTHONPATH=./module)
@@ -0,0 +1,5 @@
# add teting
add_test(test13 python test.py)
configure_file(test.py test.py)
set_property(TEST test13 PROPERTY ENVIRONMENT PYTHONPATH=./module)