Post on 12-Jan-2016
11
Usage of ROOT Usage of ROOT geometry with geometry with
GEANT4GEANT4
Andrei Gheata, Mihaela Gheata Andrei Gheata, Mihaela Gheata (CERN/ALICE)(CERN/ALICE)
ROOT 2007, March 26-28ROOT 2007, March 26-28
22
OutlineOutline
MotivationMotivation
TGeo@VMCTGeo@VMC
ImplementationImplementation
Integration in GEANT4 VMCIntegration in GEANT4 VMC
Ongoing tests & validation Ongoing tests & validation procedureprocedure
Preliminary resultsPreliminary results
ConclusionsConclusions
33
MotivationMotivationRunning GEANT4 simulation with ROOT geometry Running GEANT4 simulation with ROOT geometry modellermodeller
The only way to run full ALICE simulation with G4The only way to run full ALICE simulation with G4 ROOT TGeo is a multi-purpose geometry engine independent ROOT TGeo is a multi-purpose geometry engine independent
from any MC frameworkfrom any MC frameworkDeveloped by ALICE offline in collaboration with ROOT teamDeveloped by ALICE offline in collaboration with ROOT teamOptimized for Optimized for navigation performancenavigation performance in detector geometries in detector geometriesAdditional features:Additional features: checking tools, visualization, alignment checking tools, visualization, alignment tools, ROOT persistency, …tools, ROOT persistency, …
Having an external geometry description as alternative Having an external geometry description as alternative to MC-embedded modelsto MC-embedded models
Geometry is used a lot outside the simulation frameworkGeometry is used a lot outside the simulation framework Having 3 transport MC’s interfaced with Having 3 transport MC’s interfaced with TGeoTGeo Important component in making a simulation application Important component in making a simulation application
survive outside the specific MC framework survive outside the specific MC framework → → VVirtual irtual MMonte onte CCarloarlo
44
Can take advantage of
graphics accelerators
Automatic illegal overlap detection
Run-time volume assemblies
Misalignment of ideal geometry
55
The Virtual Monte Carlo ideaThe Virtual Monte Carlo idea
Make user application independent of Make user application independent of specific transport codespecific transport code
GEANT3, GEANT4 and FLUKAGEANT3, GEANT4 and FLUKA supported so far supported so far Keeping the Keeping the SAMESAME definition for geometry, I/O definition for geometry, I/O
formats and detector response simulationformats and detector response simulationAllows running the same application with different Allows running the same application with different MC’sMC’s
VMC decouples user code from the concrete VMC decouples user code from the concrete MC MC
Provides MC-independent API for :Provides MC-independent API for :Geometry definitionGeometry definition, setting up physics, setting up , setting up physics, setting up cuts, handling particle stack … cuts, handling particle stack … (features very (features very different from one MC to another)different from one MC to another)Querying MC machine state and kinematics during Querying MC machine state and kinematics during stepping callbacks stepping callbacks (very similar mechanisms)(very similar mechanisms)
66
VMC conceptVMC concept
UserCode
VMC
GEANT4 VMC
ParticlesHits
GEANT4
GEANT3
Output
FLUKA VMC
FLUKA
Input
GEANT3 VMC
77
VMC designVMC design
Communication only via Communication only via interfacesinterfaces
TVirtualMCApplicationTVirtualMCApplication
TVirtualMCStackTVirtualMCStack
TVirtualMCTVirtualMC
TVirtualMCDecayerTVirtualMCDecayer
UserApplicationUserApplication
UserStackUserStack TGeant3TGeant3 Pythia6Pythia6
TGeant4TGeant4
TFlukaTFluka
88
Geometry in VMCGeometry in VMCInitially the idea was to keep a unique VMC API for Initially the idea was to keep a unique VMC API for geometry constructiongeometry construction
Fill different native geometries with calls Fill different native geometries with calls à la GEANT3à la GEANT3 VMC VMC provides this API supporting some common provides this API supporting some common
featuresfeaturesGeometry models are quite different for different Geometry models are quite different for different MC’sMC’s
There is a common denominator G3/G4There is a common denominator G3/G4 FLUKA geometry completely differentFLUKA geometry completely different What do we do to provide the geometry that transport What do we do to provide the geometry that transport
MC wants?MC wants? There are several geometry convertors, working to a There are several geometry convertors, working to a certain extentcertain extent
g2root (G3 g2root (G3 → TGeo), g3tog4 (G3 → G4)→ TGeo), g3tog4 (G3 → G4) Most advanced: Most advanced: VGMVGM (G4 ↔ XML (AGDD, GDML) ↔ TGeo) (G4 ↔ XML (AGDD, GDML) ↔ TGeo)
http://ivana.home.cern.ch/ivana/VGM.html
99
Geometry definition and Geometry definition and TGeoTGeo
ROOT ROOT geometrygeometry
I/OI/OGeometry.rootGeometry.rootGeometry.CGeometry.C
Geometry.xmlGeometry.xml
User codeUser code
GEANT3 GEANT3 geometrygeometry g2rootg2root
GEANT4 GEANT4 geometrygeometry
VGMVGM
1010
External geometry – a External geometry – a coherent solutioncoherent solution
Experience shows that all conversions have Experience shows that all conversions have serious limitationsserious limitations
Not all features can be convertedNot all features can be convertedMatters a bit when results get different due to Matters a bit when results get different due to geometry differencesgeometry differencesMatters a lot when not all geometry can be convertedMatters a lot when not all geometry can be converted
One of the reasons TGeo was developedOne of the reasons TGeo was developed Navigation speed was a priorityNavigation speed was a priority
Even behind an interface TGeo gains ~8% in Even behind an interface TGeo gains ~8% in simulation speed in case of ALICE compared to simulation speed in case of ALICE compared to GEANT3 nativeGEANT3 native
Even more in case of non-optimized geometriesEven more in case of non-optimized geometries
In case of FLUKA there were no other way In case of FLUKA there were no other way out for running ALICE simulationout for running ALICE simulationWe needed to make all supported MC transport We needed to make all supported MC transport engines able to work directly with TGeoengines able to work directly with TGeo
1111
TGeo@VMC conceptTGeo@VMC concept
TGeo as navigator for all TGeo as navigator for all transport MC’stransport MC’s
UserCode
VMC
GEANT4 VMC
ParticlesHitsGEANT4
GEANT3
Output
FLUKA VMC FLUKA
Input
GEANT3 VMC
TGeo
1212
Navigation interfacesNavigation interfaces
Interface mechanisms providing geometry Interface mechanisms providing geometry answers to queries posted by transportationanswers to queries posted by transportation
Thin layer based on wrapper functions/ virtual Thin layer based on wrapper functions/ virtual methods “spying” the geometry channelsmethods “spying” the geometry channels
GEANT3 – Geant3TGeo interfaceGEANT3 – Geant3TGeo interface ValidatedValidated
FLUKA – Fluka MC Geometry interfaceFLUKA – Fluka MC Geometry interface ValidatedValidated
GEANT4 – GEANT4 – G4ROOTG4ROOT interface interface 2 modes supported:2 modes supported:
Via VMCVia VMCWith a native G4 application With a native G4 application with geometry defined with geometry defined via Root (or converted to ROOT structures)via Root (or converted to ROOT structures)
Ongoing testsOngoing tests
1313
Geometry access during MC Geometry access during MC transportationtransportation
GEANT3 GEANT3 transporttransport
GEANT4GEANT4transporttransport
FLUKAFLUKAtransporttransport
GEANT4 GEANT4 geometrygeometry
ROOT ROOT geometrygeometry
TGeant3TGeoTGeant3TGeoNavigation wrappersNavigation wrappers
G4ROOTG4ROOTNavigation interfaceNavigation interface
TFlukaMCGeometryTFlukaMCGeometryNavigation wrappersNavigation wrappers
G4NavigatorG4NavigatorNavigation interfaceNavigation interface
1414
How the navigation validation was How the navigation validation was done…done…
FLUKA electron transport in thin layers
•AlAuAl FLUKA native example
•1000 electrons at 1 MeV, EM cascades
• Same final random number after simulations with FLUKA native and TFluka
•The same for all 3 tested examples
1515
Implementation of G4 Implementation of G4 navigation interfacenavigation interface
GEANT4 transportation as well as GEANT4 transportation as well as several physics processes need real G4 several physics processes need real G4 geometry objectsgeometry objects Sensitive detectors, user limits, optical Sensitive detectors, user limits, optical
properties are connected to properties are connected to G4LogicalVolumeG4LogicalVolume
Need to provide geometry states that are Need to provide geometry states that are understandable by G4understandable by G4
TG4RootDetectorConstructionTG4RootDetectorConstruction : : public public G4VUserDetectorConstructionG4VUserDetectorConstruction
Having a Having a TGeoTGeo geometry in memory geometry in memory ((TGeoManagerTGeoManager) is a prerequisite) is a prerequisite
Construct()Construct() method building up a method building up a G4G4 hierarchy corresponding to hierarchy corresponding to TGeoTGeo one one
1616
Implementation – building the Implementation – building the structurestructure
Special user detector construction Special user detector construction registered to registered to G4RunManagerG4RunManager
Construct()Construct() method called during initialization method called during initialization G4 logical hierarchy created, but no optimization G4 logical hierarchy created, but no optimization
structures (voxels) neededstructures (voxels) needed
TGeoNode TGeoVolume
TGeoNode TGeoNodeTGeoNodeTGeoNodeTGeoVolume TGeoVolume
TGeoNode TGeoVolume TGeoNodeTGeoNodeTGeoNodeTGeoNodeTGeoNodeTGeoVolume
G4PhysicalVolume
G4LogicalVolume
G4PhysicalVolume
G4PhysicalVolumeG4Physical
VolumeG4Physical
Volume
G4LogicalVolume
G4LogicalVolume
G4PhysicalVolume
G4LogicalVolume
G4PhysicalVolumeG4Physical
VolumeG4Physical
VolumeG4Physical
VolumeG4Physical
VolumeG4LogicalVolume
Construct()
Adding only ~9MB in memory, including libs
For ALICE TGeo structures sum up to ~17MB
(optimizations included)Persistent size < 2MB
1717
Implementation – navigation Implementation – navigation interfaceinterface
G4NavigatorG4Navigator – base class for GEANT4 – base class for GEANT4 navigationnavigation Very useful help from GEANT4 team in Very useful help from GEANT4 team in
changing some methods/data members changing some methods/data members qualifications – made the implementation qualifications – made the implementation easiereasier
TG4RootNavigatorTG4RootNavigator : public : public G4NavigatorG4Navigator Implementing methods for locating a point, Implementing methods for locating a point,
finding the distance to next boundary, finding the distance to next boundary, computing the safety distance and the computing the safety distance and the normal to a crossed surface normal to a crossed surface
1818
Implementation – connecting Implementation – connecting to G4 geometryto G4 geometry
Several user-defined objects need to be Several user-defined objects need to be connected to the newly-created G4 connected to the newly-created G4 volumesvolumes Sensitive detectors manager, user limits, …Sensitive detectors manager, user limits, … G4 geometry objects are mapped to TGeo G4 geometry objects are mapped to TGeo
ones and accessible from ones and accessible from TG4RootDetectorConstructionTG4RootDetectorConstruction
TVirtualUserPostDetConstructionTVirtualUserPostDetConstruction Pure virtual plugin classPure virtual plugin class Initialize()Initialize() user method to implement for user method to implement for
connecting additional objects to geometry connecting additional objects to geometry
1919
Interface managementInterface management
Root-ified manager class allowing Root-ified manager class allowing connection to G4connection to G4 TG4RootNavMgrTG4RootNavMgr : public : public TObjectTObjectAdditional class interfacing TGeo Additional class interfacing TGeo shapes as G4 solids: shapes as G4 solids: TG4RootSolidTG4RootSolid : public G4VSolid : public G4VSolid Navigation methods of solids not used in Navigation methods of solids not used in
the interfacethe interfaceNavigation entirely redirected to TGeoNavigation entirely redirected to TGeo
Possibility to use directly TGeoShape Possibility to use directly TGeoShape objects in a native G4 geometryobjects in a native G4 geometry
Few methods not yet implemented at this levelFew methods not yet implemented at this levelThe feature will be supported by the interfaceThe feature will be supported by the interface
2020
How it worksHow it works
TGeoManager
pGeom
Import()
TG4RootNavigator
G4Navigator
TVirtualUserPostDetConstruction
MyPostDetConstruction
pPostDC
pMgr->Initialize(pPostDC)
TG4RootDetectorConstruction
G4VUserDetectorConstruction
pDC
::Initialize(pDC)
::Initialize(pPostDC)
TGeoNode
G4VPhysicalVolume
pMgr->ConnectToG4()
::SetNavigatorForTracking()
::ActivateNavigator()
G4TransportationManager
TG4RootNavMgr
TG4RootNavMgr::GetInstance(pGeom)
pMgr
G4RunManager
new G4RunManager()
Construct()
MyGeometry.root
Inputs
2121
AvailabilityAvailability
Interface introduced in ROOT as Interface introduced in ROOT as G4ROOTG4ROOT module module README file describing how to compile README file describing how to compile
the modulethe module$ROOTSYS/configure --enable-g4root $ROOTSYS/configure --enable-g4root
Available starting from:Available starting from:ROOT version 5.14ROOT version 5.14GEANT4 version 8.2GEANT4 version 8.2
Direct comparison tests between Direct comparison tests between normal/g4root navigation performed normal/g4root navigation performed on modified versions of GEANT4 on modified versions of GEANT4 novice examplesnovice examples One (N06) included in G4root/testOne (N06) included in G4root/test
2222
Example: optical photon Example: optical photon transporttransport
Modified version of Novice example Modified version of Novice example N06N06Adds few files to N06 onesAdds few files to N06 ones Demonstrating the usage of the interfaceDemonstrating the usage of the interfaceComparing results when running with Comparing results when running with G4 or G4ROOT navigationG4 or G4ROOT navigation Geometries used in the 2 cases equivalentGeometries used in the 2 cases equivalent Same initial random seedSame initial random seed Comparison plots of XY coordinates at Comparison plots of XY coordinates at
boundary crossingsboundary crossingsShowing a graphical output of tracks Showing a graphical output of tracks over the geometryover the geometry
2323
Test outputTest output Bubble in tank
2424
Support for TGeo navigation in Support for TGeo navigation in GEANT4 VMCGEANT4 VMC
Support for TGeo geometrySupport for TGeo geometry Since v1.0 (Jul 2003) - via roottog4 converterSince v1.0 (Jul 2003) - via roottog4 converter From v1.6 (Mar 2005) – via VGM (Virtual Geometry From v1.6 (Mar 2005) – via VGM (Virtual Geometry
Model, the generalized version of roottog4 Model, the generalized version of roottog4 converter)converter)
Version 2.0 (December 2006) – direct use of TGeo Version 2.0 (December 2006) – direct use of TGeo geometry in Geant4 via G4Rootgeometry in Geant4 via G4Root
Several tests for consistency already done or Several tests for consistency already done or ongoingongoing
Tested on the VGM geometry tests & VMC examplesTested on the VGM geometry tests & VMC examplesIdentical results for tracking with geantinos for basic Identical results for tracking with geantinos for basic shapesshapesSmall differences for complex geometries to be Small differences for complex geometries to be investigated with VGM testbedinvestigated with VGM testbed
By Ivana Hrivnacova, By Ivana Hrivnacova, IPN OrsayIPN Orsay
2525
GEANT4-VMC run GEANT4-VMC run configurationconfiguration
User has a choice to define geometry via:User has a choice to define geometry via: VMC – GEANT3 style VMC – GEANT3 style TGeo geometry modeller in ROOTTGeo geometry modeller in ROOT Geant4 - standard Geant4 detector construction class Geant4 - standard Geant4 detector construction class
User can choose to use G4 native or G4ROOT User can choose to use G4 native or G4ROOT navigation. navigation. Selection in the run configuration object instantiated Selection in the run configuration object instantiated in the configuration macroin the configuration macro
VMCtoGeant4 VMCtoGeant4 VMCtoRoot VMCtoRoot RootToGeant4RootToGeant4 Root Root Geant4Geant4
The first word means geometry input, the second The first word means geometry input, the second one navigator to be usedone navigator to be used
2626
GEANT4 VMC run GEANT4 VMC run configurationconfiguration
Geant4
Geant4geometry
TGeo geometry
User codevia
VMC
G3toG4TGeoMC
Geometry
G4Root
User codevia
TGeo
VGM
With both With both geometry geometry definition via definition via VMC and TGeo VMC and TGeo user has a user has a possibility to possibility to run with both run with both G4 native and G4 native and G4Root G4Root navigationnavigation
G4Navigator
Geant4 VMC connects automatically necessary packages and activates selected navigator
2727
Using G4ROOT from a native Using G4ROOT from a native G4 application G4 application
Can this be done ?Can this be done ? Yes, an example of use G4Root with G4 native application Yes, an example of use G4Root with G4 native application
with geometry defined via Root is provided with G4Root with geometry defined via Root is provided with G4Root packagepackage
The sensitive detectors and other user are connected to The sensitive detectors and other user are connected to geometry in a bit different way as it is demonstrated on geometry in a bit different way as it is demonstrated on the example the example objects to the generated G4LogicalVolume objects to the generated G4LogicalVolume objectsobjects
Possibility to convert G4 geometry to TGeoPossibility to convert G4 geometry to TGeoMost G4 geometry features existing also in TGeoMost G4 geometry features existing also in TGeoProcedure not yet automatedProcedure not yet automatedCould be avoided in future by keeping the original G4 Could be avoided in future by keeping the original G4 geometrygeometry
Does it worth trying ?Does it worth trying ? Yes, a minimal working setup for checking performance Yes, a minimal working setup for checking performance
issues can be put together quite easilyissues can be put together quite easilyCan give fast an idea if the interface usage can save some Can give fast an idea if the interface usage can save some CPUCPU
2828
Validation procedureValidation procedure
Testing with G4 native examplesTesting with G4 native examples Comparing results given by G4/G4ROOT navigationComparing results given by G4/G4ROOT navigation Equivalent TGeo geometries with G4 onesEquivalent TGeo geometries with G4 ones Done for some Novice examplesDone for some Novice examples
Most give identical results (N01, N03, N05, N06)Most give identical results (N01, N03, N05, N06)Some differences (random seed change) observed for Some differences (random seed change) observed for N02N02
Understood – due to different isotropic safety valuesUnderstood – due to different isotropic safety values
Tests within VGM test setups Tests within VGM test setups Checking various geometry configurations and Checking various geometry configurations and
different geometry featuresdifferent geometry featuresBoolean operations, divisions, replicas, …Boolean operations, divisions, replicas, …
Revealed few bugs in the navigation interface that Revealed few bugs in the navigation interface that were fixedwere fixed
More complex geometries to be compared – More complex geometries to be compared – extremely performant debugging tool !extremely performant debugging tool !
2929
Validation procedure (cont)Validation procedure (cont)
Tests with GEANT4 VMCTests with GEANT4 VMC Novice examples with either G4 or G4ROOT Novice examples with either G4 or G4ROOT
navigation available in G4_VMC navigation available in G4_VMC Comparisons with physics switched on/off to be done Comparisons with physics switched on/off to be done
for real experiments for real experiments ALICE was the first candidateALICE was the first candidateFurther testing/feedback expected from other VMC Further testing/feedback expected from other VMC users: users:
MINOS, CBM/PANDA@GSI/FAIRMINOS, CBM/PANDA@GSI/FAIR Performance comparisons for complex geometriesPerformance comparisons for complex geometries
TGeo navigation performance demonstrated against TGeo navigation performance demonstrated against GEANT3 (faster by 8%)GEANT3 (faster by 8%)Realistic timing comparisons can only be done for Realistic timing comparisons can only be done for realistic cases (example geometries much too simple)realistic cases (example geometries much too simple)Tests with ALICE TPC and MUON detectors already Tests with ALICE TPC and MUON detectors already done !done !Performance-wise optimizations not yet done for the Performance-wise optimizations not yet done for the interfaceinterface
3030
Tests and benchmarksTests and benchmarks
AliRoot – ALICE offline frameworkAliRoot – ALICE offline framework Using VMC for simulationUsing VMC for simulation
GEANT4_VMC – the interface to GEANT4GEANT4_VMC – the interface to GEANT4 VMC API used to define VMC API used to define physicsphysics and in a similar and in a similar
way for all MC’sway for all MC’sNo special ALICE physics list yetNo special ALICE physics list yetCuts equivalent to G3 onesCuts equivalent to G3 ones
VMC+TGeo used to define VMC+TGeo used to define detector geometrydetector geometryTGeo used directly via TGeo used directly via g4rootg4rootGeometry converted with VGM to a Geometry converted with VGM to a G4 geometryG4 geometry
Works for part of ALICEWorks for part of ALICE Comparisons made with Comparisons made with geantinos and full physicsgeantinos and full physics
Step distribution comparisons, profiling for different Step distribution comparisons, profiling for different geometry configurations (done)geometry configurations (done)Comparisons at the level of signal (digitization) and Comparisons at the level of signal (digitization) and tracking/reconstruction outputs (ongoing)tracking/reconstruction outputs (ongoing)
Comparisons between different MC’s – to be doneComparisons between different MC’s – to be done
3131
ALICE TPC testsALICE TPC tests
Main tracking Main tracking detector of ALICEdetector of ALICEComparisons with Comparisons with 100K geantinos in 100K geantinos in 44ππComparisons with Comparisons with physics ONphysics ON
5K parameterized 5K parameterized HIJING (0.5-999 GeV)HIJING (0.5-999 GeV)
L3 field ONL3 field ON
Profiling done for Profiling done for 500 tracks on both 500 tracks on both navigation setupsnavigation setups
3232
100K geantinos TPC100K geantinos TPC
220 sec.220 sec. 225 sec.225 sec.
3333
TPC – 5K particles, physics + TPC – 5K particles, physics + fieldfield
1013 sec.1013 sec. 2144 sec.2144 sec.
??????
3434
Isotropic safetyIsotropic safety
safety
3535
ProfilingProfiling1165042 steps
1152653 stepsG4ROOTG4ROOT G4G4
G4RootNavigator::ComputeStep 1143536 calls (25.9%)
G4Navigator::ComputeStep 2261101(62.8%)
G4PropagatorInField::IntersectChord
Multiple scattering processMultiple scattering process
CONCLUSION: Accurate isotropic safety computation can highly improve simulation time in an environment where low energy charged particles (curling tracks) need to be transported in magnetic field over considerable distances.
3636
ALICE MUON ARMALICE MUON ARM
10K geantinos 10K geantinos within within acceptanceacceptance500 HIJING 500 HIJING parameterized parameterized (0.5-999 GeV)(0.5-999 GeV)Step length Step length distributionsdistributionsMost particles Most particles stopped within stopped within the absorberthe absorber
3737
10 K geantinos MUON10 K geantinos MUON
27 sec.27 sec. 26.4 sec.26.4 sec.
3838
SummarySummary
A prototype of the navigation interface A prototype of the navigation interface of GEANT4 using TGeo geometry of GEANT4 using TGeo geometry availableavailable Starting with ROOT v5.14, GEANT4 v8.2Starting with ROOT v5.14, GEANT4 v8.2 Interface used by GEANT4_VMC v2.0Interface used by GEANT4_VMC v2.0The interface can be used ‘as is’ by G4-The interface can be used ‘as is’ by G4-based applications with a TGeo based applications with a TGeo geometry representation and minor geometry representation and minor additions (example available)additions (example available)Most benefits by usage via VMCMost benefits by usage via VMC User application kept unchanged for 3 MC’sUser application kept unchanged for 3 MC’s Navigation based on the same geometry Navigation based on the same geometry
allow reliable comparisons for the MC allow reliable comparisons for the MC predictionspredictions
3939
SummarySummary
Comparative tests in realistic ALICE Comparative tests in realistic ALICE setups show consistency between setups show consistency between GEANT4 and ROOT geometriesGEANT4 and ROOT geometries Still some differences at the level of 10 Still some differences at the level of 10
per million to be investigatedper million to be investigated Computation of the distance to next Computation of the distance to next
boundary at boundary at same level of performancesame level of performance for the tested geometriesfor the tested geometries
More realistic isotropic safety values in More realistic isotropic safety values in TGeo highly improve total simulation time TGeo highly improve total simulation time for ALICE TPCfor ALICE TPC
4040
AcknowledgementsAcknowledgements
GEANT4 teamGEANT4 team Support for changes in G4Navigator Support for changes in G4Navigator
to accommodate this interfaceto accommodate this interface
ALICE Offline & ROOT teamsALICE Offline & ROOT teams Supporting the development and Supporting the development and
facilitating the integration in ROOT facilitating the integration in ROOT frameworkframework
All current (and future) All current (and future) contributors…contributors…