ROOT
master
Reference Guide
Loading...
Searching...
No Matches
rf508_listsetmanip.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit_main
3
## \notebook
4
## 'ORGANIZATION AND SIMULTANEOUS FITS' RooFit tutorial macro #508
5
##
6
## RooArgSet and RooArgList tools and tricks
7
##
8
## \macro_code
9
## \macro_output
10
##
11
## \date February 2018
12
## \authors Clemens Lange, Wouter Verkerke (C version)
13
14
import
ROOT
15
16
17
# Create dummy objects
18
# ---------------------------------------
19
20
# Create some variables
21
a =
ROOT.RooRealVar
(
"a"
,
"a"
, 1, -10, 10)
22
b =
ROOT.RooRealVar
(
"b"
,
"b"
, 2, -10, 10)
23
c =
ROOT.RooRealVar
(
"c"
,
"c"
, 3, -10, 10)
24
d =
ROOT.RooRealVar
(
"d"
,
"d"
, 4, -10, 10)
25
x =
ROOT.RooRealVar
(
"x"
,
"x"
, 0, -10, 10)
26
c.setError
(0.5)
27
a.setConstant
()
28
b.setConstant
()
29
30
# Create a category
31
e =
ROOT.RooCategory
(
"e"
,
"e"
)
32
e.defineType
(
"sig"
)
33
e.defineType
(
"bkg"
)
34
35
# Create a pdf
36
g =
ROOT.RooGaussian
(
"g"
,
"g"
, x, a, b)
37
38
# Creating, killing RooArgSets
39
# -------------------------------------------------------
40
41
# A ROOT.RooArgSet is a set of RooAbsArg objects. Each object in the set must have
42
# a unique name
43
44
# Set constructors exists with up to 9 initial arguments
45
s =
ROOT.RooArgSet
(a, b)
46
47
# At any time objects can be added with add()
48
s.add
(e)
49
50
# Add up to 9 additional arguments in one call
51
# s.add(ROOT.RooArgSet(c, d))
52
s.add
(c)
53
s.add
(d)
54
55
# Sets can contain any type of RooAbsArg, pdf and functions
56
s.add
(g)
57
58
# Remove element d
59
s.remove
(d)
60
61
# Accessing RooArgSet contents
62
# -------------------------------------------------------
63
64
# You can look up objects by name
65
aptr =
s.find
(
"a"
)
66
67
# Construct a subset by name
68
subset1 =
s.selectByName
(
"a,b,c"
)
69
70
# Construct asubset by attribute
71
subset2 =
s.selectByAttrib
(
"Constant"
,
True
)
72
73
# Construct the subset of overlapping contents with another set
74
s1 =
ROOT.RooArgSet
(a, b, c)
75
s2 =
ROOT.RooArgSet
(c, d, e)
76
subset3 =
s1.selectCommon
(s2)
77
78
# Owning RooArgSets
79
# ---------------------------------
80
81
# You can create a RooArgSet that owns copies of the objects instead of
82
# referencing the originals. A set either owns all of its components or none,
83
# so once addClone() is used, add() can no longer be used and will result in an
84
# error message
85
s3 =
ROOT.RooArgSet
()
86
for
arg
in
[a, b, c, d, e, g]:
87
s3.addClone
(arg)
88
89
# A clone of a owning set is non-owning and its
90
# contents is owned by the originating owning set
91
sclone =
s3.Clone
(
"sclone"
)
92
93
# To make a clone of a set and its contents use
94
# the snapshot method
95
sclone2 =
s3.snapshot
()
96
97
# If a set contains function objects, the head node
98
# is cloned in a snapshot. To make a snapshot of all
99
# servers of a function object do as follows. The result
100
# of a RooArgSet snapshot with deepCloning option is a set
101
# of cloned objects, all their clone (recursive) server
102
# dependencies, together form a self-consistent
103
# set that is free of external dependencies
104
105
sclone3 =
s3.snapshot
(
True
)
106
107
# Set printing
108
# ------------------------
109
110
# Inline printing only show list of names of contained objects
111
print(
"sclone = "
, sclone)
112
113
# Plain print shows the same, by name of the set
114
sclone.Print
()
115
116
# Standard printing shows one line for each item with the items name, name
117
# and value
118
sclone.Print
(
"s"
)
119
120
# Verbose printing adds each items arguments, and 'extras' as defined by
121
# the object
122
sclone.Print
(
"v"
)
123
124
# Using RooArgLists
125
# ---------------------------------
126
127
# List constructors exists with up to 9 initial arguments
128
l =
ROOT.RooArgList
(a, b, c, d)
129
130
# Lists have an explicit order and allow multiple arguments with the same
131
# name
132
l.add
(
ROOT.RooArgList
(a, b, c, d))
133
134
# Access by index is provided
135
arg4 =
l.at
(4)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
roofit
roofit
rf508_listsetmanip.py
ROOT master - Reference Guide Generated on Fri Mar 14 2025 15:22:34 (GVA Time) using Doxygen 1.10.0