9 import g4py.Qmaterials, g4py.NISTmaterials
12 import g4py.ParticleGun, g4py.MedicalBeam
15 from subprocess
import *
24 rand_engine= Ranlux64Engine()
25 HepRandom.setTheEngine(rand_engine)
26 HepRandom.setTheSeed(20050830)
41 exN03geom= g4py.ExN03geom.ExN03DetectorConstruction()
42 gRunManager.SetUserInitialization(exN03geom)
56 exN03PL= g4py.EMSTDpl.PhysicsListEMstd()
57 gRunManager.SetUserInitialization(exN03PL)
72 pg= g4py.ParticleGun.Construct()
75 pg.SetParticleByName(
"e-")
76 pg.SetParticleEnergy(50.*MeV)
86 gRunManager.Initialize()
119 global heprepViewer, heprepDir, heprepName
120 heprepViewer = os.environ.get(
"G4HEPREPFILE_VIEWER")
121 heprepDir = os.environ.get(
"G4HEPREPFILE_DIR")
122 heprepName = os.environ.get(
"G4HEPREPFILE_NAME")
123 if heprepViewer
is not None:
128 vrmlDir = os.environ.get(
"G4VRML_DEST_DIR")
129 vrmlViewer = os.environ.get(
"G4VRMLFILE_VIEWER")
131 if vrmlViewer
is not None:
139 from tkinter
import *
148 title = Label(self, text=
"exampleN03")
149 title.grid(row=0, column=1, columnspan=3)
150 header = Label(self, text=
"empowered by \n Geant4Py")
151 header.grid(row=1, column=1, columnspan=3)
153 layerLabel = Label(self, bg=
"green", text=
"No of layers")
155 self.layerVar.set(10)
156 layer = Scale(self, orient=HORIZONTAL, length=400, from_=0, to=10, tickinterval=1, resolution=1, variable=self.
layerVar )
157 layerLabel.grid(row=2, column=0, sticky=W)
158 layer.grid(row=2, column=1, columnspan=5, sticky=W)
161 absorbermaterialLabel = Label(self, bg=
"green", text=
"Absorber Material")
162 absorbermaterialLabel.grid(row=3, column=0, sticky=W)
164 self.absorbermaterialVar.set(
"Lead")
167 for i
in (
"Aluminium",
"Lead"):
169 ra1[i].grid(row=3, column=pos, sticky=W)
173 absorberthickLabel = Label(self, bg=
"green", text=
"Thickness (mm)")
175 self.absorberthickVar.set(10.0)
176 absorberthick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.
absorberthickVar)
177 absorberthickLabel.grid(row=4, column=0, sticky=W)
178 absorberthick.grid(row=4, column=1, columnspan=5, sticky=W)
182 gapmaterialLabel = Label(self, bg=
"green", text=
"Gap Material")
183 gapmaterialLabel.grid(row=5, column=0, sticky=W)
185 self.gapmaterialVar.set(
"liquidArgon")
188 for i
in (
"liquidArgon",
"Scintillator",
"Air",
"Aerogel",
"Galactic" ):
189 ra2[i] = Radiobutton(self, text=i, variable=self.
gapmaterialVar, value=i)
190 ra2[i].grid(row=5, column=pos, sticky=W)
194 gapthickLabel = Label(self, bg=
"green", text=
"Thickness (mm)")
196 self.gapthickVar.set(5.0)
197 gapthick = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=100., resolution=0.05, tickinterval=10.0, digits=4, variable=self.
gapthickVar)
198 gapthickLabel.grid(row=6, column=0, sticky=W)
199 gapthick.grid(row=6, column=1, columnspan=5, sticky=W)
202 calorsizeYZLabel = Label(self, bg=
"green", text=
"SizeYZ (mm)")
204 self.calorsizeYZVar.set(100.0)
205 calorsizeYZ = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=200., resolution=0.05, tickinterval=20.0, digits=4, variable=self.
calorsizeYZVar)
206 calorsizeYZLabel.grid(row=7, column=0, sticky=W)
207 calorsizeYZ.grid(row=7, column=1, columnspan=5, sticky=W)
211 particleLabel = Label(self, bg=
"green", text=
"Particle")
212 particleLabel.grid(row=8, column=0, sticky=W)
214 self.particleVar.set(
"e-")
217 for i
in (
"proton",
"gamma",
"e-",
"e+",
"mu-",
"mu+"):
218 ra1[i] = Radiobutton(self, text=i, variable=self.
particleVar, value=i)
219 ra1[i].grid(row=8, column=pos1, sticky=W)
223 energyLabel = Label(self, bg=
"green", text=
"Energy (MeV)")
226 self.energyVar.set(50)
227 energy = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=1000., tickinterval=100.0, resolution=0.1, variable=self.
energyVar, digits=5 )
228 energyLabel.grid(row=9, column=0, sticky=W)
229 energy.grid(row=9, column=1, columnspan=5, sticky=W)
232 eventLabel = Label(self, bg=
"green", text=
"Events")
235 event = Scale(self, orient=HORIZONTAL, length=400, from_=0, to=100, tickinterval=10, resolution=1, variable=self.
eventVar )
236 eventLabel.grid(row=10, column=0, sticky=W)
237 event.grid(row=10, column=1, columnspan=5, sticky=W)
240 startBut = Button(self, bg=
"orange", text=
"Start a run", command=self.
cmd_beamOn)
241 startBut.grid(row=0, column=0, sticky=W)
259 processLabel=Label(self, text=
"Process on/off", bg=
"green")
260 processLabel.grid(row=11, column=0, sticky=W)
263 self.
processList = [
"phot",
"compt",
"conv",
"msc",
"eIoni",
"eBrem",
"annihil",
"muIoni",
"muBrems",
"hIoni"]
270 procTab[i].grid(row=11, column=pos, sticky=W)
272 procTab[i].grid(row=12, column=pos-3, sticky=W)
274 procTab[i].grid(row=13, column=pos-7, sticky=W)
278 cutLabel = Label(self, bg=
"green", text=
"Cut (mm)")
282 cut = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=10., tickinterval=1., resolution=0.005, variable=self.
cutVar, digits=5 )
283 cutLabel.grid(row=14, column=0, sticky=W)
284 cut.grid(row=14, column=1, columnspan=5, sticky=W)
287 magLabel = Label(self, bg=
"green", text=
"Magnetic (T)")
291 mag = Scale(self, orient=HORIZONTAL, length=400, from_=0., to=5., tickinterval=1., resolution=0.1, variable=self.
magVar, digits=3 )
292 magLabel.grid(row=15, column=0, sticky=W)
293 mag.grid(row=15, column=1, columnspan=5, sticky=W)
297 viewerLabel = Label(self, bg=
"green", text=
"Viewer")
298 viewerLabel.grid(row=16, column=0, sticky=W)
300 self.viewerVar.set(
"")
301 stateOfViewer = {
"OpenGL":
"normal",
"VRML":
"normal",
"Wired":
"normal"}
302 if vrmlViewer
is None: stateOfViewer[
"VRML"] =
"disabled"
303 if heprepViewer
is None: stateOfViewer[
"Wired"] =
"disabled"
306 for i
in (
"OpenGL",
"VRML",
"Wired"):
307 viewers[i] = Radiobutton(self, text=i, variable=self.
viewerVar, value=i, command=self.
cmd_viewer, state=stateOfViewer[i])
308 viewers[i].grid(row=16, column=pos, sticky=W)
313 g4comLabel = Label(self, text=
"Geant4 command", bg=
"orange")
315 commandEntry = Entry(self, textvariable=self.
g4commandVar, width=15)
316 self.g4commandVar.set(
"/vis/viewer/zoom 1.2")
317 comBut = Button(self, bg=
"orange", text=
"Execute", command=self.
cmd_g4command)
318 g4comLabel.grid(row=17, column=0, sticky=W)
319 commandEntry.grid(row=17, column=1, columnspan=3, sticky=E+W)
320 comBut.grid(row=17, column=5)
323 exitBut = Button(self, bg=
"red", text=
"End all", command=sys.exit)
324 exitBut.grid(row=0, column=5, sticky=W)
328 exN03geom.SetNbOfLayers(self.layerVar.get())
329 exN03geom.SetAbsorberMaterial(self.absorbermaterialVar.get())
330 exN03geom.SetAbsorberThickness(self.absorberthickVar.get() * mm/2.0)
331 exN03geom.SetGapMaterial(self.gapmaterialVar.get())
332 exN03geom.SetGapThickness(self.gapthickVar.get() * mm/2.0)
333 exN03geom.SetCalorSizeYZ(self.calorsizeYZVar.get() * mm)
334 position = -self.layerVar.get()*(self.absorberthickVar.get() + self.gapthickVar.get())*1.2
336 exN03geom.UpdateGeometry()
337 exN03PL.SetDefaultCutValue(self.cutVar.get() * mm)
338 exN03PL.SetCutsWithDefault()
339 exN03geom.SetMagField(self.magVar.get() * tesla)
341 print(
"Now geometry updated")
349 eventNum = self.eventVar.get()
350 for i
in range(eventNum):
352 pg.SetParticlePosition(
G4ThreeVector(position*mm, (i-eventNum/2)*5.*mm, 0.*cm))
353 gRunManager.BeamOn(1)
360 gProcessTable.SetProcessActivation(i, 0)
361 print(
"Process " + i +
" inactivated")
363 gProcessTable.SetProcessActivation(i, 1)
364 print(
"Process " + i +
" activated")
378 if self.viewerVar.get() ==
"OpenGL":
386 if self.viewerVar.get() ==
"VRML":
394 if self.viewerVar.get() ==
"Wired":
403 Popen(heprepViewer +
" -file " + heprepDir +
"/" + heprepName +
".heprep", shell=
True)
411 gApplyUICommand(
"/vis/viewer/pan " + self.panXYVar.get() +
" " +
" mm")
420 Frame.__init__(self, master)
const G4ParticleDefinition const G4Material *G4double range
void print(G4double elem)