Logo ROOT   6.18/05
Reference Guide
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"
21using namespace RooFit;
22
23void 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}
#define c(i)
Definition: RSha256.hxx:101
#define gPad
Definition: TVirtualPad.h:286
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:552
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:41
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1123
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558
RooPolynomial implements a polynomial p.d.f of the form.
Definition: RooPolynomial.h:28
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:31
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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
The Canvas class.
Definition: TCanvas.h:31
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Template specialisation used in RooAbsArg:
RooCmdArg ProjectionRange(const char *rangeName)
RooConstVar & RooConst(Double_t val)
RooCmdArg CutRange(const char *rangeName)
RooCmdArg Bins(Int_t nbin)
const char * Title
Definition: TXMLSetup.cxx:67