rf706_histpdf.C

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 "RooConstVar.h"
00020 #include "RooPolynomial.h"
00021 #include "RooHistPdf.h"
00022 #include "TCanvas.h"
00023 #include "TAxis.h"
00024 #include "RooPlot.h"
00025 using namespace RooFit ;
00026 
00027 
00028 void rf706_histpdf()
00029 {
00030   // C r e a t e   p d f   f o r   s a m p l i n g 
00031   // ---------------------------------------------
00032 
00033   RooRealVar x("x","x",0,20) ;
00034   RooPolynomial p("p","p",x,RooArgList(RooConst(0.01),RooConst(-0.01),RooConst(0.0004))) ;
00035 
00036 
00037 
00038   // C r e a t e   l o w   s t a t s   h i s t o g r a m
00039   // ---------------------------------------------------
00040 
00041   // Sample 500 events from p
00042   x.setBins(20) ;
00043   RooDataSet* data1 = p.generate(x,500) ;
00044   
00045   // Create a binned dataset with 20 bins and 500 events
00046   RooDataHist* hist1 = data1->binnedClone() ;
00047 
00048   // Represent data in dh as pdf in x
00049   RooHistPdf histpdf1("histpdf1","histpdf1",x,*hist1,0) ;
00050 
00051   // Plot unbinned data and histogram pdf overlaid
00052   RooPlot* frame1 = x.frame(Title("Low statistics histogram pdf"),Bins(100)) ;
00053   data1->plotOn(frame1) ;
00054   histpdf1.plotOn(frame1) ;  
00055   
00056 
00057   // C r e a t e   h i g h   s t a t s   h i s t o g r a m
00058   // -----------------------------------------------------
00059 
00060   // Sample 100000 events from p
00061   x.setBins(10) ;
00062   RooDataSet* data2 = p.generate(x,100000) ;
00063 
00064   // Create a binned dataset with 10 bins and 100K events
00065   RooDataHist* hist2 = data2->binnedClone() ;
00066 
00067   // Represent data in dh as pdf in x, apply 2nd order interpolation  
00068   RooHistPdf histpdf2("histpdf2","histpdf2",x,*hist2,2) ;
00069 
00070   // Plot unbinned data and histogram pdf overlaid
00071   RooPlot* frame2 = x.frame(Title("High stats histogram pdf with interpolation"),Bins(100)) ;
00072   data2->plotOn(frame2) ;
00073   histpdf2.plotOn(frame2) ;  
00074 
00075 
00076   TCanvas* c = new TCanvas("rf706_histpdf","rf706_histpdf",800,400) ;  
00077   c->Divide(2) ;
00078   c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
00079   c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.8) ; frame2->Draw() ;
00080 
00081 
00082 }

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