Geant4_10
__init__.py
Go to the documentation of this file.
1 """
2 # ==================================================================
3 # [Geant4] module package
4 #
5 # Welcome to Geant4Py.
6 #
7 # This package contains a set of Python interface with Geant4.
8 # ==================================================================
9 """
10 # $Id: __init__.py 66892 2013-01-17 10:57:59Z gunter $
11 __version__ ='9.5.0'
12 __date__ = '02/December/2011'
13 __author__ = 'K.Murakami (Koichi.Murakami@kek.jp)'
14 
15 # import submodules
16 from G4interface import *
17 from G4intercoms import *
18 from G4global import *
19 from G4run 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 *
30 from G4gdml import *
31 from G4graphics_reps import *
32 from hepunit import *
33 from colortable import *
34 
36  print """=============================================================
37  Welcome to Geant4Py (A Geant4-Python Bridge)
38 
39  Version : %s
40  Date : %s
41  Contact : %s
42 =============================================================
43 """ % ( __version__, __date__, __author__)
44 
45 # ==================================================================
46 # initialize
47 # ==================================================================
48 # set G4cout/G4cerr to Python stdout
50 
51 # ==================================================================
52 # globals, which start with "g"
53 # ==================================================================
54 # gRunManager
55 if G4RunManager.GetRunManager() == None:
56  gRunManager = G4RunManager()
57 else:
58  gRunManager = G4RunManager.GetRunManager()
60 
61 # gUImanager
63 
64 # gEventManager
66 
67 # gStackManager
68 gStackManager = gEventManager.GetStackManager()
69 
70 # gTrackingManager
71 gTrackingManager = gEventManager.GetTrackingManager()
72 
73 # gStateManager
75 gExceptionHandler = G4ExceptionHandler() # automatically registered
76 
77 # gGeometryManager
78 gGeometryManager = G4GeometryManager.GetInstance()
79 
80 # gTransportationManager
82 
83 # gParticleTable
85 gParticleIterator = PyG4ParticleList()
86 
87 # gProcessTable
89 
90 # gLossTableManager
91 gLossTableManager = G4LossTableManager.Instance()
92 
93 # gProductionCutsTable
95 
96 # gEmCalculator
97 gEmCalculator = G4EmCalculator()
98 
99 # gMaterial/ElementTable
100 gMaterialTable = G4Material.GetMaterialTable()
101 gElementTable = G4Element.GetElementTable()
102 
103 # gNistManager (since 7.1)
104 _material_class_list = dir(G4materials)
105 _qfind = _material_class_list.count("G4NistManager") > 0
106 if _qfind:
107  gNistManager = G4NistManager.Instance()
108 
109 # gVisManager
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
116 
118  gVisManager = G4VisManager()
119  if _q_opengl_ix:
120  _opengl_ix = G4OpenGLImmediateX()
121  if _q_opengl_sx:
122  _opengl_sx = G4OpenGLStoredX()
123  if _q_opengl_ixm:
124  _opengl_ixm = G4OpenGLImmediateXm()
125  if _q_opengl_sxm:
126  _opengl_sxm = G4OpenGLStoredXm()
127  if _q_raytracer_x:
128  _raytracer_x = G4RayTracerX()
129 
130  _vrml1 = G4VRML1File()
131  _vrml2 = G4VRML2File()
132  _dawn = G4DAWNFILE()
133  _heprep_xml = G4HepRep()
134  _heprep_file = G4HepRepFile()
135  _atree = G4ASCIITree()
136  _raytracer = G4RayTracer()
137 
138  if _q_opengl_ix:
139  gVisManager.RegisterGraphicsSystem(_opengl_ix)
140  if _q_opengl_sx:
141  gVisManager.RegisterGraphicsSystem(_opengl_sx)
142  if _q_opengl_ixm:
143  gVisManager.RegisterGraphicsSystem(_opengl_ixm)
144  if _q_opengl_sxm:
145  gVisManager.RegisterGraphicsSystem(_opengl_sxm)
146  if _q_raytracer_x:
147  gVisManager.RegisterGraphicsSystem(_raytracer_x)
148 
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)
156 
157  gVisManager.Initialize()
158 
159 # version information
160 gG4Version = G4Version
161 gG4Date = G4Date
162 gG4VERSION_NUMBER = G4VERSION_NUMBER
163 
164 # ------------------------------------------------------------------
165 # functions
166 # ------------------------------------------------------------------
167 gControlExecute = gUImanager.ExecuteMacroFile
168 gApplyUICommand = G4intercoms.ApplyUICommand
169 gGetCurrentValues = gUImanager.GetCurrentValues
170 gStartUISession = G4interface.StartUISession
171 
172 
173 # ==================================================================
174 # extentions
175 # ==================================================================
176 
177 # ------------------------------------------------------------------
178 # generate one event
179 # ------------------------------------------------------------------
180 def _one_event(self):
181  "generate one event."
182  self.BeamOn(1)
183 
184 G4RunManager.OneEvent = _one_event
185 
186 # ------------------------------------------------------------------
187 # list material information
188 # ------------------------------------------------------------------
189 def _list_material(self):
190  "list materials."
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 " |--------------------------------------------------------"\
197  "----------"
198  print " | %s: %s" % (material.GetName(),
199  G4BestUnit(material.GetDensity(),"Volumic Mass"))
200 
201  elementVec = material.GetElementVector()
202  fractionVec = material.GetFractionVector()
203  abundanceVec = material.GetVecNbOfAtomsPerVolume()
204  totNAtoms = material.GetTotNbOfAtomsPerVolume()
205 
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)
215 
216  print " +------------------------------------------------------------------"
217 
218 G4MaterialTable.ListMaterial = _list_material
219 
220 
221 # ------------------------------------------------------------------
222 # termination
223 # ------------------------------------------------------------------
225  gGeometryManager.OpenGeometry()
226 
227 
228 # ------------------------------------------------------------------
229 # signal handler
230 # ------------------------------------------------------------------
231 import signal
232 import threading
233 
234 def _run_abort(signum, frame):
235  state = gStateManager.GetCurrentState()
236 
237  if(state == G4ApplicationState.G4State_GeomClosed or
238  state == G4ApplicationState.G4State_EventProc):
239  print "aborting Run ..."
240  gRunManager.AbortRun(True)
241  else:
242  raise KeyboardInterrupt
243 
244 if (threading.activeCount() == 1):
245  signal.signal(signal.SIGINT, _run_abort)
246 
247 
static G4LossTableManager * Instance()
static G4VVisManager * GetConcreteInstance()
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:564
static G4RunManagerKernel * GetRunManagerKernel()
static G4NistManager * Instance()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
static G4StateManager * GetStateManager()
const G4ParticleDefinition const G4Material *G4double range
if(nlines<=0)
static G4GeometryManager * GetInstance()
static G4TransportationManager * GetTransportationManager()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
static G4ProductionCutsTable * GetProductionCutsTable()
static G4ParticleTable * GetParticleTable()
static G4EventManager * GetEventManager()
void SetG4PyCoutDestination()
Definition: pyglobals.cc:50
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:395
static G4ProcessTable * GetProcessTable()
def gTerminate
Definition: __init__.py:224
TDirectory * dir
Definition: macro.C:5
def print_version
Definition: __init__.py:35