4 import g4py.NISTmaterials
6 from g4py.ezgeom
import G4EzVolume
8 import g4py.ParticleGun
11 from subprocess
import *
22 g4py.NISTmaterials.Construct()
27 g4py.ezgeom.Construct()
32 g4py.ExN03pl.Construct()
37 g4py.ParticleGun.Construct()
45 print "* Constructing geometry..."
57 absorber = {
"air":air,
"aluminum":aluminum,
"iron":iron,
"lead":lead,
"water":water,
"gold":gold
59 g4py.ezgeom.SetWorldMaterial(galactic)
60 g4py.ezgeom.ResizeWorld(120.*cm, 120.*cm, 100.*cm)
62 global water_phantom, water_phantom_pv
64 water_phantom= G4EzVolume(
"WaterPhantom")
65 water_phantom.CreateBoxVolume(water, 110.*cm, 110.*cm, 10.*cm)
66 water_phantom_pv = water_phantom.PlaceIt(
G4ThreeVector(0.,0.,0.*cm))
75 rand_engine= Ranlux64Engine()
76 HepRandom.setTheEngine(rand_engine)
77 HepRandom.setTheSeed(20050830L)
87 gRunManager.Initialize()
91 global commandDic, commandList
97 ntree= atree.GetTreeEntry()
98 ncommand= atree.GetCommandEntry()
99 for i
in range(1, ncommand+1):
100 icommand= atree.GetCommand(i)
101 command = str( icommand.GetCommandPath())
102 commandList.append(command)
103 nparameter= icommand.GetParameterEntries()
105 for j
in range(0, nparameter):
106 iparam= icommand.GetParameter(j)
107 pguide = pguide +
"Parameter: " + str(iparam.GetParameterName())+
" Type: " + str(iparam.GetParameterType()) +
'\n'
108 guide = str(icommand.GetTitle()) +
'\n' + pguide
109 commandDic[command] = guide
111 for i
in range(1, ntree+1):
112 itree= atree.GetTree(i)
115 root_tree= gUImanager.GetTree()
141 global heprepViewer, heprepDir, heprepName, vrmlViewer
142 heprepViewer = os.environ.get(
"G4HEPREPFILE_VIEWER")
143 heprepDir = os.environ.get(
"G4HEPREPFILE_DIR")
144 heprepName = os.environ.get(
"G4HEPREPFILE_NAME")
145 if heprepViewer
is not None:
150 vrmlDir = os.environ.get(
"G4VRML_DEST_DIR")
151 vrmlViewer = os.environ.get(
"G4VRMLFILE_VIEWER")
152 if vrmlViewer
is not None:
164 wx.Panel.__init__(self, parent, -1)
166 self.
g4comText = wx.TextCtrl(parent, -1,
"enter Command", pos=(10,10), size=(300, 30))
168 self.
g4comExec = wx.Button(parent, -1,
"Execute", pos=(320,10), size=(60,30))
171 self.
comListBox = wx.ListBox(parent, -1, pos=(10,50), size=(300,200), choices=commandList, style=wx.LB_SINGLE)
172 self.comListBox.SetSelection(1)
175 self.
guide = wx.TextCtrl(parent, -1,
"guidance", pos=(320,50), size=(300, 200), style =wx.TE_MULTILINE)
181 g4com =str(self.comListBox.GetStringSelection())
182 self.guide.WriteText( commandDic[g4com])
183 self.g4comText.SetValue(g4com)
191 wx.Panel.__init__(self, parent, -1)
193 self.
visZoomIn = wx.Button(parent, -1,
"Zoom In", pos=(10,100), size=(80,30))
194 self.
visZoomOut = wx.Button(parent, -1,
"Zoom out", pos=(100,100), size=(80,30))
195 self.
visUp = wx.Button(parent, -1,
"Up", pos=(190,100), size=(80,30))
196 self.
visDown = wx.Button(parent, -1,
"Down", pos=(270,100), size=(80,30))
197 self.
visLeft = wx.Button(parent, -1,
"Left", pos=(360,100), size=(80,30))
198 self.
visRight = wx.Button(parent, -1,
"Left", pos=(450,100), size=(80,30))
200 viewerList = [
"OpenGL",
"VRML",
"Wired"]
201 self.
viewer = wx.RadioBox(self, -1,
"Viewer", pos=(10,10),
202 size=(210,60), choices=viewerList, majorDimension=1, style=wx.RA_SPECIFY_ROWS)
204 self.viewer.SetToolTip(wx.ToolTip(
"Select one"))
205 self.viewer.SetSelection(0)
206 if vrmlViewer ==
None: self.viewer.EnableItem(1,
False)
207 if heprepViewer ==
None: self.viewer.EnableItem(2,
False)
211 self.visUp.Bind(wx.EVT_BUTTON, self.
cmdUp, self.
visUp)
270 g4pipe=Popen(heprepViewer+
" -file " + heprepDir+
"/" +heprepName +
".heprep", shell=
True)
276 wx.StaticText.__init__(self, parent, -1, Text, pos=(20,20))
280 TheColour = self.GetForegroundColour()
281 if TheColour == (0,0,0):
282 self.SetLabel(
"Simulation is running!")
283 self.SetForegroundColour(
"red")
285 self.SetLabel(
"Click me to start a run")
286 self.SetForegroundColour(
"black")
293 wx.RadioBox.__init__(self, parent, -1, myTitle, wx.DefaultPosition,
294 wx.DefaultSize, myList, 3, wx.RA_SPECIFY_ROWS)
296 self.SetToolTip(wx.ToolTip(
"Select one"))
309 wx.Panel.__init__(self, parent, -1)
311 self.
sizer = wx.BoxSizer(wx.HORIZONTAL)
312 self.sizer.Add((10, -1))
313 self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
315 self.
intPart = wx.SpinCtrl(parent, -1,
"", wx.DefaultPosition, (60,-1))
316 self.intPart.SetRange(0,999)
317 self.intPart.SetValue(1)
318 self.intPart.Bind(wx.EVT_SPINCTRL, self.
SetFloat)
320 self.
manPart = wx.SpinCtrl(parent, -1,
"", wx.DefaultPosition, (50, -1))
321 self.manPart.SetRange(0,999)
322 self.manPart.SetValue(0)
323 self.manPart.Bind(wx.EVT_SPINCTRL, self.
SetFloat)
325 self.
unitSel = wx.Choice(parent, -1, wx.DefaultPosition, (90, -1), unitList)
327 self.unitSel.SetSelection(2)
329 self.
valAndUnit = wx.TextCtrl(parent, -1,
"value unset", wx.DefaultPosition, (150, -1))
332 self.sizer.Add((10, -1))
333 self.sizer.Add(wx.StaticText(parent, -1,
" ", wx.DefaultPosition, (30, -1)))
335 self.sizer.Add(wx.StaticText(parent, -1,
".", wx.DefaultPosition, (10, -1)))
337 self.sizer.Add((5,-1))
339 self.SetSizer(self.
sizer)
343 self.
theValue = float (self.intPart.GetValue()) + float(self.manPart.GetValue())/ 1000.
344 self.
theUnit = self.unitSel.GetStringSelection()
346 self.valAndUnit.SetValue(theText)
354 wx.Panel.__init__(self, parent, -1)
356 self.
sizer = wx.FlexGridSizer(rows=3)
357 self.sizer.AddGrowableRow(1)
364 self.SetSizer(self.
sizer)
365 self.SetBackgroundColour(
'green')
378 def __init__(self, parent, myTitle, minVal, maxVal, initVal):
379 wx.Panel.__init__(self, parent, -1)
380 self.
sizer = wx.BoxSizer(wx.HORIZONTAL)
381 self.sizer.Add((10, -1))
382 self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
383 self.
slider = wx.Slider(parent, -1, initVal, minVal, maxVal,
384 wx.DefaultPosition, (300, -1),
385 wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
386 self.slider.SetPageSize(1)
387 self.sizer.Add(self.
slider)
388 self.SetSizer(self.
sizer)
399 def __init__(self, parent, myTitle, minVal, maxVal, initVal):
400 wx.SpinCtrl.__init__(self, parent, -1,
"", wx.DefaultPosition, wx.DefaultSize, wx.TE_RIGHT)
401 self.SetRange(minVal, maxVal)
402 self.SetValue(initVal)
403 self.Bind(wx.EVT_SPINCTRL, self.
Adjusted)
405 print self.GetValue()
418 wx.Frame.__init__(self,
None, -1,
"Geant4Py", wx.DefaultPosition, size=(650,500))
419 self.
nb = wx.Notebook(self, -1, wx.DefaultPosition, size=(650,500),
426 self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.
OnPageChanged)
429 panel = wx.Panel(self.
nb)
430 self.nb.AddPage(panel,
"Lesson1")
432 commandPanel = wx.Panel(self.
nb)
433 self.nb.AddPage(commandPanel,
"Geant4 Commands")
435 gxsizer = wx.BoxSizer(wx.HORIZONTAL)
437 commandPanel.SetSizer(gxsizer)
439 visualizationPanel = wx.Panel(self.
nb)
440 self.nb.AddPage(visualizationPanel,
"Vis Commands")
442 vxsizer = wx.BoxSizer(wx.HORIZONTAL)
444 visualizationPanel.SetSizer(vxsizer)
448 bxsizer = wx.BoxSizer(wx.VERTICAL)
450 bysizer = wx.BoxSizer(wx.HORIZONTAL)
452 self.
runStart = wx.Button(panel, -1,
" Run Start", pos=(30,10), size=(80,30))
454 bxsizer.Add(self.
runStart, 0, wx.ALL)
458 materialList = absorber.keys()
461 particleList = [
'gamma',
'e-',
'proton']
464 self.
processList = [
"phot",
"compt",
"conv",
"msc",
"eIoni",
"eBrem",
"annihil",
"hIoni"]
469 self.
lengthUnit = {
'micrometer':micrometer,
'mm':mm,
'cm':cm,
'm':m}
472 self.
energyUnit = {
'keV':keV,
'MeV':MeV,
'GeV':GeV,
'TeV':TeV,
'PeV':PeV}
477 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
478 bysizer.Add((10, -1))
480 bysizer.Add((10, -1))
482 bysizer.Add((10, -1))
483 bysizer.Add(self.theProcesses.sizer, 0, wx.EXPAND, 10)
485 bxsizer.Add(bysizer, 0, wx.EXPAND)
487 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
488 bxsizer.Add(self.energySpin.sizer, 0, wx.EXPAND)
489 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
490 bxsizer.Add(self.thickSpin.sizer, 0, wx.EXPAND)
492 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
493 bxsizer.Add(self.eventNo.sizer, 0, wx.EXPAND)
495 self.
solid = g4py.ezgeom.G4EzVolume.GetSold(water_phantom)
497 panel.SetSizer(bxsizer)
499 bxsizer.SetSizeHints(self)
502 old = event.GetOldSelection()
503 new = event.GetSelection()
504 sel = self.nb.GetSelection()
508 old = event.GetOldSelection()
509 new = event.GetSelection()
510 sel = self.nb.GetSelection()
518 materialChosen = str( self.theMaterial.GetStringSelection() )
519 water_phantom.SetMaterial(absorber[materialChosen])
520 if materialChosen ==
"water":
521 water_phantom.SetColor(0., 0.9, 1.0)
522 if materialChosen ==
"air":
523 water_phantom.SetColor(0.9, 0.9, 1.0)
524 if materialChosen ==
"lead":
525 water_phantom.SetColor(0.2, 0.2, 0.2)
526 if materialChosen ==
"iron":
527 water_phantom.SetColor(0.7, 0.5, 0.7)
528 if materialChosen ==
"aluminum":
529 water_phantom.SetColor(.7, 0.9, 1.0)
530 if materialChosen ==
"gold":
531 water_phantom.SetColor(1., 0.9, .0)
533 self.solid.SetZHalfLength( self.thickSpin.theValue * self.
lengthUnit[self.thickSpin.theUnit] / 2.0 )
536 gApplyUICommand(
"/vis/scene/add/text 0 610 610 mm 20 0 0 " +
"Geant4Py in Action")
538 gApplyUICommand(
"/gun/particle " + str ( self.theParticle.GetStringSelection() ) )
541 gProcessTable.SetProcessActivation(i, 1)
542 if self.theProcesses.processCheck[i].GetValue() !=
True:
543 gProcessTable.SetProcessActivation(i, 0)
545 gApplyUICommand(
"/gun/energy " + str ( self.energySpin.valAndUnit.GetValue() ) )
547 eventNum = self.eventNo.slider.GetValue()
548 for i
in range(eventNum):
549 gunYZpos = str(i-eventNum/2) +
". -50. cm"
551 gRunManager.BeamOn(1)
555 app = wx.PySimpleApp(
False)