 ROOT   Reference Guide rf316_llratioplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Multidimensional models: using the likelihood ratio technique to construct a signal
5 /// enhanced one-dimensional projection of a multi-dimensional pdf
6 ///
7 /// \macro_image
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date July 2008
12 /// \author Wouter Verkerke
13
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooPolynomial.h"
20 #include "RooProdPdf.h"
21 #include "TCanvas.h"
22 #include "TAxis.h"
23 #include "RooPlot.h"
24 using namespace RooFit;
25
26 void rf316_llratioplot()
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  // D e f i n e p r o j e c t e d s i g n a l l i k e l i h o o d r a t i o
64  // ----------------------------------------------------------------------------------
65
66  // Calculate projection of signal and total likelihood on (y,z) observables
67  // i.e. integrate signal and composite model over x
68  RooAbsPdf *sigyz = sig.createProjection(x);
69  RooAbsPdf *totyz = model.createProjection(x);
70
71  // Construct the log of the signal / signal+background probability
72  RooFormulaVar llratio_func("llratio", "log10(@0)-log10(@1)", RooArgList(*sigyz, *totyz));
73
74  // P l o t d a t a w i t h a L L r a t i o c u t
75  // -------------------------------------------------------
76
77  // Calculate the llratio value for each event in the dataset
79
80  // Extract the subset of data with large signal likelihood
81  RooDataSet *dataSel = (RooDataSet *)data->reduce(Cut("llratio>0.7"));
82
83  // Make plot frame
84  RooPlot *frame2 = x.frame(Title("Same projection on X with LLratio(y,z)>0.7"), Bins(40));
85
86  // Plot select data on frame
87  dataSel->plotOn(frame2);
88
89  // M a k e M C p r o j e c t i o n o f p d f w i t h s a m e L L r a t i o c u t
90  // ---------------------------------------------------------------------------------------------
91
92  // Generate large number of events for MC integration of pdf projection
93  RooDataSet *mcprojData = model.generate(RooArgSet(x, y, z), 10000);
94
95  // Calculate LL ratio for each generated event and select MC events with llratio)0.7
97  RooDataSet *mcprojDataSel = (RooDataSet *)mcprojData->reduce(Cut("llratio>0.7"));
98
99  // Project model on x, integrating projected observables (y,z) with Monte Carlo technique
100  // on set of events with the same llratio cut as was applied to data
101  model.plotOn(frame2, ProjWData(*mcprojDataSel));
102
103  TCanvas *c = new TCanvas("rf316_llratioplot", "rf316_llratioplot", 800, 400);
104  c->Divide(2);
105  c->cd(1);
107  frame->GetYaxis()->SetTitleOffset(1.4);
108  frame->Draw();
109  c->cd(2);
111  frame2->GetYaxis()->SetTitleOffset(1.4);
112  frame2->Draw();
113 }
c
#define c(i)
Definition: RSha256.hxx:101
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooFit::ProjWData
RooCmdArg ProjWData(const RooAbsData &projData, Bool_t binData=kFALSE)
Definition: RooGlobalFunc.cxx:47
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition: RooGlobalFunc.cxx:177
RooArgList
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
RooGaussian.h
x
Double_t x[n]
Definition: legend1.C:17
RooGaussian
Plain Gaussian p.d.f.
Definition: RooGaussian.h:24
TCanvas.h
RooDataSet.h
RooPolynomial.h
RooFit::Cut
RooCmdArg Cut(const char *cutSpec)
Definition: RooGlobalFunc.cxx:81
RooFormulaVar
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:30
RooProdPdf.h
RooFit
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition: RooCFunction1Binding.h:29
RooPolynomial
RooPolynomial implements a polynomial p.d.f of the form.
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:1258
RooPlot
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
y
Double_t y[n]
Definition: legend1.C:17
RooRealVar.h
RooConstVar.h
RooAbsPdf::createProjection
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Definition: RooAbsPdf.cxx:3417
TCanvas
The Canvas class.
Definition: TCanvas.h:23
RooAbsData::reduce
RooAbsData * reduce(const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg())
Create a reduced copy of this dataset.
Definition: RooAbsData.cxx:382
TAxis.h
RooDataSet
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
make_cnn_model.model
model
Definition: make_cnn_model.py:6
RooAbsPdf
Definition: RooAbsPdf.h:43
rf316_llratioplot
Definition: rf316_llratioplot.py:1
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:37
RooProdPdf
RooProdPdf is an efficient implementation of a product of PDFs of the form.
Definition: RooProdPdf.h:37
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:176
RooArgSet
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:29