CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/CommonTools/Statistics/src/IncompleteGammaComplement.cc

Go to the documentation of this file.
00001 #include "CommonTools/Statistics/src/IncompleteGammaComplement.h"
00002 #include "CommonTools/Statistics/src/GammaContinuedFraction.h"
00003 #include "CommonTools/Statistics/src/GammaSeries.h"
00004 #include "CommonTools/Statistics/src/GammaLn.h"
00005 
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 
00009 #include <iostream>
00010 #include <cmath>
00011 
00012 float IncompleteGammaComplement::value(float a, float x)
00013 {
00014   if( x < 0.0 || a <= 0.0 ) 
00015     edm::LogInfo("IncompleteGammaComplement")<< "IncompleteGammaComplement::invalid arguments";
00016   if( x < (a+1.0) )
00017     // take the complement of the series representation
00018     return 1.-GammaSeries(a,x)*(exp(-x + a*log(x) - GammaLn(a)));
00019   else
00020     // use the continued fraction representation
00021     return GammaContinuedFraction(a,x)*(exp(-x + a*log(x) - GammaLn(a)));
00022 }
00023 
00024 
00025 float IncompleteGammaComplement::ln(float a, float x)
00026 {
00027   if( x < 0.0 || a <= 0.0 ) 
00028 edm::LogInfo("IncompleteGammaComplement")<< "IncompleteGammaComplement::invalid arguments";
00029   if( x < (a+1.0) )
00030     // take the complement of the series representation    
00031     return log(1.-GammaSeries(a,x)*(exp(-x + a*log(x) - GammaLn(a))));
00032   else
00033     // use the continued fraction representation
00034     return log(GammaContinuedFraction(a,x)) -x + a*log(x) - GammaLn(a);
00035 }