Logo ROOT   6.10/09
Reference Guide
PdfFuncMathMore.cxx
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta 10/2010
3 
4 #include <cmath>
5 
8 #include "Math/PdfFuncMathCore.h"
10 
11 
12 #include "gsl/gsl_sf_hyperg.h" // needed for 0F1
13 
14 
15 namespace ROOT {
16 namespace Math {
17 
18 
19 //non central chisquare pdf (impelmentation from Kyle Cranmer)
20 // formula from Wikipedia http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution
21 // but use hybergeometric form for k < 2
22 double noncentral_chisquared_pdf(double x, double k, double lambda) {
23 
24  // special case (form below doesn't work when lambda==0)
25  if(lambda==0){
26  return ROOT::Math::chisquared_pdf(x,k);
27  }
28  double ret = 0;
29  if (k < 2.0) {
30 
31  // expression using regularized confluent hypergeometric limit function.
32  //see http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html
33  // (note 0\tilde{F}(a,x) = 0F1(a,x)/ Gamma(a)
34  // or wikipedia
35  // NOTE : this has problems for large k (so use only fr k <= 2)
36 
37  ret = std::exp( - 0.5 *(x + lambda) ) * 1./(std::pow(2.0, 0.5 * k) * ROOT::Math::tgamma(0.5*k)) * std::pow( x, 0.5 * k - 1.0)
38  * gsl_sf_hyperg_0F1( 0.5 * k, 0.25 * lambda * x );
39 
40  }
41  else {
42 
43  // SECOND FORM
44  // 1/2 exp(-(x+lambda)/2) (x/lambda)^(k/4-1/2) I_{k/2 -1}(\sqrt(lamba x))
45  // where I_v(z) is modified bessel of the first kind
46  // bessel defined only for nu > 0
47 
48  ret = 0.5 * std::exp(-0.5 * (x+lambda) ) * std::pow(x/lambda, 0.25*k-0.5)
49  * ROOT::Math::cyl_bessel_i (0.5*k-1., std::sqrt(lambda*x));
50 
51 // ret = 0.5 * exp(-(_x+lambda)/2.) * pow(_x/lambda, k/4.-0.5)
52 // * ROOT::Math::cyl_bessel_i (k/2.-1., sqrt(lambda*_x));
53 
54  }
55 
56  return ret;
57 }
58 
59 
60 } // namespace Math
61 
62 
63 } // namespace ROOT
64 
65 #include "Math/Error.h"
66 
67 // dummy method called to force auto-loading of MathMore Library
68 //
69 // note: a typdef MathMoreLIb to MathMoreLibrary has been introduced because for unknown reasons
70 // loading on the MathMoreLibrary does not work while it works for the class name MathMoreLib
71 // see ROOT-8455
72 
74  MATH_INFO_MSG("MathMoreLibrary","libMathMore has been loaded.");
75  }
76 
double chisquared_pdf(double x, double r, double x0=0)
Probability density function of the distribution with degrees of freedom.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double tgamma(double x)
The gamma function is defined to be the extension of the factorial to real numbers.
double sqrt(double)
Double_t x[n]
Definition: legend1.C:17
double pow(double, double)
#define MATH_INFO_MSG(loc, str)
Definition: Error.h:44
double noncentral_chisquared_pdf(double x, double r, double lambda)
Probability density function of the non central distribution with degrees of freedom and the noon-c...
Namespace for new Math classes and functions.
double cyl_bessel_i(double nu, double x)
Calculates the modified Bessel function of the first kind (also called regular modified (cylindrical)...
double exp(double)