rf504_simwstool.C

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #504
00004 // 
00005 // Using RooSimWSTool to construct a simultaneous p.d.f that is built
00006 // of variations of an input p.d.f
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 //
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooCategory.h"
00018 #include "RooDataSet.h"
00019 #include "RooGaussian.h"
00020 #include "RooConstVar.h"
00021 #include "RooPolynomial.h"
00022 #include "RooSimultaneous.h"
00023 #include "RooAddPdf.h"
00024 #include "RooWorkspace.h"
00025 #include "RooSimWSTool.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 rf504_simwstool()
00035 {
00036   // C r e a t e   m a s t e r   p d f 
00037   // ---------------------------------
00038   
00039   // Construct gauss(x,m,s)
00040   RooRealVar x("x","x",-10,10) ;
00041   RooRealVar m("m","m",0,-10,10) ;
00042   RooRealVar s("s","s",1,-10,10) ;
00043   RooGaussian gauss("g","g",x,m,s) ;
00044 
00045   // Construct poly(x,p0)
00046   RooRealVar p0("p0","p0",0.01,0.,1.) ;
00047   RooPolynomial poly("p","p",x,p0) ;             
00048 
00049   // Construct model = f*gauss(x) + (1-f)*poly(x)
00050   RooRealVar f("f","f",0.5,0.,1.) ;
00051   RooAddPdf model("model","model",RooArgSet(gauss,poly),f) ;
00052 
00053 
00054 
00055   // C r e a t e   c a t e g o r y   o b s e r v a b l e s   f o r   s p l i t t i n g
00056   // ----------------------------------------------------------------------------------
00057 
00058   // Define two categories that can be used for splitting
00059   RooCategory c("c","c") ;
00060   c.defineType("run1") ;
00061   c.defineType("run2") ;
00062 
00063   RooCategory d("d","d") ;
00064   d.defineType("foo") ;
00065   d.defineType("bar") ;
00066 
00067 
00068 
00069   // S e t u p   S i m W S T o o l 
00070   // -----------------------------
00071 
00072   // Import ingredients in a workspace
00073   RooWorkspace w("w","w") ;
00074   w.import(RooArgSet(model,c,d)) ;
00075 
00076   // Make Sim builder tool
00077   RooSimWSTool sct(w) ;
00078 
00079 
00080   // B u i l d   a   s i m u l t a n e o u s   m o d e l   w i t h   o n e   s p l i t
00081   // ---------------------------------------------------------------------------------
00082 
00083   // Construct a simultaneous p.d.f with the following form
00084   //
00085   // model_run1(x) = f*gauss_run1(x,m_run1,s) + (1-f)*poly
00086   // model_run2(x) = f*gauss_run2(x,m_run2,s) + (1-f)*poly
00087   // simpdf(x,c) = model_run1(x) if c=="run1"
00088   //             = model_run2(x) if c=="run2"
00089   //
00090   // Returned p.d.f is owned by the workspace
00091   RooSimultaneous* model_sim = sct.build("model_sim","model",SplitParam("m","c")) ;
00092 
00093   // Print tree structure of model
00094   model_sim->Print("t") ;
00095 
00096   // Adjust model_sim parameters in workspace
00097   w.var("m_run1")->setVal(-3) ;
00098   w.var("m_run2")->setVal(+3) ;
00099 
00100   // Print contents of workspace
00101   w.Print("v") ;
00102 
00103 
00104 
00105   // B u i l d   a   s i m u l t a n e o u s   m o d e l   w i t h   p r o d u c t   s p l i t
00106   // -----------------------------------------------------------------------------------------
00107 
00108   // Build another simultaneous p.d.f using a composite split in states c X d
00109   RooSimultaneous* model_sim2 = sct.build("model_sim2","model",SplitParam("p0","c,d")) ;
00110 
00111   // Print tree structure of this model
00112   model_sim2->Print("t") ;
00113 
00114 }

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