ROOT  6.06/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  Log Normal distribution
127  */
128  double LogNormal(double zeta, double sigma) {
129  return Engine().LogNormal(zeta,sigma);
130  }
131 
132  /**
133  Chi square distribution
134  */
135  double ChiSquare(double nu) {
136  return Engine().ChiSquare(nu);
137  }
138 
139  /**
140  F distrbution
141  */
142  double FDist(double nu1, double nu2) {
143  return Engine().FDist(nu1,nu2);
144  }
145 
146  /**
147  t student distribution
148  */
149  double tDist(double nu) {
150  return Engine().tDist(nu);
151  }
152 
153  /**
154  generate random numbers in a 2D circle of radious 1
155  */
156  void Circle(double &x, double &y, double r = 1) {
157  Engine().Dir2D(x,y);
158  x *= r;
159  y *= r;
160  }
161 
162  /**
163  generate random numbers in a 3D sphere of radious 1
164  */
165  void Sphere(double &x, double &y, double &z,double r = 1) {
166  Engine().Dir3D(x,y,z);
167  x *= r;
168  y *= r;
169  z *= r;
170  }
171 
172  /**
173  Poisson distribution
174  */
175  unsigned int Poisson(double mu) {
176  return Engine().Poisson(mu);
177  }
178 
179  /**
180  Binomial distribution
181  */
182  unsigned int Binomial(unsigned int ntot, double prob) {
183  return Engine().Binomial(prob,ntot);
184  }
185 
186  /**
187  Negative Binomial distribution
188  First parameter is n, second is probability
189  To be consistent with Random::Binomial
190  */
191  unsigned int NegativeBinomial(double n, double prob) {
192  return Engine().NegativeBinomial(prob,n);
193  }
194 
195  /**
196  Multinomial distribution
197  */
198  std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) {
199  return Engine().Multinomial(ntot,p);
200  }
201 
202 
203 
204  };
205 
206 
207 
208 
209 } // namespace Math
210 } // namespace ROOT
211 
212 #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: ROOT.py:1
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
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)
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
ROOT::R::TRInterface & r
Definition: Object.C:4
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.
double GaussianTail(double a, double sigma=1)
Gaussian Tail distribution.
const Int_t n
Definition: legend1.C:16