Logo ROOT  
Reference Guide
rf512_wsfactory_oper.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -nodraw
4 ///
5 /// Organization and simultaneous fits: operator expressions and expression-based basic
6 /// p.d.f.s in the workspace factory syntax
7 ///
8 /// \macro_output
9 /// \macro_code
10 ///
11 /// \date 04/2009
12 /// \author Wouter Verkerke
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooChebychev.h"
19 #include "RooAddPdf.h"
20 #include "RooWorkspace.h"
21 #include "RooPlot.h"
22 #include "TCanvas.h"
23 #include "TAxis.h"
24 using namespace RooFit;
25 
26 void rf512_wsfactory_oper()
27 {
28  RooWorkspace *w = new RooWorkspace("w");
29 
30  // You can define typedefs for even shorter construction semantics
31  w->factory("$Typedef(Gaussian,Gaus)");
32  w->factory("$Typedef(Chebychev,Cheby)");
33 
34  // O p e r a t o r p . d . f . e x a m p l e s
35  // ------------------------------------------------
36 
37  // PDF addition is done with SUM (coef1*pdf1,pdf2)
38  w->factory("SUM::summodel( f[0,1]*Gaussian::gx(x[-10,10],m[0],1.0), Chebychev::ch(x,{0.1,0.2,-0.3}) )");
39 
40  // Extended PDF addition is done with SUM (yield1*pdf1,yield2*pdf2)
41  w->factory("SUM::extsummodel( Nsig[0,1000]*gx, Nbkg[0,1000]*ch )");
42 
43  // PDF multiplication is done with PROD ( pdf1, pdf2 )
44  w->factory("PROD::gxz( gx, Gaussian::gz(z[-10,10],0,1) )");
45 
46  // Conditional p.d.f multiplication is done with PROD ( pdf1|obs, pdf2 )
47  w->factory("Gaussian::gy( y[-10,10], x, 1.0 )");
48  w->factory("PROD::gxycond( gy|x, gx )");
49 
50  // Convolution (numeric/ fft) is done with NCONV/FCONV (obs,pdf1,pdf2)
51  w->factory("FCONV::lxg( x, Gaussian::g(x,mg[0],1), Landau::lc(x,0,1) )");
52 
53  // Simultaneous p.d.f.s are constructed with SIMUL( index, state1=pdf1, state2=pdf2,...)
54  w->factory("SIMUL::smodel( c[A=0,B=1], A=Gaussian::gs(x,m,s[1]), B=Landau::ls(x,0,1) )");
55 
56  // O p e r a t o r f u n c t i o n e x a m p l e s
57  // ---------------------------------------------------
58 
59  // Function multiplication is done with prod (func1, func2,...)
60  w->factory("prod::uv(u[10],v[10])");
61 
62  // Function addition is done with sum(func1,func2)
63  w->factory("sum::uv2(u,v)");
64 
65  // I n t e r p r e t e d a n d c o m p i l e d e x p r e s s i o n b a s e d p . d . f . s .
66  // ---------------------------------------------------------------------------------------------------
67 
68  // Create a RooGenericPdf interpreted p.d.f. You can use single quotes to pass the expression string argument
69  w->factory("EXPR::G('x*x+1',x)");
70 
71  // Create a custom compiled p.d.f similar to the above interpreted p.d.f.
72  // The code required to make this p.d.f. is automatically embedded in the workspace
73  w->factory("CEXPR::GC('x*x+a',{x,a[1]})");
74 
75  // Compiled and interpreted functions (rather than p.d.f.s) can be made with the lower case
76  // 'expr' and 'cexpr' types
77 
78  // Print workspace contents
79  w->Print();
80 
81  // Make workspace visible on command line
82  gDirectory->Add(w);
83 }
RooWorkspace.h
RooChebychev.h
RooGaussian.h
RooAddPdf.h
TCanvas.h
RooDataSet.h
RooWorkspace::factory
RooFactoryWSTool & factory()
Return instance to factory tool.
Definition: RooWorkspace.cxx:2166
RooWorkspace::Print
void Print(Option_t *opts=0) const
Print contents of the workspace.
Definition: RooWorkspace.cxx:2194
RooFit
Definition: RooCFunction1Binding.h:29
RooPlot.h
gDirectory
#define gDirectory
Definition: TDirectory.h:236
RooRealVar.h
RooConstVar.h
RooWorkspace
Definition: RooWorkspace.h:43
TAxis.h