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