Title: Random Numbers in GAUDI
1Random Numbers in GAUDI
- Requirements
- Interface
- Usage
2Requirements
- Distinguish between generator and distribution
- Flexibility
- Change the random number generator if necessary
- No need to change user code
- Generate any distribution using a single
generator - Reproducibility
- Start simulation at any point
- Initialization at each event
- Set the seed necessary to restart
3Architecture
RndmGenSvc
owns initializes
Distribution Gauss
owns
uses
RndmGen
RndmEngine
4Interface
- Generator Interface
- Service Interface
- There is a wrapper to simplify the code
/// Single shot returning single random
number virtual double shoot() const 0 ///
Multiple shots returning vector with random
number virtual StatusCode shootArray(
stdvectorltdoublegt array,
long howmany,
long start 0) const 0
/// Retrieve a valid generator from the
service. virtual StatusCode generator( const
IRndmGenParam par,
IRndmGen refpGen) 0
5IRndmGenParam ???!!!
- Defines the shape of the generated distribution
- RndmBit()
- RndmFlat(double mi, double ma)
- RndmGauss(double mean, double sigma)
- RndmPoisson(double mean)
- RndmBinomial(long n, double p)
- RndmExponential(double mean)
- RndmChi2(long n_dof)
- RndmBreitWigner(double mean, double gamma)
- RndmBreitWignerCutOff (mean, gamma, cut-off)
- RndmLandau(double mean, double sigma)
- RndmDefinedPdf(const stdvectorltdoublegt pdf,
long intpol)
See Gaudi/RandmGenSvc/RndmGenerators.h
6Local Usage
- I just need a number how do I get it quickly ?
- Needs to be initialized for every event
- There are some useful examples, but not always!
include Gaudi/RandmGenSvc/RndmGenerators.h
RndmNumbers gauss(randSvc(),
RndmGauss(0.5,0.2)) if ( gauss )
IHistogram1D his histoSvc()-gtbook() for (
long i 0 i lt 5000 i )
his-gtfill(gauss(), 1.0)
7Global Usage
- Get the generator once, then keep it!
- In the header file or your algorithm
- In myAlgorithminitialize
- In myAlgorithmexecute use it!
include Gaudi/RandmGenSvc/RndmGenerators.h cla
ss myAlgorithm public Algorithm
RndmNumbers m_gaussDist
StatusCode sc m_gaussDist.initialize( randSvc(
), RndmGauss(0.5,0.2))
his-gtfill(m_gaussDist(), 1.0)
8Dos and Donts
- The interface allows to retrieve a bunch of
random numbers - Do not keep numbers across events
Reproducibility! - Often caching does more harm than it helps
- If there is a performance penalty, better find
another solution - Use the wrapper
- its easier
- Do not access the RndmEngine directly
- Do not manipulate the engine Reproducability
9Summary
- Random generator is flexible
- Many distributions possible
- Easy to use
- Wrapper is straight forward
- Wrapper can be used with STL operator()
- Allows to be initialized by the framework in a
way to ensure reproducability - As long as everyone sticks to the rules
10GAUDI Shared Libraries
- LD_LIBRARY_PATH Its a mess!
- String becomes too long for some shells
- Load Shared libraries by environment
- requirements
- set GaudiSvcShr "GAUDISVCROOT/BINDIR/libGau
diSvc - jobOptions
- ApplicationMgr.DLLs GaudiSvc
- LD_LIBRARY_PATH becomes much shorter
- Contains only path to images needed to start the
program - Better control over usage of modules
11GAUDI CMT requirements
- Include path
- Instead of
-
- include_dirs (GAUDISVCROOT)
- Do the following for component libraries
- include_path none
- Or for public libraries
- include_path (GAUDISVCROOT)
- This shortens the compile statement(s)
dramatically