Logo ROOT   6.14/05
Reference Guide
rf315_projectpdf.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_;;;;
3 /// \notebook
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #315
5 ///
6 /// Marginizalization of multi-dimensional p.d.f.s through integration
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #include "RooRealVar.h"
15 #include "RooDataHist.h"
16 #include "RooGaussian.h"
17 #include "RooProdPdf.h"
18 #include "RooPolyVar.h"
19 #include "TH1.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "RooPlot.h"
23 #include "RooNumIntConfig.h"
24 #include "RooConstVar.h"
25 using namespace RooFit ;
26 
27 
28 void rf315_projectpdf()
29 {
30  // C r e a t e p d f m ( x , y ) = g x ( x | y ) * g ( y )
31  // --------------------------------------------------------------
32 
33  // Increase default precision of numeric integration
34  // as this exercise has high sensitivity to numeric integration precision
37 
38  // Create observables
39  RooRealVar x("x","x",-5,5) ;
40  RooRealVar y("y","y",-2,2) ;
41 
42  // Create function f(y) = a0 + a1*y
43  RooRealVar a0("a0","a0",0) ;
44  RooRealVar a1("a1","a1",-1.5,-3,1) ;
45  RooPolyVar fy("fy","fy",y,RooArgSet(a0,a1)) ;
46 
47  // Create gaussx(x,f(y),sx)
48  RooRealVar sigmax("sigmax","width of gaussian",0.5) ;
49  RooGaussian gaussx("gaussx","Gaussian in x with shifting mean in y",x,fy,sigmax) ;
50 
51  // Create gaussy(y,0,2)
52  RooGaussian gaussy("gaussy","Gaussian in y",y,RooConst(0),RooConst(2)) ;
53 
54  // Create gaussx(x,sx|y) * gaussy(y)
55  RooProdPdf model("model","gaussx(x|y)*gaussy(y)",gaussy,Conditional(gaussx,x)) ;
56 
57 
58 
59  // M a r g i n a l i z e m ( x , y ) t o m ( x )
60  // ----------------------------------------------------
61 
62  // modelx(x) = Int model(x,y) dy
63  RooAbsPdf* modelx = model.createProjection(y) ;
64 
65 
66 
67  // 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 .
68  // ------------------------------------------------------------------------------------------
69 
70  // Sample 1000 events from modelx
71  RooAbsData* data = modelx->generateBinned(x,1000) ;
72 
73  // Fit modelx to toy data
74  modelx->fitTo(*data,Verbose()) ;
75 
76  // Plot modelx over data
77  RooPlot* frame = x.frame(40) ;
78  data->plotOn(frame) ;
79  modelx->plotOn(frame) ;
80 
81  // Make 2D histogram of model(x,y)
82  TH1* hh = model.createHistogram("x,y") ;
83  hh->SetLineColor(kBlue) ;
84 
85 
86  TCanvas* c = new TCanvas("rf315_projectpdf","rf315_projectpdf",800,400) ;
87  c->Divide(2) ;
88  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
89  c->cd(2) ; gPad->SetLeftMargin(0.20) ; hh->GetZaxis()->SetTitleOffset(2.5) ; hh->Draw("surf") ;
90 
91 }
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
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1117
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:568
static RooNumIntConfig * defaultIntegratorConfig()
Returns the default numeric integration configuration for all RooAbsReals.
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())
Generate a new dataset containing the specified variables with events sampled from our distribution...
Definition: RooAbsPdf.cxx:2198
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
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
Plot (project) PDF on specified frame.
Definition: RooAbsPdf.h:105
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
Class RooPolyVar is a RooAbsReal implementing a polynomial in terms of a list of RooAbsReal coefficie...
Definition: RooPolyVar.h:28
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2974
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
The Canvas class.
Definition: TCanvas.h:31
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:56
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
RooCmdArg Verbose(Bool_t flag=kTRUE)
TAxis * GetZaxis()
Definition: TH1.h:317
RooConstVar & RooConst(Double_t val)
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
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:1079
Definition: Rtypes.h:59
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)
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558