17def fill_tree(treeName, fileName):
19 df.Define(
"b1",
"(double) rdfentry_")\
20 .Define(
"b2",
"(int) rdfentry_ * rdfentry_").Snapshot(treeName, fileName)
23fileName =
"df001_introduction_py.root"
25fill_tree(treeName, fileName)
42cutb1b2 =
'b2 % 2 && b1 < 4.'
48entries1 = d.Filter(cutb1) \
52print(
"%s entries passed all filters" %entries1.GetValue())
54entries2 = d.Filter(
"b1 < 5.").Count();
55print(
"%s entries passed all filters" %entries2.GetValue())
60b1b2_cut = d.Filter(cutb1b2)
61minVal = b1b2_cut.Min(
'b1')
62maxVal = b1b2_cut.Max(
'b1')
63meanVal = b1b2_cut.Mean(
'b1')
64nonDefmeanVal = b1b2_cut.Mean(
"b2")
65print(
"The mean is always included between the min and the max: %s <= %s <= %s" %(minVal.GetValue(), meanVal.GetValue(), maxVal.GetValue()))
72hist = d.Filter(cutb1).Histo1D(
'b1')
73print(
"Filled h %s times, mean: %s" %(hist.GetEntries(), hist.GetMean()))
82cutb1_result = d.Filter(cutb1);
83cutb1b2_result = d.Filter(cutb1b2);
84cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2)
87evts_cutb1_result = cutb1_result.Count()
88evts_cutb1b2_result = cutb1b2_result.Count()
89evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count()
91print(
"Events passing cutb1: %s" %evts_cutb1_result.GetValue())
92print(
"Events passing cutb1b2: %s" %evts_cutb1b2_result.GetValue())
93print(
"Events passing both: %s" %evts_cutb1_cutb1b2_result.GetValue())
108entries_sum = d.Define(
'sum',
'b2 + b1') \
111print(entries_sum.GetValue())
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.