00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #ifndef __CINT__
00012 #include "RooGlobalFunc.h"
00013 #endif
00014 #include "RooRealVar.h"
00015 #include "RooDataSet.h"
00016 #include "RooGaussian.h"
00017 #include "RooConstVar.h"
00018 #include "RooChebychev.h"
00019 #include "RooAddPdf.h"
00020 #include "RooMCStudy.h"
00021 #include "RooPlot.h"
00022 #include "TCanvas.h"
00023 #include "TAxis.h"
00024 #include "TH2.h"
00025 #include "RooFitResult.h"
00026 #include "TStyle.h"
00027 #include "TDirectory.h"
00028 
00029 using namespace RooFit ;
00030 
00031 
00032 void rf801_mcstudy()
00033 {
00034   
00035   
00036 
00037   
00038   RooRealVar x("x","x",0,10) ;
00039   x.setBins(40) ;
00040 
00041   
00042   RooRealVar mean("mean","mean of gaussians",5,0,10) ;
00043   RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
00044   RooRealVar sigma2("sigma2","width of gaussians",1) ;
00045 
00046   RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;  
00047   RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;  
00048   
00049   
00050   RooRealVar a0("a0","a0",0.5,0.,1.) ;
00051   RooRealVar a1("a1","a1",-0.2,-1,1.) ;
00052   RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
00053 
00054   
00055   RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00056   RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00057 
00058   
00059   RooRealVar nbkg("nbkg","number of background events,",150,0,1000) ;
00060   RooRealVar nsig("nsig","number of signal events",150,0,1000) ;
00061   RooAddPdf  model("model","g1+g2+a",RooArgList(bkg,sig),RooArgList(nbkg,nsig)) ;
00062 
00063 
00064 
00065   
00066   
00067 
00068   
00069   
00070   
00071   
00072   
00073   
00074   
00075   
00076   
00077   
00078   
00079   
00080   
00081   
00082 
00083   RooMCStudy* mcstudy = new RooMCStudy(model,x,Binned(kTRUE),Silence(),Extended(),
00084                                        FitOptions(Save(kTRUE),PrintEvalErrors(0))) ;
00085   
00086 
00087   
00088   
00089 
00090   
00091   mcstudy->generateAndFit(1000) ;
00092 
00093 
00094 
00095   
00096   
00097 
00098   
00099   RooPlot* frame1 = mcstudy->plotParam(mean,Bins(40)) ;
00100   RooPlot* frame2 = mcstudy->plotError(mean,Bins(40)) ;
00101   RooPlot* frame3 = mcstudy->plotPull(mean,Bins(40),FitGauss(kTRUE)) ;
00102 
00103   
00104   RooPlot* frame4 = mcstudy->plotNLL(Bins(40)) ;
00105 
00106   
00107   TH1* hh_cor_a0_s1f = mcstudy->fitParDataSet().createHistogram("hh",a1,YVar(sig1frac)) ;
00108   TH1* hh_cor_a0_a1  = mcstudy->fitParDataSet().createHistogram("hh",a0,YVar(a1)) ;
00109 
00110   
00111   TH2* corrHist000 = mcstudy->fitResult(0)->correlationHist("c000") ;
00112   TH2* corrHist127 = mcstudy->fitResult(127)->correlationHist("c127") ;
00113   TH2* corrHist953 = mcstudy->fitResult(953)->correlationHist("c953") ;
00114 
00115 
00116 
00117   
00118   gStyle->SetPalette(1) ;
00119   gStyle->SetOptStat(0) ;
00120   TCanvas* c = new TCanvas("rf801_mcstudy","rf801_mcstudy",900,900) ;
00121   c->Divide(3,3) ;
00122   c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
00123   c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
00124   c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.4) ; frame3->Draw() ;
00125   c->cd(4) ; gPad->SetLeftMargin(0.15) ; frame4->GetYaxis()->SetTitleOffset(1.4) ; frame4->Draw() ;
00126   c->cd(5) ; gPad->SetLeftMargin(0.15) ; hh_cor_a0_s1f->GetYaxis()->SetTitleOffset(1.4) ; hh_cor_a0_s1f->Draw("box") ;
00127   c->cd(6) ; gPad->SetLeftMargin(0.15) ; hh_cor_a0_a1->GetYaxis()->SetTitleOffset(1.4) ; hh_cor_a0_a1->Draw("box") ;
00128   c->cd(7) ; gPad->SetLeftMargin(0.15) ; corrHist000->GetYaxis()->SetTitleOffset(1.4) ; corrHist000->Draw("colz") ;
00129   c->cd(8) ; gPad->SetLeftMargin(0.15) ; corrHist127->GetYaxis()->SetTitleOffset(1.4) ; corrHist127->Draw("colz") ;
00130   c->cd(9) ; gPad->SetLeftMargin(0.15) ; corrHist953->GetYaxis()->SetTitleOffset(1.4) ; corrHist953->Draw("colz") ;
00131 
00132   
00133   
00134   gDirectory->Add(mcstudy) ;
00135 }