Logo ROOT  
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 pdfs through integration
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 "RooDataHist.h"
15 #include "RooGaussian.h"
16 #include "RooProdPdf.h"
17 #include "RooPolyVar.h"
18 #include "TH1.h"
19 #include "TCanvas.h"
20 #include "TAxis.h"
21 #include "RooPlot.h"
22 #include "RooNumIntConfig.h"
23 #include "RooConstVar.h"
24 using namespace RooFit;
25 
26 void rf315_projectpdf()
27 {
28  // C r e a t e p d f m ( x , y ) = g x ( x | y ) * g ( y )
29  // --------------------------------------------------------------
30 
31  // Increase default precision of numeric integration
32  // as this exercise has high sensitivity to numeric integration precision
35 
36  // Create observables
37  RooRealVar x("x", "x", -5, 5);
38  RooRealVar y("y", "y", -2, 2);
39 
40  // Create function f(y) = a0 + a1*y
41  RooRealVar a0("a0", "a0", 0);
42  RooRealVar a1("a1", "a1", -1.5, -3, 1);
43  RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
44 
45  // Create gaussx(x,f(y),sx)
46  RooRealVar sigmax("sigmax", "width of gaussian", 0.5);
47  RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax);
48 
49  // Create gaussy(y,0,2)
50  RooGaussian gaussy("gaussy", "Gaussian in y", y, RooConst(0), RooConst(2));
51 
52  // Create gaussx(x,sx|y) * gaussy(y)
53  RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x));
54 
55  // M a r g i n a l i z e m ( x , y ) t o m ( x )
56  // ----------------------------------------------------
57 
58  // modelx(x) = Int model(x,y) dy
59  RooAbsPdf *modelx = model.createProjection(y);
60 
61  // 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 .
62  // ------------------------------------------------------------------------------------------
63 
64  // Sample 1000 events from modelx
65  RooAbsData *data = modelx->generateBinned(x, 1000);
66 
67  // Fit modelx to toy data
68  modelx->fitTo(*data, Verbose());
69 
70  // Plot modelx over data
71  RooPlot *frame = x.frame(40);
72  data->plotOn(frame);
73  modelx->plotOn(frame);
74 
75  // Make 2D histogram of model(x,y)
76  TH1 *hh = model.createHistogram("x,y");
77  hh->SetLineColor(kBlue);
78 
79  TCanvas *c = new TCanvas("rf315_projectpdf", "rf315_projectpdf", 800, 400);
80  c->Divide(2);
81  c->cd(1);
82  gPad->SetLeftMargin(0.15);
83  frame->GetYaxis()->SetTitleOffset(1.4);
84  frame->Draw();
85  c->cd(2);
86  gPad->SetLeftMargin(0.20);
87  hh->GetZaxis()->SetTitleOffset(2.5);
88  hh->Draw("surf");
89 }
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
e
#define e(i)
Definition: RSha256.hxx:103
RooAbsData
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:47
RooNumIntConfig.h
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
rf315_projectpdf
Definition: rf315_projectpdf.py:1
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
TCanvas.h
TH1::GetZaxis
TAxis * GetZaxis()
Definition: TH1.h:322
RooAbsPdf::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 RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Helper calling plotOn(RooPlot*, RooLinkedList&) const.
Definition: RooAbsPdf.h:121
RooPolyVar.h
RooProdPdf.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
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
RooFit::Verbose
RooCmdArg Verbose(Bool_t flag=kTRUE)
Definition: RooGlobalFunc.cxx:189
RooDataHist.h
RooPlot.h
RooNumIntConfig::setEpsRel
void setEpsRel(Double_t newEpsRel)
Set relative convergence criteria (convergence if abs(Err)/abs(Int)<newEpsRel)
Definition: RooNumIntConfig.cxx:268
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
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooPolyVar
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooConstVar.h
RooFit::Conditional
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
Definition: RooGlobalFunc.cxx:231
RooAbsReal::defaultIntegratorConfig
static RooNumIntConfig * defaultIntegratorConfig()
Returns the default numeric integration configuration for all RooAbsReals.
Definition: RooAbsReal.cxx:3538
TCanvas
The Canvas class.
Definition: TCanvas.h:23
RooNumIntConfig::setEpsAbs
void setEpsAbs(Double_t newEpsAbs)
Set absolute convergence criteria (convergence if abs(Err)<newEpsAbs)
Definition: RooNumIntConfig.cxx:238
TAxis.h
TH1
TH1 is the base class of all histogramm classes in ROOT.
Definition: TH1.h:58
kBlue
@ kBlue
Definition: Rtypes.h:66
gPad
#define gPad
Definition: TVirtualPad.h:287
RooAbsPdf::generateBinned
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()) const
As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,...
Definition: RooAbsPdf.h:107
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsPdf
Definition: RooAbsPdf.h:43
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
RooProdPdf
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:37
TH1.h
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3050
RooFit::RooConst
RooConstVar & RooConst(Double_t val)
Definition: RooGlobalFunc.cxx:347
RooAbsPdf::fitTo
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:1264