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
df006_ranges.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_dataframe
3
## \notebook -nodraw
4
## Use Range to limit the amount of data processed.
5
##
6
## This tutorial shows how to express the concept of ranges when working with the RDataFrame.
7
##
8
## \macro_code
9
## \macro_output
10
##
11
## \date March 2017
12
## \author Danilo Piparo (CERN)
13
14
import
ROOT
15
16
def
fill_tree
(treeName, fileName):
17
df =
ROOT.RDataFrame
(100)
18
df.Define
(
"b1"
,
"(int) rdfentry_"
)\
19
.Define(
"b2"
,
"(float) rdfentry_ * rdfentry_"
).Snapshot(treeName, fileName)
20
21
22
# We prepare an input tree to run on
23
fileName =
"df006_ranges_py.root"
24
treeName =
"myTree"
25
26
fill_tree
(treeName, fileName)
27
28
# We read the tree from the file and create a RDataFrame.
29
d =
ROOT.RDataFrame
(treeName, fileName)
30
31
# ## Usage of ranges
32
# Now we'll count some entries using ranges
33
c_all =
d.Count
()
34
35
# This is how you can express a range of the first 30 entries
36
d_0_30 =
d.Range
(30)
37
c_0_30 =
d_0_30.Count
()
38
39
# This is how you pick all entries from 15 onwards
40
d_15_end =
d.Range
(15, 0)
41
c_15_end =
d_15_end.Count
()
42
43
# We can use a stride too, in this case we pick an event every 3 entries
44
d_15_end_3 =
d.Range
(15, 0, 3)
45
c_15_end_3 =
d_15_end_3.Count
()
46
47
# The Range here acts first on the (whole) RDataFrame graph:
48
# Not only actions (like Count) but also filters and new columns can be added to it.
49
d_0_50 =
d.Range
(50)
50
c_0_50_odd_b1 =
d_0_50.Filter
(
"1 == b1 % 2"
).Count()
51
52
# An important thing to notice is that the counts of a filter are relative to the
53
# number of entries a filter "sees". Therefore, if a Range depends on a filter,
54
# the Range will act on the entries passing the filter only.
55
c_0_3_after_even_b1 =
d.Filter
(
"0 == b1 % 2"
).
Range
(0, 3).Count()
56
57
# Ok, time to wrap up: let's print all counts!
58
print(
"Usage of ranges:"
)
59
print(
" - All entries:"
,
c_all.GetValue
())
60
print(
" - Entries from 0 to 30:"
,
c_0_30.GetValue
())
61
print(
" - Entries from 15 onwards:"
,
c_15_end.GetValue
())
62
print(
" - Entries from 15 onwards in steps of 3:"
,
c_15_end_3.GetValue
())
63
print(
" - Entries from 0 to 50, odd only:"
,
c_0_50_odd_b1.GetValue
())
64
print(
" - First three entries of all even entries:"
,
c_0_3_after_even_b1.GetValue
())
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
ROOT::RDataFrame
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Definition
RDataFrame.hxx:41
Range
Ta Range(0, 0, 1, 1)
tutorials
dataframe
df006_ranges.py
ROOT tags/6-34-04 - Reference Guide Generated on Wed Mar 26 2025 04:46:23 (GVA Time) using Doxygen 1.10.0