Logo ROOT  
Reference Guide
rf512_wsfactory_oper.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_roofit
3## \notebook
4##
5## 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #512
6##
7## Illustration of operator expressions and expression-based
8## basic p.d.f.s in the workspace factory syntax
9##
10## \macro_code
11##
12## \date February 2018
13## \author Clemens Lange
14## \author Wouter Verkerke (C version)
15
16
17import ROOT
18
19
20w = ROOT.RooWorkspace("w")
21
22# You can define typedefs for even shorter construction semantics
23w.factory("$Typedef(Gaussian,Gaus)")
24w.factory("$Typedef(Chebychev,Cheby)")
25
26# Operator pdf examples
27# ------------------------------------------------
28
29# PDF addition is done with SUM (coef1*pdf1,pdf2)
30w.factory("SUM::summodel( f[0,1]*Gaussian::gx(x[-10,10],m[0],1.0), Chebychev::ch(x,{0.1,0.2,-0.3}) )")
31
32# Extended PDF addition is done with SUM (yield1*pdf1,yield2*pdf2)
33w.factory("SUM::extsummodel( Nsig[0,1000]*gx, Nbkg[0,1000]*ch )")
34
35# PDF multiplication is done with PROD ( pdf1, pdf2 )
36w.factory("PROD::gxz( gx, Gaussian::gz(z[-10,10],0,1) )")
37
38# Conditional p.d.f multiplication is done with PROD ( pdf1|obs, pdf2 )
39w.factory("Gaussian::gy( y[-10,10], x, 1.0 )")
40w.factory("PROD::gxycond( gy|x, gx )")
41
42# Convolution (numeric/ fft) is done with NCONV/FCONV (obs,pdf1,pdf2)
43w.factory("FCONV::lxg( x, Gaussian::g(x,mg[0],1), Landau::lc(x,0,1) )")
44
45# Simultaneous p.d.f.s are constructed with SIMUL( index, state1=pdf1,
46# state2=pdf2,...)
47w.factory("SIMUL::smodel( c[A=0,B=1], A=Gaussian::gs(x,m,s[1]), B=Landau::ls(x,0,1) )")
48
49# Operator function examples
50# ---------------------------------------------------
51
52# Function multiplication is done with prod (func1, func2,...)
53w.factory("prod::uv(u[10],v[10])")
54
55# Function addition is done with sum(func1,func2)
56w.factory("sum::uv2(u,v)")
57
58# Interpreted and compiled expression based pdfs
59# ---------------------------------------------------------------------------------------------------
60
61# Create a ROOT.RooGenericPdf interpreted p.d.f. You can use single quotes
62# to pass the expression string argument
63w.factory("EXPR::G('x*x+1',x)")
64
65# Create a custom compiled p.d.f similar to the above interpreted p.d.f.
66# The code required to make self p.d.f. is automatically embedded in
67# the workspace
68w.factory("CEXPR::GC('x*x+a',{x,a[1]})")
69
70# Compiled and interpreted functions (rather than p.d.f.s) can be made with the lower case
71# 'expr' and 'cexpr' types
72
73# Print workspace contents
74w.Print()
75
76# Make workspace visible on command line
77ROOT.gDirectory.Add(w)