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 "RooPolynomial.h"
00020 #include "RooAddPdf.h"
00021 #include "RooProdPdf.h"
00022 #include "RooMCStudy.h"
00023 #include "RooPlot.h"
00024 #include "TCanvas.h"
00025 #include "TAxis.h"
00026 #include "TH1.h"
00027 using namespace RooFit ;
00028
00029
00030 void rf804_mcstudy_constr()
00031 {
00032
00033
00034
00035
00036 RooRealVar x("x","x",-10,10) ;
00037
00038
00039 RooRealVar m("m","m",0,-10,10) ;
00040 RooRealVar s("s","s",2,0.1,10) ;
00041 RooGaussian g("g","g",x,m,s) ;
00042
00043
00044 RooPolynomial p("p","p",x) ;
00045
00046
00047 RooRealVar f("f","f",0.4,0.,1.) ;
00048 RooAddPdf sum("sum","sum",RooArgSet(g,p),f) ;
00049
00050
00051 RooGaussian fconstraint("fconstraint","fconstraint",f,RooConst(0.7),RooConst(0.1)) ;
00052
00053
00054 RooProdPdf sumc("sumc","sum with constraint",RooArgSet(sum,fconstraint)) ;
00055
00056
00057
00058
00059
00060
00061
00062 RooMCStudy mcs(sumc,x,Constrain(f),Silence(),Binned(),FitOptions(PrintLevel(-1))) ;
00063
00064
00065
00066
00067 mcs.generateAndFit(500,2000) ;
00068
00069
00070 TH1* h_f_gen = mcs.fitParDataSet().createHistogram("f_gen",-40) ;
00071
00072
00073 RooPlot* frame1 = mcs.plotParam(f,Bins(40)) ;
00074 frame1->SetTitle("Distribution of fitted f values") ;
00075
00076
00077 RooPlot* frame2 = mcs.plotPull(f,Bins(40),FitGauss()) ;
00078 frame1->SetTitle("Distribution of f pull values") ;
00079
00080
00081
00082 TCanvas* c = new TCanvas("rf804_mcstudy_constr","rf804_mcstudy_constr",1200,400) ;
00083 c->Divide(3) ;
00084 c->cd(1) ; gPad->SetLeftMargin(0.15) ; h_f_gen->GetYaxis()->SetTitleOffset(1.4) ; h_f_gen->Draw() ;
00085 c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
00086 c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ;
00087
00088 }
00089