110 likes | 274 Views
Random Numbers in GAUDI. Requirements Interface Usage. Requirements. 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
E N D
Random Numbers in GAUDI Requirements Interface Usage
Requirements • 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 GAUDI
Architecture RndmGenSvc owns & initializes Distribution: Gauss owns uses RndmEngine RndmGen GAUDI
Interface • 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( std::vector<double>& array, long howmany, long start = 0) const = 0; /// Retrieve a valid generator from the service. virtual StatusCode generator( const IRndmGen::Param& par, IRndmGen*& refpGen) = 0; GAUDI
IRndmGen::Param ???!!! • Defines the shape of the generated distribution • Rndm::Bit() • Rndm::Flat(double mi, double ma) • Rndm::Gauss(double mean, double sigma) • Rndm::Poisson(double mean) • Rndm::Binomial(long n, double p) • Rndm::Exponential(double mean) • Rndm::Chi2(long n_dof) • Rndm::BreitWigner(double mean, double gamma) • Rndm::BreitWignerCutOff (mean, gamma, cut-off) • Rndm::Landau(double mean, double sigma) • Rndm::DefinedPdf(const std::vector<double>& pdf, long intpol) See Gaudi/RandmGenSvc/RndmGenerators.h GAUDI
Local 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” Rndm::Numbers gauss(randSvc(), Rndm::Gauss(0.5,0.2)); if ( gauss ) { IHistogram1D* his = histoSvc()->book(); for ( long i = 0; i < 5000; i++ ) his->fill(gauss(), 1.0); } GAUDI
Global Usage • Get the generator once, then keep it! • In the header file or your algorithm: • In myAlgorithm::initialize • In myAlgorithm::execute: use it! #include “Gaudi/RandmGenSvc/RndmGenerators.h” class myAlgorithm : public Algorithm { Rndm::Numbers m_gaussDist; StatusCode sc = m_gaussDist.initialize( randSvc(), Rndm::Gauss(0.5,0.2)); his->fill(m_gaussDist(), 1.0); GAUDI
Dos and Don’ts • 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 • it’s easier • Do not access the RndmEngine directly • Do not manipulate the engine: Reproducability GAUDI
Summary • 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 GAUDI
GAUDI: Shared Libraries • LD_LIBRARY_PATH: It’s a mess! • String becomes too long for some shells • Load Shared libraries by environment • requirements: set GaudiSvcShr "${GAUDISVCROOT}/${BINDIR}/libGaudiSvc” • jobOptions: ApplicationMgr.DLLs += {“GaudiSvc”}; • LD_LIBRARY_PATHbecomes much shorter • Contains only path to images needed to start the program • Better control over usage of modules GAUDI
GAUDI: 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 GAUDI