rf706_histpdf.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'SPECIAL PDFS' RooFit tutorial macro #706
00004 // 
00005 // Histogram based p.d.f.s and functions
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooGaussian.h"
00019 #include "RooPolynomial.h"
00020 #include "RooHistPdf.h"
00021 #include "TCanvas.h"
00022 #include "RooPlot.h"
00023 using namespace RooFit ;
00024 
00025 
00026 // Elementary operations on a gaussian PDF
00027 class TestBasic706 : public RooFitTestUnit
00028 {
00029 public: 
00030   TestBasic706(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Histogram based p.d.f.s",refFile,writeRef,verbose) {} ;
00031   Bool_t testCode() {
00032 
00033   // C r e a t e   p d f   f o r   s a m p l i n g 
00034   // ---------------------------------------------
00035 
00036   RooRealVar x("x","x",0,20) ;
00037   RooPolynomial p("p","p",x,RooArgList(RooConst(0.01),RooConst(-0.01),RooConst(0.0004))) ;
00038 
00039 
00040 
00041   // C r e a t e   l o w   s t a t s   h i s t o g r a m
00042   // ---------------------------------------------------
00043 
00044   // Sample 500 events from p
00045   x.setBins(20) ;
00046   RooDataSet* data1 = p.generate(x,500) ;
00047   
00048   // Create a binned dataset with 20 bins and 500 events
00049   RooDataHist* hist1 = data1->binnedClone() ;
00050 
00051   // Represent data in dh as pdf in x
00052   RooHistPdf histpdf1("histpdf1","histpdf1",x,*hist1,0) ;
00053 
00054   // Plot unbinned data and histogram pdf overlaid
00055   RooPlot* frame1 = x.frame(Title("Low statistics histogram pdf"),Bins(100)) ;
00056   data1->plotOn(frame1) ;
00057   histpdf1.plotOn(frame1) ;  
00058   
00059 
00060   // C r e a t e   h i g h   s t a t s   h i s t o g r a m
00061   // -----------------------------------------------------
00062 
00063   // Sample 100000 events from p
00064   x.setBins(10) ;
00065   RooDataSet* data2 = p.generate(x,100000) ;
00066 
00067   // Create a binned dataset with 10 bins and 100K events
00068   RooDataHist* hist2 = data2->binnedClone() ;
00069 
00070   // Represent data in dh as pdf in x, apply 2nd order interpolation  
00071   RooHistPdf histpdf2("histpdf2","histpdf2",x,*hist2,2) ;
00072 
00073   // Plot unbinned data and histogram pdf overlaid
00074   RooPlot* frame2 = x.frame(Title("High stats histogram pdf with interpolation"),Bins(100)) ;
00075   data2->plotOn(frame2) ;
00076   histpdf2.plotOn(frame2) ;  
00077 
00078 
00079   regPlot(frame1,"rf607_plot1") ;
00080   regPlot(frame2,"rf607_plot2") ;
00081 
00082   delete data1 ;
00083   delete hist1 ;
00084   delete data2 ;
00085   delete hist2 ;
00086 
00087   return kTRUE ;
00088   }
00089 } ;

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