Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf311_rangeplot.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Multidimensional models: projecting pdf and data ranges in continuous observables
5///
6/// \macro_image
7/// \macro_code
8/// \macro_output
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooConstVar.h"
17#include "RooProdPdf.h"
18#include "RooAddPdf.h"
19#include "RooPolynomial.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "RooPlot.h"
23using namespace RooFit;
24
25void rf311_rangeplot()
26{
27
28 // C r e a t e 3 D p d f a n d d a t a
29 // -------------------------------------------
30
31 // Create observables
32 RooRealVar x("x", "x", -5, 5);
33 RooRealVar y("y", "y", -5, 5);
34 RooRealVar z("z", "z", -5, 5);
35
36 // Create signal pdf gauss(x)*gauss(y)*gauss(z)
37 RooGaussian gx("gx", "gx", x, 0.0, 1.0);
38 RooGaussian gy("gy", "gy", y, 0.0, 1.0);
39 RooGaussian gz("gz", "gz", z, 0.0, 1.0);
40 RooProdPdf sig("sig", "sig", RooArgSet(gx, gy, gz));
41
42 // Create background pdf poly(x)*poly(y)*poly(z)
43 RooPolynomial px("px", "px", x, RooArgSet(-0.1, 0.004));
44 RooPolynomial py("py", "py", y, RooArgSet(0.1, -0.004));
45 RooPolynomial pz("pz", "pz", z);
46 RooProdPdf bkg("bkg", "bkg", RooArgSet(px, py, pz));
47
48 // Create composite pdf sig+bkg
49 RooRealVar fsig("fsig", "signal fraction", 0.1, 0., 1.);
50 RooAddPdf model("model", "model", RooArgList(sig, bkg), fsig);
51
52 std::unique_ptr<RooDataSet> data{model.generate({x, y, z}, 20000)};
53
54 // P r o j e c t p d f a n d d a t a o n x
55 // -------------------------------------------------
56
57 // Make plain projection of data and pdf on x observable
58 RooPlot *frame = x.frame(Title("Projection of 3D data and pdf on X"), Bins(40));
59 data->plotOn(frame);
60 model.plotOn(frame);
61
62 // 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
63 // ----------------------------------------------------------------------------------
64
65 // Define signal region in y and z observables
66 y.setRange("sigRegion", -1, 1);
67 z.setRange("sigRegion", -1, 1);
68
69 // Make plot frame
70 RooPlot *frame2 = x.frame(Title("Same projection on X in signal range of (Y,Z)"), Bins(40));
71
72 // Plot subset of data in which all observables are inside "sigRegion"
73 // For observables that do not have an explicit "sigRegion" range defined (e.g. observable)
74 // an implicit definition is used that is identical to the full range (i.e. [-5,5] for x)
75 data->plotOn(frame2, CutRange("sigRegion"));
76
77 // Project model on x, integrating projected observables (y,z) only in "sigRegion"
78 model.plotOn(frame2, ProjectionRange("sigRegion"));
79
80 TCanvas *c = new TCanvas("rf311_rangeplot", "rf310_rangeplot", 800, 400);
81 c->Divide(2);
82 c->cd(1);
83 gPad->SetLeftMargin(0.15);
84 frame->GetYaxis()->SetTitleOffset(1.4);
85 frame->Draw();
86 c->cd(2);
87 gPad->SetLeftMargin(0.15);
88 frame2->GetYaxis()->SetTitleOffset(1.4);
89 frame2->Draw();
90}
#define c(i)
Definition RSha256.hxx:101
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
Efficient implementation of a sum of PDFs of the form.
Definition RooAddPdf.h:33
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition RooArgList.h:22
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:45
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:225
TAxis * GetYaxis() const
Definition RooPlot.cxx:1264
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:637
RooPolynomial implements a polynomial p.d.f of the form.
Efficient implementation of a product of PDFs of the form.
Definition RooProdPdf.h:33
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
RooCmdArg Bins(Int_t nbin)
RooCmdArg ProjectionRange(const char *rangeName)
RooCmdArg CutRange(const char *rangeName)
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
const char * Title
Definition TXMLSetup.cxx:68