rf802_mcstudy_addons.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'VALIDATION AND MC STUDIES' RooFit tutorial macro #802
00004 // 
00005 // RooMCStudy: using separate fit and generator models, using the chi^2 calculator model 
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 "RooConstVar.h"
00019 #include "RooChebychev.h"
00020 #include "RooAddPdf.h"
00021 #include "RooMCStudy.h"
00022 #include "RooChi2MCSModule.h"
00023 #include "RooPlot.h"
00024 #include "TCanvas.h"
00025 #include "TAxis.h"
00026 #include "TH1.h"
00027 #include "TDirectory.h"
00028 
00029 using namespace RooFit ;
00030 
00031 
00032 void rf802_mcstudy_addons()
00033 {
00034 
00035   // C r e a t e   m o d e l 
00036   // -----------------------
00037 
00038   // Observables, parameters
00039   RooRealVar x("x","x",-10,10) ;
00040   x.setBins(10) ;
00041   RooRealVar mean("mean","mean of gaussian",0) ;
00042   RooRealVar sigma("sigma","width of gaussian",5,1,10) ;
00043 
00044   // Create Gaussian pdf
00045   RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;  
00046 
00047 
00048 
00049   // C r e a t e   m a n a g e r  w i t h   c h i ^ 2   a d d - o n   m o d u l e
00050   // ----------------------------------------------------------------------------
00051 
00052   // Create study manager for binned likelihood fits of a Gaussian pdf in 10 bins
00053   RooMCStudy* mcs = new RooMCStudy(gauss,x,Silence(),Binned()) ;
00054 
00055   // Add chi^2 calculator module to mcs
00056   RooChi2MCSModule chi2mod ;
00057   mcs->addModule(chi2mod) ;
00058 
00059   // Generate 1000 samples of 1000 events
00060   mcs->generateAndFit(2000,1000) ;
00061   
00062   // Fill histograms with distributions chi2 and prob(chi2,ndf) that
00063   // are calculated by RooChiMCSModule
00064   TH1* hist_chi2 = mcs->fitParDataSet().createHistogram("chi2") ; 
00065   TH1* hist_prob = mcs->fitParDataSet().createHistogram("prob") ;   
00066 
00067 
00068 
00069   // C r e a t e   m a n a g e r  w i t h   s e p a r a t e   f i t   m o d e l 
00070   // ----------------------------------------------------------------------------
00071 
00072   // Create alternate pdf with shifted mean
00073   RooRealVar mean2("mean2","mean of gaussian 2",0.5) ;
00074   RooGaussian gauss2("gauss2","gaussian PDF2",x,mean2,sigma) ;  
00075 
00076   // Create study manager with separate generation and fit model. This configuration
00077   // is set up to generate bad fits as the fit and generator model have different means
00078   // and the mean parameter is not floating in the fit
00079   RooMCStudy* mcs2 = new RooMCStudy(gauss2,x,FitModel(gauss),Silence(),Binned()) ;
00080 
00081   // Add chi^2 calculator module to mcs
00082   RooChi2MCSModule chi2mod2 ;
00083   mcs2->addModule(chi2mod2) ;
00084 
00085   // Generate 1000 samples of 1000 events
00086   mcs2->generateAndFit(2000,1000) ;
00087   
00088   // Fill histograms with distributions chi2 and prob(chi2,ndf) that
00089   // are calculated by RooChiMCSModule
00090   TH1* hist2_chi2 = mcs2->fitParDataSet().createHistogram("chi2") ; 
00091   TH1* hist2_prob = mcs2->fitParDataSet().createHistogram("prob") ;   
00092   hist2_chi2->SetLineColor(kRed) ;
00093   hist2_prob->SetLineColor(kRed) ;
00094 
00095   
00096 
00097   TCanvas* c = new TCanvas("rf802_mcstudy_addons","rf802_mcstudy_addons",800,400) ;
00098   c->Divide(2) ;
00099   c->cd(1) ; gPad->SetLeftMargin(0.15) ; hist_chi2->GetYaxis()->SetTitleOffset(1.4) ; hist_chi2->Draw() ; hist2_chi2->Draw("esame") ;
00100   c->cd(2) ; gPad->SetLeftMargin(0.15) ; hist_prob->GetYaxis()->SetTitleOffset(1.4) ; hist_prob->Draw() ; hist2_prob->Draw("esame") ;
00101 
00102 
00103   
00104   // Make RooMCStudy object available on command line after
00105   // macro finishes
00106   gDirectory->Add(mcs) ;
00107 }

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