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