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