Logo ROOT  
Reference Guide
rf305_condcorrprod.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4///
5/// Multidimensional models: multi-dimensional p.d.f.s with conditional p.d.fs in product
6///
7/// `pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx)` with `f(y) = a0 + a1*y`
8///
9/// \macro_image
10/// \macro_output
11/// \macro_code
12///
13/// \date 07/2008
14/// \author Wouter Verkerke
15
16#include "RooRealVar.h"
17#include "RooDataSet.h"
18#include "RooGaussian.h"
19#include "RooConstVar.h"
20#include "RooPolyVar.h"
21#include "RooProdPdf.h"
22#include "RooPlot.h"
23#include "TCanvas.h"
24#include "TAxis.h"
25#include "TH1.h"
26using namespace RooFit;
27
29{
30 // C r e a t e c o n d i t i o n a l p d f g x ( x | y )
31 // -----------------------------------------------------------
32
33 // Create observables
34 RooRealVar x("x", "x", -5, 5);
35 RooRealVar y("y", "y", -5, 5);
36
37 // Create function f(y) = a0 + a1*y
38 RooRealVar a0("a0", "a0", -0.5, -5, 5);
39 RooRealVar a1("a1", "a1", -0.5, -1, 1);
40 RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
41
42 // Create gaussx(x,f(y),sx)
43 RooRealVar sigmax("sigma", "width of gaussian", 0.5);
44 RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax);
45
46 // C r e a t e p d f g y ( y )
47 // -----------------------------------------------------------
48
49 // Create gaussy(y,0,5)
50 RooGaussian gaussy("gaussy", "Gaussian in y", y, RooConst(0), RooConst(3));
51
52 // C r e a t e p r o d u c t g x ( x | y ) * g y ( y )
53 // -------------------------------------------------------
54
55 // Create gaussx(x,sx|y) * gaussy(y)
56 RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x));
57
58 // S a m p l e , f i t a n d p l o t p r o d u c t p d f
59 // ---------------------------------------------------------------
60
61 // Generate 1000 events in x and y from model
62 RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
63
64 // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
65 RooPlot *xframe = x.frame();
66 data->plotOn(xframe);
67 model.plotOn(xframe);
68
69 // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
70 RooPlot *yframe = y.frame();
71 data->plotOn(yframe);
72 model.plotOn(yframe);
73
74 // Make two-dimensional plot in x vs y
75 TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
76 hh_model->SetLineColor(kBlue);
77
78 // Make canvas and draw RooPlots
79 TCanvas *c = new TCanvas("rf305_condcorrprod", "rf05_condcorrprod", 1200, 400);
80 c->Divide(3);
81 c->cd(1);
82 gPad->SetLeftMargin(0.15);
83 xframe->GetYaxis()->SetTitleOffset(1.6);
84 xframe->Draw();
85 c->cd(2);
86 gPad->SetLeftMargin(0.15);
87 yframe->GetYaxis()->SetTitleOffset(1.6);
88 yframe->Draw();
89 c->cd(3);
90 gPad->SetLeftMargin(0.20);
91 hh_model->GetZaxis()->SetTitleOffset(2.5);
92 hh_model->Draw("surf");
93}
#define c(i)
Definition: RSha256.hxx:101
@ kBlue
Definition: Rtypes.h:64
#define gPad
Definition: TVirtualPad.h:287
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:546
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1277
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:712
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 variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:27
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:2998
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooConstVar & RooConst(Double_t val)
RooCmdArg Conditional(const RooArgSet &pdfSet, const RooArgSet &depSet, Bool_t depsAreCond=kFALSE)
RooCmdArg Binning(const RooAbsBinning &binning)
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...