00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
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   
00036   
00037 
00038   
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   
00045   RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;  
00046 
00047 
00048 
00049   
00050   
00051 
00052   
00053   RooMCStudy* mcs = new RooMCStudy(gauss,x,Silence(),Binned()) ;
00054 
00055   
00056   RooChi2MCSModule chi2mod ;
00057   mcs->addModule(chi2mod) ;
00058 
00059   
00060   mcs->generateAndFit(2000,1000) ;
00061   
00062   
00063   
00064   TH1* hist_chi2 = mcs->fitParDataSet().createHistogram("chi2") ; 
00065   TH1* hist_prob = mcs->fitParDataSet().createHistogram("prob") ;   
00066 
00067 
00068 
00069   
00070   
00071 
00072   
00073   RooRealVar mean2("mean2","mean of gaussian 2",0.5) ;
00074   RooGaussian gauss2("gauss2","gaussian PDF2",x,mean2,sigma) ;  
00075 
00076   
00077   
00078   
00079   RooMCStudy* mcs2 = new RooMCStudy(gauss2,x,FitModel(gauss),Silence(),Binned()) ;
00080 
00081   
00082   RooChi2MCSModule chi2mod2 ;
00083   mcs2->addModule(chi2mod2) ;
00084 
00085   
00086   mcs2->generateAndFit(2000,1000) ;
00087   
00088   
00089   
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   
00105   
00106   gDirectory->Add(mcs) ;
00107 }