rf607_fitresult.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #607
00004 // 
00005 // Demonstration of options of the RooFitResult class
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooGaussian.h"
00019 #include "RooAddPdf.h"
00020 #include "RooChebychev.h"
00021 #include "RooFitResult.h"
00022 #include "TCanvas.h"
00023 #include "RooPlot.h"
00024 #include "TFile.h"
00025 #include "TStyle.h"
00026 #include "TH2.h"
00027 
00028 using namespace RooFit ;
00029 
00030 
00031 class TestBasic607 : public RooFitTestUnit
00032 {
00033 public: 
00034   TestBasic607(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Fit Result functionality",refFile,writeRef,verbose) {} ;
00035   Bool_t testCode() {
00036 
00037   // C r e a t e   p d f ,   d a t a
00038   // --------------------------------
00039 
00040   // Declare observable x
00041   RooRealVar x("x","x",0,10) ;
00042 
00043   // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their paramaters
00044   RooRealVar mean("mean","mean of gaussians",5,-10,10) ;
00045   RooRealVar sigma1("sigma1","width of gaussians",0.5,0.1,10) ;
00046   RooRealVar sigma2("sigma2","width of gaussians",1,0.1,10) ;
00047 
00048   RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;  
00049   RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;  
00050   
00051   // Build Chebychev polynomial p.d.f.  
00052   RooRealVar a0("a0","a0",0.5,0.,1.) ;
00053   RooRealVar a1("a1","a1",-0.2) ;
00054   RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
00055 
00056   // Sum the signal components into a composite signal p.d.f.
00057   RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00058   RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00059 
00060   // Sum the composite signal and background 
00061   RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
00062   RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
00063 
00064   // Generate 1000 events
00065   RooDataSet* data = model.generate(x,1000) ;
00066 
00067 
00068 
00069   // F i t   p d f   t o   d a t a ,   s a v e   f i t r e s u l t 
00070   // -------------------------------------------------------------
00071 
00072   // Perform fit and save result
00073   RooFitResult* r = model.fitTo(*data,Save()) ;
00074 
00075 
00076   // V i s u a l i z e   c o r r e l a t i o n   m a t r i x
00077   // -------------------------------------------------------
00078 
00079   // Construct 2D color plot of correlation matrix
00080   gStyle->SetOptStat(0) ;
00081   gStyle->SetPalette(1) ;
00082   TH2* hcorr = r->correlationHist() ;
00083 
00084 
00085   // Sample dataset with parameter values according to distribution
00086   // of covariance matrix of fit result
00087   RooDataSet randPars("randPars","randPars",r->floatParsFinal()) ;
00088   for (Int_t i=0 ; i<10000 ; i++) {
00089     randPars.add(r->randomizePars()) ;    
00090   }
00091 
00092   // make histogram of 2D distribution in sigma1 vs sig1frac
00093   TH1* hhrand = randPars.createHistogram("hhrand",sigma1,Binning(35,0.25,0.65),YVar(sig1frac,Binning(35,0.3,1.1))) ;
00094 
00095   regTH(hcorr,"rf607_hcorr") ;
00096   regTH(hhrand,"rf607_hhand") ;
00097 
00098   delete data ;
00099   delete r ;
00100 
00101   return kTRUE ;
00102 
00103   }
00104 } ;

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