Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf305_condcorrprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook
4 /// Multidimensional models: multi-dimensional p.d.f.s with conditional p.d.fs in product
5 ///
6 /// pdf = gauss(x,f(y),sx | y ) * gauss(y,ms,sx) with f(y) = a0 + a1*y
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 "RooConstVar.h"
17 #include "RooPolyVar.h"
18 #include "RooProdPdf.h"
19 #include "RooPlot.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "TH1.h"
23 using namespace RooFit;
24 
25 void rf305_condcorrprod()
26 {
27  // C r e a t e c o n d i t i o n a l p d f g x ( x | y )
28  // -----------------------------------------------------------
29 
30  // Create observables
31  RooRealVar x("x", "x", -5, 5);
32  RooRealVar y("y", "y", -5, 5);
33 
34  // Create function f(y) = a0 + a1*y
35  RooRealVar a0("a0", "a0", -0.5, -5, 5);
36  RooRealVar a1("a1", "a1", -0.5, -1, 1);
37  RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
38 
39  // Create gaussx(x,f(y),sx)
40  RooRealVar sigmax("sigma", "width of gaussian", 0.5);
41  RooGaussian gaussx("gaussx", "Gaussian in x with shifting mean in y", x, fy, sigmax);
42 
43  // C r e a t e p d f g y ( y )
44  // -----------------------------------------------------------
45 
46  // Create gaussy(y,0,5)
47  RooGaussian gaussy("gaussy", "Gaussian in y", y, RooConst(0), RooConst(3));
48 
49  // C r e a t e p r o d u c t g x ( x | y ) * g y ( y )
50  // -------------------------------------------------------
51 
52  // Create gaussx(x,sx|y) * gaussy(y)
53  RooProdPdf model("model", "gaussx(x|y)*gaussy(y)", gaussy, Conditional(gaussx, x));
54 
55  // 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
56  // ---------------------------------------------------------------
57 
58  // Generate 1000 events in x and y from model
59  RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
60 
61  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
62  RooPlot *xframe = x.frame();
63  data->plotOn(xframe);
64  model.plotOn(xframe);
65 
66  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
67  RooPlot *yframe = y.frame();
68  data->plotOn(yframe);
69  model.plotOn(yframe);
70 
71  // Make two-dimensional plot in x vs y
72  TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
73  hh_model->SetLineColor(kBlue);
74 
75  // Make canvas and draw RooPlots
76  TCanvas *c = new TCanvas("rf305_condcorrprod", "rf05_condcorrprod", 1200, 400);
77  c->Divide(3);
78  c->cd(1);
79  gPad->SetLeftMargin(0.15);
80  xframe->GetYaxis()->SetTitleOffset(1.6);
81  xframe->Draw();
82  c->cd(2);
83  gPad->SetLeftMargin(0.15);
84  yframe->GetYaxis()->SetTitleOffset(1.6);
85  yframe->Draw();
86  c->cd(3);
87  gPad->SetLeftMargin(0.20);
88  hh_model->GetZaxis()->SetTitleOffset(2.5);
89  hh_model->Draw("surf");
90 }