ThePEG::RandomGenerator Class Reference

RandomGenerator is an interface to the CLHEP::RandomEngine classes. More...

#include <RandomGenerator.h>

Inheritance diagram for ThePEG::RandomGenerator:

ThePEG::Interfaced ThePEG::InterfacedBase ThePEG::Base ThePEG::Named ThePEG::Pointer::ReferenceCounted ThePEG::StandardRandom

List of all members.

Public Types

typedef vector< double > RndVector
 A vector of doubles.
typedef RndVector::size_type size_type
 The size_type of RndVector.

Public Member Functions

virtual void setSeed (long seed)=0
 Reset the underlying random engine with the given seed.
gsl_rng * getGslInterface ()
 Return a gsl_rng interface to this random generator.
Standard constructors and destructors.
 RandomGenerator ()
 Default constructor.
 RandomGenerator (const RandomGenerator &)
 Copy-constructor.
virtual ~RandomGenerator ()
 Destructor.
Functions to return random numbers.
double rnd ()
 Return a (possibly cached) flat random number in the interval $]0,1[$.
template<typename Unit>
Unit rnd (Unit b)
 Return a flat random number in the interval $]0,b[$.
template<typename Unit>
Unit rnd (Unit a, Unit b)
 Return a flat random number in the interval $]a,b[$.
RndVector rndvec (int n)
 Return n flat random number in the interval $]0,1[$.
double operator() ()
 Return a (possibly cached) flat random number in the interval $]0,1[$.
long operator() (long N)
 Return a (possibly cached) flat integer random number in the interval $[0,N[$.
bool rndbool (double p=0.5)
 Return a true with probability p.
bool rndbool (double p1, double p2)
 Return a true with probability p1/(p1+p2).
int rndsign (double p1, double p2, double p3)
 Return -1, 0, or 1 with relative probabilities p1, p2, p3.
int rnd2 (double p0, double p1)
 Return an integer $i$ with probability p$i$/(p0+p1).
int rnd3 (double p0, double p1, double p2)
 Return an integer $i$ with probability p$i$/(p0+p1+p2).
int rnd4 (double p0, double p1, double p2, double p3)
 Return an integer/ $i$ with probability p$i$(p0+p1+p2+p3).
double rndExp ()
 Return a number between zero and infinity, distributed according to $e^-x$.
template<typename Unit>
Unit rndExp (Unit mean)
 Return a number between zero and infinity, distributed according to $e^-{x/\mu}$ where $\mu$ is the mean value.
double rndGauss ()
 Return a number distributed according to a Gaussian distribution with zero mean and unit variance.
template<typename Unit>
Unit rndGauss (Unit sigma, Unit mean=Unit())
 Return a number distributed according to a Gaussian distribution with a given standard deviation, sigma, and a given mean.
template<typename Unit>
Unit rndBW (Unit mean, Unit gamma)
 Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width, gamma, and a given mean.
template<typename Unit>
Unit rndBW (Unit mean, Unit gamma, Unit cut)
 Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width, gamma, and a given mean.
template<typename Unit>
Unit rndRelBW (Unit mean, Unit gamma)
 Return a positive number distributed according to a relativistic Breit-Wigner with a given width, gamma, and a given mean.
template<typename Unit>
Unit rndRelBW (Unit mean, Unit gamma, Unit cut)
 Return a positive number distributed according to a relativistic Breit-Wigner with a given width, gamma, and a given mean.
long rndPoisson (double mean)
 Return a non-negative number generated according to a Poissonian distribution with a given mean.
Access the cached random numbers from the underlying engine.
void push_back (double r)
 Give back a partly unused random number.
void pop_back ()
 Discard the next random number in the cache.
void flush ()
 Discard all random numbers in the cache.
template<typename OutputIterator>
void rnd (OutputIterator o, size_type n)
 Generate n random numbers between 0 and 1 and put them in the output iterator.
Functions used by the persistent I/O system.
void persistentOutput (PersistentOStream &os) const
 Function used to write out object persistently.
void persistentInput (PersistentIStream &is, int version)
 Function used to read in object persistently.

Static Public Member Functions

static void Init ()
 Standard Init function used to initialize the interface.

Protected Member Functions

virtual void doinit ()
 Initializes this random generator.
void setSize (size_type newSize)
 Utility function for the interface.
virtual void fill ()=0
 Fill the cache with random numbers.

Protected Attributes

RndVector theNumbers
 A vector of cached numbers.
RndVector::iterator nextNumber
 Iterator pointing to the next number to be extracted.
size_type theSize
 The size of the cache.
long theSeed
 The seed to initialize the random generator with.
double savedGauss
 A saved Gaussian random number.
bool gaussSaved
 Indicate the precense of a saved Gaussian random number.
gsl_rng * gsl
 A pinter to a gsl_rng interface to this generator.

Private Member Functions

RandomGeneratoroperator= (const RandomGenerator &)
 Private and non-existent assignment operator.

Static Private Attributes

static ClassDescription
< RandomGenerator
initRandomGenerator
 Describe a concrete class with persistent data.


Detailed Description

RandomGenerator is an interface to the CLHEP::RandomEngine classes.

To avoid excessive virtual function calls, the RandomGenerator caches random numbers generated by the engine which are then retrieved by the non-virtual inlined rnd() method.

Sub-classes of RandomGenerator should be used to implement a particular random engine.

RandomGenerator only provides a flat distribution between 0 and 1. Any other distribution can be achieved using the CLHEP random classes using the engine returned from the randomGenerator() method.

See also:
The interfaces defined for RandomGenerator.

UseRandom

Definition at line 37 of file RandomGenerator.h.


Member Typedef Documentation

typedef vector<double> ThePEG::RandomGenerator::RndVector

A vector of doubles.

Definition at line 42 of file RandomGenerator.h.

typedef RndVector::size_type ThePEG::RandomGenerator::size_type

The size_type of RndVector.

Definition at line 45 of file RandomGenerator.h.


Member Function Documentation

virtual void ThePEG::RandomGenerator::setSeed ( long  seed  )  [pure virtual]

Reset the underlying random engine with the given seed.

If the seed is set to -1 a standard seed will be used.

Implemented in ThePEG::StandardRandom.

Referenced by ThePEG::EventGenerator::setSeed().

bool ThePEG::RandomGenerator::rndbool ( double  p = 0.5  ) 

Return a true with probability p.

Uses rnd(). Also uses push_back(double).

Referenced by rnd2(), ThePEG::UseRandom::rndbool(), and rndbool().

bool ThePEG::RandomGenerator::rndbool ( double  p1,
double  p2 
) [inline]

Return a true with probability p1/(p1+p2).

Uses rnd(). Also uses push_back(double).

Definition at line 129 of file RandomGenerator.h.

References rndbool().

int ThePEG::RandomGenerator::rndsign ( double  p1,
double  p2,
double  p3 
)

Return -1, 0, or 1 with relative probabilities p1, p2, p3.

Uses rnd(). Also uses push_back(double).

Referenced by rnd3(), and ThePEG::UseRandom::rndsign().

int ThePEG::RandomGenerator::rnd2 ( double  p0,
double  p1 
) [inline]

Return an integer $i$ with probability p$i$/(p0+p1).

Uses rnd().

Definition at line 141 of file RandomGenerator.h.

References rndbool().

Referenced by ThePEG::UseRandom::rnd2().

int ThePEG::RandomGenerator::rnd3 ( double  p0,
double  p1,
double  p2 
) [inline]

Return an integer $i$ with probability p$i$/(p0+p1+p2).

Uses rnd().

Definition at line 149 of file RandomGenerator.h.

References rndsign().

Referenced by ThePEG::UseRandom::rnd3().

int ThePEG::RandomGenerator::rnd4 ( double  p0,
double  p1,
double  p2,
double  p3 
)

Return an integer/ $i$ with probability p$i$(p0+p1+p2+p3).

Uses rnd().

Referenced by ThePEG::UseRandom::rnd4().

template<typename Unit>
Unit ThePEG::RandomGenerator::rndBW ( Unit  mean,
Unit  gamma,
Unit  cut 
) [inline]

Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width, gamma, and a given mean.

The distribution is cut-off so that the number is between mean - cut and mean + cut

Definition at line 217 of file RandomGenerator.h.

References rnd().

template<typename Unit>
Unit ThePEG::RandomGenerator::rndRelBW ( Unit  mean,
Unit  gamma,
Unit  cut 
) [inline]

Return a positive number distributed according to a relativistic Breit-Wigner with a given width, gamma, and a given mean.

The distribution is cut-off so that the number is between mean - cut and mean + cut

Definition at line 241 of file RandomGenerator.h.

References rnd().

long ThePEG::RandomGenerator::rndPoisson ( double  mean  ) 

Return a non-negative number generated according to a Poissonian distribution with a given mean.

Warning: the method implemented is very slow for large mean and large return values. For this reason the maximum return value is given by nmax.

Referenced by ThePEG::UseRandom::rndPoisson().

void ThePEG::RandomGenerator::push_back ( double  r  )  [inline]

Give back a partly unused random number.

This is typically used when generating integral random numbers. In eg. rndbool(double p) a random number r is drawn and if it is less than p true is returned, but r is still a good random number in the interval ]0,p[. Hence r/p is still a good random number in the interval ]0,1[ and this is then pushed back into the cache and is used by the next call to rnd(). Note that the resulting random number is of lesser quality, and successive calls to push_back() should be avoided. To ensure a highest quality random number random number in the next call to rnd(), pop_back() should be used.

Definition at line 275 of file RandomGenerator.h.

References nextNumber, and theNumbers.

void ThePEG::RandomGenerator::flush (  )  [inline]

Discard all random numbers in the cache.

Typically used after the internal random engine has been reinitialized for some reason.

Definition at line 291 of file RandomGenerator.h.

References nextNumber, and theNumbers.

virtual void ThePEG::RandomGenerator::doinit (  )  [protected, virtual]

Initializes this random generator.

This should be done first of all before the initialization of any other object associated with an event generator.

Reimplemented from ThePEG::InterfacedBase.

void ThePEG::RandomGenerator::persistentOutput ( PersistentOStream os  )  const

Function used to write out object persistently.

Parameters:
os the persistent output stream written to.

Reimplemented from ThePEG::Interfaced.

Reimplemented in ThePEG::StandardRandom.

void ThePEG::RandomGenerator::persistentInput ( PersistentIStream is,
int  version 
)

Function used to read in object persistently.

Parameters:
is the persistent input stream read from.
version the version number of the object when written.

Reimplemented from ThePEG::Interfaced.

Reimplemented in ThePEG::StandardRandom.


Member Data Documentation

Describe a concrete class with persistent data.

Note that the class should in principle be abstract.

Definition at line 394 of file RandomGenerator.h.


The documentation for this class was generated from the following file:

Generated on Thu Apr 29 12:43:22 2010 for ThePEG by  doxygen 1.5.5