Logo ROOT   6.14/05
Reference Guide
rf304_uncorrprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'MULTIDIMENSIONAL MODELS' RooFit tutorial macro #304
5 ///
6 /// Simple uncorrelated multi-dimensional p.d.f.s
7 ///
8 /// pdf = gauss(x,mx,sx) * gauss(y,my,sy)
9 ///
10 /// \macro_image
11 /// \macro_output
12 /// \macro_code
13 /// \author 07/2008 - Wouter Verkerke
14 
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "RooProdPdf.h"
19 #include "TCanvas.h"
20 #include "TAxis.h"
21 #include "RooPlot.h"
22 using namespace RooFit ;
23 
24 
25 
26 void rf304_uncorrprod()
27 {
28 
29  // 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
30  // ----------------------------------------------------------------
31 
32  // Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables
33  RooRealVar x("x","x",-5,5) ;
34  RooRealVar y("y","y",-5,5) ;
35 
36  RooRealVar meanx("mean1","mean of gaussian x",2) ;
37  RooRealVar meany("mean2","mean of gaussian y",-2) ;
38  RooRealVar sigmax("sigmax","width of gaussian x",1) ;
39  RooRealVar sigmay("sigmay","width of gaussian y",5) ;
40 
41  RooGaussian gaussx("gaussx","gaussian PDF",x,meanx,sigmax) ;
42  RooGaussian gaussy("gaussy","gaussian PDF",y,meany,sigmay) ;
43 
44 
45 
46  // 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
47  // -------------------------------------------------------------------
48 
49  // Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
50  RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgList(gaussx,gaussy)) ;
51 
52 
53 
54  // 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
55  // ---------------------------------------------------------------------------
56 
57  // Generate 10000 events in x and y from gaussxy
58  RooDataSet *data = gaussxy.generate(RooArgSet(x,y),10000) ;
59 
60  // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)
61  RooPlot* xframe = x.frame(Title("X projection of gauss(x)*gauss(y)")) ;
62  data->plotOn(xframe) ;
63  gaussxy.plotOn(xframe) ;
64 
65  // Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y)
66  RooPlot* yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)")) ;
67  data->plotOn(yframe) ;
68  gaussxy.plotOn(yframe) ;
69 
70 
71 
72  // Make canvas and draw RooPlots
73  TCanvas *c = new TCanvas("rf304_uncorrprod","rf304_uncorrprod",800, 400);
74  c->Divide(2);
75  c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.4) ; xframe->Draw() ;
76  c->cd(2) ; gPad->SetLeftMargin(0.15) ; yframe->GetYaxis()->SetTitleOffset(1.4) ; yframe->Draw() ;
77 
78 }
79 
80 
81 
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
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 Title(const char *name)
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
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
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 void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558