Logo ROOT   6.10/09
Reference Guide
rf706_histpdf.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'SPECIAL PDFS' RooFit tutorial macro #706
4 //
5 // Histogram based p.d.f.s and functions
6 //
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooPolynomial.h"
20 #include "RooHistPdf.h"
21 #include "TCanvas.h"
22 #include "RooPlot.h"
23 using namespace RooFit ;
24 
25 
26 // Elementary operations on a gaussian PDF
27 class TestBasic706 : public RooFitTestUnit
28 {
29 public:
30  TestBasic706(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Histogram based p.d.f.s",refFile,writeRef,verbose) {} ;
31  Bool_t testCode() {
32 
33  // C r e a t e p d f f o r s a m p l i n g
34  // ---------------------------------------------
35 
36  RooRealVar x("x","x",0,20) ;
37  RooPolynomial p("p","p",x,RooArgList(RooConst(0.01),RooConst(-0.01),RooConst(0.0004))) ;
38 
39 
40 
41  // C r e a t e l o w s t a t s h i s t o g r a m
42  // ---------------------------------------------------
43 
44  // Sample 500 events from p
45  x.setBins(20) ;
46  RooDataSet* data1 = p.generate(x,500) ;
47 
48  // Create a binned dataset with 20 bins and 500 events
49  RooDataHist* hist1 = data1->binnedClone() ;
50 
51  // Represent data in dh as pdf in x
52  RooHistPdf histpdf1("histpdf1","histpdf1",x,*hist1,0) ;
53 
54  // Plot unbinned data and histogram pdf overlaid
55  RooPlot* frame1 = x.frame(Title("Low statistics histogram pdf"),Bins(100)) ;
56  data1->plotOn(frame1) ;
57  histpdf1.plotOn(frame1) ;
58 
59 
60  // C r e a t e h i g h s t a t s h i s t o g r a m
61  // -----------------------------------------------------
62 
63  // Sample 100000 events from p
64  x.setBins(10) ;
65  RooDataSet* data2 = p.generate(x,100000) ;
66 
67  // Create a binned dataset with 10 bins and 100K events
68  RooDataHist* hist2 = data2->binnedClone() ;
69 
70  // Represent data in dh as pdf in x, apply 2nd order interpolation
71  RooHistPdf histpdf2("histpdf2","histpdf2",x,*hist2,2) ;
72 
73  // Plot unbinned data and histogram pdf overlaid
74  RooPlot* frame2 = x.frame(Title("High stats histogram pdf with interpolation"),Bins(100)) ;
75  data2->plotOn(frame2) ;
76  histpdf2.plotOn(frame2) ;
77 
78 
79  regPlot(frame1,"rf607_plot1") ;
80  regPlot(frame2,"rf607_plot2") ;
81 
82  delete data1 ;
83  delete hist1 ;
84  delete data2 ;
85  delete hist2 ;
86 
87  return kTRUE ;
88  }
89 } ;
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooCmdArg Title(const char *name)
RooDataSet is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
Double_t x[n]
Definition: legend1.C:17
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:981
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooHistPdf implements a probablity density function sampled from a multidimensional histogram...
Definition: RooHistPdf.h:28
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooConstVar & RooConst(Double_t val)
RooCmdArg Bins(Int_t nbin)
RooPolynomial implements a polynomial p.d.f of the form By default coefficient a_0 is chosen to be 1...
Definition: RooPolynomial.h:28
const Bool_t kTRUE
Definition: RtypesCore.h:91