00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __CINT__
00017 #include "RooGlobalFunc.h"
00018 #endif
00019 #include "RooRealVar.h"
00020 #include "RooDataSet.h"
00021 #include "RooGaussian.h"
00022 #include "RooConstVar.h"
00023 #include "RooChebychev.h"
00024 #include "RooAddPdf.h"
00025 #include "RooWorkspace.h"
00026 #include "RooPlot.h"
00027 #include "TCanvas.h"
00028 #include "TAxis.h"
00029 #include "TFile.h"
00030 #include "TH1.h"
00031 using namespace RooFit ;
00032
00033
00034 void fillWorkspace(RooWorkspace& w) ;
00035
00036 void rf509_wsinteractive()
00037 {
00038
00039
00040
00041
00042
00043 RooWorkspace* w = new RooWorkspace("w",kTRUE) ;
00044
00045
00046 fillWorkspace(*w) ;
00047
00048
00049 w->Print() ;
00050
00051
00052
00053
00054
00055 RooDataSet* d = w::model.generate(w::x,1000) ;
00056 RooFitResult* r = w::model.fitTo(*d) ;
00057
00058 RooPlot* frame = w::x.frame() ;
00059 d->plotOn(frame) ;
00060
00061
00062
00063
00064 using namespace w;
00065 model.plotOn(frame) ;
00066 model.plotOn(frame,Components(bkg),LineStyle(kDashed)) ;
00067
00068
00069
00070 new TCanvas("rf509_wsinteractive","rf509_wsinteractive",600,600) ;
00071 gPad->SetLeftMargin(0.15) ; frame->GetYaxis()->SetTitleOffset(1.4) ; frame->Draw() ;
00072
00073
00074 }
00075
00076
00077
00078
00079 void fillWorkspace(RooWorkspace& w)
00080 {
00081
00082
00083
00084
00085 RooRealVar x("x","x",0,10) ;
00086
00087
00088 RooRealVar mean("mean","mean of gaussians",5,0,10) ;
00089 RooRealVar sigma1("sigma1","width of gaussians",0.5) ;
00090 RooRealVar sigma2("sigma2","width of gaussians",1) ;
00091
00092 RooGaussian sig1("sig1","Signal component 1",x,mean,sigma1) ;
00093 RooGaussian sig2("sig2","Signal component 2",x,mean,sigma2) ;
00094
00095
00096 RooRealVar a0("a0","a0",0.5,0.,1.) ;
00097 RooRealVar a1("a1","a1",-0.2,0.,1.) ;
00098 RooChebychev bkg("bkg","Background",x,RooArgSet(a0,a1)) ;
00099
00100
00101 RooRealVar sig1frac("sig1frac","fraction of component 1 in signal",0.8,0.,1.) ;
00102 RooAddPdf sig("sig","Signal",RooArgList(sig1,sig2),sig1frac) ;
00103
00104
00105 RooRealVar bkgfrac("bkgfrac","fraction of background",0.5,0.,1.) ;
00106 RooAddPdf model("model","g1+g2+a",RooArgList(bkg,sig),bkgfrac) ;
00107
00108 w.import(model) ;
00109
00110 }