Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf304_uncorrprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Multidimensional models: simple uncorrelated multi-dimensional p.d.f.s
5 ///
6 /// pdf = gauss(x,mx,sx) * gauss(y,my,sy)
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 #include "RooRealVar.h"
14 #include "RooDataSet.h"
15 #include "RooGaussian.h"
16 #include "RooProdPdf.h"
17 #include "TCanvas.h"
18 #include "TAxis.h"
19 #include "RooPlot.h"
20 using namespace RooFit;
21 
22 void rf304_uncorrprod()
23 {
24 
25  // 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
26  // ----------------------------------------------------------------
27 
28  // Create two p.d.f.s gaussx(x,meanx,sigmax) gaussy(y,meany,sigmay) and its variables
29  RooRealVar x("x", "x", -5, 5);
30  RooRealVar y("y", "y", -5, 5);
31 
32  RooRealVar meanx("mean1", "mean of gaussian x", 2);
33  RooRealVar meany("mean2", "mean of gaussian y", -2);
34  RooRealVar sigmax("sigmax", "width of gaussian x", 1);
35  RooRealVar sigmay("sigmay", "width of gaussian y", 5);
36 
37  RooGaussian gaussx("gaussx", "gaussian PDF", x, meanx, sigmax);
38  RooGaussian gaussy("gaussy", "gaussian PDF", y, meany, sigmay);
39 
40  // 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
41  // -------------------------------------------------------------------
42 
43  // Multiply gaussx and gaussy into a two-dimensional p.d.f. gaussxy
44  RooProdPdf gaussxy("gaussxy", "gaussx*gaussy", RooArgList(gaussx, gaussy));
45 
46  // 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
47  // ---------------------------------------------------------------------------
48 
49  // Generate 10000 events in x and y from gaussxy
50  RooDataSet *data = gaussxy.generate(RooArgSet(x, y), 10000);
51 
52  // Plot x distribution of data and projection of gaussxy on x = Int(dy) gaussxy(x,y)
53  RooPlot *xframe = x.frame(Title("X projection of gauss(x)*gauss(y)"));
54  data->plotOn(xframe);
55  gaussxy.plotOn(xframe);
56 
57  // Plot x distribution of data and projection of gaussxy on y = Int(dx) gaussxy(x,y)
58  RooPlot *yframe = y.frame(Title("Y projection of gauss(x)*gauss(y)"));
59  data->plotOn(yframe);
60  gaussxy.plotOn(yframe);
61 
62  // Make canvas and draw RooPlots
63  TCanvas *c = new TCanvas("rf304_uncorrprod", "rf304_uncorrprod", 800, 400);
64  c->Divide(2);
65  c->cd(1);
66  gPad->SetLeftMargin(0.15);
67  xframe->GetYaxis()->SetTitleOffset(1.4);
68  xframe->Draw();
69  c->cd(2);
70  gPad->SetLeftMargin(0.15);
71  yframe->GetYaxis()->SetTitleOffset(1.4);
72  yframe->Draw();
73 }