Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf301_composition.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 through composition
5 /// e.g. substituting a p.d.f parameter with a function that depends on other observables
6 ///
7 /// pdf = gauss(x,f(y),s) with f(y) = a0 + a1*y
8 ///
9 /// \macro_image
10 /// \macro_output
11 /// \macro_code
12 /// \author 07/2008 - Wouter Verkerke
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooPolyVar.h"
18 #include "RooPlot.h"
19 #include "TCanvas.h"
20 #include "TAxis.h"
21 #include "TH1.h"
22 using namespace RooFit;
23 
24 void rf301_composition()
25 {
26  // S e t u p c o m p o s e d m o d e l g a u s s ( x , m ( y ) , s )
27  // -----------------------------------------------------------------------
28 
29  // Create observables
30  RooRealVar x("x", "x", -5, 5);
31  RooRealVar y("y", "y", -5, 5);
32 
33  // Create function f(y) = a0 + a1*y
34  RooRealVar a0("a0", "a0", -0.5, -5, 5);
35  RooRealVar a1("a1", "a1", -0.5, -1, 1);
36  RooPolyVar fy("fy", "fy", y, RooArgSet(a0, a1));
37 
38  // Create gauss(x,f(y),s)
39  RooRealVar sigma("sigma", "width of gaussian", 0.5);
40  RooGaussian model("model", "Gaussian with shifting mean", x, fy, sigma);
41 
42  // S a m p l e d a t a , p l o t d a t a a n d p d f o n x a n d y
43  // ---------------------------------------------------------------------------------
44 
45  // Generate 10000 events in x and y from model
46  RooDataSet *data = model.generate(RooArgSet(x, y), 10000);
47 
48  // Plot x distribution of data and projection of model on x = Int(dy) model(x,y)
49  RooPlot *xframe = x.frame();
50  data->plotOn(xframe);
51  model.plotOn(xframe);
52 
53  // Plot x distribution of data and projection of model on y = Int(dx) model(x,y)
54  RooPlot *yframe = y.frame();
55  data->plotOn(yframe);
56  model.plotOn(yframe);
57 
58  // Make two-dimensional plot in x vs y
59  TH1 *hh_model = model.createHistogram("hh_model", x, Binning(50), YVar(y, Binning(50)));
60  hh_model->SetLineColor(kBlue);
61 
62  // Make canvas and draw RooPlots
63  TCanvas *c = new TCanvas("rf301_composition", "rf301_composition", 1200, 400);
64  c->Divide(3);
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  c->cd(3);
74  gPad->SetLeftMargin(0.20);
75  hh_model->GetZaxis()->SetTitleOffset(2.5);
76  hh_model->Draw("surf");
77 }