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