Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
rf605_profilell.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// Likelihood and minimization: working with the profile likelihood estimator
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 "RooGaussian.h"
14 #include "RooConstVar.h"
15 #include "RooAddPdf.h"
16 #include "RooMinimizer.h"
17 #include "TCanvas.h"
18 #include "TAxis.h"
19 #include "RooPlot.h"
20 using namespace RooFit;
21 
22 void rf605_profilell()
23 {
24  // C r e a t e m o d e l a n d d a t a s e t
25  // -----------------------------------------------
26 
27  // Observable
28  RooRealVar x("x", "x", -20, 20);
29 
30  // Model (intentional strong correlations)
31  RooRealVar mean("mean", "mean of g1 and g2", 0, -10, 10);
32  RooRealVar sigma_g1("sigma_g1", "width of g1", 3);
33  RooGaussian g1("g1", "g1", x, mean, sigma_g1);
34 
35  RooRealVar sigma_g2("sigma_g2", "width of g2", 4, 3.0, 6.0);
36  RooGaussian g2("g2", "g2", x, mean, sigma_g2);
37 
38  RooRealVar frac("frac", "frac", 0.5, 0.0, 1.0);
39  RooAddPdf model("model", "model", RooArgList(g1, g2), frac);
40 
41  // Generate 1000 events
42  RooDataSet *data = model.generate(x, 1000);
43 
44  // C o n s t r u c t p l a i n l i k e l i h o o d
45  // ---------------------------------------------------
46 
47  // Construct unbinned likelihood
48  RooAbsReal *nll = model.createNLL(*data, NumCPU(2));
49 
50  // Minimize likelihood w.r.t all parameters before making plots
51  RooMinimizer(*nll).migrad();
52 
53  // Plot likelihood scan frac
54  RooPlot *frame1 = frac.frame(Bins(10), Range(0.01, 0.95), Title("LL and profileLL in frac"));
55  nll->plotOn(frame1, ShiftToZero());
56 
57  // Plot likelihood scan in sigma_g2
58  RooPlot *frame2 = sigma_g2.frame(Bins(10), Range(3.3, 5.0), Title("LL and profileLL in sigma_g2"));
59  nll->plotOn(frame2, ShiftToZero());
60 
61  // 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
62  // -----------------------------------------------------------------------
63 
64  // The profile likelihood estimator on nll for frac will minimize nll w.r.t
65  // all floating parameters except frac for each evaluation
66 
67  RooAbsReal *pll_frac = nll->createProfile(frac);
68 
69  // Plot the profile likelihood in frac
70  pll_frac->plotOn(frame1, LineColor(kRed));
71 
72  // Adjust frame maximum for visual clarity
73  frame1->SetMinimum(0);
74  frame1->SetMaximum(3);
75 
76  // 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
77  // -------------------------------------------------------------------------------
78 
79  // The profile likelihood estimator on nll for sigma_g2 will minimize nll
80  // w.r.t all floating parameters except sigma_g2 for each evaluation
81  RooAbsReal *pll_sigmag2 = nll->createProfile(sigma_g2);
82 
83  // Plot the profile likelihood in sigma_g2
84  pll_sigmag2->plotOn(frame2, LineColor(kRed));
85 
86  // Adjust frame maximum for visual clarity
87  frame2->SetMinimum(0);
88  frame2->SetMaximum(3);
89 
90  // Make canvas and draw RooPlots
91  TCanvas *c = new TCanvas("rf605_profilell", "rf605_profilell", 800, 400);
92  c->Divide(2);
93  c->cd(1);
94  gPad->SetLeftMargin(0.15);
95  frame1->GetYaxis()->SetTitleOffset(1.4);
96  frame1->Draw();
97  c->cd(2);
98  gPad->SetLeftMargin(0.15);
99  frame2->GetYaxis()->SetTitleOffset(1.4);
100  frame2->Draw();
101 
102  delete pll_frac;
103  delete pll_sigmag2;
104  delete nll;
105 }