Top Banner
Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics processes SNA + MC 2010 Joint International Conference on Supercomputing in Nuclear Applications + Monte Carlo 2010 Maria Grazia Pia INFN Genova, Italy Maria Grazia Pia 1 , Mauro Augelli 2 , Marcia Begalli 3 , Lina Quintieri 4 , Paolo Saracco 1 , Manju Sudhakar 1 , Georg Weidenspointner 5 , Andreas Zoglauer 6 1 INFN Sezione di Genova, Italy – 2 CNES, France 3 State University Rio de Janeiro, Brazil – 4 INFN Laboratori Nazionali di Frascati, Italy 5 MPE and MPI Halbleiterlabor, Germany 6 University of California at Berkeley, USA
21

Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Mar 28, 2015

Download

Documents

Amelia Nelson
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

New techniques in Monte Carlo simulation: experience with a prototype of generic programming

application to Geant4 physics processes

SNA + MC 2010Joint International Conference on

Supercomputing in Nuclear Applications + Monte Carlo 2010

Maria Grazia Pia INFN Genova, Italy

Maria Grazia Pia1, Mauro Augelli2, Marcia Begalli3, Lina Quintieri4, Paolo Saracco1, Manju Sudhakar1, Georg Weidenspointner5, Andreas Zoglauer6

1 INFN Sezione di Genova, Italy – 2 CNES, France3 State University Rio de Janeiro, Brazil – 4 INFN Laboratori Nazionali di Frascati, Italy 5 MPE and MPI Halbleiterlabor, Germany – 6 University of California at Berkeley, USA

Page 2: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Acknowledgments

The physics models and original implementations of the physics processes mentioned in this talk derive from Geant4 Standard and Low Energy Electromagnetic packages as in Geant4 9.1 (9.2)

Thanks to Sergio Bertolucci (INFN and CERN) Tom Evans (ORNL) Simone Giani (CERN) Alessandro Montanari (INFN Bologna) Andreas Pfeiffer (CERN)

for helpful discussions and advice

The performance results concerning Compton scattering in Geant4 are published in IEEE NSS 2008 proceedings (F. Longo, L. Pandola and M.G. Pia)

Page 3: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN GenovaCourtesy Borexino

Courtesy H. Araujo and A. Howard, IC London

ZEPLIN III

Courtesy CMS Collaboration

Courtesy ATLAS Collaboration

Courtesy GATE Collaboration

Courtesy R. Nartallo et al.,ESA

Widely used also in Space science and astronomy Medical physics, nuclear medicine Radiation protection Accelerator physics Humanitarian projects, security etc.Technology transfer to industry, hospitals…

Born from the requirements of large scale HEP experiments

Most cited “Nuclear Science and Technology”

publication!>140000 papers

since 1990

2nd most cited CERN/INFN paper

“Modern classic”

S. Agostinelli et al.GEANT4 - a simulation toolkit

NIM A 506 (2003) 250-303

Page 4: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Geant4 is a mature Monte Carlo system nowadays

Widely used in a variety of experimental applicationsLHC has entered production phase

1994 – 1998Pioneering project in HEP environment

Cutting-edge technologyRigorous software development methodologies

πάντα ῥεῖ

New software technologies have emerged since thenCould Geant4 profit from them?

More than one decade’s growth since RD44Could Geant4 be rejuvenated by pruning ?

Page 5: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Generic programmingPowerful paradigm “Bringing aspects of generic programming into the mainstream is most

likely C++’s greatest contribution to the software development community during this period.” B. Stroustrup, Proc. 3rd ACM SIGPLAN Conf. on History of programming languages, 2007

Drawbacks code bloat compiler support poor error messages, cumbersome debugging

Explore pro and contra by means of a prototype

Small enough to require relatively limited investmentLarge enough for the exercise to be meaningful

Quantitative metrics

Page 6: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

A policy defines a class or class template interface

Policy host classes are parameterised classes

Advantages Policies are not required to inherit from a base class The code is bound at compile time

No need of virtual methods, resulting in faster execution

Policy-based design

Syntax-oriented rather than signature-oriented

Weak dependency of the policy and the policy based class on the policy interface

Highly customizable design

First introduced in Geant4S. Chauvie et al., Geant4 physics processes for microdosimetry simulation: design foundation and implementation of the first set of models

IEEE Trans. Nucl. Sci., vol. 54, no. 6, 2619-2628, 2007

R&D!

C++ is capable of a Turing machine

at two levels

Exploit bothMix and match

Page 7: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

1st cycle: propaedeutic exploration

R&D on generic programming techniquesin Geant4 physics

Problem domain analysis

Dismount Geant4 physics processesIdentify objects subject to mutability

Added complexity Deterioration of performance?

Side requirementsAgility of configuration

TransparencyEasy verification & validation

Technology Support to requirements

UP: iterative and incremental software process

Page 8: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Vision

1st prototype: photon interactionsMetrics

Software development processSoftware performance

Extension to charged particle interactions

MetricsI2: Low Energy Electrons and Photons

Design, development and validation of electron ionisation models for nano-scale simulation

Evaluation on satellite domains

MetricsG3: Information Technology and its Applications

Physics data management tools: computational evolutions and benchmarks  

b-testing in concrete use casesMetrics

Som

e of these processes are concurrent

Page 9: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

G4ComptonDataLib<<typedef>>

TCrossSectionTGenerator

G4TRDPhotonProcess

G4CrossSectionDataLib, G4GeneratorComptonDataLib

<<bind>>

G4ComptonPenelope<<typedef>>

G4ComptonStandard<<typedef>>

G4ComptonStandardDataLib<<typedef>>

G4CrossSectionComptonPenelope,G4GeneratorComptonPenelope

<<bind>>

G4CrossSectionComptonStandard,G4GeneratorComptonStandard

<<bind>>

G4CrossSectionComptonStandard,G4GeneratorComptonDataLib

<<bind>>

etc.

Page 10: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

G4IInterpolator

TCrossSection

G4TCrossSectionAssistant

-interpolator

TCrossSection(from G4TCrossSectionAssistant)

<<template_param>>

G4VDiscreteProcess

<<abstract>> GetMeanFreePath()

(from managment)

G4TCrossSectionAssistant<TCrossSection><<anonymous_type>>

TCrossSectionTGenerator

G4TRDPhotonProcess

GetMeanFreePath()BuildPhysicsTable()IsApplicable()PostStepDoIt()

TGenerator(from G4TRDPhotonProcess)

<<template_param>>

G4VProcess

<<abstract>> AlongStepDoIt()<<abstract>> AlongStepGetPhysicalInteractionLength()<<abstract>> AtRestDoIt()<<abstract>> AtRestGetPhysicalInteractionLength()<<abstract>> PostStepDoIt()<<abstract>> PostStepGetPhysicalInteractionLength()<<virtual>> BuildPhysicsTable()<<virtual>> IsApplicable()

(from managment)

G4CrossSectionComptonStandard

ApplicableRangeMax()ApplicableRangeMin()Build()CrossSection()Name()

G4GeneratorComptonStandard

ApplicableRangeMax()ApplicableRangeMin()Generate()Initialize()Name()

G4CrossSectionDataLib G4GeneratorComptonDataLib

G4CrossSectionComptonPenelope G4GeneratorComptonPenelope

A condition of complete simplicity (Costing not less than everything)T.S. Eliot, Four Quartets (Little Gidding)

typedef G4PhotonProcess<G4CrossSectionComptonStandard,G4GeneratorComptonStandard> G4ComptonStandard>

Interface: only mandatory inherited pure virtual functions

Preliminary

Refinements in further design iterations

(based on metrics)

Page 11: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

G4ComptonScattering

<<virtual>> InitialiseProcess()<<virtual>> IsApplicable()<<virtual>> PrintInfo()

(from standard)

G4VDiscreteProcess

<<abstract>> GetMeanFreePath()

(from managment)

G4PolarizedComptonScattering

PostStepDoIt()SetNewPolarization()SetPhi()

(from standard)

G4KleinNishinaCompton

ComputeCrossSectionPerAtom()Initialise()SampleSecondaries()

(from standard)

G4VEmModel

SetCurrentElement()ActivateNuclearStopping()ComputeCrossSectionPerAtom()ComputeDEDX()ComputeMeanFreePath()CrossSection()GetModelOfFluctuations()InitialiseElementSelectors()MaxSecondaryKinEnergy()SelectIsotopeNumber()SelectRandomAtom()SelectRandomAtom()SetCurrentCouple()SetDeexcitationFlag()SetHighEnergyLimit()SetLPMFlag()SetLowEnergyLimit()SetParticleChange()SetPolarAngleLimit()SetSecondaryThreshold()<<abstract>> Initialise()<<abstract>> SampleSecondaries()<<const>> CurrentCouple()<<const>> GetCurrentElement()<<const>> DeexcitationFlag()<<const>> GetName()<<const>> HighEnergyLimit()<<const>> LPMFlag()<<const>> LowEnergyLimit()<<const>> PolarAngleLimit()<<const>> SecondaryThreshold()<<virtual>> MaxSecondaryEnergy()<<virtual>> ComputeCrossSectionPerAtom()<<virtual>> ComputeDEDXPerVolume()<<virtual>> ComputeGeomPathLength()<<virtual>> ComputeTruePathLengthLimit()<<virtual>> ComputeTrueStepLength()<<virtual>> CorrectionsAlongStep()<<virtual>> CrossSectionPerVolume()<<virtual>> DefineForRegion()<<virtual>> GetChargeSquareRatio()<<virtual>> GetParticleCharge()<<virtual>> MinEnergyCut()<<virtual>> SampleDeexcitationAlongStep()<<virtual>> SampleScattering()<<virtual>> SetupForMaterial()

(from utils)

G4VEmProcess

GetElectronEnergyCut()GetGammaEnergyCut()GetMeanFreePath()GetParticleChange()LambdaPhysicsVector()RecalculateLambda()SelectModel()SetBuildTableFlag()SetParticle()SetSecondaryParticle()SetStartFromNullFlag()ActivateDeexcitation()AddEmModel()BuildPhysicsTable()ComputeCrossSectionPerAtom()CrossSectionPerVolume()GetLambda()GetModelByIndex()MeanFreePath()Model()PostStepDoIt()PostStepGetPhysicalInteractionLength()PreparePhysicsTable()PrintInfoDefinition()RetrievePhysicsTable()SetApplyCuts()SetIntegral()SetLambdaBinning()SetLambdaFactor()SetMaxKinEnergy()SetMinKinEnergy()SetModel()SetPolarAngleLimit()StorePhysicsTable()UpdateEmModel()<<abstract>> InitialiseProcess()<<abstract>> IsApplicable()<<abstract>> PrintInfo()<<const>> CurrentMaterialCutsCoupleIndex()<<const>> IsIntegral()<<const>> LambdaBinning()<<const>> LambdaTable()<<const>> MaxKinEnergy()<<const>> MinKinEnergy()<<const>> Particle()<<const>> PolarAngleLimit()<<const>> SecondaryParticle()<<const>> SelectModelForMaterial()

(from utils)

G4ComptonScattering52

BuildPhysicsTable()ComputeMeanFreePath()GetCrossSectionPerAtom()GetMeanFreePath()IsApplicable()PostStepDoIt()PrintInfoDefinition()SetPhysicsTableBining()StorePhysicsTable()<<virtual>> ComputeCrossSectionPerAtom()

(from standard)

G4VProcess

<<abstract>> AlongStepDoIt()<<abstract>> AlongStepGetPhysicalInteractionLength()<<abstract>> AtRestDoIt()<<abstract>> AtRestGetPhysicalInteractionLength()<<abstract>> PostStepDoIt()<<abstract>> PostStepGetPhysicalInteractionLength()<<virtual>> BuildPhysicsTable()

(from managment)Minimalism…

G4VEMProcess

G4VEMModel

Page 12: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Compton cross section % difference

c2 test NIST Phys. Ref. Data

p-value

Library 0.982

Penelope <0.0010.993 excluding 1 keV

Standard 0.189

Library-Penelope Si, Z=14

Different scale!

Library-Standard Si, Z=14

Different scale!

Penelope-Standard Si, Z=14

Different scale!

Example: Compton in Si 1 keV – 100 GeV

Agility

Page 13: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Doppler broadening in Compton scattering

Library Penelope Standard final state Generators

Si, 40 keV Cs, 400 keV

Yes, physics does make sense. And is transparently exposed.

Validation on experimental data by Namito et al.

There is only the fight to recover what has been lostAnd found and lost again and again: and now, under conditionsThat seem unpropitious. T.S. Eliot, Four Quartets (East Coker)

Page 14: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Performance improvement(where no improvement is expected)

Policy-based design Geant4 9.1 Gain

C 4.15 6.08 32%

Si 6.23 8.37 26%

Cu 7.64 10.78 29%

W 14.06 19.18 27%

Move lowenergy-Penelope to Standard package design: ~10% gain, including implementation improvements

Source: L. Pandola, http://workgroup.lngs.infn.it/geant4lns/group-meetings-directory/l.pandola

Example: Penelope ComptonNO ATTEMPT [yet] TO IMPROVE THE IMPLEMENTATION

40 keV, 106 events, Intel Core2 Duo Processor E6420, 2.13 GZ, 4 GB RAM

Low Energy – Library: 28% gain with policy-based design

Preliminary

Page 15: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Metrics

Old G4-NIST comparison test4134 LoC*

O(months) CPU+human time

Photon cross sections test

Test with new design <50 LoC*, O(human minutes)

K. Amako et al.,Comparison of Geant4 electromagnetic physics models against the NIST reference dataIEEE Trans. Nucl. Sci., vol. 52, no. 4, pp. 910-918, Aug. 2005

Page 16: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Adopt best practices, build on existing body of knowledge

Page 17: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

Physics on a dietThe design exposes the physics at very fine granularity Unprecedented opportunity for thorough validation Identification of epistemic uncertainties

Similarities and differences among Geant4 models Accuracy Computational performance

Toolkit nature of Geant4: provide a variety of models Replicas of the same physics functionality? Often result of evolution: initially they were different Pruning keeps trees healthier!

Cost of maintenance of a complex software system Long time scale of LHC operation (various developers will be retired)

Only a fraction of Geant4 physics has documented validation in the literature

Strive for simplicity, transparency, agility

Page 18: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

G4VEmModel

ActivateNuclearStopping()<<virtual>> ComputeGeomPathLength()<<virtual>> ComputeTruePathLengthLimit()<<virtual>> ComputeTrueStepLength()<<virtual>> GetChargeSquareRatio()

(from utils)

G4KleinNishinaCompton

<<virtual>> ComputeCrossSectionPerAtom()<<virtual>> Initialise()<<virtual>> SampleSecondaries()

(from standard)

No charged photons

Page 19: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

G4KleinNishinaCompton

<<virtual>> SampleSecondaries( : std::vector<G4DynamicParticle*>*, : const G4MaterialCutsCouple*, : const G4DynamicParticle*, tmin : G4double, maxEnergy : G4double) : void

(from standard)

G4VEmModel

<<abstract>> SampleSecondaries( : std::vector<G4DynamicParticle*>*, : const G4MaterialCutsCouple*, : const G4DynamicParticle*, tmin : G4double = 0.0, tmax : G4double = DBL_MAX) : void

(from utils)

G4VEmProcess

theCutsGamma : const std::vector<G4double>*theCutsElectron : const std::vector<G4double>*theCutsPositron : const std::vector<G4double>*currentCouple : const G4MaterialCutsCouple*currentMaterialIndex : size_temModels : std::vector<G4VEmModel*>theCuts : const std::vector<G4double>*deRegions : std::vector<const G4Region*>secParticles : std::vector<G4DynamicParticle*>

PostStepDoIt( : const G4Track&, : const G4Step&) : G4VParticleChange*

(from utils)

-currentModel

PostStepDoIt

currentModel->SampleSecondaries(&secParticles, currentCouple, track.GetDynamicParticle(),(*theCuts)[currentMaterialIndex]);

No nostalgia of FORTRAN common block…

Encapsulation

robustness, transparency

G4VEMProcess

G4VEMModel

Page 20: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

src/G4BetheBlochModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForLoss*>src/G4BetheHeitlerModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForGamma*>(pParticleChange);src/G4BraggIonModel.cc: reinterpret_cast<G4ParticleChangeForLoss*>(pParticleChange);src/G4BraggModel.cc: reinterpret_cast<G4ParticleChangeForLoss*>(pParticleChange);src/G4eBremsstrahlungModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForLoss*>(pParticleChange);src/G4eBremsstrahlungRelModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForLoss*>(pParticleChange);src/G4eCoulombScatteringModel.cc: reinterpret_cast<G4ParticleChangeForGamma*>(pParticleChange);src/G4KleinNishinaCompton.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForGamma*>(pParticleChange);src/G4MollerBhabhaModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForLoss*>src/G4MscModel71.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForMSC*>(pParticleChange);src/G4MultipleScattering71.cc: model = dynamic_cast<G4MscModel71*>(SelectModel(e));src/G4PEEffectModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForGamma*>(pParticleChange);src/G4UrbanMscModel2.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForMSC*>(pParticleChange);src/G4UrbanMscModel90.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForMSC*>(pParticleChange);src/G4UrbanMscModel.cc: fParticleChange = reinterpret_cast<G4ParticleChangeForMSC*>(pParticleChange);

Design, design, design…

Page 21: Maria Grazia Pia, INFN Genova New techniques in Monte Carlo simulation: experience with a prototype of generic programming application to Geant4 physics.

Maria Grazia Pia, INFN Genova

The only wisdom we can hope to acquireIs the wisdom of humility: humility is endless.T.S. Eliot, Four Quartets (East Coker)

First considerationsThe technology looks promising for application to a large, complex, computationally intensive physics simulation domain

Enormous gain in Transparency Agility Easy verification and validation Maintenance effort

Significant performance improvement At a very early stage of the project, still room for further improvement

But there is still a long way to go…