15/jul/054th workshop on geant4 bio-medical developments and physics validation 1 python interface...
Post on 27-Dec-2015
218 Views
Preview:
TRANSCRIPT
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
1
Python Interface forPython Interface forGeant4 Medical Geant4 Medical
ApplicationsApplications
K.Murakami
(KEK)
15/Jul/05
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
2
IntroductionIntroduction Missing functionalities of current Geant4 command-line interface
more powerful scripting environment only simple flow control is available, but not enough. flow control, variables, arithmetic operation
direct handling each object of G4XXX only limited manager-like classes can be exposed via G4UIcommand.
Python is believed to be the most promising technological choice in terms of Python as a powerful scripting language
Python can work as front-end of a light framework modularization of user classes with dynamic loading scheme
DetectorConstruction, PhysicsList, PrimaryGeneratorAction, UserAction-s It helps avoid code duplication.
Python as “Software Component Bus” C++ objects can be exposed to python. interconnectivity with many Python external modules,
analysis tools (ROOT/AIDA), web interface,...
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
3
Project Aim of Geant4PyProject Aim of Geant4Py
Generic and straight forward approach of Pythonization of Geant4 not specific to particular applications minimal dependencies of external packages
only depending on Boost-Python, which is a common, well-established and freely available library.
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
4
Use-Case of Medical Use-Case of Medical ApplicationApplication System integration of developed components...
geometry modeling (DICOM, DICOM-RT, beam line, ...) physics list (EM, Hadron, Ion [BC, JQMD], ...) MPI parallelization (MPICH2) Analysis packages (ROOT, HBOOK, AIDA, ...) Visualization (Real Intage, DoctorView, AVS, ...) Web applications (mod-python, CherryPy) (G)UI (Java, Python, Web App., Qt, Tk, ...) Grid service (LCG, Clarens)
Interconnectivity with these items can be realized via Python interface.
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
5
Software StructureSoftware Structure Applications
C++ application, Python scripts, Web applications, ...
Component Implementation geometry modeling physics list scoring, ...
Simulation Framework component models plug-in management scripting parallelization
Other Frameworks analysis (ROOT) visualization, ...
Software Component Bus Python, API, original interface
Applications
Sim
ula
tion
Fram
ew
ork
FoundationLibraries
OptionalLibraries
XX
XFr
am
ew
ork
Oth
er
Fram
ew
ork
s...
Software Component Bus
Foundation Libraries Geant4, JQMD, ... MPICH, ... LCG Python, Boost-Python CLHEP ...
Optional Libraries ROOT, CERNLIB, ... JAVA, Qt, Tk ...
Components Implementation
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
6
Tools for Geant4/Python interfaceTools for Geant4/Python interface There are several activities; SWIG
supports for multiple languages Implementation of G4/Python interface can be found in advanced
examples (Tiara).
LCG Python Geant4 interface using PyReflex tool
Boost-Python a part of comprehensive Boost C++ library, but independent from
other components focused to C++/python interface, so performance loss is not so m
uch.
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
7
What is/isnot ExposedWhat is/isnot ExposedWhat is exposed: Classes for main Geant4 flow control
G4RunManager, G4UImanager, G4UIterminal Some Utility classes
G4String, G4ThreeVector, G4RotationMatrix, ... Classes of base classes of user actions
G4UserDetetorConstruction, G4UserPhysicsList, G4UserXXXAction (PrimaryGenerator, Run, Event, Stepping,...) can be inherited in Python side
Classes having information to be analyzed G4Step, G4Track, G4StepPoint, G4ParticleDefinition, ...
Classes for construction user inputs G4ParticleGun, G4Box, G4PVPlacement, ...
What is not exposed: NOT all methods are exposed.
only safe methods (getting internal information) are exposed. Out of Scope
implementation of physics processes implementation of internal control flows It just ends in deterioration of performance.
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
8
Module StructureModule Structure
Python module name : “Geant4” including CLHEP components typedef-ed as G4XXX, like
G4ThreeVector, G4RotationMatrix, ... Units definition (“HEPUnit” as namespace)
From users side,>>> import Geant4
>>> from Geant4 import * “Geant4” module consists of a collection of submodu
les same as Geant4 directory structure. run/event/particle/geometry/track/...
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
9
Name Policy in Python sideName Policy in Python side
Names of classes as well as methods are same as used in Geant4.
>>> gRunManager= Geant4.G4RunManager()>>> gRunManager.BeamOn(10)
This makes it easy to translate from C++ to Python, and vice versa.
As an exception, pure singleton class, which has no public constructor, like G4UImanager, can not be exposed in Boost-Python. So, necessary members of such classes are exposed directly in Geant4 namespace.
>>> Geant4.gApplyUIcommand(“/run/beamOn”)>>> Geant4.gGetCurrentValues(“/run/verbose”) >>> Geant4.gStartUISession()
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
10
Global Variables/FunctionsGlobal Variables/Functions Some global variables/functions starting with "g“ are predefined.
gRunManager gVisManager gApplyUIcommand() gGetCurrentValues() gStartUISession()
gRunManager and gVisManager are taken care not so as to be doubly instantiated, so that users do not have to take any more care about the timing of object instantiation in python side.
All of visualization drivers (OpenGL, VRML, DAWN, ...) are automatically registered. So users are now free from implementation of VisManager.
Note that care from C++ side is of course in need!if(G4RunManager::GetRunManager() ==0 ) G4RunManager* runManager= new G4RunManager();
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
11
List of Current Exposed ClassesList of Current Exposed Classes global
G4String G4ThreeVector
interface G4UImanager G4UIterminal
run G4RunManager G4VUserDetectorConstruction G4VUserPhysicsList G4UserRunAction G4VUserPrimaryGeneratorAction G4Run
event G4Event G4ParticleGun G4UserEventAction
tracking G4UserSteppingAction
track G4Step G4Track G4StepPoint G4StepStatus G4TrackStatus
particles G4ParticleDefinition G4DynamicParticle G4PrimaryParticle G4PrimaryVertex
geometry G4VTouchable G4TouchableHistotry G4VPhysicalVolume
material G4Material
visualization G4VisManager G4VGraphicSystem G4OpenGLStoredX ...
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
12
Various Levels of PythonizationVarious Levels of Pythonization
Various level of pythonized application can be realized. It is completely up to users!
Two metrics Execution Speed
just wrapping current existing applications Interactivity
interactive analysis rapid prototyping educational use for G4 primer
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
13
Use-case of PythonizationUse-case of PythonizationExecution Speed
Interactivity/Pythonization
large scale of mass production
a collection of short productionswith various running conditions
applications having interconnections with other software components
interactive analysis
free from compilation- rapid prototyping- educational uses
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
14
An Example of Exposure of Users’ An Example of Exposure of Users’ ApplicationApplication
Uses’ existing applications are easily exposed to python following a simple prescription of Boost-Python manner.
BOOST_PYTHON_MODULE(demo_wp){ class_<MyApplication>("MyApplication", "my application") .def("Configure", &MyApplication::Configure) ; class_<MyMaterials>("MyMaterials", "my material") .def("Construct", &MyMaterials::Construct) ; class_<MyDetectorConstruction, MyDetectorConstruction*, b
ases<G4VUserDetectorConstruction> > ("MyDetectorConstruction", "my detector")
; class_<MyPhysicsList, MyPhysicsList*, bases<G4VUserPhy
sicsList> > ("MyPhysicsList", "my physics list") ;}
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
15
A Medical Application ExampleA Medical Application Example Several examples of using Python interface are/will be pr
esented. An example of “water phantom dosimetry”
This demo program shows that a Geant4 applicationwell coworks with ROOT on Python front end.VisManager, PrimaryGeneratorAction, UserAction-s, histogramming with ROOT are implemented in Python.
dose calculation in a water phantom Python overloading of user actions on-line histogramming with ROOT visualization
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
16
Example of A Python ScriptExample of A Python Scriptfrom Geant4 import *import demo_wp # module of a user G4 applicationimport ROOT
# -------------------------------------------------------------class MyRunAction(G4UserRunAction): # Python inheritance "My Run Action“def EndOfRunAction(self, run): # method override print "*** End of Run“ print "- Run sammary : (id= %d, #events= %d)" \ % (run.runID, run.numberOfEventToBeProcessed)
# -------------------------------------------------------------class MyPrimaryGeneratorAction(G4VUserPrimaryGeneratorAction): "My Primary Generator Action“ def __init__(self): G4VUserPrimaryGeneratorAction.__init__(self) self.particleGun= G4ParticleGun(1)
def GeneratePrimaries(self, event): self.particleGun.GeneratePrimaryVertex(event)
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
17
# user detector construction (C++)myDC= demo_wp.MyDetectorConstruction() gRunManager.SetUserInitialization(myDC)
# user physics list (C++)myPL= demo_wp.MyPhysicsList()gRunManager.SetUserInitialization(myPL)
# user P.G.A (Python)myPGA= MyPrimaryGeneratorAction()gRunManager.SetUserAction(myPGA)
...# setting particle gunpg= myPGA.particleGunpg.SetParticleByName("proton")pg.SetParticleEnergy(230.*HEPUnit.MeV)pg.SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.))pg.SetParticlePosition(G4ThreeVector(0.,0.,-20.)*HEPUnit.cm)
gRunManager.Initialize()
gApplyUICommand("/control/execute vis.mac")gRunManager.BeamOn(100)
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
18
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
19
Further to go...Further to go...
Making rapid progress for implementation of missing elements
Realize interconnection with various software components; example of using AIDA example of using GDML multi-thread and parallelization web application GUI support in specific application contexts GRID service ...
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
20
Software RequirementsSoftware Requirements All libraries should be compiled in shared libraries. Python BOOST-Python
1.32, latest Geant4
7.0 or later - should be built in "global" and "shared" libraries. - All header files should be collected into $(G4INSTALL)/include by "make
includes" CLHEP
1.9.1.1 or later - building shared objects is supported since version 1.9.
Platforms SUSE Linux 9.3 is a development environment.
It is the easiest way to go, because Boost C++ library is preinstalled. Scientific Linux 3 (SL3) is checked for well working. SL4 will be checked as well.
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
21
SummarySummary Python Interface of Geant4 (Geant4Py) has been well designed a
nd implementation is now rapidly on-going. Python as a powerful scripting language
much better interactivity configuration rapid prototyping
Python as “Software Component Bus” interconnectivity with various kind of software components.
histogramming with ROOT system integration
We have a plan to commit the package into the next December release. “environments/” directory is a suitable position
GUIPython
math...shell
GRIDGUI
PyROOT
RootClasses
MPI
Geant4Py
Geat4Classes
15/Jul/05 4th Workshop on Geant4 Bio-medical Developments and Physics Validation
22
ResourcesResources
Project Home Page http://www-geant4.kek.jp/projects/Geant4Py/
CVS view http://www-geant4.kek.jp/projects/Geant4Py/cvs/
Wiki Technical notes for the developers http://www-geant4.kek.jp/projects/Geant4Py/puki
wiki/
top related