Python G4
Python G4
• Global picture
• Conclusions
Manuel Gallas
CERN PH-SFT
2
Some questions to begin with:
• What? be able to configure different Geant4 Applications from the Python prompt and provide an
interactive approach. “Configure” in a sense in which the end-user can go from very top configuration
(simulation options and flags) to the detail and be able to build and customize the simulation [we expect
different use-cases].
• Why?
✦ The ATLAS Athena framework provides a Python prompt and the configuration of the jobs (generation,
simulation, digitization, reconstruction, physics analysis ...) is done through Python scripts
(“jobOptions”). So it makes sense to provide a way to not only launch but also configure the simulation
jobs.
✦ The standard “G4 macros” are not well integrated in this Python infrastructure:
✦ they are txt files that we do not want to parse, copy here or there or build on the fly.
✦ At the end the interactivity becomes a heavy editing activity on these macro files.
• How? This is the topic of the talk and covers the work done by Andrea Dell’Acqua and myself during
the last months to solve the equation : Geant4+PyLCGDict+Python+ATLAS specific = PyG4AtlasApps a
particular (and not for this more easy!) case of the general case: Geant4+PyLCGDict+Python=PyG4Apps
• Where? This approach is working for the different ATLAS Geant4 simulation applications (2004
Combined Test Beam in GRID production since May 2005 and ~ 5 Million events, ATLAS full simulations for
the commissioning and cosmic studies by Andrea Di Simone)
Manuel Gallas
CERN PH-SFT
3
Global picture: ATLAS simulation road map (I = migration)
Pythonizing G4Atlas
Atlas 10.0.0
release
Atlas.mac (March 2005)
atlas_envelopes.mac
InnerDetectorGeometry.mac
pixelgeometry.mac
sctgeometry.mac
trtgeometry.mac
LarCal.mac !!
r y here
TileCal.mac e t
geom
MuonSystem.mac Only
DC-2 production
Rome production • The number of macro files increase rapidly as soon as you need to gain flexibility
CTB-preproduction (CTB has ~50 macro files only for the combined layout) --> Structure unmanageable.
• The only flexibility that can be ported to the jobOptions is the selection
of one or another macro file or at the limit the on-fly macro file creation. --> Dangerous
Framework for Atlas Detector Simulation • A quite large number of XML files needed at the running time.
•The interactive configuration of the simulation job and navigation in the Athena
prompt is complicated (ex: Which are the cuts am I applying?).
Manuel Gallas
CERN PH-SFT
4
Global picture: ATLAS simulation road map (II = new life)
Application environment
Python modules in the $PHYTONPATH
can be accessed from everywhere
jobOptionG4Atlas_Sim.py
FADS
jobOptionG4Cosmic.py
Facade jobOptionG4InDetcosmic.py
jobOptionsG4CTB_Sim.py
...........
test_ATLAS-evgenmu_pt5_eta60.py
test_ATLAS-singleE_ParLArBarrel.py
...........
Geant4
G4AtlasApps
Athena
Manuel Gallas
CERN PH-SFT
6
Global picture: (IV = generic view)
Framework
exp
Detector PyG4: Python generic clases
specific for simulation: Engine,
DetFacility, SensitiveDet G4Engine Simulation Apps
Simulation
Configuration modules
Frame
Work
Geant4
Manuel Gallas
CERN PH-SFT
7
What do we look for?
1. Provide user-functionality for the simulation jobs and of course 2. Minimize the spread of configuration files/
make happy all users (difficult!!), but let us see what they may modules.
need: - we really want to forget the “mac” files and
• User at Entry-Level their uncontrolled growing.
(entry-point JobOption.py and use of flags) 3. Full Atlas/CTB/…. and other simulation must
r
el use • Switch on/off detectors (DetFlags) and build be run in the same way and in the same
r y Lev the simulation automatically in accordance. place, sharing as much as possible.
En t
•
Run the simulation with run conditions. - users may need to run both simulations
•
Run different geometries for the sub-detectors. (or other configurations) and the change must
•
Access to different physics lists/regions/cuts. be in selecting the right jobOption.py not the
•
Of course select particle/energy/magnetic field
package.
•
user User that wants to configure/customize the application
ed 4. Flags mechanism under control:
d v anc (entry-point JobOption.py)
A - users do not need to be exposed to more
•
Possibility to modify the existing simulation from
flags than needed and should know where
the jobOption.py (no needed to touch G4AtlasApps
package, only access to the modules defined there). to find them (documentation).
•
To do what?: - but the flags mechanism has to be flexible
- change the position of the detectors, (particular enough to define new configurations (actual
studies, misalignments…) full Atlas and CTB simulation have common and
u c ture - add materials, scintillators, define new regions.. different flags.
r
ast
I nfr er 5. A some point we maybe need to be able
u •
pAdvanced user which implements the simulation entities
Sim develo (simulation infrastructure) to run getting the run conditions from a DB.
. Navigate the complete set of simulation objects
(detector facilities, sensitive detectors, cuts,
positions, envelopes hierarchy)
. Use and reuse as much as possible python objects
r already defined and speed up the setup of a new
o n use
d u cti simulation
Pro . Production user: (production team)
•
Flexibility to run what the Physics Community requires
but avoid complicated scripts to customize the
simulation on-fly.
•
Hits/Digits jobs (same running conditions)
Manuel Gallas
CERN PH-SFT
8
The result product
Geant4+PyLCGDict+Python+ATLAS specific = PyG4Atlas
PyG4Atlas defines the python classes for: DetectorFacilities, Sensitive Detectors, Mctruth
strategies, PhysicsRegions and Cuts, PhysicsLists,UserActions…
PyG4Atlas.G4AtlasEngine puts everything together (it should be possible to access any python object
involved) and takes care of the different phases of initialization, log-service, etc...
PyG4Atlas always does a selective import of python modules, lib, dictionaries based on the user
requirements.
Manuel Gallas
CERN PH-SFT
The result product
Manuel Gallas
CERN PH-SFT
Some use cases(1): Entry level user Configuration of the simulation job
Manuel Gallas
CERN PH-SFT
11
Some use cases(1): Entry level user Configuration of the simulation job
Inspection
ATLAS full simulation
For the user the three cases we have described here behaves in the same way.
But if the user does a little “inspection” of what is in the simulation, he can
ATLAS CTB test beam understand what is the simulation he is dealing with
Manuel Gallas
CERN PH-SFT
Some use cases(2): Advanced User
“Real case”: a ATLAS CTB test beam user is studying the longitudinal shower profiles in the LAr and he thinks that maybe
some material is missing in the “official” simulation. He wants to prove it and for this he wants to add extra material in a
far upstream position and also in front of the inner detector.
Here it is how he can customize the simulation (adding the following lines to the standard jobOption)
Manuel Gallas
CERN PH-SFT
Conclusions:
- Different types of users can access, inspect and modify the pre-
configured simulation (provided by the G4AtlasApps package) in the
same way. Python offers interactivity, and helps to keep job-
configuration under control.
- PyLCGDict is a key point in all the process and not all the classes
need to be exported
Manuel Gallas
CERN PH-SFT
Backup slides
Manuel Gallas
CERN PH-SFT
Backup slides: Flag documentation (I)
Flags and options for simulation (Simflags) are kept updated and full
documented in the LXR server.
Manuel Gallas
CERN PH-SFT
17
Backup slides: Flag documentation (II)
athena> help(SimFlags.IdetOracleTag)
Flags and options for simulation (Simflags) are written in the log
files and can be accessed in interactive mode,
(help, meaning, possible values etc)
Manuel Gallas
CERN PH-SFT
18