2 # ==================================================================
3 # [Geant4] module package
7 # This package contains a set of Python interface with Geant4.
8 # ==================================================================
11 __date__ =
'December/2019'
12 __author__ =
'K.Murakami (Koichi.Murakami@kek.jp)'
15 from .G4interfaces
import *
16 from .G4intercoms
import *
17 from .G4global
import *
19 from .G4event
import *
20 from .G4tracking
import *
21 from .G4track
import *
22 from .G4particles
import *
23 from .G4processes
import *
24 from .G4geometry
import *
25 from .G4materials
import *
26 from .G4physicslists
import *
27 from .G4digits_hits
import *
28 from .G4visualization
import *
29 from .G4graphics_reps
import *
30 from .hepunit
import *
31 from .colortable
import *
34 print(
"""=============================================================
35 Welcome to Geant4Py (A Geant4-Python Bridge)
39 =============================================================
40 """ % ( __version__, __date__) )
65 gStackManager = gEventManager.GetStackManager()
68 gTrackingManager = gEventManager.GetTrackingManager()
98 _material_class_list =
dir(G4materials)
99 _qfind = _material_class_list.count(
"G4NistManager") > 0
104 _visdriver_list =
dir(G4visualization)
105 _q_opengl_ix =
"G4OpenGLImmediateX" in _visdriver_list
106 _q_opengl_sx =
"G4OpenGLStoredX" in _visdriver_list
107 _q_opengl_ixm =
"G4OpenGLImmediateXm" in _visdriver_list
108 _q_opengl_sxm =
"G4OpenGLStoredXm" in _visdriver_list
109 _q_raytracer_x =
"G4RayTracerX" in _visdriver_list
122 _raytracer_x = G4RayTracerX()
133 gVisManager.RegisterGraphicsSystem(_opengl_ix)
135 gVisManager.RegisterGraphicsSystem(_opengl_sx)
137 gVisManager.RegisterGraphicsSystem(_opengl_ixm)
139 gVisManager.RegisterGraphicsSystem(_opengl_sxm)
141 gVisManager.RegisterGraphicsSystem(_raytracer_x)
143 gVisManager.RegisterGraphicsSystem(_vrml1)
144 gVisManager.RegisterGraphicsSystem(_vrml2)
145 gVisManager.RegisterGraphicsSystem(_dawn)
146 gVisManager.RegisterGraphicsSystem(_heprep_xml)
147 gVisManager.RegisterGraphicsSystem(_heprep_file)
148 gVisManager.RegisterGraphicsSystem(_atree)
149 gVisManager.RegisterGraphicsSystem(_raytracer)
151 gVisManager.Initialize()
154 gG4Version = G4Version
156 gG4VERSION_NUMBER = G4VERSION_NUMBER
161 gControlExecute = gUImanager.ExecuteMacroFile
162 gApplyUICommand = G4intercoms.ApplyUICommand
163 gGetCurrentValues = gUImanager.GetCurrentValues
164 gStartUISession = G4interfaces.StartUISession
175 "generate one event."
178 G4RunManager.OneEvent = _one_event
185 n_materials = len(gMaterialTable)
186 print(
" +------------------------------------------------------------------")
187 print(
" | Table of G4Material-s (%d materails defined)" % (n_materials))
188 for i
in range(0, n_materials) :
189 material = gMaterialTable[i]
190 print(
" |--------------------------------------------------------"\
192 print(
" | %s: %s" % (material.GetName(),
193 G4BestUnit(material.GetDensity(),
"Volumic Mass")))
195 elementVec = material.GetElementVector()
196 fractionVec = material.GetFractionVector()
197 abundanceVec = material.GetVecNbOfAtomsPerVolume()
198 totNAtoms = material.GetTotNbOfAtomsPerVolume()
200 n_elements = len(elementVec)
201 for j
in range(0, n_elements):
202 print(
" | + (%1d) %s(%s): A=%4.1f, N=%5.1f, " \
203 "Frac.=(%4.1f%%m,%4.1f%%a)" % \
204 (j+1, elementVec[j].GetName(), elementVec[j].GetSymbol(),
205 elementVec[j].GetZ(),
206 elementVec[j].GetN(),
207 fractionVec[j]/hepunit.perCent,
208 abundanceVec[j]/totNAtoms/hepunit.perCent))
210 print(
" +------------------------------------------------------------------")
212 G4MaterialTable.ListMaterial = _list_material
219 gGeometryManager.OpenGeometry()
229 state = gStateManager.GetCurrentState()
231 if(state == G4ApplicationState.G4State_GeomClosed
or
232 state == G4ApplicationState.G4State_EventProc):
233 print(
"aborting Run ...")
234 gRunManager.AbortRun(
True)
236 raise KeyboardInterrupt
238 if (threading.activeCount() == 1):
239 signal.signal(signal.SIGINT, _run_abort)