rf110_normintegration.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #110
00004 // 
00005 // Examples on normalization of p.d.f.s,
00006 // integration of p.d.fs, construction
00007 // of cumulative distribution functions from p.d.f.s
00008 // in one dimension
00009 //
00010 // 07/2008 - Wouter Verkerke 
00011 //
00012 /////////////////////////////////////////////////////////////////////////
00013 
00014 #ifndef __CINT__
00015 #include "RooGlobalFunc.h"
00016 #endif
00017 #include "RooRealVar.h"
00018 #include "RooGaussian.h"
00019 #include "RooAbsReal.h"
00020 #include "RooPlot.h"
00021 #include "TCanvas.h"
00022 using namespace RooFit ;
00023 
00024 class TestBasic110 : public RooFitTestUnit
00025 {
00026 public: 
00027   TestBasic110(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Normalization of p.d.f.s in 1D",refFile,writeRef,verbose) {} ;
00028   Bool_t testCode() {
00029 
00030     // S e t u p   m o d e l 
00031     // ---------------------
00032     
00033     // Create observables x,y
00034     RooRealVar x("x","x",-10,10) ;
00035     
00036     // Create p.d.f. gaussx(x,-2,3) 
00037     RooGaussian gx("gx","gx",x,RooConst(-2),RooConst(3)) ;
00038     
00039     
00040     // R e t r i e v e   r a w  &   n o r m a l i z e d   v a l u e s   o f   R o o F i t   p . d . f . s
00041     // --------------------------------------------------------------------------------------------------
00042     
00043     // Return 'raw' unnormalized value of gx
00044     regValue(gx.getVal(),"rf110_gx") ;
00045     
00046     // Return value of gx normalized over x in range [-10,10]
00047     RooArgSet nset(x) ;
00048 
00049     regValue(gx.getVal(&nset),"rf110_gx_Norm[x]") ;
00050     
00051     // Create object representing integral over gx
00052     // which is used to calculate  gx_Norm[x] == gx / gx_Int[x]
00053     RooAbsReal* igx = gx.createIntegral(x) ;
00054     regValue(igx->getVal(),"rf110_gx_Int[x]") ;
00055     
00056     
00057     // I n t e g r a t e   n o r m a l i z e d   p d f   o v e r   s u b r a n g e
00058     // ----------------------------------------------------------------------------
00059     
00060     // Define a range named "signal" in x from -5,5
00061     x.setRange("signal",-5,5) ;
00062     
00063     // Create an integral of gx_Norm[x] over x in range "signal"
00064     // This is the fraction of of p.d.f. gx_Norm[x] which is in the
00065     // range named "signal"
00066     RooAbsReal* igx_sig = gx.createIntegral(x,NormSet(x),Range("signal")) ;
00067     regValue(igx_sig->getVal(),"rf110_gx_Int[x|signal]_Norm[x]") ;
00068     
00069     
00070     
00071     // C o n s t r u c t   c u m u l a t i v e   d i s t r i b u t i o n   f u n c t i o n   f r o m   p d f
00072     // -----------------------------------------------------------------------------------------------------
00073     
00074     // Create the cumulative distribution function of gx
00075     // i.e. calculate Int[-10,x] gx(x') dx'
00076     RooAbsReal* gx_cdf = gx.createCdf(x) ;
00077     
00078     // Plot cdf of gx versus x
00079     RooPlot* frame = x.frame(Title("c.d.f of Gaussian p.d.f")) ;
00080     gx_cdf->plotOn(frame) ;
00081     
00082     
00083     regPlot(frame,"rf110_plot1") ;
00084 
00085     delete igx ;
00086     delete igx_sig ;
00087     delete gx_cdf ;
00088 
00089     return kTRUE ;
00090   }
00091 } ;

Generated on Tue Jul 5 15:07:46 2011 for ROOT_528-00b_version by  doxygen 1.5.1