ROOT
master
Reference Guide
Loading...
Searching...
No Matches
rf511_wsfactory_basic.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit
3
## \notebook -nodraw
4
## Organization and simultaneous fits: basic use of the 'object factory' associated with a
5
## workspace to rapidly build pdfs functions and their parameter components
6
##
7
## \macro_code
8
## \macro_output
9
##
10
## \date February 2018
11
## \authors Clemens Lange, Wouter Verkerke (C++ version)
12
13
import
ROOT
14
15
16
compact =
False
17
w = ROOT.RooWorkspace(
"w"
)
18
19
# Creating and adding basic pdfs
20
# ----------------------------------------------------------------
21
22
# Remake example pdf of tutorial rs502_wspacewrite.C:
23
#
24
# Basic pdf construction: ClassName.ObjectName(constructor arguments)
25
# Variable construction : VarName[x,xlo,xhi], VarName[xlo,xhi], VarName[x]
26
# P.d.f. addition : SUM.ObjectName(coef1*pdf1,...coefM*pdfM,pdfN)
27
#
28
29
if
not
compact:
30
# Use object factory to build pdf of tutorial rs502_wspacewrite
31
w.factory(
"Gaussian::sig1(x[-10,10],mean[5,0,10],0.5)"
)
32
w.factory(
"Gaussian::sig2(x,mean,1)"
)
33
w.factory(
"Chebychev::bkg(x,{a0[0.5,0.,1],a1[-0.2,0.,1.]})"
)
34
w.factory(
"SUM::sig(sig1frac[0.8,0.,1.]*sig1,sig2)"
)
35
w.factory(
"SUM::model(bkgfrac[0.5,0.,1.]*bkg,sig)"
)
36
37
else
:
38
39
# Use object factory to build pdf of tutorial rs502_wspacewrite but
40
# - Contracted to a single line recursive expression,
41
# - Omitting explicit names for components that are not referred to explicitly later
42
43
w.factory(
44
"SUM::model(bkgfrac[0.5,0.,1.]*Chebychev::bkg(x[-10,10],{a0[0.5,0.,1],a1[-0.2,0.,1.]}), "
45
"SUM(sig1frac[0.8,0.,1.]*Gaussian(x,mean[5,0,10],0.5), Gaussian(x,mean,1)))"
46
)
47
48
# Advanced pdf constructor arguments
49
# ----------------------------------------------------------------
50
#
51
# P.d.f. constructor arguments may by any type of ROOT.RooAbsArg, also
52
#
53
# Double_t -. converted to ROOT.RooConst(...)
54
# {a,b,c} -. converted to ROOT.RooArgSet() or ROOT.RooArgList() depending on required ctor arg
55
# dataset name -. converted to ROOT.RooAbsData reference for any dataset residing in the workspace
56
# enum -. Any enum label that belongs to an enum defined in the (base)
57
# class
58
59
# Make a dummy dataset pdf 'model' and import it in the workspace
60
data = w[
"model"
].generate({w[
"x"
]}, 1000)
61
# Cannot call 'import' directly because this is a python keyword:
62
w.Import(data, Rename=
"data"
)
63
64
# Construct a KEYS pdf passing a dataset name and an enum type defining the
65
# mirroring strategy
66
# w.factory("KeysPdf::k(x,data,NoMirror,0.2)")
67
# Workaround for pyROOT
68
x = w[
"x"
]
69
k = ROOT.RooKeysPdf(
"k"
,
"k"
, x, data, ROOT.RooKeysPdf.NoMirror, 0.2)
70
w.Import(k, RenameAllNodes=
"workspace"
)
71
72
# Print workspace contents
73
w.Print()
tutorials
roofit
rf511_wsfactory_basic.py
ROOT master - Reference Guide Generated on Tue Nov 5 2024 09:41:10 (GVA Time) using Doxygen 1.9.8