rf605_profilell¶

Likelihood and minimization: working with the profile likelihood estimator

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, November 30, 2022 at 11:23 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooMinimizer.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;


Create model and dataset¶

Observable

In [2]:
RooRealVar x("x", "x", -20, 20);


Model (intentional strong correlations)

In [3]:
RooRealVar mean("mean", "mean of g1 and g2", 0, -10, 10);
RooRealVar sigma_g1("sigma_g1", "width of g1", 3);
RooGaussian g1("g1", "g1", x, mean, sigma_g1);

RooRealVar sigma_g2("sigma_g2", "width of g2", 4, 3.0, 6.0);
RooGaussian g2("g2", "g2", x, mean, sigma_g2);

RooRealVar frac("frac", "frac", 0.5, 0.0, 1.0);
RooAddPdf model("model", "model", RooArgList(g1, g2), frac);

[#0] WARNING:InputArguments -- The parameter 'sigma_g1' with range [-1e+30, 1e+30] of the RooGaussian 'g1' exceeds the safe range of (0, inf). Advise to limit its range.


Generate 1000 events

In [4]:
RooDataSet *data = model.generate(x, 1000);

input_line_52:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration
RooDataSet *data = model.generate(x, 1000);
^


Construct plain likelihood¶

Construct unbinned likelihood

In [5]:
RooAbsReal *nll = model.createNLL(*data, NumCPU(2));

input_line_53:2:37: error: reference to 'data' is ambiguous
RooAbsReal *nll = model.createNLL(*data, NumCPU(2));
^
input_line_52:2:14: note: candidate found by name lookup is '__cling_N523::data'
RooDataSet *data = model.generate(x, 1000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


Minimize likelihood w.r.t all parameters before making plots

In [6]:
RooMinimizer(*nll).migrad();

input_line_55:2:18: error: use of undeclared identifier 'nll'
^
Error in <HandleInterpreterException>: Error evaluating expression (RooMinimizer(* nll).migrad())
Execution of your code was aborted.


Plot likelihood scan frac

In [7]:
RooPlot *frame1 = frac.frame(Bins(10), Range(0.01, 0.95), Title("LL and profileLL in frac"));
nll->plotOn(frame1, ShiftToZero());

input_line_56:3:21: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)()'
nll->plotOn(frame1, ShiftToZero());
^~~~~~~~~~~


Plot likelihood scan in sigma_g2

In [8]:
RooPlot *frame2 = sigma_g2.frame(Bins(10), Range(3.3, 5.0), Title("LL and profileLL in sigma_g2"));
nll->plotOn(frame2, ShiftToZero());

input_line_57:3:21: error: cannot initialize an array element of type 'void *' with an rvalue of type 'RooCmdArg (*)()'
nll->plotOn(frame2, ShiftToZero());
^~~~~~~~~~~


Construct profile likelihood in frac¶

The profile likelihood estimator on nll for frac will minimize nll w.r.t all floating parameters except frac for each evaluation

In [9]:
RooAbsReal *pll_frac = nll->createProfile(frac);

input_line_59:2:3: error: use of undeclared identifier 'nll'
(nll->createProfile(((*(class RooRealVar*)0x7fb3ec08e668))))
^
Error in <HandleInterpreterException>: Error evaluating expression (nll->createProfile(((*(class RooRealVar*)0x7fb3ec08e668))))
Execution of your code was aborted.


Plot the profile likelihood in frac

In [10]:
pll_frac->plotOn(frame1, LineColor(kRed));

input_line_60:2:37: error: cannot take the address of an rvalue of type 'EColor'
pll_frac->plotOn(frame1, LineColor(kRed));
^~~~
Error while creating dynamic expression for:
pll_frac->plotOn(frame1, LineColor(kRed))


Adjust frame maximum for visual clarity

In [11]:
frame1->SetMinimum(0);
frame1->SetMaximum(3);

input_line_62:2:3: error: use of undeclared identifier 'frame1'
(frame1->SetMinimum(0))
^
Error in <HandleInterpreterException>: Error evaluating expression (frame1->SetMinimum(0))
Execution of your code was aborted.


Construct profile likelihood in sigma_g2¶

The profile likelihood estimator on nll for sigma_g2 will minimize nll w.r.t all floating parameters except sigma_g2 for each evaluation

In [12]:
RooAbsReal *pll_sigmag2 = nll->createProfile(sigma_g2);

input_line_64:2:3: error: use of undeclared identifier 'nll'
(nll->createProfile(((*(class RooRealVar*)0x7fb3ec08dd28))))
^
Error in <HandleInterpreterException>: Error evaluating expression (nll->createProfile(((*(class RooRealVar*)0x7fb3ec08dd28))))
Execution of your code was aborted.


Plot the profile likelihood in sigma_g2

In [13]:
pll_sigmag2->plotOn(frame2, LineColor(kRed));

input_line_65:2:40: error: cannot take the address of an rvalue of type 'EColor'
pll_sigmag2->plotOn(frame2, LineColor(kRed));
^~~~
Error while creating dynamic expression for:
pll_sigmag2->plotOn(frame2, LineColor(kRed))


Adjust frame maximum for visual clarity

In [14]:
frame2->SetMinimum(0);
frame2->SetMaximum(3);

input_line_67:2:3: error: use of undeclared identifier 'frame2'
(frame2->SetMinimum(0))
^
Error in <HandleInterpreterException>: Error evaluating expression (frame2->SetMinimum(0))
Execution of your code was aborted.


Make canvas and draw RooPlots

In [15]:
TCanvas *c = new TCanvas("rf605_profilell", "rf605_profilell", 800, 400);
c->Divide(2);
c->cd(1);
frame1->GetYaxis()->SetTitleOffset(1.4);
frame1->Draw();
c->cd(2);
frame2->GetYaxis()->SetTitleOffset(1.4);
frame2->Draw();

delete pll_frac;
delete pll_sigmag2;
delete nll;

input_line_69:2:3: error: use of undeclared identifier 'frame1'
(frame1->GetYaxis()->SetTitleOffset(1.3999999999999999))
^
Error in <HandleInterpreterException>: Error evaluating expression (frame1->GetYaxis()->SetTitleOffset(1.3999999999999999))
Execution of your code was aborted.


Draw all canvases

In [16]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()