Logo ROOT   6.10/09
Reference Guide
rf605_profilell.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #605
4 //
5 // Working with the profile likelihood estimator
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 "RooGaussian.h"
19 #include "RooAddPdf.h"
20 #include "RooNLLVar.h"
21 #include "RooProfileLL.h"
22 #include "RooMinuit.h"
23 #include "TCanvas.h"
24 #include "RooPlot.h"
25 using namespace RooFit ;
26 
27 
28 class TestBasic605 : public RooFitTestUnit
29 {
30 public:
31  TestBasic605(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Profile Likelihood operator",refFile,writeRef,verbose) {} ;
32  Bool_t testCode() {
33 
34  // C r e a t e m o d e l a n d d a t a s e t
35  // -----------------------------------------------
36 
37  // Observable
38  RooRealVar x("x","x",-20,20) ;
39 
40  // Model (intentional strong correlations)
41  RooRealVar mean("mean","mean of g1 and g2",0,-10,10) ;
42  RooRealVar sigma_g1("sigma_g1","width of g1",3) ;
43  RooGaussian g1("g1","g1",x,mean,sigma_g1) ;
44 
45  RooRealVar sigma_g2("sigma_g2","width of g2",4,3.0,6.0) ;
46  RooGaussian g2("g2","g2",x,mean,sigma_g2) ;
47 
48  RooRealVar frac("frac","frac",0.5,0.0,1.0) ;
49  RooAddPdf model("model","model",RooArgList(g1,g2),frac) ;
50 
51  // Generate 1000 events
52  RooDataSet* data = model.generate(x,1000) ;
53 
54 
55 
56  // C o n s t r u c t p l a i n l i k e l i h o o d
57  // ---------------------------------------------------
58 
59  // Construct unbinned likelihood
60  RooNLLVar nll("nll","nll",model,*data) ;
61 
62  // Minimize likelihood w.r.t all parameters before making plots
63  RooMinuit(nll).migrad() ;
64 
65  // Plot likelihood scan frac
66  RooPlot* frame1 = frac.frame(Bins(10),Range(0.01,0.95),Title("LL and profileLL in frac")) ;
67  nll.plotOn(frame1,ShiftToZero()) ;
68 
69  // Plot likelihood scan in sigma_g2
70  RooPlot* frame2 = sigma_g2.frame(Bins(10),Range(3.3,5.0),Title("LL and profileLL in sigma_g2")) ;
71  nll.plotOn(frame2,ShiftToZero()) ;
72 
73 
74 
75  // C o n s t r u c t p r o f i l e l i k e l i h o o d i n f r a c
76  // -----------------------------------------------------------------------
77 
78  // The profile likelihood estimator on nll for frac will minimize nll w.r.t
79  // all floating parameters except frac for each evaluation
80  RooProfileLL pll_frac("pll_frac","pll_frac",nll,frac) ;
81 
82  // Plot the profile likelihood in frac
83  pll_frac.plotOn(frame1,LineColor(kRed)) ;
84 
85  // Adjust frame maximum for visual clarity
86  frame1->SetMinimum(0) ;
87  frame1->SetMaximum(3) ;
88 
89 
90 
91  // C o n s t r u c t p r o f i l e l i k e l i h o o d i n s i g m a _ g 2
92  // -------------------------------------------------------------------------------
93 
94  // The profile likelihood estimator on nll for sigma_g2 will minimize nll
95  // w.r.t all floating parameters except sigma_g2 for each evaluation
96  RooProfileLL pll_sigmag2("pll_sigmag2","pll_sigmag2",nll,sigma_g2) ;
97 
98  // Plot the profile likelihood in sigma_g2
99  pll_sigmag2.plotOn(frame2,LineColor(kRed)) ;
100 
101  // Adjust frame maximum for visual clarity
102  frame2->SetMinimum(0) ;
103  frame2->SetMaximum(3) ;
104 
105 
106  regPlot(frame1,"rf605_plot1") ;
107  regPlot(frame2,"rf605_plot2") ;
108 
109  delete data ;
110 
111  return kTRUE ;
112  }
113 } ;
114 
RooAddPdf is an efficient implementation of a sum of PDFs of the form.
Definition: RooAddPdf.h:29
Class RooProfileLL implements the profile likelihood estimator for a given likelihood and set of para...
Definition: RooProfileLL.h:26
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:56
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Int_t migrad()
Execute MIGRAD.
Definition: RooMinuit.cxx:309
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:959
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.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:949
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
RooCmdArg Bins(Int_t nbin)
const Bool_t kTRUE
Definition: RtypesCore.h:91
RooMinuit is a wrapper class around TFitter/TMinuit that provides a seamless interface between the MI...
Definition: RooMinuit.h:39