rf601_intminuit.cxx

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #601
00004 // 
00005 // Interactive minimization with MINUIT
00006 //
00007 //
00008 // 07/2008 - Wouter Verkerke 
00009 //
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #endif
00015 #include "RooRealVar.h"
00016 #include "RooDataSet.h"
00017 #include "RooGaussian.h"
00018 #include "RooProdPdf.h"
00019 #include "RooAddPdf.h"
00020 #include "RooMinuit.h"
00021 #include "RooNLLVar.h"
00022 #include "RooFitResult.h"
00023 #include "RooPlot.h"
00024 #include "TCanvas.h"
00025 #include "TH1.h"
00026 using namespace RooFit ;
00027 
00028 
00029 class TestBasic601 : public RooFitTestUnit
00030 {
00031 public: 
00032   TestBasic601(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Interactive Minuit",refFile,writeRef,verbose) {} ;
00033   Bool_t testCode() {
00034 
00035   // S e t u p   p d f   a n d   l i k e l i h o o d 
00036   // -----------------------------------------------
00037 
00038   // Observable
00039   RooRealVar x("x","x",-20,20) ;
00040 
00041   // Model (intentional strong correlations)
00042   RooRealVar mean("mean","mean of g1 and g2",0) ;
00043   RooRealVar sigma_g1("sigma_g1","width of g1",3) ;
00044   RooGaussian g1("g1","g1",x,mean,sigma_g1) ;
00045 
00046   RooRealVar sigma_g2("sigma_g2","width of g2",4,3.0,6.0) ;
00047   RooGaussian g2("g2","g2",x,mean,sigma_g2) ;
00048 
00049   RooRealVar frac("frac","frac",0.5,0.0,1.0) ;
00050   RooAddPdf model("model","model",RooArgList(g1,g2),frac) ;
00051 
00052   // Generate 1000 events
00053   RooDataSet* data = model.generate(x,1000) ;
00054   
00055   // Construct unbinned likelihood
00056   RooNLLVar nll("nll","nll",model,*data) ;
00057 
00058 
00059   // 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
00060   // -------------------------------------------------------------------------------
00061 
00062   // Create MINUIT interface object
00063   RooMinuit m(nll) ;
00064 
00065   // Call MIGRAD to minimize the likelihood
00066   m.migrad() ;
00067 
00068   // Run HESSE to calculate errors from d2L/dp2
00069   m.hesse() ;
00070 
00071   // Run MINOS on sigma_g2 parameter only
00072   m.minos(sigma_g2) ;
00073 
00074 
00075   // 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 
00076   // ---------------------------------------------------------
00077 
00078   // Save a snapshot of the fit result. This object contains the initial
00079   // fit parameters, the final fit parameters, the complete correlation
00080   // matrix, the EDM, the minimized FCN , the last MINUIT status code and
00081   // the number of times the RooFit function object has indicated evaluation
00082   // problems (e.g. zero probabilities during likelihood evaluation)
00083   RooFitResult* r = m.save() ;
00084 
00085 
00086   // 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
00087   // -----------------------------------------------------------------
00088 
00089   // At any moment you can manually change the value of a (constant)
00090   // parameter
00091   mean = 0.3 ;
00092   
00093   // Rerun MIGRAD,HESSE
00094   m.migrad() ;
00095   m.hesse() ;
00096 
00097   // Now fix sigma_g2
00098   sigma_g2.setConstant(kTRUE) ;
00099 
00100   // Rerun MIGRAD,HESSE
00101   m.migrad() ;
00102   m.hesse() ;
00103 
00104   RooFitResult* r2 = m.save() ;
00105 
00106   regResult(r,"rf601_r") ;
00107   regResult(r2,"rf601_r2") ;
00108 
00109   delete data ;
00110 
00111   return kTRUE ;
00112   } 
00113 } ;

Generated on Tue Jul 5 15:07:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1