thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.2.1
UseRandom.h
1 // -*- C++ -*-
2 //
3 // UseRandom.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2019 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 
182  static int rnd5(double p0, double p1, double p2, double p3, double p4) {
183  return current().rnd5(p0, p1, p2, p3, p4);
184  }
185 
189  static long irnd(long xu = 2) { return long(rnd() * xu); }
190 
194  static long irnd(long xl, long xu) { return xl + irnd(xu-xl); }
195 
200  static double rndExp() { return current().rndExp(); }
201 
206  template <typename Unit>
207  static Unit rndExp(Unit mean) { return current().rndExp(mean); }
208 
213  static double rndGauss() { return current().rndGauss(); }
214 
219  template <typename Unit>
220  static Unit rndGauss(Unit sigma, Unit mean = Unit()) {
221  return current().rndGauss(sigma, mean);
222  }
223 
229  template <typename Unit>
230  static Unit rndBW(Unit mean, Unit gamma) {
231  return current().rndBW(mean, gamma);
232  }
233 
240  template <typename Unit>
241  static Unit rndBW(Unit mean, Unit gamma, Unit cut) {
242  return current().rndBW(mean, gamma, cut);
243  }
244 
249  template <typename Unit>
250  static Unit rndRelBW(Unit mean, Unit gamma) {
251  return current().rndRelBW(mean, gamma);
252  }
253 
260  template <typename Unit>
261  static Unit rndRelBW(Unit mean, Unit gamma, Unit cut) {
262  return current().rndRelBW(mean, gamma, cut);
263  }
264 
269  static long rndPoisson(double mean) {
270  return current().rndPoisson(mean);
271  }
272 
273 private:
274 
278  static vector<RanGenPtr> theRandomStack;
279 
285 
286 private:
287 
291  UseRandom & operator=(const UseRandom &) = delete;
292 
293 };
294 
295 }
296 
297 #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:261
static double rndExp()
Return a number between zero and infinity, distributed according to .
Definition: UseRandom.h:200
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:250
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...
int rnd5(double p0, double p1, double p2, double p3, double p4)
Return an integer/ with probability p (p0+p1+p2+p3+p4).
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:194
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:278
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:230
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:189
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:241
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:220
int rnd4(double p0, double p1, double p2, double p3)
Return an integer/ with probability p (p0+p1+p2+p3).
static int rnd5(double p0, double p1, double p2, double p3, double p4)
Return an integer/ with probability p (p0+p1+p2+p3+p4).
Definition: UseRandom.h:182
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:284
static double rndGauss()
Return a number distributed according to a Gaussian distribution with zero mean and unit variance...
Definition: UseRandom.h:213
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:207
static long rndPoisson(double mean)
Return a non-negative number generated according to a Poissonian distribution with a given mean...
Definition: UseRandom.h:269