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