11 import g4py.emcalculator
15 from cStringIO
import StringIO
22 g4py.EMSTDpl.Construct()
31 gRunManager.Initialize()
32 gRunManagerKernel.RunInitialization()
36 for n
in range(-3, 3):
37 for i
in range(10,99):
38 elist.append(i/10.*10.**n *MeV)
43 sys.stdout = mycout = StringIO()
44 dedx_list= g4py.emcalculator.CalculateDEDX(pname, material, elist, 1)
50 xlist_tot.append((x[0], x[1][
"tot"]/(MeV*cm2/g)))
51 xlist_ioni.append((x[0], x[1][
"ioni"]/(MeV*cm2/g)))
52 xlist_brems.append((x[0], x[1][
"brems"]/(MeV*cm2/g)))
55 global myCanvas, aplot, bplot, cplot
58 "dE/dX (MeV cm^{2}/g)")
60 "dE/dX (MeV cm^{2}/g)", 1)
62 "dE/dX (MeV cm^{2}/g)", 3)
63 myCanvas.SaveAs(
"/tmp/sp.png")
73 gRunManager.Initialize()
74 gRunManagerKernel.RunInitialization()
78 for n
in range(-3, 4):
79 for i
in range(10,99):
80 elist.append(i/10.*10.**n *MeV)
85 sys.stdout = mycout = StringIO()
86 xsection_list= g4py.emcalculator.CalculatePhotonCrossSection(material,
92 for x
in xsection_list:
93 xlist_tot.append((x[0]/MeV, x[1][
"tot"]/(cm2/g)))
94 xlist_comp.append((x[0]/MeV, x[1][
"compt"]/(cm2/g)))
95 xlist_pe.append((x[0]/MeV, x[1][
"phot"]/(cm2/g)))
96 xlist_conv.append((x[0]/MeV, x[1][
"conv"]/(cm2/g)))
99 global myCanvas, aplot, bplot, cplot, dplot
102 "Cross Section (cm^{2}/g)")
104 "Cross Section (cm^{2}/g)", 1)
106 "Cross Section (cm^{2}/g)", 7)
108 "Cross Section (cm^{2}/g)", 3)
109 myCanvas.SaveAs(
"/tmp/cs.png")
128 self.mainwindow.set_title(
'Em Calculator')
129 self.mainwindow.set_position(gtk.WIN_POS_MOUSE)
130 self.mainwindow.set_default_size(500, 300)
131 self.mainwindow.connect(
'delete-event',
lambda w,d: gtk.main_quit())
132 self.mainwindow.connect(
'destroy-event',
lambda w,d: gtk.main_quit())
138 particle_frame.set_border_width(self.
__margin)
141 material_frame.set_border_width(self.
__margin)
143 separator = gtk.HSeparator()
146 action_box.set_border_width(self.
__margin)
150 vbox.pack_start(header)
151 vbox.pack_start(particle_frame)
152 vbox.pack_start(material_frame)
153 vbox.pack_start(separator)
154 vbox.pack_start(action_box)
156 self.mainwindow.add(vbox)
157 self.mainwindow.show_all()
164 buttons=gtk.BUTTONS_CLOSE, type=gtk.MESSAGE_ERROR,
165 message_format=
"Material is not defined in G4Nist materials")
172 label.set_markup(
"<big><b>EM Calculator</b></big>")
173 hbox.pack_start(label)
179 - stopping power for e/mu/proton
180 - cross sections for gamma
182 label.set_markup(text)
183 hbox.pack_start(label)
188 frame = gtk.Frame(
"Particle")
192 hbox.set_border_width(self.
__margin)
194 button = gtk.RadioButton(
None,
"electron")
196 hbox.pack_start(button,
True,
True, 0)
200 button = gtk.RadioButton(button,
"positron")
202 hbox.pack_start(button,
True,
True, 0)
205 button = gtk.RadioButton(button,
"mu-")
207 hbox.pack_start(button,
True,
True, 0)
210 button = gtk.RadioButton(button,
"mu+")
212 hbox.pack_start(button,
True,
True, 0)
215 button = gtk.RadioButton(button,
"proton")
217 hbox.pack_start(button,
True,
True, 0)
220 button = gtk.RadioButton(button,
"gamma")
222 hbox.pack_start(button,
True,
True, 0)
228 frame = gtk.Frame(
"Material (G4Nist)")
232 hbox.set_border_width(self.
__margin)
235 "G4_Ge",
"G4_Ag",
"G4_W",
"G4_Au",
"G4_Pb",
236 "G4_AIR",
"G4_Galactic",
"G4_WATER",
"G4_CESIUM_IODIDE",
237 "G4_SODIUM_IODIDE",
"G4_PLASTIC_SC_VINYLTOLUENE",
243 self.material_combo.append_text(name)
244 self.material_combo.set_active(0)
251 box = gtk.HButtonBox()
252 box.set_layout(gtk.BUTTONBOX_END)
255 exec_button = gtk.Button(stock = gtk.STOCK_EXECUTE)
256 text_button = gtk.Button(
"Text View")
257 quit_button = gtk.Button(stock = gtk.STOCK_QUIT)
264 quit_button.connect(
"clicked",
lambda w: gtk.main_quit())
270 window = self.textview.get_window()
277 entry = widget.get_child()
281 g4mate = gNistManager.FindOrBuildMaterial(self.
material)
282 if (g4mate ==
None) :
283 self.error_dialog.show_all()
286 if (self.material_list.count(self.
material) == 0) :
287 self.material_combo.append_text(self.
material)
293 self.textview.textbuffer.set_text(mycout.getvalue())
306 self.text_window.set_title(
'Value with Text')
307 self.text_window.set_position(gtk.WIN_POS_MOUSE)
308 self.text_window.set_default_size(500, 300)
311 self.text_window.add(vbox)
313 sw = gtk.ScrolledWindow()
314 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
318 textview = gtk.TextView()
322 hbox = gtk.HButtonBox()
323 hbox.set_layout(gtk.BUTTONBOX_END)
324 hbox.set_border_width(self.
__margin)
325 vbox.pack_start(hbox, expand=
False)
327 close_button = gtk.Button(stock = gtk.STOCK_CLOSE)
329 hbox.add(close_button)
335 self.text_window.hide_all()
345 default_stdout = sys.stdout
347 sys.stdout = mycout = StringIO()
357 sys.stdout = default_stdout
360 if __name__ ==
"__main__":
363 except KeyboardInterrupt :