thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
UseRandom.h
1 // -*- C++ -*-
2 //
3 // UseRandom.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2017 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef ThePEG_UseRandom_H
10 #define ThePEG_UseRandom_H
11 // This is the declaration of the UseRandom class.
12 
13 #include "ThePEG/Repository/RandomGenerator.h"
14 
15 namespace ThePEG {
16 
33 class UseRandom {
34 
35 public:
36 
40  UseRandom() : randomPushed(false) {}
41 
45  UseRandom(const UseRandom &) : randomPushed(false) {}
46 
51  UseRandom(const RanGenPtr & r) : randomPushed(false) {
52  if ( r ) {
53  theRandomStack.push_back(r);
54  randomPushed = true;
55  }
56  }
57 
62  ~UseRandom() { if ( randomPushed ) theRandomStack.pop_back(); }
63 
64 public:
65 
69  static RandomGenerator & current() { return *theRandomStack.back(); }
70 
74 // static RandomEngine * currentEngine() {
75 // return &(current().randomGenerator());
76 // }
77 
82  static double rnd() { return current().rnd(); }
83 
89  return current().rndvec(n);
90  }
91 
96  template <typename Unit>
97  static Unit rnd(Unit xu) { return current().rnd(xu); }
98 
103  template <typename Unit>
104  static Unit rnd(Unit xl, Unit xu) {
105  return current().rnd(xl, xu);
106  }
107 
111  static bool rndbool(double p = 0.5) {
112  return current().rndbool(p);
113  }
114 
119  static bool prndbool(double p = 0.5) {
120  return current().rndbool(p);
121  }
122 
126  static bool rndbool(double p1, double p2) {
127  return current().rndbool(p1, p2);
128  }
129 
134  static bool prndbool(double p1, double p2) {
135  return current().rndbool(p1, p2);
136  }
137 
142  static int rndsign(double p1, double p2, double p3) {
143  return current().rndsign(p1, p2, p3);
144  }
145 
150  static int prndsign(double p1, double p2, double p3) {
151  return current().rndsign(p1, p2, p3);
152  }
153 
158  static int rnd2(double p0, double p1) {
159  return current().rnd2(p0, p1);
160  }
161 
166  static int rnd3(double p0, double p1, double p2) {
167  return current().rnd3(p0, p1, p2);
168  }
169 
174  static int rnd4(double p0, double p1, double p2, double p3) {
175  return current().rnd4(p0, p1, p2, p3);
176  }
177 
181  static long irnd(long xu = 2) { return long(rnd() * xu); }
182 
186  static long irnd(long xl, long xu) { return xl + irnd(xu-xl); }
187 
192  static double rndExp() { return current().rndExp(); }
193 
198  template <typename Unit>
199  static Unit rndExp(Unit mean) { return current().rndExp(mean); }
200 
205  static double rndGauss() { return current().rndGauss(); }
206 
211  template <typename Unit>
212  static Unit rndGauss(Unit sigma, Unit mean = Unit()) {
213  return current().rndGauss(sigma, mean);
214  }
215 
221  template <typename Unit>
222  static Unit rndBW(Unit mean, Unit gamma) {
223  return current().rndBW(mean, gamma);
224  }
225 
232  template <typename Unit>
233  static Unit rndBW(Unit mean, Unit gamma, Unit cut) {
234  return current().rndBW(mean, gamma, cut);
235  }
236 
241  template <typename Unit>
242  static Unit rndRelBW(Unit mean, Unit gamma) {
243  return current().rndRelBW(mean, gamma);
244  }
245 
252  template <typename Unit>
253  static Unit rndRelBW(Unit mean, Unit gamma, Unit cut) {
254  return current().rndRelBW(mean, gamma, cut);
255  }
256 
261  static long rndPoisson(double mean) {
262  return current().rndPoisson(mean);
263  }
264 
265 private:
266 
270  static vector<RanGenPtr> theRandomStack;
271 
277 
278 private:
279 
283  UseRandom & operator=(const UseRandom &) = delete;
284 
285 };
286 
287 }
288 
289 #endif /* ThePEG_UseRandom_H */
static bool prndbool(double p=0.5)
Return a true with probability p (default 0.5).
Definition: UseRandom.h:119
static int rndsign(double p1, double p2, double p3)
Return -1, 0, or 1 with relative probabilities p1, p2, p3.
Definition: UseRandom.h:142
RndVector rndvec(int n)
Return n flat random number in the interval .
static Unit rndRelBW(Unit mean, Unit gamma, Unit cut)
Return a positive number distributed according to a relativistic Breit-Wigner with a given width...
Definition: UseRandom.h:253
static double rndExp()
Return a number between zero and infinity, distributed according to .
Definition: UseRandom.h:192
static int prndsign(double p1, double p2, double p3)
Return -1, 0, or 1 with relative probabilities p1, p2, p3.
Definition: UseRandom.h:150
static int rnd2(double p0, double p1)
Return an integer with probability p /(p0+p1).
Definition: UseRandom.h:158
This UseRandom class keeps a static stack of RandomGenerator objects which can be used anywhere by an...
Definition: UseRandom.h:33
static Unit rndRelBW(Unit mean, Unit gamma)
Return a positive number distributed according to a relativistic Breit-Wigner with a given width...
Definition: UseRandom.h:242
static bool rndbool(double p1, double p2)
Return a true with probability p1/(p1+p2).
Definition: UseRandom.h:126
double rndGauss()
Return a number distributed according to a Gaussian distribution with zero mean and unit variance...
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
RandomGenerator is an interface to the CLHEP::RandomEngine classes.
static double rnd()
Return a pointer to the currently chosen RandomGenerator object.
Definition: UseRandom.h:82
static bool prndbool(double p1, double p2)
Return a true with probability p1/(p1+p2).
Definition: UseRandom.h:134
Unit rndBW(Unit mean, Unit gamma)
Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width...
static bool rndbool(double p=0.5)
Return a true with probability p (default 0.5).
Definition: UseRandom.h:111
UseRandom & operator=(const UseRandom &)=delete
Private and non-existent assignment operator.
static long irnd(long xl, long xu)
Return a simple flat random integrer number in the range [xl,xu[.
Definition: UseRandom.h:186
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 .
~UseRandom()
The destructor removing the RandomGenerator specified in the constructor from the stack...
Definition: UseRandom.h:62
static vector< RanGenPtr > theRandomStack
The stack of RandomGenerators requested.
Definition: UseRandom.h:270
UseRandom()
Default constructor does nothing.
Definition: UseRandom.h:40
static Unit rnd(Unit xu)
Return a simple flat random number (from the current RandomGenerator object) in the range ]0...
Definition: UseRandom.h:97
static Unit rnd(Unit xl, Unit xu)
Return a simple flat random number (from the current RandomGenerator object) in the range ]xl...
Definition: UseRandom.h:104
static int rnd4(double p0, double p1, double p2, double p3)
Return an integer/ with probability p (p0+p1+p2+p3).
Definition: UseRandom.h:174
static Unit rndBW(Unit mean, Unit gamma)
Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width...
Definition: UseRandom.h:222
UseRandom(const RanGenPtr &r)
Construct a new object specifying a new RandomGenerator, r, to be used during this objects lifetime...
Definition: UseRandom.h:51
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
Unit rndRelBW(Unit mean, Unit gamma)
Return a positive number distributed according to a relativistic Breit-Wigner with a given width...
static long irnd(long xu=2)
Return a simple flat random integrer number in the range [0,xu[.
Definition: UseRandom.h:181
vector< double > RndVector
A vector of doubles.
UseRandom(const UseRandom &)
Copy-constructor does nothing.
Definition: UseRandom.h:45
int rndsign(double p1, double p2, double p3)
Return -1, 0, or 1 with relative probabilities p1, p2, p3.
bool rndbool(double p=0.5)
Return a true with probability p.
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...
Definition: UseRandom.h:233
static RandomGenerator::RndVector rndvec(int n)
Return n simple flat random number (from the current RandomGenerator object) in the range ]0...
Definition: UseRandom.h:88
static Unit rndGauss(Unit sigma, Unit mean=Unit())
Return a number distributed according to a Gaussian distribution with a given standard deviation...
Definition: UseRandom.h:212
int rnd4(double p0, double p1, double p2, double p3)
Return an integer/ with probability p (p0+p1+p2+p3).
static RandomGenerator & current()
Return a reference to the currently chosen RandomGenerator object.
Definition: UseRandom.h:69
static int rnd3(double p0, double p1, double p2)
Return an integer with probability p /(p0+p1+p2).
Definition: UseRandom.h:166
long rndPoisson(double mean)
Return a non-negative number generated according to a Poissonian distribution with a given mean...
bool randomPushed
True if this object is responsible for pushing a RandomGenerator onto the stack.
Definition: UseRandom.h:276
static double rndGauss()
Return a number distributed according to a Gaussian distribution with zero mean and unit variance...
Definition: UseRandom.h:205
double rndExp()
Return a number between zero and infinity, distributed according to .
static Unit rndExp(Unit mean)
Return a number between zero and infinity, distributed according to where is the mean value...
Definition: UseRandom.h:199
static long rndPoisson(double mean)
Return a non-negative number generated according to a Poissonian distribution with a given mean...
Definition: UseRandom.h:261