9 #ifndef ThePEG_RandomGenerator_H
10 #define ThePEG_RandomGenerator_H
13 #include "ThePEG/Config/ThePEG.h"
14 #include "ThePEG/Interface/Interfaced.h"
15 #include "gsl/gsl_rng.h"
71 virtual void setSeed(
long seed) = 0;
88 template <
typename Unit> Unit
rnd(Unit b) {
return b*
rnd(); }
94 template <
typename Unit>
95 Unit
rnd(Unit a, Unit b) {
return a +
rnd(b - a); }
103 for (
int i = 0; i < n; ++i ) ret[i] =
rnd();
135 int rndsign(
double p1,
double p2,
double p3);
141 int rnd2(
double p0,
double p1) {
149 int rnd3(
double p0,
double p1,
double p2) {
150 return 1 +
rndsign(p0, p1, p2);
157 int rnd4(
double p0,
double p1,
double p2,
double p3);
171 template <
typename Unit>
183 double r = sqrt(-2.0*log(
rnd()));
194 template <
typename Unit>
204 template <
typename Unit>
206 if ( gamma <= Unit() )
return mean;
216 template <
typename Unit>
217 Unit
rndBW(Unit mean, Unit gamma, Unit cut) {
218 if ( gamma <= Unit() || cut <= Unit() )
return mean;
219 return mean + 0.5*gamma*tan(
rnd(atan(-2.0*min(mean,cut)/gamma),
220 atan(2.0*cut/gamma)));
227 template <
typename Unit>
229 if ( gamma <= Unit() )
return mean;
230 return sqrt(sqr(mean) + mean*gamma*tan(
rnd(atan(-mean/gamma),
240 template <
typename Unit>
242 if ( gamma <= Unit() || cut <= Unit() )
return mean;
243 double minarg = cut > mean? -mean/gamma:
244 (sqr(mean - cut) - sqr(mean))/(gamma*mean);
245 double maxarg = (sqr(mean + cut) - sqr(mean))/(mean*gamma);
246 return sqrt(sqr(mean) + mean*gamma*tan(
rnd(atan(minarg), atan(maxarg))));
297 template <
typename OutputIterator>
298 void rnd(OutputIterator o, size_type n) {
299 while ( n-- ) *o++ =
rnd();
346 void setSize(size_type newSize);
351 virtual void fill() = 0;
416 struct ClassTraits<RandomGenerator>:
417 public ClassTraitsBase<RandomGenerator> {
419 static string className() {
return "ThePEG::RandomGenerator";
424 throw std::logic_error(
"Tried to instantiate abstract class"
425 "'Pythis7::RandomGenerator'");
RndVector rndvec(int n)
Return n flat random number in the interval .
gsl_rng * gsl
A pinter to a gsl_rng interface to this generator.
PersistentIStream is used to read persistent objects from a stream where they were previously written...
Unit rnd(Unit a, Unit b)
Return a flat random number in the interval .
void flush()
Discard all random numbers in the cache.
ClassTraitsType is an empty, non-polymorphic, base class.
A concreate implementation of ClassDescriptionBase describing a concrete class with persistent data...
RndVector::iterator nextNumber
Iterator pointing to the next number to be extracted.
RandomGenerator()
Default constructor.
PersistentOStream is used to write objects persistently to a stream from which they can be read in ag...
size_type theSize
The size of the cache.
void push_back(double r)
Give back a partly unused random number.
long operator()(long N)
Return a (possibly cached) flat integer random number in the interval .
static void Init()
Standard Init function used to initialize the interface.
double rndGauss()
Return a number distributed according to a Gaussian distribution with zero mean and unit variance...
virtual void setSeed(long seed)=0
Reset the underlying random engine with the given seed.
This is the main namespace within which all identifiers in ThePEG are declared.
RandomGenerator is an interface to the CLHEP::RandomEngine classes.
Unit rndBW(Unit mean, Unit gamma)
Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width...
Unit rndExp(Unit mean)
Return a number between zero and infinity, distributed according to where is the mean value...
int rnd2(double p0, double p1)
Return an integer with probability p /(p0+p1).
int rnd3(double p0, double p1, double p2)
Return an integer with probability p /(p0+p1+p2).
double rnd()
Return a (possibly cached) flat random number in the interval .
static ClassDescription< RandomGenerator > initRandomGenerator
Describe a concrete class with persistent data.
void pop_back()
Discard the next random number in the cache.
void setSize(size_type newSize)
Utility function for the interface.
virtual void fill()=0
Fill the cache with random numbers.
Unit rnd(Unit b)
Return a flat random number in the interval .
virtual void doinit()
Initializes this random generator.
RndVector theNumbers
A vector of cached numbers.
double operator()()
Return a (possibly cached) flat random number in the interval .
void persistentInput(PersistentIStream &is, int version)
Function used to read in object persistently.
Unit rndRelBW(Unit mean, Unit gamma)
Return a positive number distributed according to a relativistic Breit-Wigner with a given width...
vector< double > RndVector
A vector of doubles.
void persistentOutput(PersistentOStream &os) const
Function used to write out object persistently.
int rndsign(double p1, double p2, double p3)
Return -1, 0, or 1 with relative probabilities p1, p2, p3.
bool gaussSaved
Indicate the precense of a saved Gaussian random number.
bool rndbool(double p1, double p2)
Return a true with probability p1/(p1+p2).
The Interfaced class is derived from the InterfacedBase class adding a couple of things particular to...
bool rndbool(double p=0.5)
Return a true with probability p.
const double pi
Good old .
Unit rndGauss(Unit sigma, Unit mean=Unit())
Return a number distributed according to a Gaussian distribution with a given standard deviation...
Unit rndBW(Unit mean, Unit gamma, Unit cut)
Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width...
double savedGauss
A saved Gaussian random number.
void rnd(OutputIterator o, size_type n)
Generate n random numbers between 0 and 1 and put them in the output iterator.
int rnd4(double p0, double p1, double p2, double p3)
Return an integer/ with probability p (p0+p1+p2+p3).
RandomGenerator & operator=(const RandomGenerator &)
Private and non-existent assignment operator.
static TPtr create()
Create a T object and return a smart pointer to it.
long rndPoisson(double mean)
Return a non-negative number generated according to a Poissonian distribution with a given mean...
static string className()
Return the name of class T.
int NthBase
The type of the BaseN'th base class (int means there are no further base classes).
Unit rndRelBW(Unit mean, Unit gamma, Unit cut)
Return a positive number distributed according to a relativistic Breit-Wigner with a given width...
long theSeed
The seed to initialize the random generator with.
double rndExp()
Return a number between zero and infinity, distributed according to .
RndVector::size_type size_type
The size_type of RndVector.
ThePEG::Ptr< T >::pointer TPtr
Alias for a reference counted pointer to T .
BaseClassTraits describes the base classes of the templated class.
gsl_rng * getGslInterface()
Return a gsl_rng interface to this random generator.
virtual ~RandomGenerator()
Destructor.