17def fill_tree(treeName, fileName):
18 tdf = ROOT.ROOT.RDataFrame(10)
19 tdf.Define(
"b1",
"(double) tdfentry_")\
20 .Define(
"b2",
"(int) tdfentry_ * tdfentry_").Snapshot(treeName, fileName)
23fileName =
"df001_introduction_py.root"
25fill_tree(treeName, fileName)
30RDF = ROOT.ROOT.RDataFrame
31d = RDF(treeName, fileName)
43cutb1b2 =
'b2 % 2 && b1 < 4.'
49entries1 = d.Filter(cutb1) \
53print(
"%s entries passed all filters" %entries1.GetValue())
55entries2 = d.Filter(
"b1 < 5.").Count();
56print(
"%s entries passed all filters" %entries2.GetValue())
61b1b2_cut = d.Filter(cutb1b2)
62minVal = b1b2_cut.Min(
'b1')
63maxVal = b1b2_cut.Max(
'b1')
64meanVal = b1b2_cut.Mean(
'b1')
65nonDefmeanVal = b1b2_cut.Mean(
"b2")
66print(
"The mean is always included between the min and the max: %s <= %s <= %s" %(minVal.GetValue(), meanVal.GetValue(), maxVal.GetValue()))
73hist = d.Filter(cutb1).Histo1D(
'b1')
74print(
"Filled h %s times, mean: %s" %(hist.GetEntries(), hist.GetMean()))
83cutb1_result = d.Filter(cutb1);
84cutb1b2_result = d.Filter(cutb1b2);
85cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2)
88evts_cutb1_result = cutb1_result.Count()
89evts_cutb1b2_result = cutb1b2_result.Count()
90evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count()
92print(
"Events passing cutb1: %s" %evts_cutb1_result.GetValue())
93print(
"Events passing cutb1b2: %s" %evts_cutb1b2_result.GetValue())
94print(
"Events passing both: %s" %evts_cutb1_cutb1b2_result.GetValue())
109entries_sum = d.Define(
'sum',
'b2 + b1') \
112print(entries_sum.GetValue())
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.