11
M.Frank LHCb/CERN Random Numbers in GAUDI Requirements Interface Usage

Random Numbers in GAUDI

  • Upload
    kosey

  • View
    36

  • Download
    1

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: Random Numbers in GAUDI

M.Frank LHCb/CERN

Random Numbers in GAUDI

Requirements Interface Usage

Page 2: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

Requirements

Distinguish between generator and distribution

FlexibilityChange the random number generator if necessaryNo need to change user codeGenerate any distribution using a single generator

ReproducibilityStart simulation at any point

Initialization at each eventSet the seed necessary to restart

Page 3: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

Architecture

RndmGenSvc

RndmGen RndmEngine

Distribution:Gauss

owns & initializes

usesowns

Page 4: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

Interface

/// Single shot returning single random numbervirtual double shoot() const = 0;

/// Multiple shots returning vector with random numbervirtual StatusCode shootArray( std::vector<double>& array, long howmany, long start = 0) const = 0;

Generator Interface

Service Interface

There is a wrapper to simplify the code

/// Retrieve a valid generator from the service.virtual StatusCode generator( const IRndmGen::Param& par, IRndmGen*& refpGen) = 0;

Page 5: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

IRndmGen::Param ???!!!

Defines the shape of the generated distributionRndm::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

Page 6: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

I just need a number how do I get it quickly ?

Needs to be initialized for every eventThere 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); }

Local Usage

Page 7: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

Get the generator once, then keep it!In the header file or your algorithm:

In myAlgorithm::initialize

In myAlgorithm::execute: use it!

StatusCode sc = m_gaussDist.initialize(randSvc(), Rndm::Gauss(0.5,0.2));

Global Usage

#include “Gaudi/RandmGenSvc/RndmGenerators.h”

class myAlgorithm : public Algorithm { Rndm::Numbers m_gaussDist;

his->fill(m_gaussDist(), 1.0);

Page 8: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

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

Page 9: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

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

Page 10: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

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_PATH becomes much shorterContains only path to images needed to start the

program

Better control over usage of modules

Page 11: Random Numbers in GAUDI

M.Frank LHCb/CERNGAUDI

GAUDI: CMT requirements

Include path Instead of

include_dirs $(GAUDISVCROOT)

Do the following for component librariesinclude_path none

Or for public libraries:include_path $(GAUDISVCROOT)

This shortens the compile statement(s) dramatically