Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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"
18 using namespace RooFit;
19 
20 void 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 }