Logo ROOT  
Reference Guide
rf304_uncorrprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 ///
5 /// Multidimensional models: simple uncorrelated multi-dimensional p.d.f.s
6 ///
7 /// `pdf = gauss(x,mx,sx) * gauss(y,my,sy)`
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 "RooProdPdf.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "RooPlot.h"
23 using namespace RooFit;
24 
25 void rf304_uncorrprod()
26 {
27 
28  // C r e a t e c o m p o n e n t p d f s i n x a n d y
29  // ----------------------------------------------------------------
30 
31  // Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables
32  RooRealVar x("x", "x", -5, 5);
33  RooRealVar y("y", "y", -5, 5);
34 
35  RooRealVar meanx("mean1", "mean of gaussian x", 2);
36  RooRealVar meany("mean2", "mean of gaussian y", -2);
37  RooRealVar sigmax("sigmax", "width of gaussian x", 1);
38  RooRealVar sigmay("sigmay", "width of gaussian y", 5);
39 
40  RooGaussian gaussx("gaussx", "gaussian PDF", x, meanx, sigmax);
41  RooGaussian gaussy("gaussy", "gaussian PDF", y, meany, sigmay);
42 
43  // C o n s t r u c t u n c o r r e l a t e d p r o d u c t p d f
44  // -------------------------------------------------------------------
45 
46  // Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
47  RooProdPdf gaussxy("gaussxy", "gaussx*gaussy", RooArgList(gaussx, gaussy));
48 
49  // S a m p l e p d f , p l o t p r o j e c t i o n o n x a n d y
50  // ---------------------------------------------------------------------------
51 
52  // Generate 10000 events in x and y from gaussxy
53  RooDataSet *data = gaussxy.generate(RooArgSet(x, y), 10000);
54 
55  // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)
56  RooPlot *xframe = x.frame(Title("X projection of gauss(x)*gauss(y)"));
57  data->plotOn(xframe);
58  gaussxy.plotOn(xframe);
59 
60  // Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y)
61  RooPlot *yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)"));
62  data->plotOn(yframe);
63  gaussxy.plotOn(yframe);
64 
65  // Make canvas and draw RooPlots
66  TCanvas *c = new TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400);
67  c->Divide(2);
68  c->cd(1);
69  gPad->SetLeftMargin(0.15);
70  xframe->GetYaxis()->SetTitleOffset(1.4);
71  xframe->Draw();
72  c->cd(2);
73  gPad->SetLeftMargin(0.15);
74  yframe->GetYaxis()->SetTitleOffset(1.4);
75  yframe->Draw();
76 }
c
#define c(i)
Definition: RSha256.hxx:119
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooArgList
Definition: RooArgList.h:21
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Definition: RooGaussian.h:25
TCanvas.h
RooDataSet.h
rf304_uncorrprod
Definition: rf304_uncorrprod.py:1
RooProdPdf.h
RooFit
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
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
RooPlot
Definition: RooPlot.h:44
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
TCanvas
Definition: TCanvas.h:23
TAxis.h
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
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
Definition: RooRealVar.h:35
RooProdPdf
Definition: RooProdPdf.h:33
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173
RooArgSet
Definition: RooArgSet.h:28