Logo ROOT   6.14/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' RooFit tutorial macro #606
5 ///
6 /// Understanding and customizing error handling in likelihood evaluations
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
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 
24 void rf606_nllerrorhandling()
25 {
26  // C r e a t e m o d e l a n d d a t a s e t
27  // ----------------------------------------------
28 
29  // Observable
30  RooRealVar m("m","m",5.20,5.30) ;
31 
32  // Parameters
33  RooRealVar m0("m0","m0",5.291,5.20,5.30) ;
34  RooRealVar k("k","k",-30,-50,-10) ;
35 
36  // Pdf
37  RooArgusBG argus("argus","argus",m,m0,k) ;
38 
39  // Sample 1000 events in m from argus
40  RooDataSet* data = argus.generate(m,1000) ;
41 
42 
43 
44  // P l o t m o d e l a n d d a t a
45  // --------------------------------------
46 
47  RooPlot* frame1 = m.frame(Bins(40),Title("Argus model and data")) ;
48  data->plotOn(frame1) ;
49  argus.plotOn(frame1) ;
50 
51 
52 
53  // F i t m o d e l t o d a t a
54  // ---------------------------------
55 
56  // The ARGUS background shape has a sharp kinematic cutoff at m=m0
57  // and is prone to evaluation errors if the cutoff parameter m0
58  // is floated: when the pdf cutoff value is lower than that in data
59  // events with m>m0 will have zero probability
60 
61  // Perform unbinned ML fit. Print detailed error messages for up to
62  // 10 events per likelihood evaluation. The default error handling strategy
63  // is to return a very high value of the likelihood to MINUIT if errors occur,
64  // which will force MINUIT to retreat from the problematic area
65 
66  argus.fitTo(*data,PrintEvalErrors(10)) ;
67 
68  // Perform another fit. In this configuration only the number of errors per
69  // likelihood evaluation is shown, if it is greater than zero. The
70  // EvalErrorWall(kFALSE) arguments disables the default error handling strategy
71  // and will cause the actual (problematic) value of the likelihood to be passed
72  // to MINUIT.
73  //
74  // NB: Use of this option is NOT recommended as default strategy as broken -log(L) values
75  // can often be lower than 'good' ones because offending events are removed.
76  // This may effectively create a false minimum in problem areas. This is clearly
77  // illustrated in the second plot
78 
79  m0.setError(0.1) ;
80  argus.fitTo(*data,PrintEvalErrors(0),EvalErrorWall(kFALSE)) ;
81 
82 
83 
84  // 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
85  // ------------------------------------------------------------------
86 
87  // Construct likelihood function of model and data
88  RooNLLVar nll("nll","nll",argus,*data) ;
89 
90  // Plot likelihood in m0 in range that includes problematic values
91  // In this configuration no messages are printed for likelihood evaluation errors,
92  // but if an likelihood value evaluates with error, the corresponding value
93  // on the curve will be set to the value given in EvalErrorValue().
94 
95  RooPlot* frame2 = m0.frame(Range(5.288,5.293),Title("-log(L) scan vs m0, problematic regions masked")) ;
96  nll.plotOn(frame2,PrintEvalErrors(-1),ShiftToZero(),EvalErrorValue(nll.getVal()+10),LineColor(kRed)) ;
97  frame2->SetMaximum(15) ;
98  frame2->SetMinimum(0) ;
99 
100 
101  TCanvas* c = new TCanvas("rf606_nllerrorhandling","rf606_nllerrorhandling",1200,400) ;
102  c->Divide(2) ;
103  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
104  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
105 
106 }
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
RooCmdArg EvalErrorWall(Bool_t flag)
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1117
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
Plot dataset on specified frame.
Definition: RooAbsData.cxx:568
auto * m
Definition: textangle.C:8
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:59
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
RooCmdArg PrintEvalErrors(Int_t numErrors)
RooCmdArg Title(const char *name)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
virtual void SetMinimum(Double_t minimum=-1111)
Set minimum value of Y axis.
Definition: RooPlot.cxx:958
RooArgusBG is a RooAbsPdf implementation describing the ARGUS background shape.
Definition: RooArgusBG.h:25
RooCmdArg ShiftToZero()
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
Class RooNLLVar implements a a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:26
virtual void SetMaximum(Double_t maximum=-1111)
Set maximum value of Y axis.
Definition: RooPlot.cxx:948
RooCmdArg EvalErrorValue(Double_t value)
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
The Canvas class.
Definition: TCanvas.h:31
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
RooCmdArg Bins(Int_t nbin)
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558