Python Interface for Geant 4 Medical Applications K
- Slides: 22
Python Interface for Geant 4 Medical Applications K. Murakami (KEK) 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 1
Introduction l Missing functionalities of current Geant 4 command-line interface l more powerful scripting environment l l l direct handling each object of G 4 XXX l l only simple flow control is available, but not enough. flow control, variables, arithmetic operation only limited manager-like classes can be exposed via G 4 UIcommand. Python is believed to be the most promising technological choice in terms of l Python as a powerful scripting language l Python can work as front-end of a light framework l modularization of user classes with dynamic loading scheme § § l Python as “Software Component Bus” l l C++ objects can be exposed to python. interconnectivity with many Python external modules, § 15/Jul/05 Detector. Construction, Physics. List, Primary. Generator. Action, User. Action-s It helps avoid code duplication. analysis tools (ROOT/AIDA), web interface, . . . 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 2
Project Aim of Geant 4 Py l Generic and straight forward approach of Pythonization of Geant 4 l l not specific to particular applications minimal dependencies of external packages l 15/Jul/05 only depending on Boost-Python, which is a common, well-established and freely available library. 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 3
Use-Case of Medical Application l System integration of developed components. . . l l l l l geometry modeling (DICOM, DICOM-RT, beam line, . . . ) physics list (EM, Hadron, Ion [BC, JQMD], . . . ) MPI parallelization (MPICH 2) Analysis packages (ROOT, HBOOK, AIDA, . . . ) Visualization (Real Intage, Doctor. View, AVS, . . . ) Web applications (mod-python, Cherry. Py) (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 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 4
Software Structure Applications l Components Implementation l Component Implementation l Other Frameworks XXX Framework Simulation Framework l . . . l l l Foundation Libraries l l l l l 15/Jul/05 Geant 4, JQMD, . . . MPICH, . . . LCG Python, Boost-Python CLHEP. . . l analysis (ROOT) visualization, . . . Software Component Bus l Foundation Libraries component models plug-in management scripting parallelization Other Frameworks l Optional Libraries geometry modeling physics list scoring, . . . Simulation Framework l Software Component Bus C++ application, Python scripts, Web applications, . . . Python, API, original interface Optional Libraries l l l ROOT, CERNLIB, . . . JAVA, Qt, Tk. . . 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 5
Tools for Geant 4/Python interface l l There are several activities; SWIG l l l LCG Python Geant 4 interface l l supports for multiple languages Implementation of G 4/Python interface can be found in advanced examples (Tiara). using Py. Reflex tool Boost-Python l l 15/Jul/05 a part of comprehensive Boost C++ library, but independent from other components focused to C++/python interface, so performance loss is not so much. 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 6
What is/isnot Exposed What is exposed: l Classes for main Geant 4 flow control l l Some Utility classes l l G 4 User. Detetor. Construction, G 4 User. Physics. List, G 4 User. XXXAction (Primary. Generator, Run, Event, Stepping, . . . ) can be inherited in Python side Classes having information to be analyzed l l G 4 String, G 4 Three. Vector, G 4 Rotation. Matrix, . . . Classes of base classes of user actions l l G 4 Run. Manager, G 4 UImanager, G 4 UIterminal G 4 Step, G 4 Track, G 4 Step. Point, G 4 Particle. Definition, . . . Classes for construction user inputs l G 4 Particle. Gun, G 4 Box, G 4 PVPlacement, . . . What is not exposed: l NOT all methods are exposed. l l only safe methods (getting internal information) are exposed. Out of Scope l l l 15/Jul/05 implementation of physics processes implementation of internal control flows It just ends in deterioration of performance. 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 7
Module Structure l Python module name : “Geant 4” l including CLHEP components typedef-ed as G 4 XXX, like l G 4 Three. Vector, G 4 Rotation. Matrix, . . . l l Units definition (“HEPUnit” as namespace) From users side, >>> import Geant 4 >>> from Geant 4 import * l “Geant 4” module consists of a collection of submodules same as Geant 4 directory structure. l run/event/particle/geometry/track/. . . 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 8
Name Policy in Python side l Names of classes as well as methods are same as used in Geant 4. >>> g. Run. Manager= Geant 4. G 4 Run. Manager() >>> g. Run. Manager. Beam. On(10) l l 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 G 4 UImanager, can not be exposed in Boost. Python. So, necessary members of such classes are exposed directly in Geant 4 namespace. >>> Geant 4. g. Apply. UIcommand(“/run/beam. On”) >>> Geant 4. g. Get. Current. Values(“/run/verbose”) >>> Geant 4. g. Start. UISession() 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 9
Global Variables/Functions l Some global variables/functions starting with "g“ are predefined. l g. Run. Manager l g. Vis. Manager l g. Apply. UIcommand() l g. Get. Current. Values() l g. Start. UISession() l l l g. Run. Manager and g. Vis. Manager 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 (Open. GL, VRML, DAWN, . . . ) are automatically registered. So users are now free from implementation of Vis. Manager. Note that care from C++ side is of course in need! if(G 4 Run. Manager: : Get. Run. Manager() ==0 ) G 4 Run. Manager* run. Manager= new G 4 Run. Manager(); 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 10
List of Current Exposed Classes l l l l G 4 UImanager G 4 UIterminal l l G 4 Run. Manager G 4 VUser. Detector. Construction G 4 VUser. Physics. List G 4 User. Run. Action G 4 VUser. Primary. Generator. Action G 4 Run l l l G 4 Event G 4 Particle. Gun G 4 User. Event. Action tracking l l G 4 User. Stepping. Action l G 4 Material visualization l l 15/Jul/05 G 4 VTouchable G 4 Touchable. Histotry G 4 VPhysical. Volume material l l G 4 Particle. Definition G 4 Dynamic. Particle G 4 Primary. Vertex geometry l l G 4 Step G 4 Track G 4 Step. Point G 4 Step. Status G 4 Track. Status particles l event l l l run l track l G 4 String G 4 Three. Vector interface l l l global G 4 Vis. Manager G 4 VGraphic. System G 4 Open. GLStored. X. . . 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 11
Various Levels of Pythonization l Various level of pythonized application can be realized. l l It is completely up to users! Two metrics l l 15/Jul/05 Execution Speed l just wrapping current existing applications Interactivity l interactive analysis l rapid prototyping l educational use for G 4 primer 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 12
Use-case of Pythonization Execution Speed large scale of mass production a collection of short productions with various running conditions applications having interconnections with other software components interactive analysis free from compilation - rapid prototyping - educational uses 15/Jul/05 Interactivity/ Pythonization 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 13
An Example of Exposure of Users’ Application l Uses’ existing applications are easily exposed to python following a simple prescription of Boost-Python manner. BOOST_PYTHON_MODULE(demo_wp){ class_<My. Application>("My. Application", "my application"). def("Configure", &My. Application: : Configure) ; class_<My. Materials>("My. Materials", "my material"). def("Construct", &My. Materials: : Construct) ; class_<My. Detector. Construction, My. Detector. Construction*, bases<G 4 VUser. Detector. Construction> > ("My. Detector. Construction", "my detector") ; class_<My. Physics. List, My. Physics. List*, bases<G 4 VUser. Physics. List> > ("My. Physics. List", "my physics list") ; } 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 14
A Medical Application Example l l Several examples of using Python interface are/will be presented. An example of “water phantom dosimetry” This demo program shows that a Geant 4 application well coworks with ROOT on Python front end. Vis. Manager, Primary. Generator. Action, User. Action-s, histogramming with ROOT are implemented in Python. l l 15/Jul/05 dose calculation in a water phantom Python overloading of user actions on-line histogramming with ROOT visualization 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 15
Example of A Python Script from Geant 4 import * import demo_wp # module of a user G 4 application import ROOT # ------------------------------class My. Run. Action(G 4 User. Run. Action): # Python inheritance "My Run Action“ def End. Of. Run. Action(self, run): # method override print "*** End of Run“ print "- Run sammary : (id= %d, #events= %d)" % (run. ID, run. number. Of. Event. To. Be. Processed) # ------------------------------class My. Primary. Generator. Action(G 4 VUser. Primary. Generator. Action): "My Primary Generator Action“ def __init__(self): G 4 VUser. Primary. Generator. Action. __init__(self) self. particle. Gun= G 4 Particle. Gun(1) def Generate. Primaries(self, event): self. particle. Gun. Generate. Primary. Vertex(event) 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 16
# user detector construction (C++) my. DC= demo_wp. My. Detector. Construction() g. Run. Manager. Set. User. Initialization(my. DC) # user physics list (C++) my. PL= demo_wp. My. Physics. List() g. Run. Manager. Set. User. Initialization(my. PL) # user P. G. A (Python) my. PGA= My. Primary. Generator. Action() g. Run. Manager. Set. User. Action(my. PGA). . . # setting particle gun pg= my. PGA. particle. Gun pg. Set. Particle. By. Name("proton") pg. Set. Particle. Energy(230. *HEPUnit. Me. V) pg. Set. Particle. Momentum. Direction(G 4 Three. Vector(0. , 1. )) pg. Set. Particle. Position(G 4 Three. Vector(0. , -20. )*HEPUnit. cm) g. Run. Manager. Initialize() g. Apply. UICommand("/control/execute vis. mac") g. Run. Manager. Beam. On(100) 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 17
15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 18
Further to go. . . l Making rapid progress for implementation of missing elements l Realize interconnection with various software components; l l l l 15/Jul/05 example of using AIDA example of using GDML multi-thread and parallelization web application GUI support in specific application contexts GRID service. . . 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 19
Software Requirements l l l All libraries should be compiled in shared libraries. Python BOOST-Python l l Geant 4 l 7. 0 or later l - should be built in "global" and "shared" libraries. - All header files should be collected into $(G 4 INSTALL)/include by "make includes" l l CLHEP l l l 1. 32, latest 1. 9. 1. 1 or later - building shared objects is supported since version 1. 9. Platforms l SUSE Linux 9. 3 is a development environment. l l l 15/Jul/05 It is the easiest way to go, because Boost C++ library is preinstalled. Scientific Linux 3 (SL 3) is checked for well working. SL 4 will be checked as well. 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 20
Summary l l Python Interface of Geant 4 (Geant 4 Py) has been well designed and implementation is now rapidly on-going. GRID MPI Python as a powerful scripting language l much better interactivity Python l l configuration rapid prototyping Geant 4 Py Py. ROOT math. . . GUI shell Geat 4 Root Classes l Python as “Software Component Bus” l interconnectivity with various kind of software components. l l l histogramming with ROOT system integration We have a plan to commit the package into the next December release. l “environments/” directory is a suitable position 15/Jul/05 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 21
Resources l Project Home Page l l CVS view l l http: //www-geant 4. kek. jp/projects/Geant 4 Py/cvs/ Wiki l l 15/Jul/05 Technical notes for the developers http: //wwwgeant 4. kek. jp/projects/Geant 4 Py/pukiwiki/ 4 th Workshop on Geant 4 Bio-medical Developments and Physics Validation 22
- Interface in interface java
- Office interface vs industrial interface
- Office interface vs industrial interface
- An interface
- Myrtillier géant
- Geant network map
- Sanglier de turquie
- La plus grosse pelle du monde
- Action geant
- Geant computer
- Geant simulation
- Geant 4
- Fernand bachelard
- Exposé panda géant
- Geant 4
- Niconical
- Pub geant
- Gate geant
- Pion geant
- Chenille brahmin
- Python gui design
- Interface python 3
- Desktop automation using python