This example shows processing of a TTree-based dataset with horizontal concatenations (friends) and event matching (based on TTreeIndex). In case the current event being processed does not match one (or more) of the friend datasets, one can use the FilterAvailable and DefaultValueFor functionalities to act upon the situation.
import array
import os
import ROOT
"""A helper class to create the dataset for the tutorial below."""
main_file = "df037_TTreeEventMatching_py_main.root"
aux_file_1 = "df037_TTreeEventMatching_py_aux_1.root"
aux_file_2 = "df037_TTreeEventMatching_py_aux_2.root"
main_tree_name = "events"
aux_tree_name_1 = "auxdata_1"
aux_tree_name_2 = "auxdata_2"
def __init__(self):
main_tree =
ROOT.TTree(self.main_tree_name, self.main_tree_name)
idx[0] = 1
x[0] = 1
idx[0] = 2
x[0] = 2
idx[0] = 3
x[0] = 3
aux_tree_1 =
ROOT.TTree(self.aux_tree_name_1, self.aux_tree_name_1)
idx[0] = 1
y[0] = 4
idx[0] = 2
y[0] = 5
aux_tree_2 =
ROOT.TTree(self.aux_tree_name_2, self.aux_tree_name_2)
idx[0] = 1
z[0] = 6
idx[0] = 3
z[0] = 7
return self
def df037_TTreeEventMatching(dataset: DatasetContext):
display_1 = (
.DefaultValueFor(aux_tree_1_coly, default_value)
.DefaultValueFor(aux_tree_2_colidx, default_value)
.DefaultValueFor(aux_tree_2_colz, default_value)
.Display(("idx", aux_tree_1_colidx, aux_tree_2_colidx, "x", aux_tree_1_coly, aux_tree_2_colz))
)
display_2 = (
.DefaultValueFor(aux_tree_2_colz, default_value)
.FilterAvailable(aux_tree_1_coly)
.Display(("idx", aux_tree_1_colidx, aux_tree_2_colidx, "x", aux_tree_1_coly, aux_tree_2_colz))
)
print("Example 1: provide default values for all columns")
print("Example 2: always skip the entry when there is no match")
print("Example 3: keep entries from the main tree for which there is no match in the auxiliary tree")
if __name__ == "__main__":
df037_TTreeEventMatching(dataset)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Example 1: provide default values for all columns
+-----+-----+---------------+---------------+---+-------------+-------------+
| Row | idx | auxdata_1.idx | auxdata_2.idx | x | auxdata_1.y | auxdata_2.z |
+-----+-----+---------------+---------------+---+-------------+-------------+
| 0 | 1 | 1 | 1 | 1 | 4 | 6 |
+-----+-----+---------------+---------------+---+-------------+-------------+
| 1 | 2 | 2 | -2147483648 | 2 | 5 | -2147483648 |
+-----+-----+---------------+---------------+---+-------------+-------------+
| 2 | 3 | -2147483648 | 3 | 3 | -2147483648 | 7 |
+-----+-----+---------------+---------------+---+-------------+-------------+
Example 2: always skip the entry when there is no match
+-----+-----+---------------+---------------+---+-------------+-------------+
| Row | idx | auxdata_1.idx | auxdata_2.idx | x | auxdata_1.y | auxdata_2.z |
+-----+-----+---------------+---------------+---+-------------+-------------+
| 0 | 1 | 1 | 1 | 1 | 4 | 6 |
+-----+-----+---------------+---------------+---+-------------+-------------+
| 1 | 2 | 2 | -2147483648 | 2 | 5 | -2147483648 |
+-----+-----+---------------+---------------+---+-------------+-------------+
Example 3: keep entries from the main tree for which there is no match in the auxiliary tree
+-----+-----+---+
| Row | idx | x |
+-----+-----+---+
| 2 | 3 | 3 |
+-----+-----+---+
- Date
- September 2024
- Author
- Vincenzo Eduardo Padulano (CERN)
Definition in file df037_TTreeEventMatching.py.