thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
ThePEG::UseRandom Class Reference

This UseRandom class keeps a static stack of RandomGenerator objects which can be used anywhere by any class. More...

#include <UseRandom.h>

Public Member Functions

 UseRandom ()
 Default constructor does nothing.
 
 UseRandom (const UseRandom &)
 Copy-constructor does nothing.
 
 UseRandom (const RanGenPtr &r)
 Construct a new object specifying a new RandomGenerator, r, to be used during this objects lifetime.
 
 ~UseRandom ()
 The destructor removing the RandomGenerator specified in the constructor from the stack.
 

Static Public Member Functions

static RandomGeneratorcurrent ()
 Return a reference to the currently chosen RandomGenerator object.
 
static double rnd ()
 Return a pointer to the currently chosen RandomGenerator object.
 
static RandomGenerator::RndVector rndvec (int n)
 Return n simple flat random number (from the current RandomGenerator object) in the range ]0,1[.
 
template<typename Unit >
static Unit rnd (Unit xu)
 Return a simple flat random number (from the current RandomGenerator object) in the range ]0,xu[.
 
template<typename Unit >
static Unit rnd (Unit xl, Unit xu)
 Return a simple flat random number (from the current RandomGenerator object) in the range ]xl,xu[.
 
static bool rndbool (double p=0.5)
 Return a true with probability p (default 0.5).
 
static bool prndbool (double p=0.5)
 Return a true with probability p (default 0.5).
 
static bool rndbool (double p1, double p2)
 Return a true with probability p1/(p1+p2).
 
static bool prndbool (double p1, double p2)
 Return a true with probability p1/(p1+p2).
 
static int rndsign (double p1, double p2, double p3)
 Return -1, 0, or 1 with relative probabilities p1, p2, p3.
 
static int prndsign (double p1, double p2, double p3)
 Return -1, 0, or 1 with relative probabilities p1, p2, p3.
 
static int rnd2 (double p0, double p1)
 Return an integer \(i\) with probability p \(i\)/(p0+p1).
 
static int rnd3 (double p0, double p1, double p2)
 Return an integer \(i\) with probability p \(i\)/(p0+p1+p2).
 
static int rnd4 (double p0, double p1, double p2, double p3)
 Return an integer/ \(i\) with probability p \(i\)(p0+p1+p2+p3).
 
static int rnd5 (double p0, double p1, double p2, double p3, double p4)
 Return an integer/ \(i\) with probability p \(i\)(p0+p1+p2+p3+p4).
 
static long irnd (long xu=2)
 Return a simple flat random integrer number in the range [0,xu[.
 
static long irnd (long xl, long xu)
 Return a simple flat random integrer number in the range [xl,xu[.
 
static double rndExp ()
 Return a number between zero and infinity, distributed according to \(e^-x\).
 
template<typename Unit >
static Unit rndExp (Unit mean)
 Return a number between zero and infinity, distributed according to \(e^-{x/\mu}\) where \(\mu\) is the mean value.
 
static double rndGauss ()
 Return a number distributed according to a Gaussian distribution with zero mean and unit variance.
 
template<typename Unit >
static 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 >
static 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 >
static 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 >
static 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 >
static 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.
 
static long rndPoisson (double mean)
 Return a non-negative number generated according to a Poissonian distribution with a given mean.
 

Private Member Functions

UseRandomoperator= (const UseRandom &)=delete
 Private and non-existent assignment operator.
 

Private Attributes

bool randomPushed
 True if this object is responsible for pushing a RandomGenerator onto the stack.
 

Static Private Attributes

static vector< RanGenPtrtheRandomStack
 The stack of RandomGenerators requested.
 

Detailed Description

This UseRandom class keeps a static stack of RandomGenerator objects which can be used anywhere by any class.

When an EventGenerator is initialized or run it adds a RandomGenerator object to the stack which can be used by any other object being initialized or run through the static functions of the UseRandom class. If someone needs to use an alternative RandomGenerator object a new UseRandom object can be constructed with a pointer to the desired RandomGenerator object as argument and that object will the be used by the static UseRandom functions until the UseRandom object is destructed.

See also
RandomGenerator
EventGenerator

Definition at line 33 of file UseRandom.h.

Constructor & Destructor Documentation

◆ UseRandom() [1/3]

ThePEG::UseRandom::UseRandom ( )
inline

Default constructor does nothing.

Definition at line 40 of file UseRandom.h.

◆ UseRandom() [2/3]

ThePEG::UseRandom::UseRandom ( const UseRandom )
inline

Copy-constructor does nothing.

Definition at line 45 of file UseRandom.h.

◆ UseRandom() [3/3]

ThePEG::UseRandom::UseRandom ( const RanGenPtr r)
inline

Construct a new object specifying a new RandomGenerator, r, to be used during this objects lifetime.

Definition at line 51 of file UseRandom.h.

References randomPushed, and theRandomStack.

◆ ~UseRandom()

ThePEG::UseRandom::~UseRandom ( )
inline

The destructor removing the RandomGenerator specified in the constructor from the stack.

Definition at line 62 of file UseRandom.h.

References randomPushed, and theRandomStack.

Member Function Documentation

◆ current()

static RandomGenerator & ThePEG::UseRandom::current ( )
inlinestatic

Return a reference to the currently chosen RandomGenerator object.

Definition at line 69 of file UseRandom.h.

References theRandomStack.

Referenced by prndbool(), prndsign(), rnd(), rnd2(), rnd3(), rnd4(), rnd5(), rndbool(), rndBW(), rndExp(), rndGauss(), rndPoisson(), rndRelBW(), rndsign(), and rndvec().

◆ irnd() [1/2]

static long ThePEG::UseRandom::irnd ( long  xl,
long  xu 
)
inlinestatic

Return a simple flat random integrer number in the range [xl,xu[.

Definition at line 194 of file UseRandom.h.

References irnd().

Referenced by irnd().

◆ irnd() [2/2]

static long ThePEG::UseRandom::irnd ( long  xu = 2)
inlinestatic

Return a simple flat random integrer number in the range [0,xu[.

Definition at line 189 of file UseRandom.h.

References rnd().

◆ prndbool() [1/2]

static bool ThePEG::UseRandom::prndbool ( double  p1,
double  p2 
)
inlinestatic

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

Uses push_back to reuse random number.

Definition at line 134 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndbool().

◆ prndbool() [2/2]

static bool ThePEG::UseRandom::prndbool ( double  p = 0.5)
inlinestatic

Return a true with probability p (default 0.5).

Uses push_back to reuse random number.

Definition at line 119 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndbool().

◆ prndsign()

static int ThePEG::UseRandom::prndsign ( double  p1,
double  p2,
double  p3 
)
inlinestatic

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

Uses push_back to reuse random number.

Definition at line 150 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndsign().

◆ rnd() [1/3]

static double ThePEG::UseRandom::rnd ( )
inlinestatic

Return a pointer to the currently chosen RandomGenerator object.

Return a simple flat random number (from the current RandomGenerator object) in the range ]0,1[.

Definition at line 82 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd().

Referenced by irnd().

◆ rnd() [2/3]

template<typename Unit >
static Unit ThePEG::UseRandom::rnd ( Unit  xl,
Unit  xu 
)
inlinestatic

Return a simple flat random number (from the current RandomGenerator object) in the range ]xl,xu[.

Definition at line 104 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd().

◆ rnd() [3/3]

template<typename Unit >
static Unit ThePEG::UseRandom::rnd ( Unit  xu)
inlinestatic

Return a simple flat random number (from the current RandomGenerator object) in the range ]0,xu[.

Definition at line 97 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd().

◆ rnd2()

static int ThePEG::UseRandom::rnd2 ( double  p0,
double  p1 
)
inlinestatic

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

Definition at line 158 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd2().

◆ rnd3()

static int ThePEG::UseRandom::rnd3 ( double  p0,
double  p1,
double  p2 
)
inlinestatic

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

Definition at line 166 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd3().

◆ rnd4()

static int ThePEG::UseRandom::rnd4 ( double  p0,
double  p1,
double  p2,
double  p3 
)
inlinestatic

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

Definition at line 174 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd4().

◆ rnd5()

static int ThePEG::UseRandom::rnd5 ( double  p0,
double  p1,
double  p2,
double  p3,
double  p4 
)
inlinestatic

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

Definition at line 182 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rnd5().

◆ rndbool() [1/2]

static bool ThePEG::UseRandom::rndbool ( double  p1,
double  p2 
)
inlinestatic

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

Definition at line 126 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndbool().

◆ rndbool() [2/2]

static bool ThePEG::UseRandom::rndbool ( double  p = 0.5)
inlinestatic

Return a true with probability p (default 0.5).

Definition at line 111 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndbool().

◆ rndBW() [1/2]

template<typename Unit >
static Unit ThePEG::UseRandom::rndBW ( Unit  mean,
Unit  gamma 
)
inlinestatic

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

Definition at line 230 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndBW().

◆ rndBW() [2/2]

template<typename Unit >
static Unit ThePEG::UseRandom::rndBW ( Unit  mean,
Unit  gamma,
Unit  cut 
)
inlinestatic

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 241 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndBW().

◆ rndExp() [1/2]

static double ThePEG::UseRandom::rndExp ( )
inlinestatic

Return a number between zero and infinity, distributed according to \(e^-x\).

Definition at line 200 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndExp().

◆ rndExp() [2/2]

template<typename Unit >
static Unit ThePEG::UseRandom::rndExp ( Unit  mean)
inlinestatic

Return a number between zero and infinity, distributed according to \(e^-{x/\mu}\) where \(\mu\) is the mean value.

Definition at line 207 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndExp().

◆ rndGauss() [1/2]

static double ThePEG::UseRandom::rndGauss ( )
inlinestatic

Return a number distributed according to a Gaussian distribution with zero mean and unit variance.

Definition at line 213 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndGauss().

◆ rndGauss() [2/2]

template<typename Unit >
static Unit ThePEG::UseRandom::rndGauss ( Unit  sigma,
Unit  mean = Unit() 
)
inlinestatic

Return a number distributed according to a Gaussian distribution with a given standard deviation, sigma, and a given mean.

Definition at line 220 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndGauss().

◆ rndPoisson()

static long ThePEG::UseRandom::rndPoisson ( double  mean)
inlinestatic

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

Definition at line 269 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndPoisson().

◆ rndRelBW() [1/2]

template<typename Unit >
static Unit ThePEG::UseRandom::rndRelBW ( Unit  mean,
Unit  gamma 
)
inlinestatic

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

Definition at line 250 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndRelBW().

◆ rndRelBW() [2/2]

template<typename Unit >
static Unit ThePEG::UseRandom::rndRelBW ( Unit  mean,
Unit  gamma,
Unit  cut 
)
inlinestatic

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 261 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndRelBW().

◆ rndsign()

static int ThePEG::UseRandom::rndsign ( double  p1,
double  p2,
double  p3 
)
inlinestatic

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

Definition at line 142 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndsign().

◆ rndvec()

static RandomGenerator::RndVector ThePEG::UseRandom::rndvec ( int  n)
inlinestatic

Return n simple flat random number (from the current RandomGenerator object) in the range ]0,1[.

Definition at line 88 of file UseRandom.h.

References current(), and ThePEG::RandomGenerator::rndvec().

Member Data Documentation

◆ randomPushed

bool ThePEG::UseRandom::randomPushed
private

True if this object is responsible for pushing a RandomGenerator onto the stack.

Definition at line 284 of file UseRandom.h.

Referenced by UseRandom(), and ~UseRandom().

◆ theRandomStack

vector<RanGenPtr> ThePEG::UseRandom::theRandomStack
staticprivate

The stack of RandomGenerators requested.

Definition at line 278 of file UseRandom.h.

Referenced by current(), UseRandom(), and ~UseRandom().


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