Logo ROOT   6.18/05
Reference Guide
rf315_projectpdf.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4/// Multidimensional models: marginizalization of multi-dimensional p.d.f.s through integration
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9/// \author 07/2008 - Wouter Verkerke
10
11#include "RooRealVar.h"
12#include "RooDataHist.h"
13#include "RooGaussian.h"
14#include "RooProdPdf.h"
15#include "RooPolyVar.h"
16#include "TH1.h"
17#include "TCanvas.h"
18#include "TAxis.h"
19#include "RooPlot.h"
20#include "RooNumIntConfig.h"
21#include "RooConstVar.h"
22using namespace RooFit;
23
25{
26 // C r e a t e p d f m ( x , y ) = g x ( x | y ) * g ( y )
27 // --------------------------------------------------------------
28
29 // Increase default precision of numeric integration
30 // as this exercise has high sensitivity to numeric integration precision
33
34 // Create observables
35 RooRealVar x("x", "x", -5, 5);
36 RooRealVar y("y", "y", -2, 2);
37
38 // Create function f(y) = a0 + a1*y
39 RooRealVar a0("a0", "a0", 0);
40 RooRealVar a1("a1", "a1", -1.5, -3, 1);
41 RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
42
43 // Create gaussx(x,f(y),sx)
44 RooRealVar sigmax("sigmax", "width of gaussian", 0.5);
45 RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax);
46
47 // Create gaussy(y,0,2)
48 RooGaussian gaussy("gaussy", "Gaussian in y", y, RooConst(0), RooConst(2));
49
50 // Create gaussx(x,sx|y) * gaussy(y)
51 RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x));
52
53 // M a r g i n a l i z e m ( x , y ) t o m ( x )
54 // ----------------------------------------------------
55
56 // modelx(x) = Int model(x,y) dy
57 RooAbsPdf *modelx = model.createProjection(y);
58
59 // U s e m a r g i n a l i z e d p . d . f . a s r e g u l a r 1 - D p . d . f .
60 // ------------------------------------------------------------------------------------------
61
62 // Sample 1000 events from modelx
63 RooAbsData *data = modelx->generateBinned(x, 1000);
64
65 // Fit modelx to toy data
66 modelx->fitTo(*data, Verbose());
67
68 // Plot modelx over data
69 RooPlot *frame = x.frame(40);
70 data->plotOn(frame);
71 modelx->plotOn(frame);
72
73 // Make 2D histogram of model(x,y)
74 TH1 *hh = model.createHistogram("x,y");
76
77 TCanvas *c = new TCanvas("rf315_projectpdf", "rf315_projectpdf", 800, 400);
78 c->Divide(2);
79 c->cd(1);
80 gPad->SetLeftMargin(0.15);
81 frame->GetYaxis()->SetTitleOffset(1.4);
82 frame->Draw();
83 c->cd(2);
84 gPad->SetLeftMargin(0.20);
85 hh->GetZaxis()->SetTitleOffset(2.5);
86 hh->Draw("surf");
87}
#define c(i)
Definition: RSha256.hxx:101
#define e(i)
Definition: RSha256.hxx:103
@ kBlue
Definition: Rtypes.h:64
#define gPad
Definition: TVirtualPad.h:286
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:552
virtual RooFitResult * fitTo(RooAbsData &data, 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())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1119
virtual RooDataHist * generateBinned(const RooArgSet &whatVars, Double_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none())
As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,...
Definition: RooAbsPdf.h:105
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Definition: RooAbsPdf.cxx:2979
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 RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition: RooAbsPdf.h:119
static RooNumIntConfig * defaultIntegratorConfig()
Returns the default numeric integration configuration for all RooAbsReals.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1123
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:294
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:31
The TH1 histogram class.
Definition: TH1.h:56
TAxis * GetZaxis()
Definition: TH1.h:318
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2981
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Template specialisation used in RooAbsArg:
RooConstVar & RooConst(Double_t val)
RooCmdArg Verbose(Bool_t flag=kTRUE)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)