7 import g4py.Qmaterials, g4py.NISTmaterials
10 import g4py.ParticleGun, g4py.MedicalBeam
13 from subprocess
import *
22 rand_engine= Ranlux64Engine()
23 HepRandom.setTheEngine(rand_engine)
24 HepRandom.setTheSeed(20050830L)
39 exN03geom= g4py.ExN03geom.ExN03DetectorConstruction()
40 gRunManager.SetUserInitialization(exN03geom)
54 exN03PL= g4py.ExN03pl.PhysicsList()
55 gRunManager.SetUserInitialization(exN03PL)
70 pg= g4py.ParticleGun.Construct()
73 pg.SetParticleByName(
"e-")
74 pg.SetParticleEnergy(50.*MeV)
84 gRunManager.Initialize()
106 global heprepViewer, heprepDir, heprepName, vrmlViewer
107 heprepViewer = os.environ.get(
"G4HEPREPFILE_VIEWER")
108 heprepDir = os.environ.get(
"G4HEPREPFILE_DIR")
109 heprepName = os.environ.get(
"G4HEPREPFILE_NAME")
110 if heprepViewer
is not None:
115 vrmlDir = os.environ.get(
"G4VRML_DEST_DIR")
116 vrmlViewer = os.environ.get(
"G4VRMLFILE_VIEWER")
118 if vrmlViewer
is not None:
132 global commandDic, commandList
138 ntree= atree.GetTreeEntry()
139 ncommand= atree.GetCommandEntry()
140 for i
in range(1, ncommand+1):
141 icommand= atree.GetCommand(i)
142 command = str( icommand.GetCommandPath())
143 commandList.append(command)
144 nparameter= icommand.GetParameterEntries()
146 for j
in range(0, nparameter):
147 iparam= icommand.GetParameter(j)
148 pguide = pguide +
"Parameter: " + str(iparam.GetParameterName())+
" Type: " + str(iparam.GetParameterType()) +
'\n'
149 guide = str(icommand.GetTitle()) +
'\n' + pguide
150 commandDic[command] = guide
152 for i
in range(1, ntree+1):
153 itree= atree.GetTree(i)
157 root_tree= gUImanager.GetTree()
172 wx.Panel.__init__(self, parent, -1)
174 self.
g4comText = wx.TextCtrl(parent, -1,
"enter Command", pos=(10,10), size=(300, 30))
175 self.
g4comExec = wx.Button(parent, -1,
"Execute", pos=(320,10), size=(60,30))
182 self.
comListBox = wx.ListBox(parent, -1, pos=(10,50), size=(300,200), choices=commandList, style=wx.LB_SINGLE)
183 self.comListBox.SetSelection(1)
187 self.
guide = wx.TextCtrl(parent, -1,
"guidance", pos=(320,50), size=(300, 200), style =wx.TE_MULTILINE)
198 g4com =str(self.comListBox.GetStringSelection())
199 self.guide.WriteText( commandDic[g4com])
200 self.g4comText.SetValue(g4com)
207 wx.Panel.__init__(self, parent, -1)
209 self.
visZoomIn = wx.Button(parent, -1,
"Zoom In", pos=(10,100), size=(80,30))
210 self.
visZoomOut = wx.Button(parent, -1,
"Zoom out", pos=(100,100), size=(80,30))
211 self.
visUp = wx.Button(parent, -1,
"Up", pos=(190,100), size=(80,30))
212 self.
visDown = wx.Button(parent, -1,
"Down", pos=(270,100), size=(80,30))
213 self.
visLeft = wx.Button(parent, -1,
"Left", pos=(360,100), size=(80,30))
214 self.
visRight = wx.Button(parent, -1,
"Left", pos=(450,100), size=(80,30))
216 viewerList = [
"OpenGL",
"VRML",
"Wired"]
217 self.
viewer = wx.RadioBox(self, -1,
"Viewer", pos=(10,10),
218 size=(210,60), choices=viewerList, majorDimension=1, style=wx.RA_SPECIFY_ROWS)
220 self.viewer.SetToolTip(wx.ToolTip(
"Select one"))
221 self.viewer.SetSelection(0)
222 if vrmlViewer ==
None: self.viewer.EnableItem(1,
False)
223 if heprepViewer ==
None: self.viewer.EnableItem(2,
False)
245 self.visUp.Bind(wx.EVT_BUTTON, self.
cmdUp, self.
visUp)
294 g4pipe=Popen(heprepViewer+
" -file " + heprepDir+
"/" +heprepName +
".heprep", shell=
True)
301 wx.StaticText.__init__(self, parent, -1, Text, pos=(20,20))
305 TheColour = self.GetForegroundColour()
306 if TheColour == (0,0,0):
307 self.SetLabel(
"Simulation is running!")
308 self.SetForegroundColour(
"red")
310 self.SetLabel(
"Click me to start a run")
311 self.SetForegroundColour(
"black")
318 wx.RadioBox.__init__(self, parent, -1, myTitle, wx.DefaultPosition,
319 wx.DefaultSize, myList, 5, wx.RA_SPECIFY_ROWS)
321 self.SetToolTip(wx.ToolTip(
"Select one"))
334 wx.Panel.__init__(self, parent, -1)
336 self.
sizer = wx.BoxSizer(wx.HORIZONTAL)
337 self.sizer.Add((10, -1))
338 self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
340 self.
intPart = wx.SpinCtrl(parent, -1,
"", wx.DefaultPosition, (60,-1))
341 self.intPart.SetRange(0,999)
342 self.intPart.SetValue(1)
343 self.intPart.Bind(wx.EVT_SPINCTRL, self.
SetFloat)
345 self.
manPart = wx.SpinCtrl(parent, -1,
"", wx.DefaultPosition, (50, -1))
346 self.manPart.SetRange(0,999)
347 self.manPart.SetValue(0)
348 self.manPart.Bind(wx.EVT_SPINCTRL, self.
SetFloat)
350 self.
unitSel = wx.Choice(parent, -1, wx.DefaultPosition, (90, -1), unitList)
352 self.unitSel.SetSelection(2)
354 self.
valAndUnit = wx.TextCtrl(parent, -1,
"value unset", wx.DefaultPosition, (150, -1))
357 self.sizer.Add((10, -1))
358 self.sizer.Add(wx.StaticText(parent, -1,
" ", wx.DefaultPosition, (30, -1)))
360 self.sizer.Add(wx.StaticText(parent, -1,
".", wx.DefaultPosition, (10, -1)))
362 self.sizer.Add((5,-1))
364 self.SetSizer(self.
sizer)
367 self.
theValueStr = str(self.intPart.GetValue()) +
"." + str(self.manPart.GetValue()) +
" "
368 self.
theValue = float (self.intPart.GetValue()) + float(self.manPart.GetValue())/ 1000.
369 self.
theUnit = self.unitSel.GetStringSelection()
371 self.valAndUnit.SetValue(theText)
379 wx.Panel.__init__(self, parent, -1)
381 self.
sizer = wx.FlexGridSizer(rows=5)
382 self.sizer.AddGrowableRow(1)
389 self.SetSizer(self.
sizer)
390 self.SetBackgroundColour(
'green')
403 def __init__(self, parent, myTitle, minVal, maxVal, initVal):
404 wx.Panel.__init__(self, parent, -1)
405 self.
sizer = wx.BoxSizer(wx.HORIZONTAL)
406 self.sizer.Add((10, -1))
407 self.sizer.Add(wx.StaticText(parent, -1, myTitle, wx.DefaultPosition, (100, -1)))
408 self.
slider = wx.Slider(parent, -1, initVal, minVal, maxVal,
409 wx.DefaultPosition, (300, -1),
410 wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
411 self.slider.SetPageSize(1)
412 self.sizer.Add(self.
slider)
413 self.SetSizer(self.
sizer)
424 def __init__(self, parent, myTitle, minVal, maxVal, initVal):
425 wx.SpinCtrl.__init__(self, parent, -1,
"", wx.DefaultPosition, wx.DefaultSize, wx.TE_RIGHT)
426 self.SetRange(minVal, maxVal)
427 self.SetValue(initVal)
428 self.Bind(wx.EVT_SPINCTRL, self.
Adjusted)
430 print self.GetValue()
439 wx.Frame.__init__(self,
None, -1,
"Geant4Py")
440 self.
nb = wx.Notebook(self, -1, wx.DefaultPosition, wx.DefaultSize,
447 self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.
OnPageChanged)
450 panel = wx.Panel(self.
nb)
451 self.nb.AddPage(panel,
"ExampleN03")
452 commandPanel = wx.Panel(self.
nb)
453 self.nb.AddPage(commandPanel,
"Geant4 Commands")
455 gxsizer = wx.BoxSizer(wx.HORIZONTAL)
457 commandPanel.SetSizer(gxsizer)
460 visualizationPanel = wx.Panel(self.
nb)
461 self.nb.AddPage(visualizationPanel,
"Vis Commands")
463 vxsizer = wx.BoxSizer(wx.HORIZONTAL)
465 visualizationPanel.SetSizer(vxsizer)
468 bxsizer = wx.BoxSizer(wx.VERTICAL)
470 bysizer = wx.BoxSizer(wx.HORIZONTAL)
473 self.
runStart = wx.Button(panel, -1,
" Run Start", wx.DefaultPosition, wx.DefaultSize)
475 bxsizer.Add(self.
runStart, 0, wx.ALL)
478 absorberMaterialList = [
'Aluminium',
'Lead']
480 gapMaterialList = [
"liquidArgon",
"Scintillator",
"Air",
"Aerogel",
"Galactic"]
483 particleList = [
"proton",
"gamma",
"e-",
"e+",
"mu-",
"mu+"]
486 self.
processList = [
"phot",
"compt",
"conv",
"msc",
"eIoni",
"eBrem",
"annihil",
"muIoni",
"muBrems",
"hIoni"]
492 self.
lengthUnit = {
'micrometer':micrometer,
'mm':mm,
'cm':cm,
'm':m}
497 self.
magneticUnit = {
'Tesla':tesla,
'gauss':gauss,
'kilogauss':kilogauss}
500 self.
energyUnit = {
'keV':keV,
'MeV':MeV,
'GeV':GeV,
'TeV':TeV,
'PeV':PeV}
506 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
507 bysizer.Add((10, -1))
509 bysizer.Add((10, -1))
511 bysizer.Add((10, -1))
513 bysizer.Add((10, -1))
514 bysizer.Add(self.theProcesses.sizer, 0, wx.EXPAND, 10)
516 bxsizer.Add(bysizer, 0, wx.EXPAND)
518 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
519 bxsizer.Add(self.layerNo.sizer, 0, wx.EXPAND)
520 bxsizer.Add(self.absorberThickSpin.sizer, 0, wx.EXPAND)
521 bxsizer.Add(self.gapThickSpin.sizer, 0, wx.EXPAND)
522 bxsizer.Add(self.sizeYZSpin.sizer, 0, wx.EXPAND)
523 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
525 bxsizer.Add(self.energySpin.sizer, 0, wx.EXPAND)
526 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
527 bxsizer.Add(self.cutLengthSpin.sizer, 0, wx.EXPAND)
528 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
529 bxsizer.Add(self.magneticFieldSpin.sizer, 0, wx.EXPAND)
531 bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
532 bxsizer.Add(self.eventNo.sizer, 0, wx.EXPAND)
537 panel.SetSizer(bxsizer)
539 bxsizer.SetSizeHints(self)
541 old = event.GetOldSelection()
542 new = event.GetSelection()
543 sel = self.nb.GetSelection()
547 old = event.GetOldSelection()
548 new = event.GetSelection()
549 sel = self.nb.GetSelection()
554 absorberTh = self.absorberThickSpin.theValue * self.
lengthUnit[self.absorberThickSpin.theUnit]/2.0
555 gapTh = self.gapThickSpin.theValue * self.
lengthUnit[self.gapThickSpin.theUnit]/2.0
556 yzSize = self.sizeYZSpin.theValue * self.
lengthUnit[self.sizeYZSpin.theUnit]
558 cutLen = self.cutLengthSpin.theValue * self.
lengthUnit[self.cutLengthSpin.theUnit]
559 magF = self.magneticFieldSpin.theValue * self.
magneticUnit[self.magneticFieldSpin.theUnit]
561 exN03geom.SetNbOfLayers(self.layerNo.slider.GetValue())
562 exN03geom.SetAbsorberMaterial(str(self.theAbsorberMaterial.GetStringSelection()))
563 exN03geom.SetAbsorberThickness(absorberTh)
564 exN03geom.SetGapMaterial(str(self.theGapMaterial.GetStringSelection()))
565 exN03geom.SetGapThickness(gapTh)
566 exN03geom.SetCalorSizeYZ(yzSize)
567 position = -self.layerNo.slider.GetValue() * ( absorberTh + gapTh )*1.2
569 exN03geom.UpdateGeometry()
570 exN03PL.SetDefaultCutValue(cutLen)
571 exN03PL.SetCutsWithDefault()
572 exN03geom.SetMagField(magF)
574 print "Now geometry updated"
581 gApplyUICommand(
"/gun/particle " + str ( self.theParticle.GetStringSelection() ) )
584 gProcessTable.SetProcessActivation(i, 1)
585 if self.theProcesses.processCheck[i].GetValue() !=
True:
586 gProcessTable.SetProcessActivation(i, 0)
588 gApplyUICommand(
"/gun/energy " + str ( self.energySpin.valAndUnit.GetValue() ) )
590 eventNum = self.eventNo.slider.GetValue()
591 for i
in range(eventNum):
592 pg.SetParticlePosition(
G4ThreeVector(position, (i-eventNum/2)*5.*mm, 0.*cm))
593 gRunManager.BeamOn(1)
598 app = wx.PySimpleApp(
False)
const G4ParticleDefinition const G4Material *G4double range