PdfFuncMathMore.cxx

Go to the documentation of this file.
00001 // @(#)root/mathmore:$Id: PdfFuncMathMore.cxx 37162 2010-12-01 22:15:50Z moneta $
00002 // Authors: L. Moneta    10/2010 
00003 
00004 #include <cmath>
00005 
00006 #include "Math/SpecFuncMathMore.h"
00007 #include "Math/SpecFuncMathCore.h"
00008 #include "Math/PdfFuncMathCore.h"
00009 #include "Math/DistFuncMathMore.h"
00010 
00011 
00012 #include "gsl/gsl_sf_hyperg.h"  // needed for 0F1
00013 
00014 
00015 namespace ROOT {
00016 namespace Math {
00017 
00018 
00019 //non central chisquare pdf (impelmentation from Kyle Cranmer)
00020 // formula from Wikipedia http://en.wikipedia.org/wiki/Noncentral_chi-square_distribution
00021 // but use hybergeometric form for k < 2
00022 double noncentral_chisquared_pdf(double x, double k, double lambda) {
00023 
00024    // special case (form below doesn't work when lambda==0)
00025    if(lambda==0){
00026      return ROOT::Math::chisquared_pdf(x,k);
00027    }
00028    double ret = 0; 
00029    if (k < 2.0) { 
00030 
00031       //  expression using regularized confluent hypergeometric limit function.
00032       //see  http://mathworld.wolfram.com/NoncentralChi-SquaredDistribution.html
00033       //  (note  0\tilde{F}(a,x)  = 0F1(a,x)/ Gamma(a)
00034       // or  wikipedia 
00035       // NOTE : this has problems for large k (so use only fr k <= 2)
00036 
00037       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)
00038       * gsl_sf_hyperg_0F1( 0.5 * k, 0.25 * lambda * x );
00039 
00040    }
00041    else { 
00042    
00043       // SECOND FORM
00044       // 1/2 exp(-(x+lambda)/2) (x/lambda)^(k/4-1/2) I_{k/2 -1}(\sqrt(lamba x))
00045       // where I_v(z) is modified bessel of the first kind
00046       // bessel defined only for nu > 0
00047       
00048       ret = 0.5 * std::exp(-0.5 * (x+lambda) ) * std::pow(x/lambda, 0.25*k-0.5) 
00049          * ROOT::Math::cyl_bessel_i (0.5*k-1., std::sqrt(lambda*x));
00050 
00051 //       ret = 0.5 * exp(-(_x+lambda)/2.) * pow(_x/lambda, k/4.-0.5) 
00052 //      * ROOT::Math::cyl_bessel_i (k/2.-1., sqrt(lambda*_x));
00053 
00054    }
00055 
00056    return ret; 
00057 }
00058 
00059 
00060 } // namespace Math
00061 
00062 } // namespace ROOT

Generated on Tue Jul 5 14:34:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1