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"
21 using namespace RooFit;
22 
23 void 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 }
c
#define c(i)
Definition: RSha256.hxx:119
m
auto * m
Definition: textangle.C:8
RooFit::EvalErrorValue
RooCmdArg EvalErrorValue(Double_t value)
Definition: RooGlobalFunc.cxx:65
RooPlot::Draw
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:691
RooArgusBG.h
RooFit::Bins
RooCmdArg Bins(Int_t nbin)
Definition: RooGlobalFunc.cxx:174
RooFit::PrintEvalErrors
RooCmdArg PrintEvalErrors(Int_t numErrors)
Definition: RooGlobalFunc.cxx:205
RooFit::ShiftToZero
RooCmdArg ShiftToZero()
Definition: RooGlobalFunc.cxx:50
RooPlot::SetMaximum
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:1081
TCanvas.h
RooDataSet.h
RooNLLVar.h
RooPlot::frame
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
RooFit
Definition: RooCFunction1Binding.h:29
RooAbsData::plotOn
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
Definition: RooAbsData.cxx:547
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
RooNLLVar
Definition: RooNLLVar.h:27
RooPlot.h
RooPlot::GetYaxis
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1256
RooPlot
Definition: RooPlot.h:44
RooFit::EvalErrorWall
RooCmdArg EvalErrorWall(Bool_t flag)
Definition: RooGlobalFunc.cxx:206
RooRealVar.h
kRed
@ kRed
Definition: Rtypes.h:66
RooFit::LineColor
RooCmdArg LineColor(Color_t color)
Definition: RooGlobalFunc.cxx:56
TCanvas
Definition: TCanvas.h:23
TAxis.h
RooFit::Range
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Definition: RooGlobalFunc.cxx:52
RooArgusBG
Definition: RooArgusBG.h:25
RooPlot::SetMinimum
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:1091
gPad
#define gPad
Definition: TVirtualPad.h:287
RooDataSet
Definition: RooDataSet.h:33
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
RooRealVar
Definition: RooRealVar.h:35
RooFit::Title
RooCmdArg Title(const char *name)
Definition: RooGlobalFunc.cxx:173