thepeg is hosted by Hepforge, IPPP Durham
ThePEG 2.3.0
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
15namespace ThePEG {
16
33class UseRandom {
34
35public:
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
64public:
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
273private:
274
278 static vector<RanGenPtr> theRandomStack;
279
285
286private:
287
291 UseRandom & operator=(const UseRandom &) = delete;
292
293};
294
295}
296
297#endif /* ThePEG_UseRandom_H */
RCPtr is a reference counted (smart) pointer.
Definition: RCPtr.h:60
RandomGenerator is an interface to the CLHEP::RandomEngine classes.
double rnd()
Return a (possibly cached) flat random number in the interval .
int rndsign(double p1, double p2, double p3)
Return -1, 0, or 1 with relative probabilities p1, p2, p3.
RndVector rndvec(int n)
Return n flat random number in the interval .
int rnd5(double p0, double p1, double p2, double p3, double p4)
Return an integer/ with probability p (p0+p1+p2+p3+p4).
int rnd4(double p0, double p1, double p2, double p3)
Return an integer/ with probability p (p0+p1+p2+p3).
int rnd3(double p0, double p1, double p2)
Return an integer with probability p /(p0+p1+p2).
bool rndbool(double p=0.5)
Return a true with probability p.
Unit rndBW(Unit mean, Unit gamma)
Return a positive number distributed according to a non-relativistic Breit-Wigner with a given width,...
int rnd2(double p0, double p1)
Return an integer with probability p /(p0+p1).
double rndExp()
Return a number between zero and infinity, distributed according to .
long rndPoisson(double mean)
Return a non-negative number generated according to a Poissonian distribution with a given mean.
Unit rndRelBW(Unit mean, Unit gamma)
Return a positive number distributed according to a relativistic Breit-Wigner with a given width,...
double rndGauss()
Return a number distributed according to a Gaussian distribution with zero mean and unit variance.
vector< double > RndVector
A vector of doubles.
This UseRandom class keeps a static stack of RandomGenerator objects which can be used anywhere by an...
Definition: UseRandom.h:33
UseRandom & operator=(const UseRandom &)=delete
Private and non-existent assignment operator.
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()
Default constructor does nothing.
Definition: UseRandom.h:40
static bool rndbool(double p1, double p2)
Return a true with probability p1/(p1+p2).
Definition: UseRandom.h:126
~UseRandom()
The destructor removing the RandomGenerator specified in the constructor from the stack.
Definition: UseRandom.h:62
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 bool prndbool(double p=0.5)
Return a true with probability p (default 0.5).
Definition: UseRandom.h:119
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 bool rndbool(double p=0.5)
Return a true with probability p (default 0.5).
Definition: UseRandom.h:111
static double rndExp()
Return a number between zero and infinity, distributed according to .
Definition: UseRandom.h:200
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 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 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 RandomGenerator & current()
Return a reference to the currently chosen RandomGenerator object.
Definition: UseRandom.h:69
bool randomPushed
True if this object is responsible for pushing a RandomGenerator onto the stack.
Definition: UseRandom.h:284
static long irnd(long xu=2)
Return a simple flat random integrer number in the range [0,xu[.
Definition: UseRandom.h:189
static int rnd3(double p0, double p1, double p2)
Return an integer with probability p /(p0+p1+p2).
Definition: UseRandom.h:166
UseRandom(const UseRandom &)
Copy-constructor does nothing.
Definition: UseRandom.h:45
static bool prndbool(double p1, double p2)
Return a true with probability p1/(p1+p2).
Definition: UseRandom.h:134
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 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 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 long irnd(long xl, long xu)
Return a simple flat random integrer number in the range [xl,xu[.
Definition: UseRandom.h:194
UseRandom(const RanGenPtr &r)
Construct a new object specifying a new RandomGenerator, r, to be used during this objects lifetime.
Definition: UseRandom.h:51
static vector< RanGenPtr > theRandomStack
The stack of RandomGenerators requested.
Definition: UseRandom.h:278
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 double rndGauss()
Return a number distributed according to a Gaussian distribution with zero mean and unit variance.
Definition: UseRandom.h:213
static int rnd2(double p0, double p1)
Return an integer with probability p /(p0+p1).
Definition: UseRandom.h:158
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 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
static int rndsign(double p1, double p2, double p3)
Return -1, 0, or 1 with relative probabilities p1, p2, p3.
Definition: UseRandom.h:142
static double rnd()
Return a pointer to the currently chosen RandomGenerator object.
Definition: UseRandom.h:82
static long rndPoisson(double mean)
Return a non-negative number generated according to a Poissonian distribution with a given mean.
Definition: UseRandom.h:269
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28