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