Import Geant4 8.1.0 source tree
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
09 March 2006
|
||||
|
||||
Hajime Yoshida
|
||||
|
||||
The first version of mass attenuation coefficient
|
||||
|
||||
- Lesson1.py
|
||||
select absorber material
|
||||
set its thickness upto 500 mm
|
||||
select beam particle
|
||||
set its energy upto 100 MeV
|
||||
set nu of events up to 100
|
||||
run
|
||||
|
||||
and then
|
||||
zoom in (x1.1) or zoom out (x0.9)
|
||||
|
||||
execute any G4 command but /gun/particle or /gun/energy which are
|
||||
defined by the above
|
||||
|
||||
-oglx.mac
|
||||
OGLSX => important to make zooming effective after showing trajectories
|
||||
-gun.mac
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
#!/usr/bin/python
|
||||
# ==================================================================
|
||||
# python script for "measurement" of mass attenuation coefficient
|
||||
#
|
||||
#
|
||||
# - using site-module packages
|
||||
# ==================================================================
|
||||
from Geant4 import *
|
||||
import NISTmaterials
|
||||
from EZsim import EZgeom
|
||||
from EZsim.EZgeom import G4EzVolume
|
||||
import EMSTDpl
|
||||
import ParticleGun
|
||||
from time import *
|
||||
import sys
|
||||
|
||||
# ==================================================================
|
||||
# intialize
|
||||
# ==================================================================
|
||||
def Configure():
|
||||
# ------------------------------------------------------------------
|
||||
# setup for materials
|
||||
# ------------------------------------------------------------------
|
||||
# simple materials for Qgeom
|
||||
NISTmaterials.Construct()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for geometry
|
||||
# ------------------------------------------------------------------
|
||||
#Qgeom.Construct()
|
||||
EZgeom.Construct() # initialize
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for physics list
|
||||
# ------------------------------------------------------------------
|
||||
EMSTDpl.Construct()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for primary generator action
|
||||
# ------------------------------------------------------------------
|
||||
ParticleGun.Construct()
|
||||
gControlExecute("gun.mac")
|
||||
|
||||
# ==================================================================
|
||||
# constructing geometry
|
||||
# ==================================================================
|
||||
def ConstructGeom():
|
||||
print "* Constructing geometry..."
|
||||
# reset world material
|
||||
global absorber
|
||||
air= G4Material.GetMaterial("G4_AIR", 1)
|
||||
galactic = G4Material.GetMaterial("G4_Galactic", 1)
|
||||
absorber = {} # material's dictionary to be used by a radiobutton
|
||||
aluminum = G4Material.GetMaterial("G4_Al", 1)
|
||||
iron = G4Material.GetMaterial("G4_Fe", 1)
|
||||
silver = G4Material.GetMaterial("G4_Ag", 1)
|
||||
gold = G4Material.GetMaterial("G4_Au", 1)
|
||||
lead = G4Material.GetMaterial("G4_Pb", 1)
|
||||
water = G4Material.GetMaterial("G4_WATER", 1)
|
||||
absorber = {"air":air, "aluminum":aluminum, "iron":iron, "lead":lead, "water":water, "gold":gold}
|
||||
EZgeom.SetWorldMaterial(galactic)
|
||||
EZgeom.ResizeWorld(120.*cm, 120.*cm, 100.*cm)
|
||||
# water phantom
|
||||
global water_phantom, water_phantom_pv
|
||||
|
||||
water_phantom= G4EzVolume("WaterPhantom")
|
||||
water_phantom.CreateBoxVolume(water, 110.*cm, 110.*cm, 10.*cm)
|
||||
|
||||
water_phantom_pv = water_phantom.PlaceIt(G4ThreeVector(0.,0.,0.*cm))
|
||||
|
||||
# ==================================================================
|
||||
# main
|
||||
# ==================================================================
|
||||
# ------------------------------------------------------------------
|
||||
# randum number
|
||||
# ------------------------------------------------------------------
|
||||
print "Random numbers..."
|
||||
rand_engine= Ranlux64Engine()
|
||||
HepRandom.setTheEngine(rand_engine)
|
||||
HepRandom.setTheSeed(20050830L)
|
||||
|
||||
# setup...
|
||||
|
||||
Configure()
|
||||
ConstructGeom()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# go...
|
||||
# ------------------------------------------------------------------
|
||||
gRunManager.Initialize()
|
||||
|
||||
# visualization not here but after "Start a run" button
|
||||
gControlExecute("oglx.mac")
|
||||
#gControlExecute("vrml.mac")
|
||||
|
||||
# creating widgets using grid layout
|
||||
|
||||
from Tkinter import *
|
||||
|
||||
class App(Frame):
|
||||
|
||||
|
||||
|
||||
def init(self):
|
||||
|
||||
#title and header row=0, 1
|
||||
title = Label(self, text="Geant4Py for Education @ H. Yoshida Naruto Univ. of Education")
|
||||
title.grid(row=0, column=1, columnspan=5)
|
||||
header = Label(self, text="Measurement of Mass Attenuation Coefficient")
|
||||
header.grid(row=1, column=1, columnspan=5)
|
||||
|
||||
#material selection row=2
|
||||
materialLabel = Label(self, bg="green", text="Material")
|
||||
materialLabel.grid(row=2, column=0, sticky=W)
|
||||
self.materialVar = StringVar()
|
||||
self.materialVar.set("water")
|
||||
ra1 = { }
|
||||
pos=1
|
||||
for i in absorber.keys():
|
||||
ra1[i] = Radiobutton(self, text=i, variable=self.materialVar, value=i)
|
||||
ra1[i].grid(row=2, column=pos, sticky=W)
|
||||
pos=pos+1
|
||||
|
||||
#absorber thickness row=3
|
||||
thickLabel = Label(self, bg="green", text="Thickness (mm)")
|
||||
self.thickVar = DoubleVar()
|
||||
self.thickVar.set(100.0)
|
||||
thick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.thickVar)
|
||||
thickLabel.grid(row=3, column=0, sticky=W)
|
||||
thick.grid(row=3, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#get logical volume and set its half length
|
||||
self.solid = EZgeom.G4EzVolume.GetSold(water_phantom)
|
||||
|
||||
#particle row=4
|
||||
particleLabel = Label(self, bg="green", text="Particle")
|
||||
particleLabel.grid(row=4, column=0, sticky=W)
|
||||
self.particleVar = StringVar()
|
||||
self.particleVar.set("gamma")
|
||||
ra1 = { }
|
||||
pos1=1
|
||||
for i in ("gamma", "e-"):
|
||||
ra1[i] = Radiobutton(self, text=i, variable=self.particleVar, value=i)
|
||||
ra1[i].grid(row=4, column=pos1, sticky=W)
|
||||
pos1=pos1+1
|
||||
|
||||
#energy row=5
|
||||
energyLabel = Label(self, bg="green", text="Energy (MeV)")
|
||||
|
||||
self.energyVar=StringVar()
|
||||
self.energyVar.set(1)
|
||||
energy = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., tickinterval=10.0, resolution=0.1, variable=self.energyVar, digits=4 )
|
||||
energyLabel.grid(row=5, column=0, sticky=W)
|
||||
energy.grid(row=5, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#number of event row=6
|
||||
eventLabel = Label(self, bg="green", text="Events")
|
||||
self.eventVar=IntVar()
|
||||
event = Scale(self, orient=HORIZONTAL, length=400, from_=1, to=100, tickinterval=10, resolution=1, variable=self.eventVar )
|
||||
eventLabel.grid(row=6, column=0, sticky=W)
|
||||
event.grid(row=6, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#start a run button row=7
|
||||
startBut = Button(self, bg="orange", text="Start a run", command=self.cmd_beamOn)
|
||||
startBut.grid(row=0, column=0, sticky=W)
|
||||
|
||||
#Zoom in/out Pan X Y row=8
|
||||
visLabel = Label(self, text="viewer", bg="orange")
|
||||
expandBut = Button(self, text="Zoom in", command=self.cmd_expand)
|
||||
shrinkBut = Button(self, text="Zoom out", command=self.cmd_shrink)
|
||||
visLabel.grid(row=8, column=0, sticky=W)
|
||||
expandBut.grid(row=8, column=1, sticky=W)
|
||||
shrinkBut.grid(row=8, column=2, sticky=W)
|
||||
|
||||
upBut = Button(self, text="Up", command=self.cmd_up)
|
||||
downBut = Button(self, text="Down", command=self.cmd_down)
|
||||
upBut.grid(row=8, column=3, sticky=W)
|
||||
downBut.grid(row=8, column=4, sticky=W)
|
||||
|
||||
leftBut = Button(self, text="Left", command=self.cmd_left)
|
||||
rightBut = Button(self, text="Right", command=self.cmd_right)
|
||||
leftBut.grid(row=8, column=5, sticky=W)
|
||||
rightBut.grid(row=8, column=6, sticky=W)
|
||||
# later
|
||||
# resetBut = Button(self, text="Reset", command=self.cmd_reset)
|
||||
# resetBut.grid(row=8, column=7, sticky=W)
|
||||
|
||||
|
||||
# panLabel = Label(self, text="Pan X Y (mm)")
|
||||
# self.panXYVar = StringVar()
|
||||
# panXYEnt = Entry(self, textvariable=self.panXYVar)
|
||||
# panBut = Button(self, bg="orange", text="OK", command=self.cmd_pan)
|
||||
# panLabel.grid(row=8, column=3, sticky=W)
|
||||
# panXYEnt.grid(row=8, column=4)
|
||||
# panBut.grid(row=8, column=5)
|
||||
#Geant4 command entry row = 9
|
||||
# g4comLabel = Label(self, text="Geant4 command")
|
||||
# self.g4commandVar = StringVar()
|
||||
# commandEntry = Entry(self, textvariable=self.g4commandVar)
|
||||
# comBut = Button(self, bg="orange", text="Execute", command=self.cmd_g4command)
|
||||
# g4comLabel.grid(row=9, column=0, sticky=W)
|
||||
# commandEntry.grid(row=9, column=1, columnspan=4, sticky=E+W)
|
||||
# comBut.grid(row=9, column=5)
|
||||
|
||||
#exit row = 10
|
||||
exitBut = Button(self, bg="red", text="End all", command=sys.exit)
|
||||
exitBut.grid(row=0, column=6, sticky=W)
|
||||
|
||||
#on Run butto do...
|
||||
def cmd_beamOn(self):
|
||||
materialChosen = self.materialVar.get()
|
||||
water_phantom.SetMaterial(absorber[materialChosen])
|
||||
|
||||
if materialChosen == "water":
|
||||
water_phantom.SetColor(0., 0.9, 1.0)
|
||||
|
||||
if materialChosen == "air":
|
||||
water_phantom.SetColor(0.9, 0.9, 1.0)
|
||||
|
||||
if materialChosen == "lead":
|
||||
water_phantom.SetColor(0.2, 0.2, 0.2)
|
||||
|
||||
if materialChosen == "iron":
|
||||
water_phantom.SetColor(0.7, 0.5, 0.7)
|
||||
|
||||
if materialChosen == "aluminum":
|
||||
water_phantom.SetColor(.7, 0.9, 1.0)
|
||||
|
||||
if materialChosen == "gold":
|
||||
water_phantom.SetColor(1., 0.9, .0)
|
||||
|
||||
self.solid.SetZHalfLength(self.thickVar.get() * mm/2.0)
|
||||
# gControlExecute("oglx.mac") #draw for each run
|
||||
gApplyUICommand("/vis/viewer/flush")
|
||||
|
||||
self.cmd_particle(self.particleVar.get())
|
||||
self.cmd_energy(self.energyVar.get())
|
||||
# TODO later to reflesh text
|
||||
gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + " ")
|
||||
gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + self.materialVar.get() + " = " + str(self.thickVar.get()) + "mm " + self.particleVar.get() + " = "+self.energyVar.get() + "MeV")
|
||||
|
||||
eventNum = self.eventVar.get()
|
||||
for i in range(eventNum):
|
||||
gunYZpos = str(i-eventNum/2) + ". -20. cm"
|
||||
gApplyUICommand("/gun/position 0. " + gunYZpos)
|
||||
gRunManager.BeamOn(1)
|
||||
sleep(0.01)
|
||||
# self.cmd_expand() #Zoom in to the last diaplayed OGLSX
|
||||
# self.cmd_shrink()
|
||||
|
||||
|
||||
|
||||
def cmd_g4command(self):
|
||||
gApplyUICommand(self.g4commandVar.get())
|
||||
|
||||
def cmd_particle(self, particle):
|
||||
gApplyUICommand("/gun/particle " + particle)
|
||||
|
||||
|
||||
def cmd_energy(self, penergy):
|
||||
gApplyUICommand("/gun/energy " + penergy + " MeV")
|
||||
|
||||
|
||||
def cmd_expand(self):
|
||||
gApplyUICommand("/vis/viewer/zoom 1.2")
|
||||
|
||||
def cmd_up(self):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 0. 10. mm")
|
||||
|
||||
def cmd_down(self):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 0. -10. mm")
|
||||
|
||||
def cmd_right(self):
|
||||
gApplyUICommand("/vis/viewer/pan " + " -1. 0. mm")
|
||||
|
||||
def cmd_left(self):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 1. 0. mm")
|
||||
|
||||
|
||||
def cmd_shrink(self):
|
||||
gApplyUICommand("/vis/viewer/zoom 0.8")
|
||||
|
||||
|
||||
# def cmd_reset(self):
|
||||
# gApplyUICommand("/vis/viewer/pan " + " 0. 0. mm")
|
||||
|
||||
|
||||
def __init__(self, master=None):
|
||||
Frame.__init__(self, master)
|
||||
self.init()
|
||||
self.grid()
|
||||
|
||||
|
||||
app = App()
|
||||
app.mainloop()
|
||||
@@ -0,0 +1,40 @@
|
||||
09 March 2006
|
||||
26 May 2006 Geant4.8.1
|
||||
|
||||
Hajime Yoshida
|
||||
|
||||
The first version of the courseware of the mass attenuation coefficient
|
||||
|
||||
- Lesson1.py
|
||||
select absorber material
|
||||
set its thickness upto 500 mm
|
||||
select beam particle
|
||||
set its energy upto 100 MeV
|
||||
set nu of events up to 100
|
||||
run
|
||||
|
||||
and then
|
||||
zoom in (x1.1) or zoom out (x0.9)
|
||||
pan in up/down and/or right/left in the unit of mm (type in two
|
||||
numbers separated by a space)
|
||||
|
||||
execute any G4 command but /gun/particle or /gun/energy which are
|
||||
defined by the above
|
||||
|
||||
-oglx.mac
|
||||
OGLSX => important to make zooming effective after showing trajectories.
|
||||
|
||||
if you want to use VRML, you have to specify the directory where *.wrl
|
||||
file is stored and the VRML viewer to which the path is set:
|
||||
G4VRMLFILE_DEST_DIR=/home/yoshidah/tmp/
|
||||
G4VRMLFILE_VIEWER=vrmlview
|
||||
|
||||
And you have VRML drivers built.
|
||||
G4VIS_BUILD_VRML_DRIVER=1
|
||||
G4VIS_USE_VRMLFILE=1
|
||||
G4VIS_BUILD_VRMLFILE_DRIVER=1
|
||||
G4VIS_USE_VRML=1
|
||||
|
||||
|
||||
-gun.mac
|
||||
This is used only at the initialization time.
|
||||
@@ -0,0 +1,8 @@
|
||||
# gun.mac
|
||||
|
||||
/gun/number 1
|
||||
/gun/particle e-
|
||||
/gun/energy 0.2 MeV
|
||||
/gun/direction 0. 0. 1.
|
||||
/gun/position 0. -5. -30. cm
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# vis.mac
|
||||
|
||||
#OpenGL Stored mode to accumulate trajectories
|
||||
|
||||
/vis/open OGLSX
|
||||
|
||||
#VRML viewer is usable if you defined env variables
|
||||
#/vis/open VRML2FILE
|
||||
|
||||
/vis/viewer/refresh
|
||||
|
||||
/vis/scene/create
|
||||
/vis/scene/add/volume
|
||||
#/vis/scene/add/axes 0 0 0 2 m
|
||||
#/vis/drawVolume
|
||||
/vis/viewer/set/style s
|
||||
|
||||
|
||||
/vis/sceneHandler/attach
|
||||
|
||||
/vis/viewer/set/viewpointThetaPhi 90. 0.
|
||||
/vis/viewer/zoom 1.5
|
||||
|
||||
#/vis/scene/add/text 0 610 610 mm 20 -0 -0 Geant4Py
|
||||
/tracking/storeTrajectory 1
|
||||
/vis/scene/add/trajectories
|
||||
/vis/scene/endOfEventAction accumulate
|
||||
/vis/scene/endOfRunAction accumulate
|
||||
|
||||
+426
@@ -0,0 +1,426 @@
|
||||
#!/usr/bin/python
|
||||
# ==================================================================
|
||||
# python script for Geant4Py
|
||||
#
|
||||
# ExN03 : geant4/examples/novice/N03
|
||||
# using site-module packages
|
||||
# ==================================================================
|
||||
from Geant4 import *
|
||||
import Qmaterials, NISTmaterials
|
||||
import ExN03geom
|
||||
import ExN03pl
|
||||
import ParticleGun, MedicalBeam
|
||||
import sys
|
||||
from time import *
|
||||
from subprocess import *
|
||||
import os
|
||||
|
||||
# ==================================================================
|
||||
# main
|
||||
# ==================================================================
|
||||
# ------------------------------------------------------------------
|
||||
# randum number
|
||||
# ------------------------------------------------------------------
|
||||
rand_engine= Ranlux64Engine()
|
||||
HepRandom.setTheEngine(rand_engine)
|
||||
HepRandom.setTheSeed(20050830L)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for materials
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
# NIST materials
|
||||
#NISTmaterials.Construct()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for geometry
|
||||
# ------------------------------------------------------------------
|
||||
# normal way for constructing user geometry
|
||||
|
||||
|
||||
exN03geom= ExN03geom.ExN03DetectorConstruction()
|
||||
gRunManager.SetUserInitialization(exN03geom)
|
||||
|
||||
# 2nd way, short-cut way
|
||||
|
||||
#ExN01geom.Construct()
|
||||
#ExN03geom.Construct()
|
||||
|
||||
# magnetic field
|
||||
#exN03geom.SetMagField(0.1 * tesla)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for physics list
|
||||
# ------------------------------------------------------------------
|
||||
# normal way for constructing user physics list
|
||||
exN03PL= ExN03pl.ExN03PhysicsList()
|
||||
gRunManager.SetUserInitialization(exN03PL)
|
||||
|
||||
# 2nd way, short-cut way
|
||||
#ExN01pl.Construct()
|
||||
#EMSTDpl.Construct()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for primary generator action
|
||||
# ------------------------------------------------------------------
|
||||
# normal way for constructing user physics list
|
||||
#pgPGA= ParticleGun.ParticleGunAction()
|
||||
#gRunManager.SetUserAction(pgPGA)
|
||||
#pg= pgPGA.GetParticleGun()
|
||||
|
||||
# 2nd way, short-cut way
|
||||
pg= ParticleGun.Construct()
|
||||
|
||||
# set parameters of particle gun
|
||||
pg.SetParticleByName("e-")
|
||||
pg.SetParticleEnergy(50.*MeV)
|
||||
pg.SetParticlePosition(G4ThreeVector(-40.,0.,0.)*cm)
|
||||
pg.SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.))
|
||||
|
||||
# medical beam
|
||||
#beam= MedicalBeam.Construct()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# go...
|
||||
# ------------------------------------------------------------------
|
||||
gRunManager.Initialize()
|
||||
|
||||
# beamOn
|
||||
#gRunManager.BeamOn(3)
|
||||
|
||||
|
||||
#TEST
|
||||
#gProcessTable.SetProcessActivation("msc", 0)
|
||||
#gProcessTable.SetProcessActivation("conv", 0)
|
||||
#gProcessTable.SetProcessActivation("eBrem", 0)
|
||||
#gProcessTable.SetProcessActivation("eIoni", 0)
|
||||
#gProcessTable.SetProcessActivation("annihil", 0)
|
||||
|
||||
|
||||
# visualization
|
||||
# OGLSX, VRML and HEPREP sceneHandlers are all created with names
|
||||
gApplyUICommand("/vis/sceneHandler/create OGLSX OGLSX")
|
||||
gApplyUICommand("/vis/sceneHandler/create VRML2FILE VRML")
|
||||
gApplyUICommand("/vis/sceneHandler/create HepRepFile HEPREP")
|
||||
|
||||
# OGLSX is the default so, viewer is created and volume is drawn
|
||||
gApplyUICommand("/vis/viewer/create OGLSX oglsxviewer")
|
||||
gApplyUICommand("/vis/drawVolume")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
gApplyUICommand("/vis/viewer/select oglsxviewer")
|
||||
|
||||
# viewers VRML and Wired are tested by their envs vars
|
||||
# if their envs var are set, then viewers are created and drawVolume
|
||||
|
||||
global heprepViewer, heprepDir, heprepName
|
||||
heprepViewer = os.environ.get("G4HEPREPFILE_VIEWER")
|
||||
heprepDir = os.environ.get("G4HEPREPFILE_DIR")
|
||||
heprepName = os.environ.get("G4HEPREPFILE_NAME")
|
||||
if heprepViewer is not None:
|
||||
gApplyUICommand("/vis/viewer/create HEPREP wired")
|
||||
gApplyUICommand("/vis/drawVolume")
|
||||
|
||||
# VRML viewers name is user defined
|
||||
vrmlDir = os.environ.get("G4VRML_DEST_DIR")
|
||||
vrmlViewer = os.environ.get("G4VRMLFILE_VIEWER")
|
||||
|
||||
if vrmlViewer is not None:
|
||||
gApplyUICommand("/vis/viewer/create VRML vrmlviewer")
|
||||
gApplyUICommand("/vis/drawVolume")
|
||||
|
||||
|
||||
|
||||
# creating widgets using grid layout
|
||||
|
||||
from Tkinter import *
|
||||
|
||||
class App(Frame):
|
||||
|
||||
g4pipe = 0
|
||||
|
||||
def init(self):
|
||||
|
||||
#title and header row=0, 1
|
||||
title = Label(self, text="exampleN03")
|
||||
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
|
||||
layerLabel = Label(self, bg="green", text="No of layers")
|
||||
self.layerVar=IntVar()
|
||||
self.layerVar.set(10)
|
||||
layer = Scale(self, orient=HORIZONTAL, length=400, from_=0, to=10, tickinterval=1, resolution=1, variable=self.layerVar )
|
||||
layerLabel.grid(row=2, column=0, sticky=W)
|
||||
layer.grid(row=2, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#absorber material selection row=3
|
||||
absorbermaterialLabel = Label(self, bg="green", text="Absorber Material")
|
||||
absorbermaterialLabel.grid(row=3, column=0, sticky=W)
|
||||
self.absorbermaterialVar = StringVar()
|
||||
self.absorbermaterialVar.set("Lead")
|
||||
ra1 = { }
|
||||
pos=1
|
||||
for i in ("Aluminium", "Lead"):
|
||||
ra1[i] = Radiobutton(self, text=i, variable=self.absorbermaterialVar, value=i)
|
||||
ra1[i].grid(row=3, column=pos, sticky=W)
|
||||
pos=pos+1
|
||||
|
||||
#absorber thickness row=4
|
||||
absorberthickLabel = Label(self, bg="green", text="Thickness (mm)")
|
||||
self.absorberthickVar = DoubleVar()
|
||||
self.absorberthickVar.set(10.0)
|
||||
absorberthick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.absorberthickVar)
|
||||
absorberthickLabel.grid(row=4, column=0, sticky=W)
|
||||
absorberthick.grid(row=4, column=1, columnspan=5, sticky=W)
|
||||
|
||||
|
||||
#gap material selection row=5
|
||||
gapmaterialLabel = Label(self, bg="green", text="Gap Material")
|
||||
gapmaterialLabel.grid(row=5, column=0, sticky=W)
|
||||
self.gapmaterialVar = StringVar()
|
||||
self.gapmaterialVar.set("liquidArgon")
|
||||
ra2 = { }
|
||||
pos=1
|
||||
for i in ("liquidArgon","Scintillator", "Air", "Aerogel", "Galactic" ):
|
||||
ra2[i] = Radiobutton(self, text=i, variable=self.gapmaterialVar, value=i)
|
||||
ra2[i].grid(row=5, column=pos, sticky=W)
|
||||
pos=pos+1
|
||||
|
||||
#gap thickness row=6
|
||||
gapthickLabel = Label(self, bg="green", text="Thickness (mm)")
|
||||
self.gapthickVar = DoubleVar()
|
||||
self.gapthickVar.set(5.0)
|
||||
gapthick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.gapthickVar)
|
||||
gapthickLabel.grid(row=6, column=0, sticky=W)
|
||||
gapthick.grid(row=6, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#calorSizeYZ row=7
|
||||
calorsizeYZLabel = Label(self, bg="green", text="SizeYZ (mm)")
|
||||
self.calorsizeYZVar = DoubleVar()
|
||||
self.calorsizeYZVar.set(100.0)
|
||||
calorsizeYZ = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=200., resolution=0.05, tickinterval=20.0, digits=4, variable=self.calorsizeYZVar)
|
||||
calorsizeYZLabel.grid(row=7, column=0, sticky=W)
|
||||
calorsizeYZ.grid(row=7, column=1, columnspan=5, sticky=W)
|
||||
|
||||
|
||||
#particle row=8
|
||||
particleLabel = Label(self, bg="green", text="Particle")
|
||||
particleLabel.grid(row=8, column=0, sticky=W)
|
||||
self.particleVar = StringVar()
|
||||
self.particleVar.set("e-")
|
||||
ra1 = { }
|
||||
pos1=1
|
||||
for i in ("proton", "gamma", "e-", "e+", "mu-", "mu+"):
|
||||
ra1[i] = Radiobutton(self, text=i, variable=self.particleVar, value=i)
|
||||
ra1[i].grid(row=8, column=pos1, sticky=W)
|
||||
pos1=pos1+1
|
||||
|
||||
#energy row=9
|
||||
energyLabel = Label(self, bg="green", text="Energy (MeV)")
|
||||
|
||||
self.energyVar=StringVar()
|
||||
self.energyVar.set(50)
|
||||
energy = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=1000., tickinterval=100.0, resolution=0.1, variable=self.energyVar, digits=5 )
|
||||
energyLabel.grid(row=9, column=0, sticky=W)
|
||||
energy.grid(row=9, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#number of event row=10
|
||||
eventLabel = Label(self, bg="green", text="Events")
|
||||
self.eventVar=IntVar()
|
||||
self.eventVar.set(3)
|
||||
event = Scale(self, orient=HORIZONTAL, length=400, from_=0, to=100, tickinterval=10, resolution=1, variable=self.eventVar )
|
||||
eventLabel.grid(row=10, column=0, sticky=W)
|
||||
event.grid(row=10, column=1, columnspan=5, sticky=W)
|
||||
|
||||
#start a run button row=0
|
||||
startBut = Button(self, bg="orange", text="Start a run", command=self.cmd_beamOn)
|
||||
startBut.grid(row=0, column=0, sticky=W)
|
||||
|
||||
#Zoom in/out Pan X Y row=13
|
||||
# visLabel = Label(self, text="viewer", bg="orange")
|
||||
# expandBut = Button(self, text="Zoom in", command=self.cmd_expand)
|
||||
# shrinkBut = Button(self, text="Zoom out", command=self.cmd_shrink)
|
||||
# visLabel.grid(row=13, column=0, sticky=W)
|
||||
# expandBut.grid(row=13, column=1, sticky=W)
|
||||
# shrinkBut.grid(row=13, column=2, sticky=W)
|
||||
# panLabel = Label(self, text="Pan X Y(mm)")
|
||||
# self.panXYVar = StringVar()
|
||||
# panXYEnt = Entry(self, textvariable=self.panXYVar, width=6)
|
||||
# panBut = Button(self, bg="orange", text="OK", command=self.cmd_pan)
|
||||
# panLabel.grid(row=13, column=3, sticky=W)
|
||||
# panXYEnt.grid(row=13, column=4)
|
||||
# panBut.grid(row=13, column=5)
|
||||
|
||||
# process activate row 11 - 13
|
||||
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 = {}
|
||||
for i in self.processList:
|
||||
self.processVar[i] = IntVar()
|
||||
procTab[i] = Checkbutton(self, text=i, variable=self.processVar[i], command=self.cmd_setProcess)
|
||||
if pos <= 3:
|
||||
procTab[i].grid(row=11, column=pos, sticky=W)
|
||||
if 4<= pos <= 7:
|
||||
procTab[i].grid(row=12, column=pos-3, sticky=W)
|
||||
if pos >= 8:
|
||||
procTab[i].grid(row=13, column=pos-7, sticky=W)
|
||||
pos=pos+1
|
||||
procTab[i].select()
|
||||
# set cuts row 14
|
||||
cutLabel = Label(self, bg="green", text="Cut (mm)")
|
||||
|
||||
self.cutVar=DoubleVar()
|
||||
self.cutVar.set(1.)
|
||||
cut = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=10., tickinterval=1., resolution=0.005, variable=self.cutVar, digits=5 )
|
||||
cutLabel.grid(row=14, column=0, sticky=W)
|
||||
cut.grid(row=14, column=1, columnspan=5, sticky=W)
|
||||
|
||||
# set mag field row 15
|
||||
magLabel = Label(self, bg="green", text="Magnetic (T)")
|
||||
|
||||
self.magVar=DoubleVar()
|
||||
self.magVar.set(0.)
|
||||
mag = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=5., tickinterval=1., resolution=0.1, variable=self.magVar, digits=3 )
|
||||
magLabel.grid(row=15, column=0, sticky=W)
|
||||
mag.grid(row=15, column=1, columnspan=5, sticky=W)
|
||||
|
||||
|
||||
# viewer selection row=16
|
||||
viewerLabel = Label(self, bg="green", text="Viewer")
|
||||
viewerLabel.grid(row=16, column=0, sticky=W)
|
||||
self.viewerVar = StringVar()
|
||||
self.viewerVar.set("")
|
||||
stateOfViewer = {"OpenGL":"normal", "VRML":"normal", "Wired":"normal"}
|
||||
if vrmlViewer is None: stateOfViewer["VRML"] = "disabled"
|
||||
if heprepViewer is None: stateOfViewer["Wired"] = "disabled"
|
||||
viewers = { }
|
||||
pos=1
|
||||
for i in ("OpenGL", "VRML", "Wired"):
|
||||
viewers[i] = Radiobutton(self, text=i, variable=self.viewerVar, value=i, command=self.cmd_viewer, state=stateOfViewer[i])
|
||||
viewers[i].grid(row=16, column=pos, sticky=W)
|
||||
pos=pos+1
|
||||
|
||||
|
||||
#Geant4 command entry row = 17
|
||||
g4comLabel = Label(self, text="Geant4 command", bg="orange")
|
||||
self.g4commandVar = StringVar()
|
||||
commandEntry = Entry(self, textvariable=self.g4commandVar, width=15)
|
||||
self.g4commandVar.set("/vis/viewer/zoom 1.2")
|
||||
comBut = Button(self, bg="orange", text="Execute", command=self.cmd_g4command)
|
||||
g4comLabel.grid(row=17, column=0, sticky=W)
|
||||
commandEntry.grid(row=17, column=1, columnspan=3, sticky=E+W)
|
||||
comBut.grid(row=17, column=5)
|
||||
|
||||
#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...
|
||||
def cmd_beamOn(self):
|
||||
exN03geom.SetNbOfLayers(self.layerVar.get())
|
||||
exN03geom.SetAbsorberMaterial(self.absorbermaterialVar.get())
|
||||
exN03geom.SetAbsorberThickness(self.absorberthickVar.get() * mm/2.0)
|
||||
exN03geom.SetGapMaterial(self.gapmaterialVar.get())
|
||||
exN03geom.SetGapThickness(self.gapthickVar.get() * mm/2.0)
|
||||
exN03geom.SetCalorSizeYZ(self.calorsizeYZVar.get() * mm)
|
||||
position = -self.layerVar.get()*(self.absorberthickVar.get() + self.gapthickVar.get())*1.2
|
||||
|
||||
exN03geom.UpdateGeometry()
|
||||
exN03PL.SetDefaultCutValue(self.cutVar.get() * mm)
|
||||
exN03PL.SetCutsWithDefault()
|
||||
exN03geom.SetMagField(self.magVar.get() * tesla)
|
||||
|
||||
print "Now geometry updated"
|
||||
|
||||
|
||||
self.cmd_particle(self.particleVar.get())
|
||||
self.cmd_energy(self.energyVar.get())
|
||||
|
||||
print position
|
||||
|
||||
eventNum = self.eventVar.get()
|
||||
for i in range(eventNum):
|
||||
|
||||
pg.SetParticlePosition(G4ThreeVector(position*mm, (i-eventNum/2)*5.*mm, 0.*cm))
|
||||
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:
|
||||
gProcessTable.SetProcessActivation(i, 0)
|
||||
print "Process " + i + " inactivated"
|
||||
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)
|
||||
|
||||
|
||||
def cmd_energy(self, penergy):
|
||||
gApplyUICommand("/gun/energy " + penergy + " MeV")
|
||||
|
||||
|
||||
def cmd_viewer(self):
|
||||
if self.viewerVar.get() == "OpenGL":
|
||||
gApplyUICommand("/vis/viewer/select oglsxviewer")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
|
||||
if self.viewerVar.get() == "VRML":
|
||||
gApplyUICommand("/vis/viewer/select vrmlviewer")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
|
||||
if self.viewerVar.get() == "Wired":
|
||||
gApplyUICommand("/vis/viewer/select wired")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
|
||||
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")
|
||||
|
||||
def cmd_pan(self):
|
||||
gApplyUICommand("/vis/viewer/pan " + self.panXYVar.get() + " " + " mm")
|
||||
|
||||
|
||||
def cmd_shrink(self):
|
||||
gApplyUICommand("/vis/viewer/zoom 0.8")
|
||||
|
||||
|
||||
|
||||
def __init__(self, master=None):
|
||||
Frame.__init__(self, master)
|
||||
self.init()
|
||||
self.grid()
|
||||
|
||||
|
||||
app = App()
|
||||
app.mainloop()
|
||||
@@ -0,0 +1,77 @@
|
||||
26 May 2006
|
||||
revised 02 July 2006
|
||||
Geant4.8.1 release
|
||||
===============================================
|
||||
Prerequisites for G4 environment variables.
|
||||
==============================================
|
||||
|
||||
This scripts offers the choice of visualization systems;
|
||||
one among OGLSX (OpenGL stored mode), or VRML2FILE or Wired3.
|
||||
|
||||
OGLSX is the default viewer and you need no environment variables.
|
||||
|
||||
To use VRML2FILE you have to specify its viewer which is found in your
|
||||
search path and the destination directory where *.wrl file is stored.
|
||||
If you don't specify the name of the viewer, you can't choose it on the panel.
|
||||
For example,
|
||||
setenv G4VRMLFILE_VIEWER $HOME/bin/vrmlview
|
||||
setenv G4VRMLFILE_DEST_DIR $HOME/tmp/ <= terminate with /
|
||||
|
||||
To use Wired, download it and install under your directory. Java Runtime
|
||||
Environment is necessary.
|
||||
Then set, for example;
|
||||
setenv G4HEPREPFILE_VIEWER $HOME/Wired/bin/wired <= any path you use
|
||||
setenv G4HEPREPFILE_DIR $HOME/tmp/
|
||||
setenv G4HEPREPFILE_NAME lesson2_00 <= any name you choose.
|
||||
setenv G4HEPREPFILE_OVERWRITE 1 <= to reuse the file for "next event"
|
||||
G4HEPREPFILE_VIEWER isn't an official Geant4 environment variable but is employed
|
||||
here to control the vissssualization viewers.
|
||||
The name of the HepRepFile is ${G4HEPREPFILE_NAME}.heprep which will be
|
||||
stored in ${G4HEPREPFILE_DIR}.
|
||||
|
||||
ExN03.py script don't use VRML or Wired if their *_VIEWER isn't set.
|
||||
But other env variables are also used in the script to look for the
|
||||
file and to activate the viewer, you have to set all of the above variables
|
||||
in the shell where you activate ExN03.py script.
|
||||
|
||||
|
||||
NOTICE) VRML viewer blocks the window (modal), so that you have to exit it to
|
||||
display another run.
|
||||
|
||||
********* ExN03.py script ***********
|
||||
|
||||
This example id derived from examples/novice/N03.
|
||||
You can
|
||||
- choose the materials of absorber and gap
|
||||
- set the thickness of the absorber and gap
|
||||
- set the lateral (in YZ plane) size of the sandwitch cal.
|
||||
- choose an incedent particle
|
||||
- set its energy
|
||||
- set the number of events to run
|
||||
- toggle on/off of the electromagnetic processes
|
||||
- set cut length
|
||||
- set magnetic field
|
||||
- typein any Geant4 command (except related with the above functions) and execute it
|
||||
|
||||
How to run it?
|
||||
%python ExN03.py
|
||||
|
||||
You can visualize with OpenGL stored mode or VRML or Wired3
|
||||
You can choose either of the active viewers by pushing the
|
||||
radio buttons.
|
||||
=========================
|
||||
NOTICE)
|
||||
|
||||
VRML viewer runs in the modal action, and you have to exit it
|
||||
to have a new diaplay for the new run, or you want to switch to
|
||||
another viewer.
|
||||
|
||||
Wired has the "next"/"previous" event button. So to see the next
|
||||
event, first run and then "next" event. Wired doesn't block G4
|
||||
and you can have Wired and OGLSX both open.
|
||||
|
||||
|
||||
|
||||
ExN03-Wired.py is OBSOLETE. Please use ExN03.py
|
||||
|
||||
|
||||
Reference in New Issue
Block a user