rf599_wspacepersist.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #501
00004 // 
00005 // Using simultaneous p.d.f.s to describe simultaneous fits to multiple
00006 // datasets
00007 //
00008 //
00009 //
00010 // 07/2008 - Wouter Verkerke 
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       // Build Gaussian PDF in X
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       // Build Gaussian PDF in Y
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       // Make product of X and Y
00059       RooProdPdf gaussxy("gaussxy","gaussx*gaussy",RooArgSet(gaussx,gaussy)) ;
00060 
00061       // Make flat bkg in X and Y
00062       RooPolynomial flatx("flatx","flatx",x) ;
00063       RooPolynomial flaty("flaty","flaty",x) ;
00064       RooProdPdf flatxy("flatxy","flatx*flaty",RooArgSet(flatx,flaty)) ;
00065 
00066       // Make sum of gaussxy and flatxy
00067       RooRealVar frac("frac","frac",0.5,0.,1.) ;
00068       RooAddPdf sumxy("sumxy","sumxy",RooArgList(gaussxy,flatxy),frac) ;
00069 
00070       // Store p.d.f in workspace
00071       w->import(gaussx) ;
00072       w->import(gaussxy,RenameConflictNodes("set2")) ;
00073       w->import(sumxy,RenameConflictNodes("set3")) ;
00074 
00075       // Make reference plot of GaussX
00076       RooPlot* frame1 = x.frame() ;
00077       gaussx.plotOn(frame1) ;
00078       regPlot(frame1,"Basic11_gaussx_framex") ;
00079       
00080       // Make reference plots for GaussXY
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       // Make reference plots for SumXY
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       // Analytically convolved p.d.f.s
00099 
00100       // Build a simple decay PDF
00101       RooRealVar dt("dt","dt",-20,20) ;
00102       RooRealVar tau("tau","tau",1.548) ;
00103       
00104       // Build a gaussian resolution model
00105       RooRealVar bias1("bias1","bias1",0) ;
00106       RooRealVar sigma1("sigma1","sigma1",1) ;
00107       RooGaussModel gm1("gm1","gauss model 1",dt,bias1,sigma1) ;
00108       
00109       // Construct a decay PDF, smeared with single gaussian resolution model
00110       RooDecay decay_gm1("decay_gm1","decay",dt,tau,gm1,RooDecay::DoubleSided) ;
00111           
00112       // Build another gaussian resolution model
00113       RooRealVar bias2("bias2","bias2",0) ;
00114       RooRealVar sigma2("sigma2","sigma2",5) ;
00115       RooGaussModel gm2("gm2","gauss model 2",dt,bias2,sigma2) ;
00116       
00117       // Build a composite resolution model
00118       RooRealVar gm1frac("gm1frac","fraction of gm1",0.5) ;
00119       RooAddModel gmsum("gmsum","sum of gm1 and gm2",RooArgList(gm1,gm2),gm1frac) ;
00120     
00121       // Construct a decay PDF, smeared with double gaussian resolution model
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       // Construct simultaneous p.d.f
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       // Make plot with dummy dataset for index projection
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       // Retrieve p.d.f from workspace
00164       RooAbsPdf* gaussx = w->pdf("gaussx") ;
00165 
00166       // Make test plot and offer for comparison against ref plot
00167       RooPlot* frame1 = w->var("x")->frame() ;
00168       gaussx->plotOn(frame1) ;
00169       regPlot(frame1,"Basic11_gaussx_framex") ;
00170       
00171       // Retrieve p.d.f from workspace
00172       RooAbsPdf* gaussxy = w->pdf("gaussxy") ;
00173 
00174       // Make test plot and offer for comparison against ref plot
00175       RooPlot* frame2 = w->var("x")->frame() ;
00176       gaussxy->plotOn(frame2) ;
00177       regPlot(frame2,"Basic11_gaussxy_framex") ;
00178 
00179       // Make test plot and offer for comparison against ref plot
00180       RooPlot* frame3 = w->var("y")->frame() ;
00181       gaussxy->plotOn(frame3) ;
00182       regPlot(frame3,"Basic11_gaussxy_framey") ;
00183 
00184       // Retrieve p.d.f from workspace
00185       RooAbsPdf* sumxy = w->pdf("sumxy") ;
00186 
00187       // Make test plot and offer for comparison against ref plot
00188       RooPlot* frame4 = w->var("x")->frame() ;
00189       sumxy->plotOn(frame4) ;
00190       regPlot(frame4,"Basic11_sumxy_framex") ;
00191 
00192       // Make test plot and offer for comparison against ref plot
00193       RooPlot* frame5 = w->var("y")->frame() ;
00194       sumxy->plotOn(frame5) ;
00195       regPlot(frame5,"Basic11_sumxy_framey") ;
00196 
00197       // Retrieve p.d.f from workspace
00198       RooAbsPdf* decay_gm1 = w->pdf("decay_gm1") ;
00199 
00200       // Make test plot and offer for comparison against ref plot
00201       RooPlot* frame6 = w->var("dt")->frame() ;
00202       decay_gm1->plotOn(frame6) ;
00203       regPlot(frame6,"Basic11_decay_gm1_framedt") ;
00204 
00205       // Retrieve p.d.f from workspace
00206       RooAbsPdf* decay_gmsum = w->pdf("decay_gmsum") ;
00207 
00208       // Make test plot and offer for comparison against ref plot
00209       RooPlot* frame7 = w->var("dt")->frame() ;
00210       decay_gmsum->plotOn(frame7) ;
00211       regPlot(frame7,"Basic11_decay_gmsum_framedt") ;
00212 
00213       // Retrieve p.d.f. from workspace
00214       RooAbsPdf* sim = w->pdf("sim") ;
00215       RooCategory* cat = w->cat("cat") ;
00216 
00217       // Make plot with dummy dataset for index projection
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     // "Workspace persistence"
00233     return kTRUE ;
00234   }
00235 } ;

Generated on Tue Jul 5 15:07:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1