00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __CINT__
00015 #include "RooGlobalFunc.h"
00016 #endif
00017 #include "RooWorkspace.h"
00018 #include "RooProdPdf.h"
00019 #include "RooRealVar.h"
00020 #include "RooDataSet.h"
00021 #include "RooGaussian.h"
00022 #include "RooGaussModel.h"
00023 #include "RooAddModel.h"
00024 #include "RooDecay.h"
00025 #include "RooChebychev.h"
00026 #include "RooAddPdf.h"
00027 #include "RooSimultaneous.h"
00028 #include "RooCategory.h"
00029 #include "TCanvas.h"
00030 #include "RooPlot.h"
00031 using namespace RooFit ;
00032
00033
00034 class TestBasic599 : public RooFitTestUnit
00035 {
00036 public:
00037 TestBasic599(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Workspace and p.d.f. persistence",refFile,writeRef,verbose) {} ;
00038 Bool_t testCode() {
00039
00040 if (_write) {
00041
00042 RooWorkspace *w = new RooWorkspace("TestBasic11_ws") ;
00043
00044 regWS(w,"Basic11_ws") ;
00045
00046
00047 RooRealVar x("x","x",-10,10) ;
00048 RooRealVar meanx("meanx","mean of gaussian",-1) ;
00049 RooRealVar sigmax("sigmax","width of gaussian",3) ;
00050 RooGaussian gaussx("gaussx","gaussian PDF",x,meanx,sigmax) ;
00051
00052
00053 RooRealVar y("y","y",-10,10) ;
00054 RooRealVar meany("meany","mean of gaussian",-1) ;
00055 RooRealVar sigmay("sigmay","width of gaussian",3) ;
00056 RooGaussian gaussy("gaussy","gaussian PDF",y,meany,sigmay) ;
00057
00058
00059 RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgSet(gaussx,gaussy)) ;
00060
00061
00062 RooPolynomial flatx("flatx","flatx",x) ;
00063 RooPolynomial flaty("flaty","flaty",x) ;
00064 RooProdPdf flatxy("flatxy","flatx*flaty",RooArgSet(flatx,flaty)) ;
00065
00066
00067 RooRealVar frac("frac","frac",0.5,0.,1.) ;
00068 RooAddPdf sumxy("sumxy","sumxy",RooArgList(gaussxy,flatxy),frac) ;
00069
00070
00071 w->import(gaussx) ;
00072 w->import(gaussxy,RenameConflictNodes("set2")) ;
00073 w->import(sumxy,RenameConflictNodes("set3")) ;
00074
00075
00076 RooPlot* frame1 = x.frame() ;
00077 gaussx.plotOn(frame1) ;
00078 regPlot(frame1,"Basic11_gaussx_framex") ;
00079
00080
00081 RooPlot* frame2 = x.frame() ;
00082 gaussxy.plotOn(frame2) ;
00083 regPlot(frame2,"Basic11_gaussxy_framex") ;
00084
00085 RooPlot* frame3 = y.frame() ;
00086 gaussxy.plotOn(frame3) ;
00087 regPlot(frame3,"Basic11_gaussxy_framey") ;
00088
00089
00090 RooPlot* frame4 = x.frame() ;
00091 sumxy.plotOn(frame4) ;
00092 regPlot(frame4,"Basic11_sumxy_framex") ;
00093
00094 RooPlot* frame5 = y.frame() ;
00095 sumxy.plotOn(frame5) ;
00096 regPlot(frame5,"Basic11_sumxy_framey") ;
00097
00098
00099
00100
00101 RooRealVar dt("dt","dt",-20,20) ;
00102 RooRealVar tau("tau","tau",1.548) ;
00103
00104
00105 RooRealVar bias1("bias1","bias1",0) ;
00106 RooRealVar sigma1("sigma1","sigma1",1) ;
00107 RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
00108
00109
00110 RooDecay decay_gm1("decay_gm1","decay",dt,tau,gm1,RooDecay::DoubleSided) ;
00111
00112
00113 RooRealVar bias2("bias2","bias2",0) ;
00114 RooRealVar sigma2("sigma2","sigma2",5) ;
00115 RooGaussModel gm2("gm2","gauss model 2",dt,bias2,sigma2) ;
00116
00117
00118 RooRealVar gm1frac("gm1frac","fraction of gm1",0.5) ;
00119 RooAddModel gmsum("gmsum","sum of gm1 and gm2",RooArgList(gm1,gm2),gm1frac) ;
00120
00121
00122 RooDecay decay_gmsum("decay_gmsum","decay",dt,tau,gmsum,RooDecay::DoubleSided) ;
00123
00124 w->import(decay_gm1) ;
00125 w->import(decay_gmsum,RenameConflictNodes("set3")) ;
00126
00127 RooPlot* frame6 = dt.frame() ;
00128 decay_gm1.plotOn(frame6) ;
00129 regPlot(frame6,"Basic11_decay_gm1_framedt") ;
00130
00131 RooPlot* frame7 = dt.frame() ;
00132 decay_gmsum.plotOn(frame7) ;
00133 regPlot(frame7,"Basic11_decay_gmsum_framedt") ;
00134
00135
00136 RooCategory cat("cat","cat") ;
00137 cat.defineType("A") ;
00138 cat.defineType("B") ;
00139 RooSimultaneous sim("sim","sim",cat) ;
00140 sim.addPdf(gaussxy,"A") ;
00141 sim.addPdf(flatxy,"B") ;
00142
00143 w->import(sim,RenameConflictNodes("set4")) ;
00144
00145
00146 RooDataHist dh("dh","dh",cat) ;
00147 cat.setLabel("A") ;
00148 dh.add(cat) ;
00149 cat.setLabel("B") ;
00150 dh.add(cat) ;
00151
00152 RooPlot* frame8 = x.frame() ;
00153 sim.plotOn(frame8,ProjWData(cat,dh),Project(cat)) ;
00154
00155 regPlot(frame8,"Basic11_sim_framex") ;
00156
00157
00158 } else {
00159
00160 RooWorkspace* w = getWS("Basic11_ws") ;
00161 if (!w) return kFALSE ;
00162
00163
00164 RooAbsPdf* gaussx = w->pdf("gaussx") ;
00165
00166
00167 RooPlot* frame1 = w->var("x")->frame() ;
00168 gaussx->plotOn(frame1) ;
00169 regPlot(frame1,"Basic11_gaussx_framex") ;
00170
00171
00172 RooAbsPdf* gaussxy = w->pdf("gaussxy") ;
00173
00174
00175 RooPlot* frame2 = w->var("x")->frame() ;
00176 gaussxy->plotOn(frame2) ;
00177 regPlot(frame2,"Basic11_gaussxy_framex") ;
00178
00179
00180 RooPlot* frame3 = w->var("y")->frame() ;
00181 gaussxy->plotOn(frame3) ;
00182 regPlot(frame3,"Basic11_gaussxy_framey") ;
00183
00184
00185 RooAbsPdf* sumxy = w->pdf("sumxy") ;
00186
00187
00188 RooPlot* frame4 = w->var("x")->frame() ;
00189 sumxy->plotOn(frame4) ;
00190 regPlot(frame4,"Basic11_sumxy_framex") ;
00191
00192
00193 RooPlot* frame5 = w->var("y")->frame() ;
00194 sumxy->plotOn(frame5) ;
00195 regPlot(frame5,"Basic11_sumxy_framey") ;
00196
00197
00198 RooAbsPdf* decay_gm1 = w->pdf("decay_gm1") ;
00199
00200
00201 RooPlot* frame6 = w->var("dt")->frame() ;
00202 decay_gm1->plotOn(frame6) ;
00203 regPlot(frame6,"Basic11_decay_gm1_framedt") ;
00204
00205
00206 RooAbsPdf* decay_gmsum = w->pdf("decay_gmsum") ;
00207
00208
00209 RooPlot* frame7 = w->var("dt")->frame() ;
00210 decay_gmsum->plotOn(frame7) ;
00211 regPlot(frame7,"Basic11_decay_gmsum_framedt") ;
00212
00213
00214 RooAbsPdf* sim = w->pdf("sim") ;
00215 RooCategory* cat = w->cat("cat") ;
00216
00217
00218 RooPlot* frame8 = w->var("x")->frame() ;
00219
00220 RooDataHist dh("dh","dh",*cat) ;
00221 cat->setLabel("A") ;
00222 dh.add(*cat) ;
00223 cat->setLabel("B") ;
00224 dh.add(*cat) ;
00225
00226 sim->plotOn(frame8,ProjWData(*cat,dh),Project(*cat)) ;
00227
00228 regPlot(frame8,"Basic11_sim_framex") ;
00229
00230 }
00231
00232
00233 return kTRUE ;
00234 }
00235 } ;