17 void fill_tree(const char *filename, const char *treeName) 19 TFile f(filename, "RECREATE"); 20 TTree t(treeName, treeName); 25 for (int i = 0; i < 10; ++i) { 36 fileName =
"tdf001_introduction_py.root" 38 ROOT.gInterpreter.Declare(fill_tree_code)
39 ROOT.fill_tree(fileName, treeName)
44 TDF = ROOT.ROOT.Experimental.TDataFrame
45 d = TDF(treeName, fileName)
57 cutb1b2 =
'b2 % 2 && b1 < 4.' 63 entries1 = d.Filter(cutb1) \
67 print(
"%s entries passed all filters" %entries1.GetValue())
69 entries2 = d.Filter(
"b1 < 5.").Count();
70 print(
"%s entries passed all filters" %entries2.GetValue())
75 b1b2_cut = d.Filter(cutb1b2)
76 minVal = b1b2_cut.Min(
'b1')
77 maxVal = b1b2_cut.Max(
'b1')
78 meanVal = b1b2_cut.Mean(
'b1')
79 nonDefmeanVal = b1b2_cut.Mean(
"b2")
80 print(
"The mean is always included between the min and the max: %s <= %s <= %s" %(minVal.GetValue(), meanVal.GetValue(), maxVal.GetValue()))
87 hist = d.Filter(cutb1).Histo1D(
'b1')
88 print(
"Filled h %s times, mean: %s" %(hist.GetEntries(), hist.GetMean()))
97 cutb1_result = d.Filter(cutb1);
98 cutb1b2_result = d.Filter(cutb1b2);
99 cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2)
102 evts_cutb1_result = cutb1_result.Count()
103 evts_cutb1b2_result = cutb1b2_result.Count()
104 evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count()
106 print(
"Events passing cutb1: %s" %evts_cutb1_result.GetValue())
107 print(
"Events passing cutb1b2: %s" %evts_cutb1b2_result.GetValue())
108 print(
"Events passing both: %s" %evts_cutb1_cutb1b2_result.GetValue())
123 entries_sum = d.Define(
'sum',
'b2 + b1') \
124 .Filter(
'sum > 4.2') \
126 print(entries_sum.GetValue())