Rf 6 0 6_Nllerrorhandling

'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #606

Understanding and customizing error handling in likelihood evaluations

Author: Wouter Verkerke (C version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, January 19, 2022 at 10:28 AM.

In [ ]:
import ROOT

Create model and dataset


In [ ]:
m = ROOT.RooRealVar("m", "m", 5.20, 5.30)


In [ ]:
m0 = ROOT.RooRealVar("m0", "m0", 5.291, 5.20, 5.30)
k = ROOT.RooRealVar("k", "k", -30, -50, -10)


In [ ]:
argus = ROOT.RooArgusBG("argus", "argus", m, m0, k)

Sample 1000 events in m from argus

In [ ]:
data = argus.generate({m}, 1000)

Plot model and data

In [ ]:
frame1 = m.frame(Bins=40, Title="Argus model and data")

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

In [ ]:
argus.fitTo(data, PrintEvalErrors=10)

Peform 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

In [ ]:
argus.fitTo(data, PrintEvalErrors=0, EvalErrorWall=False)

Plot likelihood as function of m0

Construct likelihood function of model and data

In [ ]:
nll = ROOT.RooNLLVar("nll", "nll", argus, 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().

In [ ]:
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")

c = ROOT.TCanvas("rf606_nllerrorhandling", "rf606_nllerrorhandling", 1200, 400)


Draw all canvases

In [ ]:
from ROOT import gROOT