Logo ROOT   6.10/09
Reference Guide
rf606_nllerrorhandling.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #606
4 //
5 // Understanding and customizing error handling in likelihood evaluations
6 //
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooArgusBG.h"
19 #include "RooNLLVar.h"
20 #include "TCanvas.h"
21 #include "RooPlot.h"
22 using namespace RooFit ;
23 
24 
25 class TestBasic606 : public RooFitTestUnit
26 {
27 public:
28  TestBasic606(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("NLL error handling",refFile,writeRef,verbose) {} ;
29  Bool_t testCode() {
30 
31  // C r e a t e m o d e l a n d d a t a s e t
32  // ----------------------------------------------
33 
34  // Observable
35  RooRealVar m("m","m",5.20,5.30) ;
36 
37  // Parameters
38  RooRealVar m0("m0","m0",5.291,5.20,5.30) ;
39  RooRealVar k("k","k",-30,-50,-10) ;
40 
41  // Pdf
42  RooArgusBG argus("argus","argus",m,m0,k) ;
43 
44  // Sample 1000 events in m from argus
45  RooDataSet* data = argus.generate(m,1000) ;
46 
47 
48 
49  // P l o t m o d e l a n d d a t a
50  // --------------------------------------
51 
52  RooPlot* frame1 = m.frame(Bins(40),Title("Argus model and data")) ;
53  data->plotOn(frame1) ;
54  argus.plotOn(frame1) ;
55 
56 
57 
58  // F i t m o d e l t o d a t a
59  // ---------------------------------
60 
61  argus.fitTo(*data,PrintEvalErrors(10),Warnings(kFALSE)) ;
62  m0.setError(0.1) ;
63  argus.fitTo(*data,PrintEvalErrors(0),EvalErrorWall(kFALSE),Warnings(kFALSE)) ;
64 
65 
66 
67  // 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
68  // ------------------------------------------------------------------
69 
70  // Construct likelihood function of model and data
71  RooNLLVar nll("nll","nll",argus,*data) ;
72 
73  // Plot likelihood in m0 in range that includes problematic values
74  // In this configuration the number of errors per likelihood point
75  // evaluated for the curve is shown. A positive number in PrintEvalErrors(N)
76  // will show details for up to N events. By default the values for likelihood
77  // evaluations with errors are shown normally (unlike fitting), but the shape
78  // of the curve can be erratic in these regions.
79 
80  RooPlot* frame2 = m0.frame(Range(5.288,5.293),Title("-log(L) scan vs m0")) ;
81  nll.plotOn(frame2,PrintEvalErrors(0),ShiftToZero(),LineColor(kRed),Precision(1e-4)) ;
82 
83 
84  // Plot likelihood in m0 in range that includes problematic values
85  // In this configuration no messages are printed for likelihood evaluation errors,
86  // but if an likelihood value evaluates with error, the corresponding value
87  // on the curve will be set to the value given in EvalErrorValue().
88 
89  RooPlot* frame3 = m0.frame(Range(5.288,5.293),Title("-log(L) scan vs m0, problematic regions masked")) ;
90  nll.plotOn(frame3,PrintEvalErrors(-1),ShiftToZero(),EvalErrorValue(nll.getVal()+10),LineColor(kRed)) ;
91 
92 
93  regPlot(frame1,"rf606_plot1") ;
94  regPlot(frame2,"rf606_plot2") ;
95  regPlot(frame3,"rf606_plot3") ;
96 
97  delete data ;
98  return kTRUE ;
99 
100  }
101 } ;
RooCmdArg EvalErrorWall(Bool_t flag)
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:552
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:56
RooCmdArg PrintEvalErrors(Int_t numErrors)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooCmdArg Title(const char *name)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
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
RooCmdArg Warnings(Bool_t flag=kTRUE)
Class RooNLLVar implements a a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:26
RooCmdArg EvalErrorValue(Double_t value)
TMarker * m
Definition: textangle.C:8
bool verbose
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:92
RooCmdArg Precision(Double_t prec)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
RooCmdArg Bins(Int_t nbin)
const Bool_t kTRUE
Definition: RtypesCore.h:91