Logo ROOT  
Reference Guide
No Matches
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
6/// \macro_image
7/// \macro_code
8/// \macro_output
10/// \date July 2008
11/// \author Wouter Verkerke
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooArgusBG.h"
16#include "TCanvas.h"
17#include "TAxis.h"
18#include "RooPlot.h"
19using namespace RooFit;
23 // C r e a t e m o d e l a n d d a t a s e t
24 // ----------------------------------------------
26 // Observable
27 RooRealVar m("m", "m", 5.20, 5.30);
29 // Parameters
30 RooRealVar m0("m0", "m0", 5.291, 5.20, 5.30);
31 RooRealVar k("k", "k", -30, -50, -10);
33 // Pdf
34 RooArgusBG argus("argus", "argus", m, m0, k);
36 // Sample 1000 events in m from argus
37 std::unique_ptr<RooDataSet> data{argus.generate(m, 1000)};
39 // P l o t m o d e l a n d d a t a
40 // --------------------------------------
42 RooPlot *frame1 = m.frame(Bins(40), Title("Argus model and data"));
43 data->plotOn(frame1);
44 argus.plotOn(frame1);
46 // F i t m o d e l t o d a t a
47 // ---------------------------------
49 // The ARGUS background shape has a sharp kinematic cutoff at m=m0
50 // and is prone to evaluation errors if the cutoff parameter m0
51 // is floated: when the pdf cutoff value is lower than that in data
52 // events with m>m0 will have zero probability
54 // Perform unbinned ML fit. Print detailed error messages for up to
55 // 10 events per likelihood evaluation. The default error handling strategy
56 // is to return a very high value of the likelihood to MINUIT if errors occur,
57 // which will force MINUIT to retreat from the problematic area
59 argus.fitTo(*data, PrintEvalErrors(10));
61 // Perform another fit. In this configuration only the number of errors per
62 // likelihood evaluation is shown, if it is greater than zero. The
63 // EvalErrorWall(false) arguments disables the default error handling strategy
64 // and will cause the actual (problematic) value of the likelihood to be passed
65 // to MINUIT.
66 //
67 // NB: Use of this option is NOT recommended as default strategy as broken -log(L) values
68 // can often be lower than 'good' ones because offending events are removed.
69 // This may effectively create a false minimum in problem areas. This is clearly
70 // illustrated in the second plot
72 m0.setError(0.1);
73 argus.fitTo(*data, PrintEvalErrors(0), EvalErrorWall(false));
75 // 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
76 // ------------------------------------------------------------------
78 // Construct likelihood function of model and data
79 std::unique_ptr<RooAbsReal> nll{argus.createNLL(*data)};
81 // Plot likelihood in m0 in range that includes problematic values
82 // In this configuration no messages are printed for likelihood evaluation errors,
83 // but if an likelihood value evaluates with error, the corresponding value
84 // on the curve will be set to the value given in EvalErrorValue().
86 RooPlot *frame2 = m0.frame(Range(5.288, 5.293), Title("-log(L) scan vs m0, problematic regions masked"));
87 nll->plotOn(frame2, PrintEvalErrors(-1), ShiftToZero(), EvalErrorValue(nll->getVal() + 10), LineColor(kRed));
88 frame2->SetMaximum(15);
89 frame2->SetMinimum(0);
91 TCanvas *c = new TCanvas("rf606_nllerrorhandling", "rf606_nllerrorhandling", 1200, 400);
92 c->Divide(2);
93 c->cd(1);
94 gPad->SetLeftMargin(0.15);
95 frame1->GetYaxis()->SetTitleOffset(1.4);
96 frame1->Draw();
97 c->cd(2);
98 gPad->SetLeftMargin(0.15);
99 frame2->GetYaxis()->SetTitleOffset(1.4);
100 frame2->Draw();
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition RooArgusBG.h:22
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:237
virtual void SetMinimum(double minimum=-1111)
Set minimum value of Y axis.
Definition RooPlot.cxx:1059
virtual void SetMaximum(double maximum=-1111)
Set maximum value of Y axis.
Definition RooPlot.cxx:1049
TAxis * GetYaxis() const
Definition RooPlot.cxx:1276
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:649
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
RooCmdArg Bins(Int_t nbin)
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg EvalErrorWall(bool flag)
RooCmdArg EvalErrorValue(double value)
RooCmdArg ShiftToZero()
RooCmdArg LineColor(Color_t color)
double nll(double pdf, double weight, int binnedL, int doBinOffset)
Definition MathFuncs.h:321
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
const char * Title
Definition TXMLSetup.cxx:68
Ta Range(0, 0, 1, 1)
TMarker m
Definition textangle.C:8