Logo ROOT  
Reference Guide
rf706_histpdf.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Special pdf's: histogram-based pdfs and functions
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 ///
10 /// \date July 2008
11 /// \author Wouter Verkerke
12 
13 #include "RooRealVar.h"
14 #include "RooDataSet.h"
15 #include "RooGaussian.h"
16 #include "RooConstVar.h"
17 #include "RooPolynomial.h"
18 #include "RooHistPdf.h"
19 #include "TCanvas.h"
20 #include "TAxis.h"
21 #include "RooPlot.h"
22 using namespace RooFit;
23 
24 void rf706_histpdf()
25 {
26  // C r e a t e p d f f o r s a m p l i n g
27  // ---------------------------------------------
28 
29  RooRealVar x("x", "x", 0, 20);
30  RooPolynomial p("p", "p", x, RooArgList(RooConst(0.01), RooConst(-0.01), RooConst(0.0004)));
31 
32  // C r e a t e l o w s t a t s h i s t o g r a m
33  // ---------------------------------------------------
34 
35  // Sample 500 events from p
36  x.setBins(20);
37  RooDataSet *data1 = p.generate(x, 500);
38 
39  // Create a binned dataset with 20 bins and 500 events
40  RooDataHist *hist1 = data1->binnedClone();
41 
42  // Represent data in dh as pdf in x
43  RooHistPdf histpdf1("histpdf1", "histpdf1", x, *hist1, 0);
44 
45  // Plot unbinned data and histogram pdf overlaid
46  RooPlot *frame1 = x.frame(Title("Low statistics histogram pdf"), Bins(100));
47  data1->plotOn(frame1);
48  histpdf1.plotOn(frame1);
49 
50  // C r e a t e h i g h s t a t s h i s t o g r a m
51  // -----------------------------------------------------
52 
53  // Sample 100000 events from p
54  x.setBins(10);
55  RooDataSet *data2 = p.generate(x, 100000);
56 
57  // Create a binned dataset with 10 bins and 100K events
58  RooDataHist *hist2 = data2->binnedClone();
59 
60  // Represent data in dh as pdf in x, apply 2nd order interpolation
61  RooHistPdf histpdf2("histpdf2", "histpdf2", x, *hist2, 2);
62 
63  // Plot unbinned data and histogram pdf overlaid
64  RooPlot *frame2 = x.frame(Title("High stats histogram pdf with interpolation"), Bins(100));
65  data2->plotOn(frame2);
66  histpdf2.plotOn(frame2);
67 
68  TCanvas *c = new TCanvas("rf706_histpdf", "rf706_histpdf", 800, 400);
69  c->Divide(2);
70  c->cd(1);
71  gPad->SetLeftMargin(0.15);
72  frame1->GetYaxis()->SetTitleOffset(1.4);
73  frame1->Draw();
74  c->cd(2);
75  gPad->SetLeftMargin(0.15);
76  frame2->GetYaxis()->SetTitleOffset(1.8);
77  frame2->Draw();
78 }
c
#define c(i)
Definition: RSha256.hxx:101
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition: RooGlobalFunc.cxx:177
rf706_histpdf
Definition: rf706_histpdf.py:1
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
TCanvas.h
RooDataSet.h
RooPolynomial.h
RooDataHist
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:39
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPolynomial
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1258
RooPlot
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
RooRealVar.h
RooHistPdf
RooHistPdf implements a probablity density function sampled from a multidimensional histogram.
Definition: RooHistPdf.h:29
RooConstVar.h
RooHistPdf.h
TCanvas
The Canvas class.
Definition: TCanvas.h:23
TAxis.h
RooDataSet::binnedClone
RooDataHist * binnedClone(const char *newName=0, const char *newTitle=0) const
Return binned clone of this dataset.
Definition: RooDataSet.cxx:975
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:176
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:347