ThePEG  1.8.0
UseRandom.h
1 // -*- C++ -*-
2 //
3 // UseRandom.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 1999-2011 Leif Lonnblad
5 //
6 // ThePEG is licenced under version 2 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 
118  static bool rndbool(double p1, double p2) {
119  return current().rndbool(p1, p2);
120  }
121 
126  static int rndsign(double p1, double p2, double p3) {
127  return current().rndsign(p1, p2, p3);
128  }
129 
134  static int rnd2(double p0, double p1) {
135  return current().rnd2(p0, p1);
136  }
137 
142  static int rnd3(double p0, double p1, double p2) {
143  return current().rnd3(p0, p1, p2);
144  }
145 
150  static int rnd4(double p0, double p1, double p2, double p3) {
151  return current().rnd4(p0, p1, p2, p3);
152  }
153 
157  static long irnd(long xu = 2) { return long(rnd() * xu); }
158 
162  static long irnd(long xl, long xu) { return xl + irnd(xu-xl); }
163 
168  static double rndExp() { return current().rndExp(); }
169 
174  template <typename Unit>
175  static Unit rndExp(Unit mean) { return current().rndExp(mean); }
176 
181  static double rndGauss() { return current().rndGauss(); }
182 
187  template <typename Unit>
188  static Unit rndGauss(Unit sigma, Unit mean = Unit()) {
189  return current().rndGauss(sigma, mean);
190  }
191 
197  template <typename Unit>
198  static Unit rndBW(Unit mean, Unit gamma) {
199  return current().rndBW(mean, gamma);
200  }
201 
208  template <typename Unit>
209  static Unit rndBW(Unit mean, Unit gamma, Unit cut) {
210  return current().rndBW(mean, gamma, cut);
211  }
212 
217  template <typename Unit>
218  static Unit rndRelBW(Unit mean, Unit gamma) {
219  return current().rndRelBW(mean, gamma);
220  }
221 
228  template <typename Unit>
229  static Unit rndRelBW(Unit mean, Unit gamma, Unit cut) {
230  return current().rndRelBW(mean, gamma, cut);
231  }
232 
237  static long rndPoisson(double mean) {
238  return current().rndPoisson(mean);
239  }
240 
241 private:
242 
246  static vector<RanGenPtr> theRandomStack;
247 
253 
254 private:
255 
259  UseRandom & operator=(const UseRandom &);
260 
261 };
262 
263 }
264 
265 #endif /* ThePEG_UseRandom_H */