16 def fill_tree(treeName, fileName):
17 tdf = ROOT.ROOT.RDataFrame(10)
18 tdf.Define(
"b1",
"(double) tdfentry_")\
19 .Define(
"b2",
"(int) tdfentry_ * tdfentry_").Snapshot(treeName, fileName)
22 fileName =
"df001_introduction_py.root" 24 fill_tree(treeName, fileName)
29 RDF = ROOT.ROOT.RDataFrame
30 d = RDF(treeName, fileName)
42 cutb1b2 =
'b2 % 2 && b1 < 4.' 48 entries1 = d.Filter(cutb1) \
52 print(
"%s entries passed all filters" %entries1.GetValue())
54 entries2 = d.Filter(
"b1 < 5.").Count();
55 print(
"%s entries passed all filters" %entries2.GetValue())
60 b1b2_cut = d.Filter(cutb1b2)
61 minVal = b1b2_cut.Min(
'b1')
62 maxVal = b1b2_cut.Max(
'b1')
63 meanVal = b1b2_cut.Mean(
'b1')
64 nonDefmeanVal = b1b2_cut.Mean(
"b2")
65 print(
"The mean is always included between the min and the max: %s <= %s <= %s" %(minVal.GetValue(), meanVal.GetValue(), maxVal.GetValue()))
72 hist = d.Filter(cutb1).Histo1D(
'b1')
73 print(
"Filled h %s times, mean: %s" %(hist.GetEntries(), hist.GetMean()))
82 cutb1_result = d.Filter(cutb1);
83 cutb1b2_result = d.Filter(cutb1b2);
84 cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2)
87 evts_cutb1_result = cutb1_result.Count()
88 evts_cutb1b2_result = cutb1b2_result.Count()
89 evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count()
91 print(
"Events passing cutb1: %s" %evts_cutb1_result.GetValue())
92 print(
"Events passing cutb1b2: %s" %evts_cutb1b2_result.GetValue())
93 print(
"Events passing both: %s" %evts_cutb1_cutb1b2_result.GetValue())
108 entries_sum = d.Define(
'sum',
'b2 + b1') \
111 print(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.