Logo ROOT   6.10/09
Reference Guide
GSLRandomFunctions.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta 8/2015
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2015 , ROOT MathLib Team *
7  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for random class
12 //
13 //
14 // Created by: Lorenzo Moneta : Tue 4 Aug 2015
15 //
16 //
17 #ifndef ROOT_Math_GSLRandomFunctions
18 #define ROOT_Math_GSLRandomFunctions
19 
20 
21 //#include <type_traits>
22 
23 #include "Math/RandomFunctions.h"
24 
25 #include "Math/GSLRndmEngines.h"
26 
27 namespace ROOT {
28 namespace Math {
29 
30 
31 //___________________________________________________________________________________
32  /**
33  Specialized implementation of the Random functions based on the GSL library.
34  These will work onlmy with a GSLRandomEngine type
35 
36  @ingroup Random
37  */
38 
39 
40  template <class EngineType >
41  class RandomFunctions<EngineType, ROOT::Math::GSLRandomEngine> : public RandomFunctions<EngineType, DefaultEngineType> {
42  //class RandomFunctions<Engine, ROOT::Math::GSLRandomEngine> {
43 
44  //typdef TRandomEngine DefaulEngineType;
45 
46  public:
47 
49 
50  RandomFunctions(EngineType & rng) : RandomFunctions<EngineType, DefaultEngineType>(rng) {}
51 
52 
53  inline EngineType & Engine() { return RandomFunctions<EngineType,DefaultEngineType>::Rng(); }
54 
55  double GausZig(double mean, double sigma) {
56  return Engine().GaussianZig(sigma) + mean;
57  }
58  // double GausRatio(double mean, double sigma) {
59  // auto & r = RandomFunctions<Engine,DefaultEngineType>::Rng();
60  // return r.GaussianRatio(sigma) + mean;
61  // }
62 
63  /**
64  Gaussian distribution. Default method (use Ziggurat)
65  */
66  double Gaus(double mean = 0, double sigma = 1) {
67  return mean + Engine().GaussianZig(sigma);
68  }
69 
70  /**
71  Gaussian distribution (Box-Muller method)
72  */
73  double GausBM(double mean = 0, double sigma = 1) {
74  return mean + Engine().Gaussian(sigma);
75  }
76 
77  /**
78  Gaussian distribution (Ratio Method)
79  */
80  double GausR(double mean = 0, double sigma = 1) {
81  return mean + Engine().GaussianRatio(sigma);
82  }
83 
84  /**
85  Gaussian Tail distribution
86  */
87  double GaussianTail(double a, double sigma = 1) {
88  return Engine().GaussianTail(a,sigma);
89  }
90 
91  /**
92  Bivariate Gaussian distribution with correlation
93  */
94  void Gaussian2D(double sigmaX, double sigmaY, double rho, double &x, double &y) {
95  Engine().Gaussian2D(sigmaX, sigmaY, rho, x, y);
96  }
97 
98  /**
99  Exponential distribution
100  */
101  double Exp(double tau) {
102  return Engine().Exponential(tau);
103  }
104  /**
105  Breit Wigner distribution
106  */
107  double BreitWigner(double mean = 0., double gamma = 1) {
108  return mean + Engine().Cauchy( gamma/2.0 );
109  }
110 
111  /**
112  Landau distribution
113  */
114  double Landau(double mean = 0, double sigma = 1) {
115  return mean + sigma*Engine().Landau();
116  }
117 
118  /**
119  Gamma distribution
120  */
121  double Gamma(double a, double b) {
122  return Engine().Gamma(a,b);
123  }
124 
125  /**
126  Beta distribution
127  */
128  double Beta(double a, double b) {
129  return Engine().Beta(a,b);
130  }
131 
132  /**
133  Log Normal distribution
134  */
135  double LogNormal(double zeta, double sigma) {
136  return Engine().LogNormal(zeta,sigma);
137  }
138 
139  /**
140  Chi square distribution
141  */
142  double ChiSquare(double nu) {
143  return Engine().ChiSquare(nu);
144  }
145 
146  /**
147  F distrbution
148  */
149  double FDist(double nu1, double nu2) {
150  return Engine().FDist(nu1,nu2);
151  }
152 
153  /**
154  t student distribution
155  */
156  double tDist(double nu) {
157  return Engine().tDist(nu);
158  }
159  /**
160  Rayleigh distribution
161  */
162  double Rayleigh(double sigma) {
163  return Engine().Rayleigh(sigma);
164  }
165 
166  /**
167  Logistic distribution
168  */
169  double Logistic(double a) {
170  return Engine().Logistic(a);
171  }
172 
173  /**
174  Pareto distribution
175  */
176  double Pareto(double a, double b) {
177  return Engine().Pareto(a,b);
178  }
179 
180  /**
181  generate random numbers in a 2D circle of radious 1
182  */
183  void Circle(double &x, double &y, double r = 1) {
184  Engine().Dir2D(x,y);
185  x *= r;
186  y *= r;
187  }
188 
189  /**
190  generate random numbers in a 3D sphere of radious 1
191  */
192  void Sphere(double &x, double &y, double &z,double r = 1) {
193  Engine().Dir3D(x,y,z);
194  x *= r;
195  y *= r;
196  z *= r;
197  }
198 
199  /**
200  Poisson distribution
201  */
202  unsigned int Poisson(double mu) {
203  return Engine().Poisson(mu);
204  }
205 
206  /**
207  Binomial distribution
208  */
209  unsigned int Binomial(unsigned int ntot, double prob) {
210  return Engine().Binomial(prob,ntot);
211  }
212 
213  /**
214  Negative Binomial distribution
215  First parameter is n, second is probability
216  To be consistent with Random::Binomial
217  */
218  unsigned int NegativeBinomial(double n, double prob) {
219  return Engine().NegativeBinomial(prob,n);
220  }
221 
222  /**
223  Multinomial distribution
224  */
225  std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) {
226  return Engine().Multinomial(ntot,p);
227  }
228 
229 
230 
231  };
232 
233 
234 
235 
236 } // namespace Math
237 } // namespace ROOT
238 
239 #endif /* ROOT_Math_GSLRandomFunctions */
unsigned int NegativeBinomial(double n, double prob)
Negative Binomial distribution First parameter is n, second is probability To be consistent with Rand...
double LogNormal(double zeta, double sigma)
Log Normal distribution.
double BreitWigner(double mean=0., double gamma=1)
Breit Wigner distribution.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TArc * a
Definition: textangle.C:12
double Gaus(double mean=0, double sigma=1)
Gaussian distribution.
void Gaussian2D(double sigmaX, double sigmaY, double rho, double &x, double &y)
Bivariate Gaussian distribution with correlation.
Double_t x[n]
Definition: legend1.C:17
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t tau
Definition: TRolke.cxx:630
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
double GausBM(double mean=0, double sigma=1)
Gaussian distribution (Box-Muller method)
const Double_t sigma
double Landau(double mean=0, double sigma=1)
Landau distribution.
void Sphere(double &x, double &y, double &z, double r=1)
generate random numbers in a 3D sphere of radious 1
double gamma(double x)
void Circle(double &x, double &y, double r=1)
generate random numbers in a 2D circle of radious 1
TRandom2 r(17)
double GausR(double mean=0, double sigma=1)
Gaussian distribution (Ratio Method)
unsigned int Binomial(unsigned int ntot, double prob)
Binomial distribution.
std::vector< unsigned int > Multinomial(unsigned int ntot, const std::vector< double > &p)
Multinomial distribution.
Double_t y[n]
Definition: legend1.C:17
Namespace for new Math classes and functions.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
double GaussianTail(double a, double sigma=1)
Gaussian Tail distribution.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
const Int_t n
Definition: legend1.C:16