Import Geant4 8.2.0 source tree
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# $Id: GNUmakefile,v 1.1 2006/05/11 04:35:32 kmura Exp $
|
||||
# $Name: geant4-08-01 $
|
||||
# $Name: geant4-08-02 $
|
||||
# ===========================================================
|
||||
# Makefile for building Geant4Py modules
|
||||
# ===========================================================
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: MyDetectorConstruction.cc,v 1.3 2006/06/29 15:28:11 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// MyDetectorConstruction.cc
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: MyDetectorConstruction.hh,v 1.3 2006/06/29 15:28:13 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// MyDetectorConstruction.hh
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: MyMaterials.cc,v 1.3 2006/06/29 15:28:16 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// MyMaterials.cc
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: MyMaterials.hh,v 1.3 2006/06/29 15:28:19 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// MyMaterials.hh
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: MyPhysicsList.cc,v 1.3 2006/06/29 15:28:21 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// MyPhysicsList.cc
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: MyPhysicsList.hh,v 1.3 2006/06/29 15:28:23 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// MyPhysicsList.hh
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: Particles.cc,v 1.3 2006/06/29 15:28:25 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// Particles.cc
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: PhysicsListEMstd.cc,v 1.3 2006/06/29 15:28:29 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// PhysicsListEMstd.cc
|
||||
//
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
// $Id: pydemo_wp.cc,v 1.3 2006/06/29 15:28:40 gunter Exp $
|
||||
// $Name: geant4-08-01 $
|
||||
// $Name: geant4-08-02 $
|
||||
// ====================================================================
|
||||
// pydemo_wp.cc
|
||||
//
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
27 Sep. 2006 Hajime Yoshida
|
||||
- Lesson1.py as before
|
||||
- Lesson1withN03.py with the physics list of N03
|
||||
- Lesson2Wx.py N03 physics list AND wxPython GUI
|
||||
|
||||
09 March 2006
|
||||
|
||||
Hajime Yoshida
|
||||
|
||||
@@ -0,0 +1,555 @@
|
||||
from Geant4 import *
|
||||
import NISTmaterials
|
||||
from EZsim import EZgeom
|
||||
from EZsim.EZgeom import G4EzVolume
|
||||
import ExN03pl
|
||||
import ParticleGun
|
||||
from time import *
|
||||
import sys
|
||||
from subprocess import *
|
||||
import os
|
||||
|
||||
# ==================================================================
|
||||
# intialize
|
||||
# ==================================================================
|
||||
def Configure():
|
||||
# ------------------------------------------------------------------
|
||||
# setup for materials
|
||||
# ------------------------------------------------------------------
|
||||
# simple materials for Qgeom
|
||||
NISTmaterials.Construct()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for geometry
|
||||
# ------------------------------------------------------------------
|
||||
EZgeom.Construct() # initialize
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# setup for physics list of N03
|
||||
# ------------------------------------------------------------------
|
||||
ExN03pl.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()
|
||||
|
||||
|
||||
|
||||
global commandDic, commandList
|
||||
commandDic = {}
|
||||
commandList = []
|
||||
|
||||
def DumpTree(atree):
|
||||
|
||||
ntree= atree.GetTreeEntry()
|
||||
ncommand= atree.GetCommandEntry()
|
||||
for i in range(1, ncommand+1):
|
||||
icommand= atree.GetCommand(i)
|
||||
command = str( icommand.GetCommandPath())
|
||||
commandList.append(command)
|
||||
nparameter= icommand.GetParameterEntries()
|
||||
pguide = ""
|
||||
for j in range(0, nparameter):
|
||||
iparam= icommand.GetParameter(j)
|
||||
pguide = pguide + "Parameter: " + str(iparam.GetParameterName())+ " Type: " + str(iparam.GetParameterType()) + '\n'
|
||||
guide = str(icommand.GetTitle()) + '\n' + pguide
|
||||
commandDic[command] = guide
|
||||
|
||||
for i in range(1, ntree+1):
|
||||
itree= atree.GetTree(i)
|
||||
DumpTree(itree)
|
||||
|
||||
root_tree= gUImanager.GetTree()
|
||||
DumpTree(root_tree)
|
||||
|
||||
# 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/viewer/select 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/set/viewpointThetaPhi 90. 0.")
|
||||
gApplyUICommand("/vis/viewer/set/style s")
|
||||
|
||||
# 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, vrmlViewer
|
||||
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")
|
||||
|
||||
###############################
|
||||
###### wxPython GUI ##########
|
||||
###############################
|
||||
|
||||
import wx
|
||||
|
||||
class ComPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
|
||||
self.g4comText = wx.TextCtrl(parent, -1, "enter Command", pos=(10,10), size=(300, 30))
|
||||
|
||||
self.g4comExec = wx.Button(parent, -1, "Execute", pos=(320,10), size=(60,30))
|
||||
self.g4comExec.Bind(wx.EVT_BUTTON, self.ExecuteCommand, self.g4comExec)
|
||||
|
||||
self.comListBox = wx.ListBox(parent, -1, pos=(10,50), size=(300,200), choices=commandList, style=wx.LB_SINGLE)
|
||||
self.comListBox.SetSelection(1)
|
||||
self.comListBox.Bind(wx.EVT_LISTBOX, self.ShowGuide, self.comListBox)
|
||||
|
||||
self.guide = wx.TextCtrl(parent, -1, "guidance", pos=(320,50), size=(300, 200), style =wx.TE_MULTILINE)
|
||||
self.guide.Bind(wx.EVT_LISTBOX, self.ShowGuide, self.guide)
|
||||
|
||||
|
||||
def ShowGuide(self, event):
|
||||
self.guide.Clear() # how to cleat the whole text before showing the next
|
||||
g4com =str(self.comListBox.GetStringSelection())
|
||||
self.guide.WriteText( commandDic[g4com])
|
||||
self.g4comText.SetValue(g4com)
|
||||
|
||||
def ExecuteCommand(self, event):
|
||||
gApplyUICommand(str(self.g4comText.GetValue()))
|
||||
|
||||
|
||||
class VisPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
|
||||
self.visZoomIn = wx.Button(parent, -1, "Zoom In", pos=(10,100), size=(80,30))
|
||||
self.visZoomOut = wx.Button(parent, -1, "Zoom out", pos=(100,100), size=(80,30))
|
||||
self.visUp = wx.Button(parent, -1, "Up", pos=(190,100), size=(80,30))
|
||||
self.visDown = wx.Button(parent, -1, "Down", pos=(270,100), size=(80,30))
|
||||
self.visLeft = wx.Button(parent, -1, "Left", pos=(360,100), size=(80,30))
|
||||
self.visRight = wx.Button(parent, -1, "Left", pos=(450,100), size=(80,30))
|
||||
|
||||
viewerList = ["OpenGL", "VRML", "Wired"]
|
||||
self.viewer = wx.RadioBox(self, -1, "Viewer", pos=(10,10),
|
||||
size=(210,60), choices=viewerList, majorDimension=1, style=wx.RA_SPECIFY_ROWS)
|
||||
self.viewer.Bind(wx.EVT_RADIOBOX, self.ViewerSelected, self.viewer)
|
||||
self.viewer.SetToolTip(wx.ToolTip("Select one"))
|
||||
self.viewer.SetSelection(0)
|
||||
if vrmlViewer == None: self.viewer.EnableItem(1, False)
|
||||
if heprepViewer == None: self.viewer.EnableItem(2, False)
|
||||
|
||||
self.visZoomIn.Bind(wx.EVT_BUTTON, self.cmdExpand, self.visZoomIn)
|
||||
self.visZoomOut.Bind(wx.EVT_BUTTON, self.cmdShrink, self.visZoomOut)
|
||||
self.visUp.Bind(wx.EVT_BUTTON, self.cmdUp, self.visUp)
|
||||
self.visDown.Bind(wx.EVT_BUTTON, self.cmdDown, self.visDown)
|
||||
self.visRight.Bind(wx.EVT_BUTTON, self.cmdRight, self.visRight)
|
||||
self.visLeft.Bind(wx.EVT_BUTTON, self.cmdLeft, self.visLeft)
|
||||
|
||||
|
||||
def cmdExpand(self, event):
|
||||
gApplyUICommand("/vis/viewer/zoom 1.2")
|
||||
def cmdShrink(self, event):
|
||||
gApplyUICommand("/vis/viewer/zoom 0.8")
|
||||
def cmdUp(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 0. 10. mm")
|
||||
def cmdDown(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 0. -10. mm")
|
||||
def cmdRight(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " -1. 0. mm")
|
||||
def cmdLeft(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 1. 0. mm")
|
||||
|
||||
def ViewerSelected(self, event):
|
||||
self.viewerName = event.GetString()
|
||||
|
||||
if self.viewerName == "OpenGL":
|
||||
gApplyUICommand("/vis/viewer/select oglsxviewer")
|
||||
gApplyUICommand("/vis/drawVolume")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
|
||||
if self.viewerName == "VRML":
|
||||
gApplyUICommand("/vis/viewer/select vrmlviewer")
|
||||
|
||||
gApplyUICommand("/vis/viewer/set/viewpointThetaPhi 90. 0.")
|
||||
gApplyUICommand("/vis/viewer/set/style s")
|
||||
gApplyUICommand("/vis/drawVolume")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
|
||||
if self.viewerName == "Wired":
|
||||
|
||||
gApplyUICommand("/vis/viewer/select wired")
|
||||
|
||||
gApplyUICommand("/vis/viewer/set/viewpointThetaPhi 90. 0.")
|
||||
gApplyUICommand("/vis/viewer/set/style s")
|
||||
gApplyUICommand("/vis/drawVolume")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
|
||||
# everytime wired is chosen, a new instance of wired is created
|
||||
# to reuse single wired, g4pipe.poll() must be checked BEFORE the SECOND Popen
|
||||
# if g4pipe.poll() == None:
|
||||
g4pipe=Popen(heprepViewer+ " -file " + heprepDir+"/" +heprepName +".heprep", shell=True)
|
||||
|
||||
|
||||
# not used
|
||||
class MyText(wx.StaticText):
|
||||
def __init__(self, parent, Text):
|
||||
wx.StaticText.__init__(self, parent, -1, Text, pos=(20,20))
|
||||
self.Bind(wx.EVT_LEFT_UP, self.ChangeColor)
|
||||
|
||||
def ChangeColor(self, event):
|
||||
TheColour = self.GetForegroundColour()
|
||||
if TheColour == (0,0,0):
|
||||
self.SetLabel("Simulation is running!")
|
||||
self.SetForegroundColour("red")
|
||||
else:
|
||||
self.SetLabel("Click me to start a run")
|
||||
self.SetForegroundColour("black")
|
||||
|
||||
# to be used to choose materials and particles
|
||||
# myList is a list of keys() of a dictionary
|
||||
# f.e., materials are Python objects with their names as their keys
|
||||
class SelectOne(wx.RadioBox):
|
||||
def __init__(self, parent, myTitle, myList):
|
||||
wx.RadioBox.__init__(self, parent, -1, myTitle, wx.DefaultPosition,
|
||||
wx.DefaultSize, myList, 3, wx.RA_SPECIFY_ROWS)
|
||||
# self.Bind(wx.EVT_RADIOBOX, self.Selected)
|
||||
self.SetToolTip(wx.ToolTip("Select one"))
|
||||
self.SetSelection(0)
|
||||
# used only to test Bind and getValue
|
||||
# def Selected(self, event):
|
||||
# self.selected = event.GetString()
|
||||
|
||||
|
||||
# used to %3.3f floating point number
|
||||
# energy and length unit is given by unitList which must be a dictionary
|
||||
# with units of Python objects and their name as their keys
|
||||
|
||||
class FloatCounter(wx.Panel):
|
||||
def __init__(self, parent, myTitle, unitList):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
|
||||
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.sizer.Add((10, -1))
|
||||
self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
|
||||
|
||||
self.intPart = wx.SpinCtrl(parent, -1, "", wx.DefaultPosition, (60,-1))
|
||||
self.intPart.SetRange(0,999)
|
||||
self.intPart.SetValue(1)
|
||||
self.intPart.Bind(wx.EVT_SPINCTRL, self.SetFloat)
|
||||
|
||||
self.manPart = wx.SpinCtrl(parent, -1, "", wx.DefaultPosition, (50, -1))
|
||||
self.manPart.SetRange(0,999)
|
||||
self.manPart.SetValue(0)
|
||||
self.manPart.Bind(wx.EVT_SPINCTRL, self.SetFloat)
|
||||
|
||||
self.unitSel = wx.Choice(parent, -1, wx.DefaultPosition, (90, -1), unitList)
|
||||
self.unitSel.Bind(wx.EVT_CHOICE, self.SetFloat, self.unitSel)
|
||||
self.unitSel.SetSelection(2)
|
||||
|
||||
self.valAndUnit = wx.TextCtrl(parent, -1, "value unset", wx.DefaultPosition, (150, -1))
|
||||
|
||||
self.sizer.Add(self.valAndUnit)
|
||||
self.sizer.Add((10, -1))
|
||||
self.sizer.Add(wx.StaticText(parent, -1, " ", wx.DefaultPosition, (30, -1)))
|
||||
self.sizer.Add(self.intPart)
|
||||
self.sizer.Add(wx.StaticText(parent, -1, ".", wx.DefaultPosition, (10, -1)))
|
||||
self.sizer.Add(self.manPart)
|
||||
self.sizer.Add((5,-1))
|
||||
self.sizer.Add(self.unitSel)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
def SetFloat(self, event):
|
||||
# self.theValue = str(self.intPart.GetValue()) + "." + str(self.manPart.GetValue()) + " "
|
||||
self.theValue = float (self.intPart.GetValue()) + float(self.manPart.GetValue())/ 1000.
|
||||
self.theUnit = self.unitSel.GetStringSelection()
|
||||
theText = "%.3f" % (self.theValue) + " " + self.theUnit
|
||||
self.valAndUnit.SetValue(theText)
|
||||
# user may edit the Entry, so finnaly this value must be got
|
||||
# but it doesn't work for length but work for energy (gApplyUIcommnd)
|
||||
|
||||
|
||||
# special class for this example to set/unset processes
|
||||
class Processes(wx.Panel):
|
||||
def __init__(self, parent, myTitle, myList):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
self.processCheck = {}
|
||||
self.sizer = wx.FlexGridSizer(rows=3)
|
||||
self.sizer.AddGrowableRow(1)
|
||||
for item in myList:
|
||||
self.processCheck[item] = wx.CheckBox(parent, -1, item)
|
||||
self.processCheck[item].SetValue(True)
|
||||
# self.processCheck[item].Bind(wx.EVT_CHECKBOX, self.CheckedProcess)
|
||||
self.sizer.Add(self.processCheck[item],0,wx.EXPAND)
|
||||
|
||||
self.SetSizer(self.sizer)
|
||||
self.SetBackgroundColour('green')
|
||||
self.processState = {}
|
||||
self.myList = myList
|
||||
|
||||
# test only
|
||||
# def CheckedProcess(self, event):
|
||||
# self.processName = event.GetEventObject().GetLabel()
|
||||
# self.processState = event.GetEventObject().GetValue()
|
||||
|
||||
|
||||
# slider to set an integer value
|
||||
# title is shown
|
||||
class Adjuster(wx.Panel):
|
||||
def __init__(self, parent, myTitle, minVal, maxVal, initVal):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.sizer.Add((10, -1))
|
||||
self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
|
||||
self.slider = wx.Slider(parent, -1, initVal, minVal, maxVal,
|
||||
wx.DefaultPosition, (300, -1),
|
||||
wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
|
||||
self.slider.SetPageSize(1)
|
||||
self.sizer.Add(self.slider)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
# test only
|
||||
# self.Bind(wx.EVT_SLIDER, self.Adjusted)
|
||||
|
||||
# def Adjusted(self, event):
|
||||
# print self.GetValue()
|
||||
|
||||
|
||||
########################## no use now
|
||||
class Counter(wx.SpinCtrl):
|
||||
def __init__(self, parent, myTitle, minVal, maxVal, initVal):
|
||||
wx.SpinCtrl.__init__(self, parent, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_RIGHT)
|
||||
self.SetRange(minVal, maxVal)
|
||||
self.SetValue(initVal)
|
||||
self.Bind(wx.EVT_SPINCTRL, self.Adjusted)
|
||||
def Adjusted(self, event):
|
||||
print self.GetValue()
|
||||
|
||||
############################
|
||||
|
||||
|
||||
############################
|
||||
# WxPython Application class
|
||||
############################
|
||||
|
||||
# main class to instantiate the above classes and pack them using nested sizers
|
||||
|
||||
class MyApp(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, -1, "Geant4Py", wx.DefaultPosition, size=(650,500))
|
||||
self.nb = wx.Notebook(self, -1, wx.DefaultPosition, size=(650,500),
|
||||
style=
|
||||
wx.NB_TOP # | wx.NB_MULTILINE
|
||||
#wx.NB_BOTTOM
|
||||
#wx.NB_LEFT
|
||||
#wx.NB_RIGHT
|
||||
)
|
||||
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
|
||||
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
|
||||
|
||||
panel = wx.Panel(self.nb)
|
||||
self.nb.AddPage(panel, "Lesson1")
|
||||
|
||||
commandPanel = wx.Panel(self.nb)
|
||||
self.nb.AddPage(commandPanel, "Geant4 Commands")
|
||||
comP = ComPanel(commandPanel)
|
||||
gxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
gxsizer.Add(comP)
|
||||
commandPanel.SetSizer(gxsizer)
|
||||
|
||||
visualizationPanel = wx.Panel(self.nb)
|
||||
self.nb.AddPage(visualizationPanel, "Vis Commands")
|
||||
visP = VisPanel(visualizationPanel)
|
||||
vxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
vxsizer.Add(visP)
|
||||
visualizationPanel.SetSizer(vxsizer)
|
||||
|
||||
|
||||
# outmost sizer in the vertical direction
|
||||
bxsizer = wx.BoxSizer(wx.VERTICAL)
|
||||
# nested sizer in the horizontal direction
|
||||
bysizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
self.runStart = wx.Button(panel, -1, " Run Start", pos=(30,10), size=(80,30))
|
||||
self.Bind(wx.EVT_BUTTON, self.RunStart, self.runStart)
|
||||
bxsizer.Add(self.runStart, 0, wx.ALL)
|
||||
# widgets
|
||||
|
||||
|
||||
materialList = absorber.keys()
|
||||
self.theMaterial = SelectOne(panel, "Materials", materialList)
|
||||
|
||||
particleList = ['gamma', 'e-', 'proton']
|
||||
self.theParticle = SelectOne(panel, "Particles", particleList)
|
||||
|
||||
self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annihil", "hIoni"]
|
||||
self.theProcesses = Processes(panel, "Processes", self.processList)
|
||||
|
||||
self.eventNo = Adjuster(panel, "Number of Events", 1 , 100 , 1)
|
||||
|
||||
self.lengthUnit = {'micrometer':micrometer, 'mm':mm, 'cm':cm, 'm':m}
|
||||
self.thickSpin = FloatCounter(panel, "absorber thickness", self.lengthUnit.keys())
|
||||
|
||||
self.energyUnit = { 'keV':keV, 'MeV':MeV, 'GeV':GeV, 'TeV':TeV, 'PeV':PeV}
|
||||
self.energySpin = FloatCounter(panel, "incident beam energy", self.energyUnit.keys())
|
||||
|
||||
# now sizers
|
||||
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theMaterial, 0, wx.EXPAND, 10)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theParticle, 0, wx.EXPAND, 10)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theProcesses.sizer, 0, wx.EXPAND, 10)
|
||||
|
||||
bxsizer.Add(bysizer, 0, wx.EXPAND)
|
||||
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.energySpin.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.thickSpin.sizer, 0, wx.EXPAND)
|
||||
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.eventNo.sizer, 0, wx.EXPAND)
|
||||
|
||||
self.solid = EZgeom.G4EzVolume.GetSold(water_phantom)
|
||||
|
||||
panel.SetSizer(bxsizer)
|
||||
bxsizer.Fit(self)
|
||||
bxsizer.SetSizeHints(self)
|
||||
|
||||
def OnPageChanged(self, event):
|
||||
old = event.GetOldSelection()
|
||||
new = event.GetSelection()
|
||||
sel = self.nb.GetSelection()
|
||||
event.Skip()
|
||||
|
||||
def OnPageChanging(self, event):
|
||||
old = event.GetOldSelection()
|
||||
new = event.GetSelection()
|
||||
sel = self.nb.GetSelection()
|
||||
event.Skip()
|
||||
|
||||
|
||||
###### Run Action
|
||||
|
||||
|
||||
def RunStart(self, event):
|
||||
materialChosen = str( self.theMaterial.GetStringSelection() )
|
||||
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.thickSpin.theValue * self.lengthUnit[self.thickSpin.theUnit] / 2.0 )
|
||||
|
||||
#
|
||||
gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + "Geant4Py in Action")
|
||||
gApplyUICommand("/vis/viewer/flush")
|
||||
gApplyUICommand("/gun/particle " + str ( self.theParticle.GetStringSelection() ) )
|
||||
for i in self.processList:
|
||||
# print i, self.theProcesses.processCheck[i].GetValue()
|
||||
gProcessTable.SetProcessActivation(i, 1)
|
||||
if self.theProcesses.processCheck[i].GetValue() != True:
|
||||
gProcessTable.SetProcessActivation(i, 0)
|
||||
|
||||
gApplyUICommand("/gun/energy " + str ( self.energySpin.valAndUnit.GetValue() ) )
|
||||
|
||||
eventNum = self.eventNo.slider.GetValue()
|
||||
for i in range(eventNum):
|
||||
gunYZpos = str(i-eventNum/2) + ". -50. cm"
|
||||
gApplyUICommand("/gun/position 0. " + gunYZpos)
|
||||
gRunManager.BeamOn(1)
|
||||
# next line is necessary for vrml to draw trajectories
|
||||
gApplyUICommand("/vis/viewer/update")
|
||||
|
||||
app = wx.PySimpleApp(False)
|
||||
MyApp().Show()
|
||||
app.MainLoop()
|
||||
@@ -0,0 +1,319 @@
|
||||
#!/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 ExN03pl
|
||||
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
|
||||
# ------------------------------------------------------------------
|
||||
ExN03pl.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-", "proton"):
|
||||
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)
|
||||
|
||||
|
||||
#on off processes
|
||||
|
||||
processLabel = Label(self, text="Process On/Off", bg="green")
|
||||
processLabel.grid(row=8, column=0, sticky=W)
|
||||
procTab = {}
|
||||
self.processList = ["phot", "compt", "msc", "conv", "eIoni", "eBrem", "hIoni"]
|
||||
self.processVar = {}
|
||||
pos = 1
|
||||
for i in self.processList:
|
||||
self.processVar[i] = IntVar()
|
||||
procTab[i] = Checkbutton(self, text=i, variable=self.processVar[i], command=self.cmd_setProcess)
|
||||
procTab[i].grid(row=8, column=pos, sticky=W)
|
||||
pos = pos + 1
|
||||
procTab[i].select()
|
||||
|
||||
|
||||
#Zoom in/out Pan X Y row=9
|
||||
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=9, column=0, sticky=W)
|
||||
expandBut.grid(row=9, column=1, sticky=W)
|
||||
shrinkBut.grid(row=9, 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=9, column=3, sticky=W)
|
||||
downBut.grid(row=9, 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=9, column=5, sticky=W)
|
||||
rightBut.grid(row=9, 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_setProcess(self):
|
||||
for i in self.processList:
|
||||
if self.processVar[i].get() == 0:
|
||||
gProcessTable.SetProcessActivation(i, 0)
|
||||
else:
|
||||
gProcessTable.SetProcessActivation(i, 1)
|
||||
|
||||
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()
|
||||
@@ -1,7 +1,21 @@
|
||||
09 March 2006
|
||||
Hajime Yoshida
|
||||
|
||||
******* README of lesson1 ******
|
||||
|
||||
26 September 2006
|
||||
- Lesson1.py as before
|
||||
- Lesson1withN03.py
|
||||
- physics is list is taken from examples/novice/N03
|
||||
- process on/off
|
||||
- Leson1Wx.py
|
||||
- same as Lesson1withN03 but
|
||||
- New GUI toolkit is used and the default Python isn't enough
|
||||
- wxPython is necessary
|
||||
|
||||
|
||||
26 May 2006 Geant4.8.1
|
||||
|
||||
Hajime Yoshida
|
||||
|
||||
|
||||
The first version of the courseware of the mass attenuation coefficient
|
||||
|
||||
|
||||
@@ -0,0 +1,598 @@
|
||||
#### 2006 Sep 26, the first draft version
|
||||
## Wired not yet. g4pipe control and Popen
|
||||
|
||||
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()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 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()
|
||||
|
||||
|
||||
# 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, vrmlViewer
|
||||
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")
|
||||
|
||||
|
||||
# test############################################################################TESSSSSSST
|
||||
gApplyUICommand("/vis/viewer/select oglsxviewer")
|
||||
gApplyUICommand("/vis/scene/add/trajectories")
|
||||
|
||||
gApplyUICommand("/tracking/storeTrajectory 1")
|
||||
gApplyUICommand("/vis/scene/endOfEventAction accumulate")
|
||||
gApplyUICommand("/vis/scene/endOfRunAction accumulate")
|
||||
#test########################################################################################
|
||||
|
||||
global commandDic, commandList
|
||||
commandDic = {}
|
||||
commandList = []
|
||||
|
||||
def DumpTree(atree):
|
||||
|
||||
ntree= atree.GetTreeEntry()
|
||||
ncommand= atree.GetCommandEntry()
|
||||
for i in range(1, ncommand+1):
|
||||
icommand= atree.GetCommand(i)
|
||||
command = str( icommand.GetCommandPath())
|
||||
commandList.append(command)
|
||||
nparameter= icommand.GetParameterEntries()
|
||||
pguide = ""
|
||||
for j in range(0, nparameter):
|
||||
iparam= icommand.GetParameter(j)
|
||||
pguide = pguide + "Parameter: " + str(iparam.GetParameterName())+ " Type: " + str(iparam.GetParameterType()) + '\n'
|
||||
guide = str(icommand.GetTitle()) + '\n' + pguide
|
||||
commandDic[command] = guide
|
||||
|
||||
for i in range(1, ntree+1):
|
||||
itree= atree.GetTree(i)
|
||||
DumpTree(itree)
|
||||
|
||||
|
||||
root_tree= gUImanager.GetTree()
|
||||
DumpTree(root_tree)
|
||||
|
||||
|
||||
|
||||
|
||||
###### wxPython GUI ##########
|
||||
|
||||
|
||||
import wx
|
||||
|
||||
|
||||
|
||||
class ComPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
|
||||
self.g4comText = wx.TextCtrl(parent, -1, "enter Command", pos=(10,10), size=(300, 30))
|
||||
self.g4comExec = wx.Button(parent, -1, "Execute", pos=(320,10), size=(60,30))
|
||||
self.g4comExec.Bind(wx.EVT_BUTTON, self.ExecuteCommand, self.g4comExec)
|
||||
# self.sizerE = wx.BoxSizer(wx.HORIZONTAL)
|
||||
# self.sizerE.Add(self.g4comText)
|
||||
# self.sizerE.Add(self.g4comExec)
|
||||
|
||||
# self.sizerL = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.comListBox = wx.ListBox(parent, -1, pos=(10,50), size=(300,200), choices=commandList, style=wx.LB_SINGLE)
|
||||
self.comListBox.SetSelection(1)
|
||||
self.comListBox.Bind(wx.EVT_LISTBOX, self.ShowGuide, self.comListBox)
|
||||
# self.sizerL.Add(self.comListBox)
|
||||
|
||||
self.guide = wx.TextCtrl(parent, -1, "guidance", pos=(320,50), size=(300, 200), style =wx.TE_MULTILINE)
|
||||
self.guide.Bind(wx.EVT_LISTBOX, self.ShowGuide, self.guide)
|
||||
|
||||
# self.sizerL.Add(self.guide)
|
||||
# self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
# self.sizer.Add(self.sizerE)
|
||||
# self.sizer.Add(self.sizerL)
|
||||
# self.SetSizer(self.sizer)
|
||||
|
||||
def ShowGuide(self, event):
|
||||
self.guide.Clear() # how to cleat the whole text before showing the next
|
||||
g4com =str(self.comListBox.GetStringSelection())
|
||||
self.guide.WriteText( commandDic[g4com])
|
||||
self.g4comText.SetValue(g4com)
|
||||
|
||||
def ExecuteCommand(self, event):
|
||||
gApplyUICommand(str(self.g4comText.GetValue()))
|
||||
|
||||
class VisPanel(wx.Panel):
|
||||
def __init__(self, parent):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
|
||||
self.visZoomIn = wx.Button(parent, -1, "Zoom In", pos=(10,100), size=(80,30))
|
||||
self.visZoomOut = wx.Button(parent, -1, "Zoom out", pos=(100,100), size=(80,30))
|
||||
self.visUp = wx.Button(parent, -1, "Up", pos=(190,100), size=(80,30))
|
||||
self.visDown = wx.Button(parent, -1, "Down", pos=(270,100), size=(80,30))
|
||||
self.visLeft = wx.Button(parent, -1, "Left", pos=(360,100), size=(80,30))
|
||||
self.visRight = wx.Button(parent, -1, "Left", pos=(450,100), size=(80,30))
|
||||
|
||||
viewerList = ["OpenGL", "VRML", "Wired"]
|
||||
self.viewer = wx.RadioBox(self, -1, "Viewer", pos=(10,10),
|
||||
size=(210,60), choices=viewerList, majorDimension=1, style=wx.RA_SPECIFY_ROWS)
|
||||
self.viewer.Bind(wx.EVT_RADIOBOX, self.ViewerSelected, self.viewer)
|
||||
self.viewer.SetToolTip(wx.ToolTip("Select one"))
|
||||
self.viewer.SetSelection(0)
|
||||
if vrmlViewer == None: self.viewer.EnableItem(1, False)
|
||||
if heprepViewer == None: self.viewer.EnableItem(2, False)
|
||||
# self.sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
# self.sizer.Add((20,30))
|
||||
# self.sizer.Add(self.visZoomIn)
|
||||
# self.sizer.Add(self.visZoomOut)
|
||||
# self.sizer.Add(self.visUp)
|
||||
# self.sizer.Add(self.visDown)
|
||||
# self.sizer.Add(self.visRight)
|
||||
# self.sizer.Add(self.visLeft)
|
||||
# self.SetSizer(self.sizer)
|
||||
|
||||
# self.visZoomIn = wx.Button(parent, -1, "Zoom In", pos=(10,70), size=(80,30))
|
||||
# self.visZoomOut = wx.Button(parent, -1, "Zoom out", pos=(100,70), size=(80,30))
|
||||
# self.visUp = wx.Button(parent, -1, "Up", pos=(10,50), size=(190,70))
|
||||
# self.visDown = wx.Button(parent, -1, "Down", pos=(100,50), size=(270,70))
|
||||
# self.visLeft = wx.Button(parent, -1, "Left", pos=(10,90), size=(360,70))
|
||||
# self.visRight = wx.Button(parent, -1, "Left", pos=(100,90), size=(450,70))
|
||||
|
||||
|
||||
|
||||
self.visZoomIn.Bind(wx.EVT_BUTTON, self.cmdExpand, self.visZoomIn)
|
||||
self.visZoomOut.Bind(wx.EVT_BUTTON, self.cmdShrink, self.visZoomOut)
|
||||
self.visUp.Bind(wx.EVT_BUTTON, self.cmdUp, self.visUp)
|
||||
self.visDown.Bind(wx.EVT_BUTTON, self.cmdDown, self.visDown)
|
||||
self.visRight.Bind(wx.EVT_BUTTON, self.cmdRight, self.visRight)
|
||||
self.visLeft.Bind(wx.EVT_BUTTON, self.cmdLeft, self.visLeft)
|
||||
|
||||
def cmdExpand(self, event):
|
||||
gApplyUICommand("/vis/viewer/zoom 1.2")
|
||||
def cmdShrink(self, event):
|
||||
gApplyUICommand("/vis/viewer/zoom 0.8")
|
||||
def cmdUp(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 0. 10. mm")
|
||||
def cmdDown(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 0. -10. mm")
|
||||
def cmdRight(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " -10. 0. mm")
|
||||
def cmdLeft(self, event):
|
||||
gApplyUICommand("/vis/viewer/pan " + " 10. 0. mm")
|
||||
|
||||
def ViewerSelected(self, event):
|
||||
self.viewerName = event.GetString()
|
||||
|
||||
if self.viewerName == "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.viewerName == "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.viewerName == "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")
|
||||
|
||||
# everytime wired is chosen, a new instance of wired is created
|
||||
# to reuse single wired, g4pipe.poll() must be checked BEFORE the SECOND Popen
|
||||
# if g4pipe.poll() == None:
|
||||
g4pipe=Popen(heprepViewer+ " -file " + heprepDir+"/" +heprepName +".heprep", shell=True)
|
||||
|
||||
|
||||
|
||||
# not used
|
||||
class MyText(wx.StaticText):
|
||||
def __init__(self, parent, Text):
|
||||
wx.StaticText.__init__(self, parent, -1, Text, pos=(20,20))
|
||||
self.Bind(wx.EVT_LEFT_UP, self.ChangeColor)
|
||||
|
||||
def ChangeColor(self, event):
|
||||
TheColour = self.GetForegroundColour()
|
||||
if TheColour == (0,0,0):
|
||||
self.SetLabel("Simulation is running!")
|
||||
self.SetForegroundColour("red")
|
||||
else:
|
||||
self.SetLabel("Click me to start a run")
|
||||
self.SetForegroundColour("black")
|
||||
|
||||
# to be used to choose materials and particles
|
||||
# myList is a list of keys() of a dictionary
|
||||
# f.e., materials are Python objects with their names as their keys
|
||||
class SelectOne(wx.RadioBox):
|
||||
def __init__(self, parent, myTitle, myList):
|
||||
wx.RadioBox.__init__(self, parent, -1, myTitle, wx.DefaultPosition,
|
||||
wx.DefaultSize, myList, 5, wx.RA_SPECIFY_ROWS)
|
||||
# self.Bind(wx.EVT_RADIOBOX, self.Selected)
|
||||
self.SetToolTip(wx.ToolTip("Select one"))
|
||||
self.SetSelection(0)
|
||||
# used only to test Bind and getValue
|
||||
# def Selected(self, event):
|
||||
# self.selected = event.GetString()
|
||||
|
||||
|
||||
# used to %3.3f floating point number
|
||||
# energy and length unit is given by unitList which must be a dictionary
|
||||
# with units of Python objects and their name as their keys
|
||||
|
||||
class FloatCounter(wx.Panel):
|
||||
def __init__(self, parent, myTitle, unitList):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
|
||||
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.sizer.Add((10, -1))
|
||||
self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
|
||||
|
||||
self.intPart = wx.SpinCtrl(parent, -1, "", wx.DefaultPosition, (60,-1))
|
||||
self.intPart.SetRange(0,999)
|
||||
self.intPart.SetValue(1)
|
||||
self.intPart.Bind(wx.EVT_SPINCTRL, self.SetFloat)
|
||||
|
||||
self.manPart = wx.SpinCtrl(parent, -1, "", wx.DefaultPosition, (50, -1))
|
||||
self.manPart.SetRange(0,999)
|
||||
self.manPart.SetValue(0)
|
||||
self.manPart.Bind(wx.EVT_SPINCTRL, self.SetFloat)
|
||||
|
||||
self.unitSel = wx.Choice(parent, -1, wx.DefaultPosition, (90, -1), unitList)
|
||||
self.unitSel.Bind(wx.EVT_CHOICE, self.SetFloat, self.unitSel)
|
||||
self.unitSel.SetSelection(2)
|
||||
|
||||
self.valAndUnit = wx.TextCtrl(parent, -1, "value unset", wx.DefaultPosition, (150, -1))
|
||||
|
||||
self.sizer.Add(self.valAndUnit)
|
||||
self.sizer.Add((10, -1))
|
||||
self.sizer.Add(wx.StaticText(parent, -1, " ", wx.DefaultPosition, (30, -1)))
|
||||
self.sizer.Add(self.intPart)
|
||||
self.sizer.Add(wx.StaticText(parent, -1, ".", wx.DefaultPosition, (10, -1)))
|
||||
self.sizer.Add(self.manPart)
|
||||
self.sizer.Add((5,-1))
|
||||
self.sizer.Add(self.unitSel)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
def SetFloat(self, event):
|
||||
self.theValueStr = str(self.intPart.GetValue()) + "." + str(self.manPart.GetValue()) + " "
|
||||
self.theValue = float (self.intPart.GetValue()) + float(self.manPart.GetValue())/ 1000.
|
||||
self.theUnit = self.unitSel.GetStringSelection()
|
||||
theText = "%.3f" % (self.theValue) + " " + self.theUnit
|
||||
self.valAndUnit.SetValue(theText)
|
||||
# user may edit the Entry, so finnaly this value must be got
|
||||
# but it doesn't work for length but work for energy (gApplyUIcommnd)
|
||||
theTextWithStar = "%.3f" % (self.theValue) + " * " + self.theUnit
|
||||
|
||||
# special class for this example to set/unset processes
|
||||
class Processes(wx.Panel):
|
||||
def __init__(self, parent, myTitle, myList):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
self.processCheck = {}
|
||||
self.sizer = wx.FlexGridSizer(rows=5)
|
||||
self.sizer.AddGrowableRow(1)
|
||||
for item in myList:
|
||||
self.processCheck[item] = wx.CheckBox(parent, -1, item)
|
||||
self.processCheck[item].SetValue(True)
|
||||
# self.processCheck[item].Bind(wx.EVT_CHECKBOX, self.CheckedProcess)
|
||||
self.sizer.Add(self.processCheck[item],0,wx.EXPAND)
|
||||
|
||||
self.SetSizer(self.sizer)
|
||||
self.SetBackgroundColour('green')
|
||||
self.processState = {}
|
||||
self.myList = myList
|
||||
|
||||
# test only
|
||||
# def CheckedProcess(self, event):
|
||||
# self.processName = event.GetEventObject().GetLabel()
|
||||
# self.processState = event.GetEventObject().GetValue()
|
||||
|
||||
|
||||
# slider to set an integer value
|
||||
# title is shown
|
||||
class Adjuster(wx.Panel):
|
||||
def __init__(self, parent, myTitle, minVal, maxVal, initVal):
|
||||
wx.Panel.__init__(self, parent, -1)
|
||||
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.sizer.Add((10, -1))
|
||||
self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
|
||||
self.slider = wx.Slider(parent, -1, initVal, minVal, maxVal,
|
||||
wx.DefaultPosition, (300, -1),
|
||||
wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
|
||||
self.slider.SetPageSize(1)
|
||||
self.sizer.Add(self.slider)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
# test only
|
||||
# self.Bind(wx.EVT_SLIDER, self.Adjusted)
|
||||
|
||||
# def Adjusted(self, event):
|
||||
# print self.GetValue()
|
||||
|
||||
|
||||
########################## no use now
|
||||
class Counter(wx.SpinCtrl):
|
||||
def __init__(self, parent, myTitle, minVal, maxVal, initVal):
|
||||
wx.SpinCtrl.__init__(self, parent, -1, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_RIGHT)
|
||||
self.SetRange(minVal, maxVal)
|
||||
self.SetValue(initVal)
|
||||
self.Bind(wx.EVT_SPINCTRL, self.Adjusted)
|
||||
def Adjusted(self, event):
|
||||
print self.GetValue()
|
||||
|
||||
############################
|
||||
|
||||
# main class to instantiate the above classes and pack them using nested sizers
|
||||
g4pipe=0
|
||||
|
||||
class MyApp(wx.Frame):
|
||||
def __init__(self):
|
||||
wx.Frame.__init__(self, None, -1, "Geant4Py")
|
||||
self.nb = wx.Notebook(self, -1, wx.DefaultPosition, wx.DefaultSize,
|
||||
style=
|
||||
wx.NB_TOP # | wx.NB_MULTILINE
|
||||
#wx.NB_BOTTOM
|
||||
#wx.NB_LEFT
|
||||
#wx.NB_RIGHT
|
||||
)
|
||||
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
|
||||
self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
|
||||
|
||||
panel = wx.Panel(self.nb)
|
||||
self.nb.AddPage(panel, "ExampleN03")
|
||||
commandPanel = wx.Panel(self.nb)
|
||||
self.nb.AddPage(commandPanel, "Geant4 Commands")
|
||||
comP = ComPanel(commandPanel)
|
||||
gxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
gxsizer.Add(comP)
|
||||
commandPanel.SetSizer(gxsizer)
|
||||
|
||||
|
||||
visualizationPanel = wx.Panel(self.nb)
|
||||
self.nb.AddPage(visualizationPanel, "Vis Commands")
|
||||
visP = VisPanel(visualizationPanel)
|
||||
vxsizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
vxsizer.Add(visP)
|
||||
visualizationPanel.SetSizer(vxsizer)
|
||||
|
||||
# outmost sizer in the vertical direction
|
||||
bxsizer = wx.BoxSizer(wx.VERTICAL)
|
||||
# nested sizer in the horizontal direction
|
||||
bysizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
|
||||
|
||||
self.runStart = wx.Button(panel, -1, " Run Start", wx.DefaultPosition, wx.DefaultSize)
|
||||
self.Bind(wx.EVT_BUTTON, self.RunStart, self.runStart)
|
||||
bxsizer.Add(self.runStart, 0, wx.ALL)
|
||||
# widgets
|
||||
|
||||
absorberMaterialList = ['Aluminium', 'Lead']
|
||||
self.theAbsorberMaterial = SelectOne(panel, "Absorber Materials", absorberMaterialList)
|
||||
gapMaterialList = ["liquidArgon","Scintillator", "Air", "Aerogel", "Galactic"]
|
||||
self.theGapMaterial = SelectOne(panel, "Gap Materials", gapMaterialList)
|
||||
|
||||
particleList = ["proton", "gamma", "e-", "e+", "mu-", "mu+"]
|
||||
self.theParticle = SelectOne(panel, "Particles", particleList)
|
||||
|
||||
self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annihil","muIoni", "muBrems", "hIoni"]
|
||||
self.theProcesses = Processes(panel, "Processes", self.processList)
|
||||
|
||||
self.eventNo = Adjuster(panel, "Number of Events", 1 , 100 , 1)
|
||||
self.layerNo = Adjuster(panel, "Number of Layers", 1, 10, 10)
|
||||
|
||||
self.lengthUnit = {'micrometer':micrometer, 'mm':mm, 'cm':cm, 'm':m}
|
||||
self.absorberThickSpin = FloatCounter(panel, "Absorber Thickness", self.lengthUnit.keys())
|
||||
self.gapThickSpin = FloatCounter(panel, "Gap Thickness", self.lengthUnit.keys())
|
||||
self.sizeYZSpin = FloatCounter(panel, "Section Size", self.lengthUnit.keys())
|
||||
self.cutLengthSpin = FloatCounter(panel, "Cut Length", self.lengthUnit.keys())
|
||||
self.magneticUnit = {'Tesla':tesla, 'gauss':gauss, 'kilogauss':kilogauss}
|
||||
self.magneticFieldSpin = FloatCounter(panel, "Magnetic Field", self.magneticUnit.keys())
|
||||
|
||||
self.energyUnit = { 'keV':keV, 'MeV':MeV, 'GeV':GeV, 'TeV':TeV, 'PeV':PeV}
|
||||
self.energySpin = FloatCounter(panel, "incident beam energy", self.energyUnit.keys())
|
||||
|
||||
|
||||
# now sizers
|
||||
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theAbsorberMaterial, 0, wx.EXPAND, 10)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theGapMaterial, 0, wx.EXPAND, 10)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theParticle, 0, wx.EXPAND, 10)
|
||||
bysizer.Add((10, -1))
|
||||
bysizer.Add(self.theProcesses.sizer, 0, wx.EXPAND, 10)
|
||||
|
||||
bxsizer.Add(bysizer, 0, wx.EXPAND)
|
||||
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.layerNo.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(self.absorberThickSpin.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(self.gapThickSpin.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(self.sizeYZSpin.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
|
||||
bxsizer.Add(self.energySpin.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.cutLengthSpin.sizer, 0, wx.EXPAND)
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.magneticFieldSpin.sizer, 0, wx.EXPAND)
|
||||
|
||||
bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
|
||||
bxsizer.Add(self.eventNo.sizer, 0, wx.EXPAND)
|
||||
|
||||
# self.solid = EZgeom.G4EzVolume.GetSold(water_phantom)
|
||||
# gControlExecute("oglx.mac")
|
||||
|
||||
panel.SetSizer(bxsizer)
|
||||
bxsizer.Fit(self)
|
||||
bxsizer.SetSizeHints(self)
|
||||
def OnPageChanged(self, event):
|
||||
old = event.GetOldSelection()
|
||||
new = event.GetSelection()
|
||||
sel = self.nb.GetSelection()
|
||||
event.Skip()
|
||||
|
||||
def OnPageChanging(self, event):
|
||||
old = event.GetOldSelection()
|
||||
new = event.GetSelection()
|
||||
sel = self.nb.GetSelection()
|
||||
event.Skip()
|
||||
|
||||
def RunStart(self, event):
|
||||
|
||||
absorberTh = self.absorberThickSpin.theValue * self.lengthUnit[self.absorberThickSpin.theUnit]/2.0
|
||||
gapTh = self.gapThickSpin.theValue * self.lengthUnit[self.gapThickSpin.theUnit]/2.0
|
||||
yzSize = self.sizeYZSpin.theValue * self.lengthUnit[self.sizeYZSpin.theUnit]
|
||||
print "BUG"
|
||||
cutLen = self.cutLengthSpin.theValue * self.lengthUnit[self.cutLengthSpin.theUnit]
|
||||
magF = self.magneticFieldSpin.theValue * self.magneticUnit[self.magneticFieldSpin.theUnit]
|
||||
|
||||
exN03geom.SetNbOfLayers(self.layerNo.slider.GetValue())
|
||||
exN03geom.SetAbsorberMaterial(str(self.theAbsorberMaterial.GetStringSelection()))
|
||||
exN03geom.SetAbsorberThickness(absorberTh)
|
||||
exN03geom.SetGapMaterial(str(self.theGapMaterial.GetStringSelection()))
|
||||
exN03geom.SetGapThickness(gapTh)
|
||||
exN03geom.SetCalorSizeYZ(yzSize)
|
||||
position = -self.layerNo.slider.GetValue() * ( absorberTh + gapTh )*1.2
|
||||
|
||||
exN03geom.UpdateGeometry()
|
||||
exN03PL.SetDefaultCutValue(cutLen)
|
||||
exN03PL.SetCutsWithDefault()
|
||||
exN03geom.SetMagField(magF)
|
||||
|
||||
print "Now geometry updated"
|
||||
|
||||
print position
|
||||
|
||||
# gApplyUICommand("/vis/viewer/flush")
|
||||
# gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + "wxPython")
|
||||
|
||||
gApplyUICommand("/gun/particle " + str ( self.theParticle.GetStringSelection() ) )
|
||||
for i in self.processList:
|
||||
# print i, self.theProcesses.processCheck[i].GetValue()
|
||||
gProcessTable.SetProcessActivation(i, 1)
|
||||
if self.theProcesses.processCheck[i].GetValue() != True:
|
||||
gProcessTable.SetProcessActivation(i, 0)
|
||||
|
||||
gApplyUICommand("/gun/energy " + str ( self.energySpin.valAndUnit.GetValue() ) )
|
||||
|
||||
eventNum = self.eventNo.slider.GetValue()
|
||||
for i in range(eventNum):
|
||||
pg.SetParticlePosition(G4ThreeVector(position, (i-eventNum/2)*5.*mm, 0.*cm))
|
||||
gRunManager.BeamOn(1)
|
||||
# sleep(0.01)
|
||||
gApplyUICommand("/vis/viewer/update")
|
||||
|
||||
|
||||
app = wx.PySimpleApp(False)
|
||||
MyApp().Show()
|
||||
app.MainLoop()
|
||||
@@ -1,3 +1,8 @@
|
||||
26 Sep 2006
|
||||
- added Lesson2Wx.py
|
||||
New version using wxPython
|
||||
functionas are identical with ExN03.py
|
||||
|
||||
26 May 2006
|
||||
revised 02 July 2006
|
||||
Geant4.8.1 release
|
||||
|
||||
Reference in New Issue
Block a user