rf602_chi2fit.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'LIKELIHOOD AND MINIMIZATION' RooFit tutorial macro #602
00004 // 
00005 // Setting up a binning chi^2 fit
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 "RooChebychev.h"
00020 #include "RooAddPdf.h"
00021 #include "RooChi2Var.h"
00022 #include "RooMinuit.h"
00023 #include "TCanvas.h"
00024 #include "RooPlot.h"
00025 using namespace RooFit ;
00026 
00027 
00028 class TestBasic602 : public RooFitTestUnit
00029 {
00030 public: 
00031   TestBasic602(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Chi2 minimization",refFile,writeRef,verbose) {} ;
00032   Bool_t testCode() {
00033 
00034   // S e t u p   m o d e l
00035   // ---------------------
00036 
00037   // Declare observable x
00038   RooRealVar x("x","x",0,10) ;
00039 
00040   // Create two Gaussian PDFs g1(x,mean1,sigma) anf g2(x,mean2,sigma) and their paramaters
00041   RooRealVar mean("mean","mean of gaussians",5) ;
00042   RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
00043   RooRealVar sigma2("sigma2","width of gaussians",1) ;
00044 
00045   RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;  
00046   RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;  
00047   
00048   // Build Chebychev polynomial p.d.f.  
00049   RooRealVar a0("a0","a0",0.5,0.,1.) ;
00050   RooRealVar a1("a1","a1",-0.2,0.,1.) ;
00051   RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
00052 
00053   // Sum the signal components into a composite signal p.d.f.
00054   RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00055   RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00056 
00057   // Sum the composite signal and background 
00058   RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
00059   RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
00060 
00061 
00062   // C r e a t e   b i n n e d   d a t a s e t
00063   // -----------------------------------------
00064 
00065   RooDataSet* d = model.generate(x,10000) ;
00066   RooDataHist* dh = d->binnedClone() ;
00067 
00068 
00069   // Construct a chi^2 of the data and the model,
00070   // which is the input probability density scaled
00071   // by the number of events in the dataset
00072   RooChi2Var chi2("chi2","chi2",model,*dh) ;
00073 
00074   // Use RooMinuit interface to minimize chi^2
00075   RooMinuit m(chi2) ;
00076   m.migrad() ;
00077   m.hesse() ;
00078 
00079   RooFitResult* r = m.save() ;
00080 
00081   regResult(r,"rf602_r") ;
00082   
00083   delete d ;
00084   delete dh ;
00085 
00086   return kTRUE ;
00087   }
00088 } ;

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