Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:17

0001 // @(#)root/mathmore:$Id$
0002 // Authors: L. Moneta    8/2015
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2015 , ROOT MathLib Team                             *
0007  *                                                                    *
0008  *                                                                    *
0009  **********************************************************************/
0010 
0011 // Header file for random class
0012 //
0013 //
0014 // Created by: Lorenzo Moneta  : Tue 4 Aug 2015
0015 //
0016 //
0017 #ifndef ROOT_Math_GSLRandomFunctions
0018 #define ROOT_Math_GSLRandomFunctions
0019 
0020 
0021 //#include <type_traits>
0022 
0023 #include "Math/RandomFunctions.h"
0024 
0025 #include "Math/GSLRndmEngines.h"
0026 
0027 #include <vector>
0028 
0029 namespace ROOT {
0030 namespace Math {
0031 
0032 
0033 //___________________________________________________________________________________
0034    /**
0035        Specialized implementation of the Random functions based on the GSL library.
0036        These will work onlmy with a GSLRandomEngine type
0037 
0038        @ingroup  Random
0039    */
0040 
0041 
0042    template <class EngineType >
0043    class RandomFunctions<EngineType, ROOT::Math::GSLRandomEngine> : public RandomFunctions<EngineType, DefaultEngineType> {
0044       //class RandomFunctions<Engine, ROOT::Math::GSLRandomEngine>  {
0045 
0046       //typedef TRandomEngine DefaultEngineType;
0047 
0048    public:
0049 
0050       RandomFunctions() {}
0051 
0052       RandomFunctions(EngineType & rng) : RandomFunctions<EngineType, DefaultEngineType>(rng) {}
0053 
0054 
0055       inline EngineType & Engine() { return  RandomFunctions<EngineType,DefaultEngineType>::Rng(); }
0056 
0057       double GausZig(double mean, double sigma) {
0058          return Engine().GaussianZig(sigma) + mean;
0059       }
0060       // double GausRatio(double mean, double sigma) {
0061       //    auto & r =  RandomFunctions<Engine,DefaultEngineType>::Rng();
0062       //    return r.GaussianRatio(sigma) + mean;
0063       // }
0064 
0065       /**
0066          Gaussian distribution. Default method (use Ziggurat)
0067       */
0068       double Gaus(double mean = 0, double sigma = 1) {
0069          return mean + Engine().GaussianZig(sigma);
0070       }
0071 
0072       /**
0073          Gaussian distribution (Box-Muller method)
0074       */
0075       double GausBM(double mean = 0, double sigma = 1) {
0076          return mean + Engine().Gaussian(sigma);
0077       }
0078 
0079       /**
0080          Gaussian distribution (Ratio Method)
0081       */
0082       double GausR(double mean = 0, double sigma = 1) {
0083          return mean + Engine().GaussianRatio(sigma);
0084       }
0085 
0086       /**
0087          Gaussian Tail distribution
0088       */
0089       double GaussianTail(double a, double sigma = 1) {
0090          return Engine().GaussianTail(a,sigma);
0091       }
0092 
0093       /**
0094          Bivariate Gaussian distribution with correlation
0095       */
0096       void Gaussian2D(double sigmaX, double sigmaY, double rho, double &x, double &y) {
0097          Engine().Gaussian2D(sigmaX, sigmaY, rho, x, y);
0098       }
0099 
0100       /**
0101          Multi-variate Gaussian distribution with correlation. The covMatrix is a pointer to
0102          the covcariance matrix (NxN)
0103          Lmat is a pointer to store the factorized Cholesky decomposition C  = LL^T of the covariance matrix
0104          If the generator is to be called again with the same covariance one can provide a null CovMAtrix and only
0105          lmat
0106       */
0107       void GaussianND(size_t n, const double * meanVec, const double * covMatrix, double * x, double * lmat = nullptr) {
0108          Engine().GaussianND(n, meanVec,covMatrix,x,lmat);
0109       }
0110 
0111       /**
0112          Exponential distribution
0113       */
0114       double Exp(double tau) {
0115          return Engine().Exponential(tau);
0116       }
0117       /**
0118          Breit Wigner distribution
0119       */
0120       double BreitWigner(double mean = 0., double gamma = 1) {
0121          return mean + Engine().Cauchy( gamma/2.0 );
0122       }
0123 
0124       /**
0125          Landau distribution
0126       */
0127       double Landau(double mean = 0, double sigma = 1) {
0128          return mean + sigma*Engine().Landau();
0129       }
0130 
0131       /**
0132          Gamma distribution
0133       */
0134       double Gamma(double a, double b) {
0135          return Engine().Gamma(a,b);
0136       }
0137 
0138       /**
0139          Beta distribution
0140       */
0141       double Beta(double a, double b) {
0142          return Engine().Beta(a,b);
0143       }
0144 
0145       /**
0146          Log Normal distribution
0147       */
0148       double LogNormal(double zeta, double sigma) {
0149          return Engine().LogNormal(zeta,sigma);
0150       }
0151 
0152       /**
0153          Chi square distribution
0154       */
0155       double ChiSquare(double nu) {
0156          return Engine().ChiSquare(nu);
0157       }
0158 
0159       /**
0160          F distribution
0161       */
0162       double FDist(double nu1, double nu2) {
0163          return Engine().FDist(nu1,nu2);
0164       }
0165 
0166       /**
0167          t student distribution
0168       */
0169       double tDist(double nu) {
0170          return Engine().tDist(nu);
0171       }
0172       /**
0173          Rayleigh distribution
0174       */
0175       double Rayleigh(double sigma)  {
0176          return Engine().Rayleigh(sigma);
0177       }
0178 
0179       /**
0180          Logistic distribution
0181       */
0182       double Logistic(double a) {
0183          return Engine().Logistic(a);
0184       }
0185 
0186       /**
0187          Pareto distribution
0188       */
0189       double Pareto(double a, double b)  {
0190          return Engine().Pareto(a,b);
0191       }
0192 
0193       /**
0194          generate random numbers in a 2D circle of radious 1
0195       */
0196       void Circle(double &x, double &y, double r = 1) {
0197          Engine().Dir2D(x,y);
0198          x *= r;
0199          y *= r;
0200       }
0201 
0202       /**
0203          generate random numbers in a 3D sphere of radious 1
0204       */
0205       void Sphere(double &x, double &y, double &z,double r = 1) {
0206          Engine().Dir3D(x,y,z);
0207          x *= r;
0208          y *= r;
0209          z *= r;
0210       }
0211 
0212       /**
0213          Poisson distribution
0214       */
0215       unsigned int Poisson(double mu) {
0216          return Engine().Poisson(mu);
0217       }
0218 
0219       /**
0220          Binomial distribution
0221       */
0222       unsigned int Binomial(unsigned int ntot, double prob) {
0223          return Engine().Binomial(prob,ntot);
0224       }
0225 
0226       /**
0227          Negative Binomial distribution
0228          First parameter is n, second is probability
0229          To be consistent with Random::Binomial
0230       */
0231       unsigned int NegativeBinomial(double n, double prob) {
0232          return Engine().NegativeBinomial(prob,n);
0233       }
0234 
0235       /**
0236          Multinomial distribution
0237       */
0238       std::vector<unsigned int> Multinomial( unsigned int ntot, const std::vector<double> & p ) {
0239          return Engine().Multinomial(ntot,p);
0240       }
0241 
0242 
0243 
0244    };
0245 
0246 
0247 
0248 
0249 } // namespace Math
0250 } // namespace ROOT
0251 
0252 #endif /* ROOT_Math_GSLRandomFunctions */