19def fill_tree(treeName, fileName):
21 df.Define(
"b1",
"(double) rdfentry_")\
22 .Define(
"b2",
"(int) rdfentry_ * rdfentry_").Snapshot(treeName, fileName)
25fileName =
"df001_introduction_py.root"
27fill_tree(treeName, fileName)
44cutb1b2 =
'b2 % 2 && b1 < 4.'
50entries1 = d.Filter(cutb1) \
54print(
"%s entries passed all filters" %entries1.GetValue())
56entries2 = d.Filter(
"b1 < 5.").Count();
57print(
"%s entries passed all filters" %entries2.GetValue())
62b1b2_cut = d.Filter(cutb1b2)
63minVal = b1b2_cut.Min(
'b1')
64maxVal = b1b2_cut.Max(
'b1')
65meanVal = b1b2_cut.Mean(
'b1')
66nonDefmeanVal = b1b2_cut.Mean(
"b2")
67print(
"The mean is always included between the min and the max: %s <= %s <= %s" %(minVal.GetValue(), meanVal.GetValue(), maxVal.GetValue()))
74hist = d.Filter(cutb1).Histo1D(
'b1')
75print(
"Filled h %s times, mean: %s" %(hist.GetEntries(), hist.GetMean()))
84cutb1_result = d.Filter(cutb1);
85cutb1b2_result = d.Filter(cutb1b2);
86cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2)
89evts_cutb1_result = cutb1_result.Count()
90evts_cutb1b2_result = cutb1b2_result.Count()
91evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count()
93print(
"Events passing cutb1: %s" %evts_cutb1_result.GetValue())
94print(
"Events passing cutb1b2: %s" %evts_cutb1b2_result.GetValue())
95print(
"Events passing both: %s" %evts_cutb1_cutb1b2_result.GetValue())
110entries_sum = d.Define(
'sum',
'b2 + b1') \
111 .Filter(
'sum > 4.2') \
113print(entries_sum.GetValue())
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTree,...