Lets start with import Geant 4 A Geant

  • Slides: 15
Download presentation
Let's start with " >>> import Geant 4" A Geant 4 -Python Bridge Application

Let's start with " >>> import Geant 4" A Geant 4 -Python Bridge Application of Geant 4 Python Interface Koichi Murakami KEK / CRC Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006)

Python n Shell Environment ü front end shell ü script language n Programming Language

Python n Shell Environment ü front end shell ü script language n Programming Language ü ü much easier than C++ supporting Object-Oriented programming providing multi-language binding (C-API) dynamic binding » modularization of software components » many third-party modules (just plug-in) » software component bus n Runtime Performance ü slower than compiled codes, but not so slow. ü Performance can be tunable between speed and interactivity. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 2

Motivation of Geant 4 -Python Bridge n Improving functionalities of current Geant 4 UI

Motivation of Geant 4 -Python Bridge n Improving functionalities of current Geant 4 UI ü more powerful scripting environment » driving Geant 4 on a Python front end » flow control, variables, arithmetic operation n flexibility in the configuration of user applications ü Modularization of user classes with dynamic loading scheme » Detector. Construction, Physics. List, Primary. Generator. Action, User. Action-s » It helps avoid code duplication. ü quick prototyping and testing n Software component bus ü interconnectivity with many Python external modules, » analysis tools (ROOT/AIDA), plotting tools (Sci. Py/matplotlib) ü middleware for application developers » GUI applications/web applications » much quicker development cycle Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 3

Modular Approach and Software Component Bus Analysis • ROOT • AIDA GUI • QT

Modular Approach and Software Component Bus Analysis • ROOT • AIDA GUI • QT • Wx Web App. Python Bus User Application Analysis-A Ex. N 02 Geometry Particle. Gun import Geometry modules Ex. N 03 Geometry-A Koichi Murakami Physics. List-EMstd import Analysis modules import PGA modules import Analysis-B PL modules Analysis-C Particle. Beam Medical. Beam Physics. List-Em. Low. E Physics. List-A Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 4

Geant 4 Py n “Geant 4 Py” is included in the Geant 4 distribution

Geant 4 Py n “Geant 4 Py” is included in the Geant 4 distribution since the 8. 1 release. ü please check the directory “environments/g 4 py/” ü Linux and Mac. OSX(10. 4+XCode 2. 3/4) are currently supported. n A G 4 -Python bridge as “Natural Pythonization” of Geant 4 ü start with just importing the module; » >>> import Geant 4 ü ü not specific to particular applications same class names and their methods keeping compatibility with the current UI scheme minimal dependencies of external packages » only depending on Boost-Python C++ Library, which is a common, well -established and freely available library. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 5

What is Exposed to Python n Currently, over 100 classes over different categories are

What is Exposed to Python n Currently, over 100 classes over different categories are exposed to Python. ü Classes for Geant 4 managers » G 4 Run. Manager, G 4 Event. Manager, … ü UI classes » G 4 UImanager, G 4 UIterminal, G 4 UIcommand, … ü Utility classes » G 4 String, G 4 Three. Vector, G 4 Rotation. Matrix, . . . ü Classes of base classes of user actions » 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 » G 4 Step, G 4 Track, G 4 Step. Point, G 4 Particle. Definition, . . . ü Classes for construction user inputs » G 4 Particle. Gun, G 4 Box, G 4 PVPlacement, . . . n NOT all methods are exposed. ü Only safe methods are exposed. » Getting internal information are exposed. » Some setter methods can easily break simulation results. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 6

Extensibility n Your own classes can be exposed, and create your own modules in

Extensibility n Your own classes can be exposed, and create your own modules in the Boost-Python manner. BOOST_PYTHON_MODULE(mymodule){   class_<My. Application>("My. Application", "my application")     . def("Configure", &My. Application: : Configure) ; n Once an abstract class is exposed to Python, you can implement/override its derived class in the Python side. class My. Run. Action(G 4 User. Run. Action):   “””My Run Action”””   def Begin. Of. Run. Action(self, run):     print "*** #event to be processed (BRA)=“,     run. Get. Number. Of. Event. To. Be. Processed()   def End. Of. Run. Action(self, run): print "*** run end run(ERA)=", run. Get. Run. ID() Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 7

Compatibility with G 4 UImanager n Geant 4 Py provides a bridge to G

Compatibility with G 4 UImanager n Geant 4 Py provides a bridge to G 4 UImanager. ü Keeping compatibility with current usability n UI Commands ü g. Apply. UICommand(“/xxx”) allows to execute any G 4 UI commands. ü Current values can be obtained by g. Get. Current. Values(“/xxx”). n Existing G 4 macro files can be reused. ü g. Control. Execute(“macro_file_name”) n Front end shell can be activated from Python ü g. Start. UISession() starts G 4 UIsession. » g 4 py(Idle): // invoke a G 4 UI session » when exit the session, go back to the Python front end n Python variables/methods starting “g” are global. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 8

Predefined Modules n We will also provide site-module package as predefined components for easy-to-use

Predefined Modules n We will also provide site-module package as predefined components for easy-to-use as well as good examples. ü Material » NIST materials via G 4 Nist. Manager ü Geometry » “ex. N 03” geometry as pre-defined geometry » “EZgeometry” ― provides functionalities for easy geometry setup ü Physics List » pre-defined physics lists » easy access to cross sections, stopping powers, . . . via G 4 Em. Calculator ü Primary Generator Action » particle gun / particle beam ü Sensitive Detector » calorimeter type / tracker type ü Scorer » MC particle/vertex n They can be used just by importing modules. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 9

Yet Another Way to Create Geometry n “EZgeom” module provides an easy way to

Yet Another Way to Create Geometry n “EZgeom” module provides an easy way to create simple users geometries; ü structure of geometry construction is hidden; » Solid/Logical Volume/World Volume » “EZvolume” is the only gateway to a physical volume from users side. ü automatic creation of the world volume » volume size should be cared. ü creating CSG-solid volumes (Box, Tube, Sphere, …) ü changing volume materials ü creating nested volumes » placing a volume in the world by default ü creating replicas / voxelizing BOX volumes ü setting detector sensitivities ü setting visualization attributes Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 10

Example of using EZgeom package import NISTmaterials from EZsim import EZgeom from EZsim. EZgeom

Example of using EZgeom package import NISTmaterials from EZsim import EZgeom from EZsim. EZgeom import G 4 Ez. Volume less than 20 lines!! NISTmaterials. Construct() # set Detector. Construction to the Run. Manager EZgeom. Construct() # reset world material air= g. Nist. Manager. Find. Or. Build. Material("G 4_AIR") EZgeom. Set. World. Material(air) # dummy box detector_box=G 4 Ez. Volume("Detector. Box") detector_box. Create. Box. Volume(air, 20. *cm, 40. *cm) detector_box_pv= detector_box. Place. It(G 4 Three. Vector(0. , 20. *cm)) # calorimeter placed inside the box cal= G 4 Ez. Volume("Calorimeter") nai= g. Nist. Manager. Find. Or. Build. Material("G 4_SODIUM_IODIDE") cal. Create. Box. Volume(nai, 5. *cm, 30. *cm) dd= 5. *cm for ical in range(-1, 2): cal. Pos= G 4 Three. Vector(dd*ical, 0. ) cal. Place. It(cal. Pos, ical+1, detector_box) Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 0 1 2 11

A Medical Application Example n Several examples of using Python interface are/will be presented.

A Medical Application Example n Several examples of using Python interface are/will be presented. n An example of “water phantom dosimetry” ü This demo program shows that a Geant 4 application well coworks with ROOT on the Python front end. n You can look features of; ü dose calculation in a water phantom ü Python implementation of sensitive detector ü Python overloading of user actions ü on-line histogramming with ROOT ü visualization Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 12

Pythonization Level n Various level of pythonized application can be realized. ü It is

Pythonization Level n Various level of pythonized application can be realized. ü It is completely up to users! ü Optimized point depends on what you want to do in Python. n There are two metrics; ü Execution Speed » wrap out current existing C++ components, and configure them » no performance loss in case of object controller ü Interactivity » more scripting in interactive analysis/rapid prototyping » pay performance penalty to interpretation in stepping actions. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 13

Applications of Pythonization modularized “compiled” components. Execution Speed - detector construction Productions changing conditions

Applications of Pythonization modularized “compiled” components. Execution Speed - detector construction Productions changing conditions - physics list - physics validation/verification - user actions , and handling components by scripting Coworking with other software components - interactive analysis “radiotherapy simulation for histogramming with ROOT” “online different configurations of “web application: Users can execute server different facilities” applications via web compiled modules and scripting user actions browsers” - filling histograms Fully scripting - rapid prototyping - educational uses “GUI control panel for educational uses: using “predefined” module and scripting Various parameters (detector parameters, initial particles, processes, etc) can be Interactivity/ “plotting photon cross sections” changed on GUI” Pythonization Koichi Murakami Performance can be tunable between speed and interactivity. Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 14

Summary n A Python interface of Geant 4 (Geant 4 Py) has been well

Summary n A Python interface of Geant 4 (Geant 4 Py) has been well designed and Geant 4 Py is now included in the latest release, 8. 1. ü check the “environments/g 4 py/” directory n Python as a powerful scripting language ü much better interactivity » easy and flex configuration » rapid prototyping n Python as “Software Component Bus” ü modularization of Geant 4 application ü natural support for dynamic loading scheme ü interconnectivity with various kind of software components. » histogramming with ROOT n These applications show the flexibility and usefulness of dynamic configuration of user applications using Python. Koichi Murakami Geant 4 Users Conference – LIP / Lisboa (9/Oct. /2006) 15