RooChiSquarePdf.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitModels                                                     *
00004  * @(#)root/roofit:$Id: RooChiSquarePdf.cxx 28259 2009-04-16 16:21:16Z wouter $
00005  * Authors:                                                                  *
00006  *   Kyle Cranmer
00007  *                                                                           *
00008  *****************************************************************************/
00009 
00010 //////////////////////////////////////////////////////////////////////////////
00011 //
00012 // BEGIN_HTML
00013 // The PDF of the Chi Square distribution for n degrees of freedom.  
00014 // Oddly, this is hard to find in ROOT (except via relation to GammaDist).
00015 // Here we also implement the analytic integral.
00016 // END_HTML
00017 //
00018 
00019 #include "RooFit.h"
00020 
00021 #include "Riostream.h"
00022 #include "Riostream.h"
00023 #include <math.h>
00024 #include "TMath.h"
00025 #include "RooChiSquarePdf.h"
00026 #include "RooAbsReal.h"
00027 #include "RooRealVar.h"
00028 
00029 ClassImp(RooChiSquarePdf)
00030 ;
00031 
00032 
00033 //_____________________________________________________________________________
00034 RooChiSquarePdf::RooChiSquarePdf()
00035 {
00036 }
00037 
00038 
00039 //_____________________________________________________________________________
00040 RooChiSquarePdf::RooChiSquarePdf(const char* name, const char* title, 
00041                            RooAbsReal& x, RooAbsReal& ndof): 
00042   RooAbsPdf(name, title),
00043   _x("x", "Dependent", this, x),
00044   _ndof("ndof","ndof", this, ndof)
00045 {
00046 }
00047 
00048 
00049 
00050 //_____________________________________________________________________________
00051 RooChiSquarePdf::RooChiSquarePdf(const RooChiSquarePdf& other, const char* name) :
00052   RooAbsPdf(other, name), 
00053   _x("x", this, other._x), 
00054   _ndof("ndof",this,other._ndof)
00055 {
00056 }
00057 
00058 
00059 //_____________________________________________________________________________
00060 Double_t RooChiSquarePdf::evaluate() const 
00061 {
00062 
00063   if(_x <= 0) return 0;
00064 
00065   return  pow(_x,(_ndof/2.)-1.) * exp(-_x/2.) / TMath::Gamma(_ndof/2.) / pow(2.,_ndof/2.);
00066 
00067 
00068 }
00069 
00070 
00071 //_____________________________________________________________________________
00072 Int_t RooChiSquarePdf::getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName) const 
00073 {
00074   // No analytical calculation available (yet) of integrals over subranges
00075   if (rangeName && strlen(rangeName)) {
00076     return 0 ;
00077   }
00078 
00079 
00080   if (matchArgs(allVars, analVars, _x)) return 1;
00081   return 0;
00082 }
00083 
00084 
00085 //_____________________________________________________________________________
00086 Double_t RooChiSquarePdf::analyticalIntegral(Int_t code, const char* rangeName) const 
00087 {
00088   assert(code==1) ;
00089   Double_t xmin = _x.min(rangeName); Double_t xmax = _x.max(rangeName);
00090 
00091   // TMath::Prob needs ndof to be an integer, or it returns 0.
00092   //  return TMath::Prob(xmin, _ndof) - TMath::Prob(xmax,_ndof);
00093 
00094   // cumulative is known based on lower incomplete gamma function, or regularized gamma function
00095   // Wikipedia defines lower incomplete gamma function without the normalization 1/Gamma(ndof), 
00096   // but it is included in the ROOT implementation.  
00097   Double_t pmin = TMath::Gamma(_ndof/2,xmin/2);
00098   Double_t pmax = TMath::Gamma(_ndof/2,xmax/2);
00099 
00100   // only use this if range is appropriate
00101   return pmax-pmin;
00102 }
00103 

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