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