2 # ==================================================================
3 # [Geant4] module package
7 # This package contains a set of Python interface with Geant4.
8 # ==================================================================
12 __date__ =
'November/2016'
13 __author__ =
'K.Murakami (Koichi.Murakami@kek.jp)'
16 from .G4interface
import *
17 from .G4intercoms
import *
18 from .G4global
import *
20 from .G4event
import *
21 from .G4tracking
import *
22 from .G4track
import *
23 from .G4particles
import *
24 from .G4processes
import *
25 from .G4geometry
import *
26 from .G4materials
import *
27 from .G4physicslists
import *
28 from .G4digits_hits
import *
29 from .G4visualization
import *
31 from .G4graphics_reps
import *
32 from .hepunit
import *
33 from .colortable
import *
36 print(
"""=============================================================
37 Welcome to Geant4Py (A Geant4-Python Bridge)
42 =============================================================
43 """ % ( __version__, __date__, __author__) )
68 gStackManager = gEventManager.GetStackManager()
71 gTrackingManager = gEventManager.GetTrackingManager()
104 _material_class_list = dir(G4materials)
105 _qfind = _material_class_list.count(
"G4NistManager") > 0
110 _visdriver_list = dir(G4visualization)
111 _q_opengl_ix =
"G4OpenGLImmediateX" in _visdriver_list
112 _q_opengl_sx =
"G4OpenGLStoredX" in _visdriver_list
113 _q_opengl_ixm =
"G4OpenGLImmediateXm" in _visdriver_list
114 _q_opengl_sxm =
"G4OpenGLStoredXm" in _visdriver_list
115 _q_raytracer_x =
"G4RayTracerX" in _visdriver_list
128 _raytracer_x = G4RayTracerX()
139 gVisManager.RegisterGraphicsSystem(_opengl_ix)
141 gVisManager.RegisterGraphicsSystem(_opengl_sx)
143 gVisManager.RegisterGraphicsSystem(_opengl_ixm)
145 gVisManager.RegisterGraphicsSystem(_opengl_sxm)
147 gVisManager.RegisterGraphicsSystem(_raytracer_x)
149 gVisManager.RegisterGraphicsSystem(_vrml1)
150 gVisManager.RegisterGraphicsSystem(_vrml2)
151 gVisManager.RegisterGraphicsSystem(_dawn)
152 gVisManager.RegisterGraphicsSystem(_heprep_xml)
153 gVisManager.RegisterGraphicsSystem(_heprep_file)
154 gVisManager.RegisterGraphicsSystem(_atree)
155 gVisManager.RegisterGraphicsSystem(_raytracer)
157 gVisManager.Initialize()
160 gG4Version = G4Version
162 gG4VERSION_NUMBER = G4VERSION_NUMBER
167 gControlExecute = gUImanager.ExecuteMacroFile
168 gApplyUICommand = G4intercoms.ApplyUICommand
169 gGetCurrentValues = gUImanager.GetCurrentValues
170 gStartUISession = G4interface.StartUISession
180 def _one_event(self):
181 "generate one event."
184 G4RunManager.OneEvent = _one_event
189 def _list_material(self):
191 n_materials = len(gMaterialTable)
192 print(
" +------------------------------------------------------------------")
193 print(
" | Table of G4Material-s (%d materails defined)" % (n_materials))
194 for i
in range(0, n_materials) :
195 material = gMaterialTable[i]
196 print(
" |--------------------------------------------------------"\
198 print(
" | %s: %s" % (material.GetName(),
199 G4BestUnit(material.GetDensity(),
"Volumic Mass")))
201 elementVec = material.GetElementVector()
202 fractionVec = material.GetFractionVector()
203 abundanceVec = material.GetVecNbOfAtomsPerVolume()
204 totNAtoms = material.GetTotNbOfAtomsPerVolume()
206 n_elements = len(elementVec)
207 for j
in range(0, n_elements):
208 print(
" | + (%1d) %s(%s): A=%4.1f, N=%5.1f, " \
209 "Frac.=(%4.1f%%m,%4.1f%%a)" % \
210 (j+1, elementVec[j].GetName(), elementVec[j].GetSymbol(),
211 elementVec[j].GetZ(),
212 elementVec[j].GetN(),
213 fractionVec[j]/hepunit.perCent,
214 abundanceVec[j]/totNAtoms/hepunit.perCent))
216 print(
" +------------------------------------------------------------------")
218 G4MaterialTable.ListMaterial = _list_material
225 gGeometryManager.OpenGeometry()
234 def _run_abort(signum, frame):
235 state = gStateManager.GetCurrentState()
237 if(state == G4ApplicationState.G4State_GeomClosed
or
238 state == G4ApplicationState.G4State_EventProc):
239 print(
"aborting Run ...")
240 gRunManager.AbortRun(
True)
242 raise KeyboardInterrupt
244 if (threading.activeCount() == 1):
245 signal.signal(signal.SIGINT, _run_abort)
static G4LossTableManager * Instance()
static G4VVisManager * GetConcreteInstance()
static G4MaterialTable * GetMaterialTable()
static G4RunManagerKernel * GetRunManagerKernel()
static G4NistManager * Instance()
static G4UImanager * GetUIpointer()
static G4StateManager * GetStateManager()
const G4ParticleDefinition const G4Material *G4double range
static G4GeometryManager * GetInstance()
void print(G4double elem)
static G4TransportationManager * GetTransportationManager()
static G4RunManager * GetRunManager()
static G4ProductionCutsTable * GetProductionCutsTable()
static G4ParticleTable * GetParticleTable()
static G4EventManager * GetEventManager()
void SetG4PyCoutDestination()
static G4ElementTable * GetElementTable()
static G4ProcessTable * GetProcessTable()