Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf606_nllerrorhandling.C File Reference

Detailed Description

View in nbviewer Open in SWAN
Likelihood and minimization: understanding and customizing error handling in likelihood evaluations

#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooArgusBG.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
using namespace RooFit;
{
// C r e a t e m o d e l a n d d a t a s e t
// ----------------------------------------------
// Observable
RooRealVar m("m", "m", 5.20, 5.30);
// Parameters
RooRealVar m0("m0", "m0", 5.291, 5.20, 5.30);
RooRealVar k("k", "k", -30, -50, -10);
// Pdf
RooArgusBG argus("argus", "argus", m, m0, k);
// Sample 1000 events in m from argus
std::unique_ptr<RooDataSet> data{argus.generate(m, 1000)};
// P l o t m o d e l a n d d a t a
// --------------------------------------
RooPlot *frame1 = m.frame(Bins(40), Title("Argus model and data"));
data->plotOn(frame1);
argus.plotOn(frame1);
// F i t m o d e l t o d a t a
// ---------------------------------
// The ARGUS background shape has a sharp kinematic cutoff at m=m0
// and is prone to evaluation errors if the cutoff parameter m0
// is floated: when the pdf cutoff value is lower than that in data
// events with m>m0 will have zero probability
// Perform unbinned ML fit. Print detailed error messages for up to
// 10 events per likelihood evaluation. The default error handling strategy
// is to return a very high value of the likelihood to MINUIT if errors occur,
// which will force MINUIT to retreat from the problematic area
argus.fitTo(*data, PrintEvalErrors(10));
// Perform another fit. In this configuration only the number of errors per
// likelihood evaluation is shown, if it is greater than zero. The
// EvalErrorWall(false) arguments disables the default error handling strategy
// and will cause the actual (problematic) value of the likelihood to be passed
// to MINUIT.
//
// NB: Use of this option is NOT recommended as default strategy as broken -log(L) values
// can often be lower than 'good' ones because offending events are removed.
// This may effectively create a false minimum in problem areas. This is clearly
// illustrated in the second plot
m0.setError(0.1);
argus.fitTo(*data, PrintEvalErrors(0), EvalErrorWall(false));
// P l o t l i k e l i h o o d a s f u n c t i o n o f m 0
// ------------------------------------------------------------------
// Construct likelihood function of model and data
std::unique_ptr<RooAbsReal> nll{argus.createNLL(*data)};
// Plot likelihood in m0 in range that includes problematic values
// In this configuration no messages are printed for likelihood evaluation errors,
// but if an likelihood value evaluates with error, the corresponding value
// on the curve will be set to the value given in EvalErrorValue().
RooPlot *frame2 = m0.frame(Range(5.288, 5.293), Title("-log(L) scan vs m0, problematic regions masked"));
nll->plotOn(frame2, PrintEvalErrors(-1), ShiftToZero(), EvalErrorValue(nll->getVal() + 10), LineColor(kRed));
frame2->SetMaximum(15);
frame2->SetMinimum(0);
TCanvas *c = new TCanvas("rf606_nllerrorhandling", "rf606_nllerrorhandling", 1200, 400);
c->Divide(2);
c->cd(1);
gPad->SetLeftMargin(0.15);
frame1->GetYaxis()->SetTitleOffset(1.4);
frame1->Draw();
c->cd(2);
gPad->SetLeftMargin(0.15);
frame2->GetYaxis()->SetTitleOffset(1.4);
frame2->Draw();
}
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition RooArgusBG.h:22
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
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:185
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition RooPlot.cxx:1007
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
Definition RooPlot.cxx:997
TAxis * GetYaxis() const
Definition RooPlot.cxx:1224
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:597
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 PrintEvalErrors(Int_t numErrors)
RooCmdArg EvalErrorValue(double value)
RooCmdArg ShiftToZero()
RooCmdArg LineColor(Color_t color)
double nll(double pdf, double weight, int binnedL, int doBinOffset)
Definition MathFuncs.h:358
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:64
const char * Title
Definition TXMLSetup.cxx:68
Ta Range(0, 0, 1, 1)
TMarker m
Definition textangle.C:8
[#1] INFO:Fitting -- RooAbsPdf::fitTo(argus_over_argus_Int[m]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- using CPU computation library compiled with -mavx2
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_argus_over_argus_Int[m]_argusData) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
Minuit2Minimizer: Minimize with max-calls 1000 convergence for edm < 1 strategy 1
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-2417.08) to force MIGRAD to back out of this region. Error log follows.
Parameter values: k=-33.8075 m0=5.29014
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ]
getLogVal() top-level p.d.f not greater than zero @ numerator=argus=0.387202, denominator=argus_Int[m]=0.0305662
RooAbsMinimizerFcn: Minimized function has error status.
Returning maximum FCN so far (-2417.08) to force MIGRAD to back out of this region. Error log follows.
Parameter values: k=-36.7074 m0=5.2901
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ]
getLogVal() top-level p.d.f not greater than zero @ numerator=argus=0.370612, denominator=argus_Int[m]=0.0290505
Minuit2Minimizer : Valid minimum - status = 0
FVAL = -2419.30692128725559
Edm = 2.90497786168460102e-06
Nfcn = 47
k = -35.3713 +/- 3.51942 (limited)
m0 = 5.2904 +/- 0.000261877 (limited)
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Fitting -- RooAbsPdf::fitTo(argus_over_argus_Int[m]) fixing normalization set for coefficient determination to observables in data
[#1] INFO:Fitting -- RooAddition::defaultErrorLevel(nll_argus_over_argus_Int[m]_argusData) Summation contains a RooNLLVar, using its error level
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: activating const optimization
Minuit2Minimizer: Minimize with max-calls 1000 convergence for edm < 1 strategy 1
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28877
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 4 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 2000 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.27133
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 166 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28726
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 9 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.2898
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 1 errors
Minuit2Minimizer : Invalid minimum - status = 3
FVAL = -2419.31
Edm = -nan
Nfcn = 34
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.2898
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28374
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 44 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.27133
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 166 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28726
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 9 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.2898
RooFit::Detail::RooNormalizedPdf::argus_over_argus_Int[m][ numerator=argus denominator=argus_Int[m] ] has 1 errors
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
[#1] INFO:Fitting -- RooAbsPdf::fitTo(argus_over_argus_Int[m]) fixing normalization set for coefficient determination to observables in data
Date
July 2008
Author
Wouter Verkerke

Definition in file rf606_nllerrorhandling.C.