Logo ROOT  
Reference Guide
 
Loading...
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 //typedef TRandomEngine DefaultEngineType;
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 Multi-variate Gaussian distribution with correlation. The covMatrix is a pointer to
102 the covcariance matrix (NxN)
103 Lmat is a pointer to store the factorized Cholesky decomposition C = LL^T of the covariance matrix
104 If the generator is to be called again with the same covariance one can provide a null CovMAtrix and only
105 lmat
106 */
107 void GaussianND(size_t n, const double * meanVec, const double * covMatrix, double * x, double * lmat = nullptr) {
108 Engine().GaussianND(n, meanVec,covMatrix,x,lmat);
109 }
110
111 /**
112 Exponential distribution
113 */
114 double Exp(double tau) {
115 return Engine().Exponential(tau);
116 }
117 /**
118 Breit Wigner distribution
119 */
120 double BreitWigner(double mean = 0., double gamma = 1) {
121 return mean + Engine().Cauchy( gamma/2.0 );
122 }
123
124 /**
125 Landau distribution
126 */
127 double Landau(double mean = 0, double sigma = 1) {
128 return mean + sigma*Engine().Landau();
129 }
130
131 /**
132 Gamma distribution
133 */
134 double Gamma(double a, double b) {
135 return Engine().Gamma(a,b);
136 }
137
138 /**
139 Beta distribution
140 */
141 double Beta(double a, double b) {
142 return Engine().Beta(a,b);
143 }
144
145 /**
146 Log Normal distribution
147 */
148 double LogNormal(double zeta, double sigma) {
149 return Engine().LogNormal(zeta,sigma);
150 }
151
152 /**
153 Chi square distribution
154 */
155 double ChiSquare(double nu) {
156 return Engine().ChiSquare(nu);
157 }
158
159 /**
160 F distribution
161 */
162 double FDist(double nu1, double nu2) {
163 return Engine().FDist(nu1,nu2);
164 }
165
166 /**
167 t student distribution
168 */
169 double tDist(double nu) {
170 return Engine().tDist(nu);
171 }
172 /**
173 Rayleigh distribution
174 */
175 double Rayleigh(double sigma) {
176 return Engine().Rayleigh(sigma);
177 }
178
179 /**
180 Logistic distribution
181 */
182 double Logistic(double a) {
183 return Engine().Logistic(a);
184 }
185
186 /**
187 Pareto distribution
188 */
189 double Pareto(double a, double b) {
190 return Engine().Pareto(a,b);
191 }
192
193 /**
194 generate random numbers in a 2D circle of radious 1
195 */
196 void Circle(double &x, double &y, double r = 1) {
197 Engine().Dir2D(x,y);
198 x *= r;
199 y *= r;
200 }
201
202 /**
203 generate random numbers in a 3D sphere of radious 1
204 */
205 void Sphere(double &x, double &y, double &z,double r = 1) {
206 Engine().Dir3D(x,y,z);
207 x *= r;
208 y *= r;
209 z *= r;
210 }
211
212 /**
213 Poisson distribution
214 */
215 unsigned int Poisson(double mu) {
216 return Engine().Poisson(mu);
217 }
218
219 /**
220 Binomial distribution
221 */
222 unsigned int Binomial(unsigned int ntot, double prob) {
223 return Engine().Binomial(prob,ntot);
224 }
225
226 /**
227 Negative Binomial distribution
228 First parameter is n, second is probability
229 To be consistent with Random::Binomial
230 */
231 unsigned int NegativeBinomial(double n, double prob) {
232 return Engine().NegativeBinomial(prob,n);
233 }
234
235 /**
236 Multinomial distribution
237 */
238 std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) {
239 return Engine().Multinomial(ntot,p);
240 }
241
242
243
244 };
245
246
247
248
249} // namespace Math
250} // namespace ROOT
251
252#endif /* ROOT_Math_GSLRandomFunctions */
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
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 GaussianND(size_t n, const double *meanVec, const double *covMatrix, double *x, double *lmat=nullptr)
Multi-variate Gaussian distribution with correlation.
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.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.