Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf311_rangeplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Multidimensional models: projecting p.d.f and data ranges in continuous observables
5 ///
6 /// \macro_image
7 /// \macro_output
8 /// \macro_code
9 /// \author 07/2008 - Wouter Verkerke
10 
11 #include "RooRealVar.h"
12 #include "RooDataSet.h"
13 #include "RooGaussian.h"
14 #include "RooConstVar.h"
15 #include "RooProdPdf.h"
16 #include "RooAddPdf.h"
17 #include "RooPolynomial.h"
18 #include "TCanvas.h"
19 #include "TAxis.h"
20 #include "RooPlot.h"
21 using namespace RooFit;
22 
23 void rf311_rangeplot()
24 {
25 
26  // C r e a t e 3 D p d f a n d d a t a
27  // -------------------------------------------
28 
29  // Create observables
30  RooRealVar x("x", "x", -5, 5);
31  RooRealVar y("y", "y", -5, 5);
32  RooRealVar z("z", "z", -5, 5);
33 
34  // Create signal pdf gauss(x)*gauss(y)*gauss(z)
35  RooGaussian gx("gx", "gx", x, RooConst(0), RooConst(1));
36  RooGaussian gy("gy", "gy", y, RooConst(0), RooConst(1));
37  RooGaussian gz("gz", "gz", z, RooConst(0), RooConst(1));
38  RooProdPdf sig("sig", "sig", RooArgSet(gx, gy, gz));
39 
40  // Create background pdf poly(x)*poly(y)*poly(z)
41  RooPolynomial px("px", "px", x, RooArgSet(RooConst(-0.1), RooConst(0.004)));
42  RooPolynomial py("py", "py", y, RooArgSet(RooConst(0.1), RooConst(-0.004)));
43  RooPolynomial pz("pz", "pz", z);
44  RooProdPdf bkg("bkg", "bkg", RooArgSet(px, py, pz));
45 
46  // Create composite pdf sig+bkg
47  RooRealVar fsig("fsig", "signal fraction", 0.1, 0., 1.);
48  RooAddPdf model("model", "model", RooArgList(sig, bkg), fsig);
49 
50  RooDataSet *data = model.generate(RooArgSet(x, y, z), 20000);
51 
52  // P r o j e c t p d f a n d d a t a o n x
53  // -------------------------------------------------
54 
55  // Make plain projection of data and pdf on x observable
56  RooPlot *frame = x.frame(Title("Projection of 3D data and pdf on X"), Bins(40));
57  data->plotOn(frame);
58  model.plotOn(frame);
59 
60  // P r o j e c t p d f a n d d a t a o n x i n s i g n a l r a n g e
61  // ----------------------------------------------------------------------------------
62 
63  // Define signal region in y and z observables
64  y.setRange("sigRegion", -1, 1);
65  z.setRange("sigRegion", -1, 1);
66 
67  // Make plot frame
68  RooPlot *frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"), Bins(40));
69 
70  // Plot subset of data in which all observables are inside "sigRegion"
71  // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
72  // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
73  data->plotOn(frame2, CutRange("sigRegion"));
74 
75  // Project model on x, integrating projected observables (y,z) only in "sigRegion"
76  model.plotOn(frame2, ProjectionRange("sigRegion"));
77 
78  TCanvas *c = new TCanvas("rf311_rangeplot", "rf310_rangeplot", 800, 400);
79  c->Divide(2);
80  c->cd(1);
81  gPad->SetLeftMargin(0.15);
82  frame->GetYaxis()->SetTitleOffset(1.4);
83  frame->Draw();
84  c->cd(2);
85  gPad->SetLeftMargin(0.15);
86  frame2->GetYaxis()->SetTitleOffset(1.4);
87  frame2->Draw();
88 }