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

Namespaces

namespace  rf606_nllerrorhandling
 

Detailed Description

View in nbviewer Open in SWAN

'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #606

Understanding and customizing error handling in likelihood evaluations

import ROOT
# Create model and dataset
# ----------------------------------------------
# Observable
m = ROOT.RooRealVar("m", "m", 5.20, 5.30)
# Parameters
m0 = ROOT.RooRealVar("m0", "m0", 5.291, 5.20, 5.30)
k = ROOT.RooRealVar("k", "k", -30, -50, -10)
# Pdf
argus = ROOT.RooArgusBG("argus", "argus", m, m0, k)
# Sample 1000 events in m from argus
data = argus.generate({m}, 1000)
# Plot model and data
# --------------------------------------
frame1 = m.frame(Bins=40, Title="Argus model and data")
data.plotOn(frame1)
argus.plotOn(frame1)
# Fit model to data
# ---------------------------------
# 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 self configuration only the number of errors per
# likelihood evaluation is shown, it is greater than zero. The
# EvalErrorWall(kFALSE) 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 self option is NOT recommended as default strategt as broken -log(L) values
# can often be lower than 'good' ones because offending events are removed.
# ROOT.This may effectively create a False minimum in problem areas. ROOT.This is clearly
# illustrated in the second plot
m0.setError(0.1)
argus.fitTo(data, PrintEvalErrors=0, EvalErrorWall=False)
# Plot likelihood as function of m0
# ------------------------------------------------------------------
# Construct likelihood function of model and data
nll = argus.createNLL(data)
# Plot likelihood in m0 in range that includes problematic values
# In self configuration no messages are printed for likelihood evaluation errors,
# but if an likelihood value evaluates with error, corresponding value
# on the curve will be set to the value given in EvalErrorValue().
frame2 = m0.frame(Range=(5.288, 5.293), Title="-log(L) scan vs m0, regions masked")
nll.plotOn(frame2, ShiftToZero=True, PrintEvalErrors=-1, EvalErrorValue=(nll.getVal() + 10), LineColor="r")
frame2.SetMaximum(15)
frame2.SetMinimum(0)
c = ROOT.TCanvas("rf606_nllerrorhandling", "rf606_nllerrorhandling", 1200, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
frame1.GetYaxis().SetTitleOffset(1.4)
frame1.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
frame2.GetYaxis().SetTitleOffset(1.4)
frame2.Draw()
c.SaveAs("rf606_nllerrorhandling.png")
[#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
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ]
getLogVal() top-level p.d.f evaluates to zero @ m=m=5.29019, m0=m0=5.29014, c=k=-33.8075, p=0.5=0.5
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ]
function value is NAN @ parameters=(k = -33.8075,m0 = 5.29014)
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
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ]
getLogVal() top-level p.d.f evaluates to zero @ m=m=5.29019, m0=m0=5.2901, c=k=-36.7074, p=0.5=0.5
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ]
function value is NAN @ parameters=(k = -36.7074,m0 = 5.2901)
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: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
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 4 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=nan m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=nan
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 2000 errors
RooRealIntegral::argus_Int[m][ Int argusd[Ana](m) ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.27133
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 166 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28726
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 9 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.2898
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] 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
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 1 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28374
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 44 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.27133
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 166 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.28726
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 9 errors
RooAbsMinimizerFcn: Minimized function has error status but is ignored.
Parameter values: k=-35.3713 m0=5.2898
RooNLLVar::nll_argus_argusData[ parameters=(k,m0) ] has 1 errors
RooArgusBG::argus[ m=m m0=m0 c=k p=0.5 ] has 1 errors
[#1] INFO:Minimization -- RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization
Date
February 2018
Authors
Clemens Lange, Wouter Verkerke (C version)

Definition in file rf606_nllerrorhandling.py.