ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf601_intminuit.cxx
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////
2 //
3 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #601
4 //
5 // Interactive minimization with MINUIT
6 //
7 //
8 // 07/2008 - Wouter Verkerke
9 //
10 /////////////////////////////////////////////////////////////////////////
11 
12 #ifndef __CINT__
13 #include "RooGlobalFunc.h"
14 #endif
15 #include "RooRealVar.h"
16 #include "RooDataSet.h"
17 #include "RooGaussian.h"
18 #include "RooProdPdf.h"
19 #include "RooAddPdf.h"
20 #include "RooMinuit.h"
21 #include "RooNLLVar.h"
22 #include "RooFitResult.h"
23 #include "RooPlot.h"
24 #include "TCanvas.h"
25 #include "TH1.h"
26 using namespace RooFit ;
27 
28 
29 class TestBasic601 : public RooFitTestUnit
30 {
31 public:
32  TestBasic601(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Interactive Minuit",refFile,writeRef,verbose) {} ;
33  Bool_t testCode() {
34 
35  // S e t u p p d f a n d l i k e l i h o o d
36  // -----------------------------------------------
37 
38  // Observable
39  RooRealVar x("x","x",-20,20) ;
40 
41  // Model (intentional strong correlations)
42  RooRealVar mean("mean","mean of g1 and g2",0) ;
43  RooRealVar sigma_g1("sigma_g1","width of g1",3) ;
44  RooGaussian g1("g1","g1",x,mean,sigma_g1) ;
45 
46  RooRealVar sigma_g2("sigma_g2","width of g2",4,3.0,6.0) ;
47  RooGaussian g2("g2","g2",x,mean,sigma_g2) ;
48 
49  RooRealVar frac("frac","frac",0.5,0.0,1.0) ;
50  RooAddPdf model("model","model",RooArgList(g1,g2),frac) ;
51 
52  // Generate 1000 events
53  RooDataSet* data = model.generate(x,1000) ;
54 
55  // Construct unbinned likelihood
56  RooNLLVar nll("nll","nll",model,*data) ;
57 
58 
59  // I n t e r a c t i v e m i n i m i z a t i o n , e r r o r a n a l y s i s
60  // -------------------------------------------------------------------------------
61 
62  // Create MINUIT interface object
63  RooMinuit m(nll) ;
64 
65  // Call MIGRAD to minimize the likelihood
66  m.migrad() ;
67 
68  // Run HESSE to calculate errors from d2L/dp2
69  m.hesse() ;
70 
71  // Run MINOS on sigma_g2 parameter only
72  m.minos(sigma_g2) ;
73 
74 
75  // S a v i n g r e s u l t s , c o n t o u r p l o t s
76  // ---------------------------------------------------------
77 
78  // Save a snapshot of the fit result. This object contains the initial
79  // fit parameters, the final fit parameters, the complete correlation
80  // matrix, the EDM, the minimized FCN , the last MINUIT status code and
81  // the number of times the RooFit function object has indicated evaluation
82  // problems (e.g. zero probabilities during likelihood evaluation)
83  RooFitResult* r = m.save() ;
84 
85 
86  // C h a n g e p a r a m e t e r v a l u e s , f l o a t i n g
87  // -----------------------------------------------------------------
88 
89  // At any moment you can manually change the value of a (constant)
90  // parameter
91  mean = 0.3 ;
92 
93  // Rerun MIGRAD,HESSE
94  m.migrad() ;
95  m.hesse() ;
96 
97  // Now fix sigma_g2
98  sigma_g2.setConstant(kTRUE) ;
99 
100  // Rerun MIGRAD,HESSE
101  m.migrad() ;
102  m.hesse() ;
103 
104  RooFitResult* r2 = m.save() ;
105 
106  regResult(r,"rf601_r") ;
107  regResult(r2,"rf601_r2") ;
108 
109  delete data ;
110 
111  return kTRUE ;
112  }
113 } ;
tuple g2
Definition: multifit.py:39
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
tuple g1
Definition: multifit.py:38
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
Class RooNLLVar implements a a -log(likelihood) calculation from a dataset and a PDF.
Definition: RooNLLVar.h:26
TMarker * m
Definition: textangle.C:8
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
const Bool_t kTRUE
Definition: Rtypes.h:91
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
RooMinuit is a wrapper class around TFitter/TMinuit that provides a seamless interface between the MI...
Definition: RooMinuit.h:39