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