Geant4_10
Lesson2Wx.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 #### 2006 Sep 26, the first draft version
4 ## Wired not yet. g4pipe control and Popen
5 
6 from Geant4 import *
7 import g4py.Qmaterials, g4py.NISTmaterials
8 import g4py.ExN03geom
9 import g4py.ExN03pl
10 import g4py.ParticleGun, g4py.MedicalBeam
11 import sys
12 from time import *
13 from subprocess import *
14 import os
15 
16 # ==================================================================
17 # main
18 # ==================================================================
19 # ------------------------------------------------------------------
20 # randum number
21 # ------------------------------------------------------------------
22 rand_engine= Ranlux64Engine()
23 HepRandom.setTheEngine(rand_engine)
24 HepRandom.setTheSeed(20050830L)
25 
26 # ------------------------------------------------------------------
27 # setup for materials
28 # ------------------------------------------------------------------
29 
30 
31 # NIST materials
32 #g4py.NISTmaterials.Construct()
33 
34 # ------------------------------------------------------------------
35 # setup for geometry
36 # ------------------------------------------------------------------
37 # normal way for constructing user geometry
38 
39 exN03geom= g4py.ExN03geom.ExN03DetectorConstruction()
40 gRunManager.SetUserInitialization(exN03geom)
41 
42 # 2nd way, short-cut way
43 
44 #g4py.ExN01geom.Construct()
45 #g4py.ExN03geom.Construct()
46 
47 # magnetic field
48 #exN03geom.SetMagField(0.1 * tesla)
49 
50 # ------------------------------------------------------------------
51 # setup for physics list
52 # ------------------------------------------------------------------
53 # normal way for constructing user physics list
54 exN03PL= g4py.ExN03pl.PhysicsList()
55 gRunManager.SetUserInitialization(exN03PL)
56 
57 # 2nd way, short-cut way
58 #g4py.ExN01pl.Construct()
59 
60 
61 # ------------------------------------------------------------------
62 # setup for primary generator action
63 # ------------------------------------------------------------------
64 # normal way for constructing user physics list
65 #pgPGA= g4py.ParticleGun.ParticleGunAction()
66 #gRunManager.SetUserAction(pgPGA)
67 #pg= pgPGA.GetParticleGun()
68 
69 # 2nd way, short-cut way
70 pg= g4py.ParticleGun.Construct()
71 
72 # set parameters of particle gun
73 pg.SetParticleByName("e-")
74 pg.SetParticleEnergy(50.*MeV)
75 pg.SetParticlePosition(G4ThreeVector(-40.,0.,0.)*cm)
76 pg.SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.))
77 
78 # medical beam
79 #beam= MedicalBeam.Construct()
80 
81 # ------------------------------------------------------------------
82 # go...
83 # ------------------------------------------------------------------
84 gRunManager.Initialize()
85 
86 
87 # visualization
88 # OGLSX, VRML and HEPREP sceneHandlers are all created with names
89 gApplyUICommand("/vis/sceneHandler/create OGLSX OGLSX")
90 gApplyUICommand("/vis/sceneHandler/create VRML2FILE VRML")
91 gApplyUICommand("/vis/sceneHandler/create HepRepFile HEPREP")
92 
93 # OGLSX is the default so, viewer is created and volume is drawn
94 gApplyUICommand("/vis/viewer/create OGLSX oglsxviewer")
95 gApplyUICommand("/vis/drawVolume")
96 gApplyUICommand("/vis/scene/add/trajectories")
97 
98 gApplyUICommand("/tracking/storeTrajectory 1")
99 gApplyUICommand("/vis/scene/endOfEventAction accumulate")
100 gApplyUICommand("/vis/scene/endOfRunAction accumulate")
101 gApplyUICommand("/vis/viewer/select oglsxviewer")
102 
103 # viewers VRML and Wired are tested by their envs vars
104 # if their envs var are set, then viewers are created and drawVolume
105 
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:
111  gApplyUICommand("/vis/viewer/create HEPREP wired")
112  gApplyUICommand("/vis/drawVolume")
113 
114 # VRML viewers name is user defined
115 vrmlDir = os.environ.get("G4VRML_DEST_DIR")
116 vrmlViewer = os.environ.get("G4VRMLFILE_VIEWER")
117 
118 if vrmlViewer is not None:
119  gApplyUICommand("/vis/viewer/create VRML vrmlviewer")
120  gApplyUICommand("/vis/drawVolume")
121 
122 
123 # test############################################################################TESSSSSSST
124 gApplyUICommand("/vis/viewer/select oglsxviewer")
125 gApplyUICommand("/vis/scene/add/trajectories")
126 
127 gApplyUICommand("/tracking/storeTrajectory 1")
128 gApplyUICommand("/vis/scene/endOfEventAction accumulate")
129 gApplyUICommand("/vis/scene/endOfRunAction accumulate")
130 #test########################################################################################
131 
132 global commandDic, commandList
133 commandDic = {}
134 commandList = []
135 
136 def DumpTree(atree):
137 
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()
145  pguide = ""
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
151 
152  for i in range(1, ntree+1):
153  itree= atree.GetTree(i)
154  DumpTree(itree)
155 
156 
157 root_tree= gUImanager.GetTree()
158 DumpTree(root_tree)
159 
160 
161 
162 
163 ###### wxPython GUI ##########
164 
165 
166 import wx
167 
168 
169 
170 class ComPanel(wx.Panel):
171  def __init__(self, parent):
172  wx.Panel.__init__(self, parent, -1)
173 
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))
176  self.g4comExec.Bind(wx.EVT_BUTTON, self.ExecuteCommand, self.g4comExec)
177 # self.sizerE = wx.BoxSizer(wx.HORIZONTAL)
178 # self.sizerE.Add(self.g4comText)
179 # self.sizerE.Add(self.g4comExec)
180 
181 # self.sizerL = wx.BoxSizer(wx.HORIZONTAL)
182  self.comListBox = wx.ListBox(parent, -1, pos=(10,50), size=(300,200), choices=commandList, style=wx.LB_SINGLE)
183  self.comListBox.SetSelection(1)
184  self.comListBox.Bind(wx.EVT_LISTBOX, self.ShowGuide, self.comListBox)
185 # self.sizerL.Add(self.comListBox)
186 
187  self.guide = wx.TextCtrl(parent, -1, "guidance", pos=(320,50), size=(300, 200), style =wx.TE_MULTILINE)
188  self.guide.Bind(wx.EVT_LISTBOX, self.ShowGuide, self.guide)
189 
190 # self.sizerL.Add(self.guide)
191 # self.sizer = wx.BoxSizer(wx.VERTICAL)
192 # self.sizer.Add(self.sizerE)
193 # self.sizer.Add(self.sizerL)
194 # self.SetSizer(self.sizer)
195 
196  def ShowGuide(self, event):
197  self.guide.Clear() # how to cleat the whole text before showing the next
198  g4com =str(self.comListBox.GetStringSelection())
199  self.guide.WriteText( commandDic[g4com])
200  self.g4comText.SetValue(g4com)
201 
202  def ExecuteCommand(self, event):
203  gApplyUICommand(str(self.g4comText.GetValue()))
204 
205 class VisPanel(wx.Panel):
206  def __init__(self, parent):
207  wx.Panel.__init__(self, parent, -1)
208 
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))
215 
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)
219  self.viewer.Bind(wx.EVT_RADIOBOX, self.ViewerSelected, self.viewer)
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)
224 # self.sizer = wx.BoxSizer(wx.HORIZONTAL)
225 # self.sizer.Add((20,30))
226 # self.sizer.Add(self.visZoomIn)
227 # self.sizer.Add(self.visZoomOut)
228 # self.sizer.Add(self.visUp)
229 # self.sizer.Add(self.visDown)
230 # self.sizer.Add(self.visRight)
231 # self.sizer.Add(self.visLeft)
232 # self.SetSizer(self.sizer)
233 
234 # self.visZoomIn = wx.Button(parent, -1, "Zoom In", pos=(10,70), size=(80,30))
235 # self.visZoomOut = wx.Button(parent, -1, "Zoom out", pos=(100,70), size=(80,30))
236 # self.visUp = wx.Button(parent, -1, "Up", pos=(10,50), size=(190,70))
237 # self.visDown = wx.Button(parent, -1, "Down", pos=(100,50), size=(270,70))
238 # self.visLeft = wx.Button(parent, -1, "Left", pos=(10,90), size=(360,70))
239 # self.visRight = wx.Button(parent, -1, "Left", pos=(100,90), size=(450,70))
240 
241 
242 
243  self.visZoomIn.Bind(wx.EVT_BUTTON, self.cmdExpand, self.visZoomIn)
244  self.visZoomOut.Bind(wx.EVT_BUTTON, self.cmdShrink, self.visZoomOut)
245  self.visUp.Bind(wx.EVT_BUTTON, self.cmdUp, self.visUp)
246  self.visDown.Bind(wx.EVT_BUTTON, self.cmdDown, self.visDown)
247  self.visRight.Bind(wx.EVT_BUTTON, self.cmdRight, self.visRight)
248  self.visLeft.Bind(wx.EVT_BUTTON, self.cmdLeft, self.visLeft)
249 
250  def cmdExpand(self, event):
251  gApplyUICommand("/vis/viewer/zoom 1.2")
252  def cmdShrink(self, event):
253  gApplyUICommand("/vis/viewer/zoom 0.8")
254  def cmdUp(self, event):
255  gApplyUICommand("/vis/viewer/pan " + " 0. 10. mm")
256  def cmdDown(self, event):
257  gApplyUICommand("/vis/viewer/pan " + " 0. -10. mm")
258  def cmdRight(self, event):
259  gApplyUICommand("/vis/viewer/pan " + " -10. 0. mm")
260  def cmdLeft(self, event):
261  gApplyUICommand("/vis/viewer/pan " + " 10. 0. mm")
262 
263  def ViewerSelected(self, event):
264  self.viewerName = event.GetString()
265 
266  if self.viewerName == "OpenGL":
267  gApplyUICommand("/vis/viewer/select oglsxviewer")
268  gApplyUICommand("/vis/scene/add/trajectories")
269 
270  gApplyUICommand("/tracking/storeTrajectory 1")
271  gApplyUICommand("/vis/scene/endOfEventAction accumulate")
272  gApplyUICommand("/vis/scene/endOfRunAction accumulate")
273 
274  if self.viewerName == "VRML":
275  gApplyUICommand("/vis/viewer/select vrmlviewer")
276  gApplyUICommand("/vis/scene/add/trajectories")
277 
278  gApplyUICommand("/tracking/storeTrajectory 1")
279  gApplyUICommand("/vis/scene/endOfEventAction accumulate")
280  gApplyUICommand("/vis/scene/endOfRunAction accumulate")
281 
282  if self.viewerName == "Wired":
283 
284  gApplyUICommand("/vis/viewer/select wired")
285  gApplyUICommand("/vis/scene/add/trajectories")
286 
287  gApplyUICommand("/tracking/storeTrajectory 1")
288  gApplyUICommand("/vis/scene/endOfEventAction accumulate")
289  gApplyUICommand("/vis/scene/endOfRunAction accumulate")
290 
291 # everytime wired is chosen, a new instance of wired is created
292 # to reuse single wired, g4pipe.poll() must be checked BEFORE the SECOND Popen
293 # if g4pipe.poll() == None:
294  g4pipe=Popen(heprepViewer+ " -file " + heprepDir+"/" +heprepName +".heprep", shell=True)
295 
296 
297 
298 # not used
299 class MyText(wx.StaticText):
300  def __init__(self, parent, Text):
301  wx.StaticText.__init__(self, parent, -1, Text, pos=(20,20))
302  self.Bind(wx.EVT_LEFT_UP, self.ChangeColor)
303 
304  def ChangeColor(self, event):
305  TheColour = self.GetForegroundColour()
306  if TheColour == (0,0,0):
307  self.SetLabel("Simulation is running!")
308  self.SetForegroundColour("red")
309  else:
310  self.SetLabel("Click me to start a run")
311  self.SetForegroundColour("black")
312 
313 # to be used to choose materials and particles
314 # myList is a list of keys() of a dictionary
315 # f.e., materials are Python objects with their names as their keys
316 class SelectOne(wx.RadioBox):
317  def __init__(self, parent, myTitle, myList):
318  wx.RadioBox.__init__(self, parent, -1, myTitle, wx.DefaultPosition,
319  wx.DefaultSize, myList, 5, wx.RA_SPECIFY_ROWS)
320 # self.Bind(wx.EVT_RADIOBOX, self.Selected)
321  self.SetToolTip(wx.ToolTip("Select one"))
322  self.SetSelection(0)
323 # used only to test Bind and getValue
324 # def Selected(self, event):
325 # self.selected = event.GetString()
326 
327 
328 # used to %3.3f floating point number
329 # energy and length unit is given by unitList which must be a dictionary
330 # with units of Python objects and their name as their keys
331 
332 class FloatCounter(wx.Panel):
333  def __init__(self, parent, myTitle, unitList):
334  wx.Panel.__init__(self, parent, -1)
335 
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)))
339 
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)
344 
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)
349 
350  self.unitSel = wx.Choice(parent, -1, wx.DefaultPosition, (90, -1), unitList)
351  self.unitSel.Bind(wx.EVT_CHOICE, self.SetFloat, self.unitSel)
352  self.unitSel.SetSelection(2)
353 
354  self.valAndUnit = wx.TextCtrl(parent, -1, "value unset", wx.DefaultPosition, (150, -1))
355 
356  self.sizer.Add(self.valAndUnit)
357  self.sizer.Add((10, -1))
358  self.sizer.Add(wx.StaticText(parent, -1, " ", wx.DefaultPosition, (30, -1)))
359  self.sizer.Add(self.intPart)
360  self.sizer.Add(wx.StaticText(parent, -1, ".", wx.DefaultPosition, (10, -1)))
361  self.sizer.Add(self.manPart)
362  self.sizer.Add((5,-1))
363  self.sizer.Add(self.unitSel)
364  self.SetSizer(self.sizer)
365 
366  def SetFloat(self, event):
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()
370  theText = "%.3f" % (self.theValue) + " " + self.theUnit
371  self.valAndUnit.SetValue(theText)
372 # user may edit the Entry, so finnaly this value must be got
373 # but it doesn't work for length but work for energy (gApplyUIcommnd)
374  theTextWithStar = "%.3f" % (self.theValue) + " * " + self.theUnit
375 
376 # special class for this example to set/unset processes
377 class Processes(wx.Panel):
378  def __init__(self, parent, myTitle, myList):
379  wx.Panel.__init__(self, parent, -1)
380  self.processCheck = {}
381  self.sizer = wx.FlexGridSizer(rows=5)
382  self.sizer.AddGrowableRow(1)
383  for item in myList:
384  self.processCheck[item] = wx.CheckBox(parent, -1, item)
385  self.processCheck[item].SetValue(True)
386 # self.processCheck[item].Bind(wx.EVT_CHECKBOX, self.CheckedProcess)
387  self.sizer.Add(self.processCheck[item],0,wx.EXPAND)
388 
389  self.SetSizer(self.sizer)
390  self.SetBackgroundColour('green')
391  self.processState = {}
392  self.myList = myList
393 
394 # test only
395 # def CheckedProcess(self, event):
396 # self.processName = event.GetEventObject().GetLabel()
397 # self.processState = event.GetEventObject().GetValue()
398 
399 
400 # slider to set an integer value
401 # title is shown
402 class Adjuster(wx.Panel):
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)
414 
415 # test only
416 # self.Bind(wx.EVT_SLIDER, self.Adjusted)
417 
418 # def Adjusted(self, event):
419 # print self.GetValue()
420 
421 
422 ########################## no use now
423 class Counter(wx.SpinCtrl):
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)
429  def Adjusted(self, event):
430  print self.GetValue()
431 
432 ############################
433 
434 # main class to instantiate the above classes and pack them using nested sizers
435 g4pipe=0
436 
437 class MyApp(wx.Frame):
438  def __init__(self):
439  wx.Frame.__init__(self, None, -1, "Geant4Py")
440  self.nb = wx.Notebook(self, -1, wx.DefaultPosition, wx.DefaultSize,
441  style=
442  wx.NB_TOP # | wx.NB_MULTILINE
443  #wx.NB_BOTTOM
444  #wx.NB_LEFT
445  #wx.NB_RIGHT
446  )
447  self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
448  self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
449 
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")
454  comP = ComPanel(commandPanel)
455  gxsizer = wx.BoxSizer(wx.HORIZONTAL)
456  gxsizer.Add(comP)
457  commandPanel.SetSizer(gxsizer)
458 
459 
460  visualizationPanel = wx.Panel(self.nb)
461  self.nb.AddPage(visualizationPanel, "Vis Commands")
462  visP = VisPanel(visualizationPanel)
463  vxsizer = wx.BoxSizer(wx.HORIZONTAL)
464  vxsizer.Add(visP)
465  visualizationPanel.SetSizer(vxsizer)
466 
467 # outmost sizer in the vertical direction
468  bxsizer = wx.BoxSizer(wx.VERTICAL)
469 # nested sizer in the horizontal direction
470  bysizer = wx.BoxSizer(wx.HORIZONTAL)
471 
472 
473  self.runStart = wx.Button(panel, -1, " Run Start", wx.DefaultPosition, wx.DefaultSize)
474  self.Bind(wx.EVT_BUTTON, self.RunStart, self.runStart)
475  bxsizer.Add(self.runStart, 0, wx.ALL)
476 # widgets
477 
478  absorberMaterialList = ['Aluminium', 'Lead']
479  self.theAbsorberMaterial = SelectOne(panel, "Absorber Materials", absorberMaterialList)
480  gapMaterialList = ["liquidArgon","Scintillator", "Air", "Aerogel", "Galactic"]
481  self.theGapMaterial = SelectOne(panel, "Gap Materials", gapMaterialList)
482 
483  particleList = ["proton", "gamma", "e-", "e+", "mu-", "mu+"]
484  self.theParticle = SelectOne(panel, "Particles", particleList)
485 
486  self.processList = ["phot", "compt", "conv", "msc", "eIoni", "eBrem", "annihil","muIoni", "muBrems", "hIoni"]
487  self.theProcesses = Processes(panel, "Processes", self.processList)
488 
489  self.eventNo = Adjuster(panel, "Number of Events", 1 , 100 , 1)
490  self.layerNo = Adjuster(panel, "Number of Layers", 1, 10, 10)
491 
492  self.lengthUnit = {'micrometer':micrometer, 'mm':mm, 'cm':cm, 'm':m}
493  self.absorberThickSpin = FloatCounter(panel, "Absorber Thickness", self.lengthUnit.keys())
494  self.gapThickSpin = FloatCounter(panel, "Gap Thickness", self.lengthUnit.keys())
495  self.sizeYZSpin = FloatCounter(panel, "Section Size", self.lengthUnit.keys())
496  self.cutLengthSpin = FloatCounter(panel, "Cut Length", self.lengthUnit.keys())
497  self.magneticUnit = {'Tesla':tesla, 'gauss':gauss, 'kilogauss':kilogauss}
498  self.magneticFieldSpin = FloatCounter(panel, "Magnetic Field", self.magneticUnit.keys())
499 
500  self.energyUnit = { 'keV':keV, 'MeV':MeV, 'GeV':GeV, 'TeV':TeV, 'PeV':PeV}
501  self.energySpin = FloatCounter(panel, "incident beam energy", self.energyUnit.keys())
502 
503 
504 # now sizers
505 
506  bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
507  bysizer.Add((10, -1))
508  bysizer.Add(self.theAbsorberMaterial, 0, wx.EXPAND, 10)
509  bysizer.Add((10, -1))
510  bysizer.Add(self.theGapMaterial, 0, wx.EXPAND, 10)
511  bysizer.Add((10, -1))
512  bysizer.Add(self.theParticle, 0, wx.EXPAND, 10)
513  bysizer.Add((10, -1))
514  bysizer.Add(self.theProcesses.sizer, 0, wx.EXPAND, 10)
515 
516  bxsizer.Add(bysizer, 0, wx.EXPAND)
517 
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)
524 
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)
530 
531  bxsizer.Add(wx.StaticLine(panel), 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5)
532  bxsizer.Add(self.eventNo.sizer, 0, wx.EXPAND)
533 
534 # self.solid = EZgeom.G4EzVolume.GetSold(water_phantom)
535 # gControlExecute("oglx.mac")
536 
537  panel.SetSizer(bxsizer)
538  bxsizer.Fit(self)
539  bxsizer.SetSizeHints(self)
540  def OnPageChanged(self, event):
541  old = event.GetOldSelection()
542  new = event.GetSelection()
543  sel = self.nb.GetSelection()
544  event.Skip()
545 
546  def OnPageChanging(self, event):
547  old = event.GetOldSelection()
548  new = event.GetSelection()
549  sel = self.nb.GetSelection()
550  event.Skip()
551 
552  def RunStart(self, event):
553 
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]
557  print "BUG"
558  cutLen = self.cutLengthSpin.theValue * self.lengthUnit[self.cutLengthSpin.theUnit]
559  magF = self.magneticFieldSpin.theValue * self.magneticUnit[self.magneticFieldSpin.theUnit]
560 
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
568 
569  exN03geom.UpdateGeometry()
570  exN03PL.SetDefaultCutValue(cutLen)
571  exN03PL.SetCutsWithDefault()
572  exN03geom.SetMagField(magF)
573 
574  print "Now geometry updated"
575 
576  print position
577 
578 # gApplyUICommand("/vis/viewer/flush")
579 # gApplyUICommand("/vis/scene/add/text 0 610 610 mm 20 0 0 " + "wxPython")
580 
581  gApplyUICommand("/gun/particle " + str ( self.theParticle.GetStringSelection() ) )
582  for i in self.processList:
583 # print i, self.theProcesses.processCheck[i].GetValue()
584  gProcessTable.SetProcessActivation(i, 1)
585  if self.theProcesses.processCheck[i].GetValue() != True:
586  gProcessTable.SetProcessActivation(i, 0)
587 
588  gApplyUICommand("/gun/energy " + str ( self.energySpin.valAndUnit.GetValue() ) )
589 
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)
594 # sleep(0.01)
595  gApplyUICommand("/vis/viewer/update")
596 
597 
598 app = wx.PySimpleApp(False)
599 MyApp().Show()
600 app.MainLoop()
const G4ParticleDefinition const G4Material *G4double range
gApplyUICommand
Definition: __init__.py:168
def DumpTree
Definition: Lesson2Wx.py:136