Logo ROOT  
Reference Guide
rf606_nllerrorhandling.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4///
5/// Likelihood and minimization: understanding and customizing error handling in likelihood evaluations
6///
7/// \macro_image
8/// \macro_output
9/// \macro_code
10///
11/// \date 07/2008
12/// \author Wouter Verkerke
13
14#include "RooRealVar.h"
15#include "RooDataSet.h"
16#include "RooArgusBG.h"
17#include "RooNLLVar.h"
18#include "TCanvas.h"
19#include "TAxis.h"
20#include "RooPlot.h"
21using namespace RooFit;
22
23void rf606_nllerrorhandling()
24{
25 // C r e a t e m o d e l a n d d a t a s e t
26 // ----------------------------------------------
27
28 // Observable
29 RooRealVar m("m", "m", 5.20, 5.30);
30
31 // Parameters
32 RooRealVar m0("m0", "m0", 5.291, 5.20, 5.30);
33 RooRealVar k("k", "k", -30, -50, -10);
34
35 // Pdf
36 RooArgusBG argus("argus", "argus", m, m0, k);
37
38 // Sample 1000 events in m from argus
39 RooDataSet *data = argus.generate(m, 1000);
40
41 // P l o t m o d e l a n d d a t a
42 // --------------------------------------
43
44 RooPlot *frame1 = m.frame(Bins(40), Title("Argus model and data"));
45 data->plotOn(frame1);
46 argus.plotOn(frame1);
47
48 // F i t m o d e l t o d a t a
49 // ---------------------------------
50
51 // The ARGUS background shape has a sharp kinematic cutoff at m=m0
52 // and is prone to evaluation errors if the cutoff parameter m0
53 // is floated: when the pdf cutoff value is lower than that in data
54 // events with m>m0 will have zero probability
55
56 // Perform unbinned ML fit. Print detailed error messages for up to
57 // 10 events per likelihood evaluation. The default error handling strategy
58 // is to return a very high value of the likelihood to MINUIT if errors occur,
59 // which will force MINUIT to retreat from the problematic area
60
61 argus.fitTo(*data, PrintEvalErrors(10));
62
63 // Perform another fit. In this configuration only the number of errors per
64 // likelihood evaluation is shown, if it is greater than zero. The
65 // EvalErrorWall(kFALSE) arguments disables the default error handling strategy
66 // and will cause the actual (problematic) value of the likelihood to be passed
67 // to MINUIT.
68 //
69 // NB: Use of this option is NOT recommended as default strategy as broken -log(L) values
70 // can often be lower than 'good' ones because offending events are removed.
71 // This may effectively create a false minimum in problem areas. This is clearly
72 // illustrated in the second plot
73
74 m0.setError(0.1);
75 argus.fitTo(*data, PrintEvalErrors(0), EvalErrorWall(kFALSE));
76
77 // 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
78 // ------------------------------------------------------------------
79
80 // Construct likelihood function of model and data
81 RooNLLVar nll("nll", "nll", argus, *data);
82
83 // Plot likelihood in m0 in range that includes problematic values
84 // In this configuration no messages are printed for likelihood evaluation errors,
85 // but if an likelihood value evaluates with error, the corresponding value
86 // on the curve will be set to the value given in EvalErrorValue().
87
88 RooPlot *frame2 = m0.frame(Range(5.288, 5.293), Title("-log(L) scan vs m0, problematic regions masked"));
89 nll.plotOn(frame2, PrintEvalErrors(-1), ShiftToZero(), EvalErrorValue(nll.getVal() + 10), LineColor(kRed));
90 frame2->SetMaximum(15);
91 frame2->SetMinimum(0);
92
93 TCanvas *c = new TCanvas("rf606_nllerrorhandling", "rf606_nllerrorhandling", 1200, 400);
94 c->Divide(2);
95 c->cd(1);
96 gPad->SetLeftMargin(0.15);
97 frame1->GetYaxis()->SetTitleOffset(1.4);
98 frame1->Draw();
99 c->cd(2);
100 gPad->SetLeftMargin(0.15);
101 frame2->GetYaxis()->SetTitleOffset(1.4);
102 frame2->Draw();
103}
#define c(i)
Definition: RSha256.hxx:101
const Bool_t kFALSE
Definition: RtypesCore.h:90
@ kRed
Definition: Rtypes.h:64
#define gPad
Definition: TVirtualPad.h:287
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:546
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition: RooArgusBG.h:25
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
Class RooNLLVar implements a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:26
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:1112
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1277
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition: RooPlot.cxx:277
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:1102
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:712
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
The Canvas class.
Definition: TCanvas.h:27
RooCmdArg Bins(Int_t nbin)
RooCmdArg EvalErrorWall(Bool_t flag)
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg EvalErrorValue(Double_t value)
RooCmdArg ShiftToZero()
RooCmdArg LineColor(Color_t color)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
const char * Title
Definition: TXMLSetup.cxx:67
Ta Range(0, 0, 1, 1)
auto * m
Definition: textangle.C:8