20void fill_tree(
const char *treeName,
const char *fileName)
23 d.Define(
"b1", [](
ULong64_t entry) ->
double {
return entry; }, {
"rdfentry_"})
24 .Define(
"b2", [](
ULong64_t entry) ->
int {
return entry * entry; }, {
"rdfentry_"})
25 .Snapshot(treeName, fileName);
32 auto fileName =
"df001_introduction.root";
33 auto treeName =
"myTree";
34 fill_tree(treeName, fileName);
52 auto cutb1 = [](
double b1) {
return b1 < 5.; };
53 auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
59 auto entries1 =
d.Filter(cutb1)
60 .Filter(cutb1b2, {
"b2",
"b1"})
63 std::cout << *entries1 <<
" entries passed all filters" << std::endl;
68 auto entries2 =
d.Filter(
"b1 < 5.").Count();
69 std::cout << *entries2 <<
" entries passed the string filter" << std::endl;
74 auto b1b2_cut =
d.Filter(cutb1b2, {
"b2",
"b1"});
75 auto minVal = b1b2_cut.Min();
76 auto maxVal = b1b2_cut.Max();
77 auto meanVal = b1b2_cut.Mean();
78 auto nonDefmeanVal = b1b2_cut.Mean(
"b2");
79 std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *meanVal
80 <<
" <= " << *maxVal << std::endl;
86 auto b1_cut =
d.Filter(cutb1);
87 auto b1Vec = b1_cut.Take<
double>();
88 auto b1List = b1_cut.Take<
double, std::list<double>>();
90 std::cout <<
"Selected b1 entries" << std::endl;
91 for (
auto b1_entry : *b1List)
92 std::cout << b1_entry <<
" ";
93 std::cout << std::endl;
95 std::cout <<
"The type of b1Vec is " << b1VecCl->GetName() << std::endl;
102 auto hist =
d.Filter(cutb1).Histo1D();
103 std::cout <<
"Filled h " << hist->GetEntries() <<
" times, mean: " << hist->GetMean() << std::endl;
109 TH1F h(
"h",
"h", 12, -1, 11);
110 d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.Fill(b1); });
112 std::cout <<
"Filled h with " <<
h.GetEntries() <<
" entries" << std::endl;
121 auto cutb1_result =
d.Filter(cutb1);
122 auto cutb1b2_result =
d.Filter(cutb1b2, {
"b2",
"b1"});
123 auto cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2, {
"b2",
"b1"});
125 auto evts_cutb1_result = cutb1_result.Count();
126 auto evts_cutb1b2_result = cutb1b2_result.Count();
127 auto evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count();
129 std::cout <<
"Events passing cutb1: " << *evts_cutb1_result << std::endl
130 <<
"Events passing cutb1b2: " << *evts_cutb1b2_result << std::endl
131 <<
"Events passing both: " << *evts_cutb1_cutb1b2_result << std::endl;
146 auto entries_sum =
d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
149 std::cout << *entries_sum << std::endl;
154 auto entries_sum2 =
d.Define(
"sum2",
"b1 + b2").Filter(
"sum2 > 4.2").Count();
155 std::cout << *entries_sum2 << std::endl;
162 auto printEntrySlot = [](
ULong64_t iEntry,
unsigned int slot) {
163 std::cout <<
"Entry: " << iEntry <<
" Slot: " << slot << std::endl;
165 d.Foreach(printEntrySlot, {
"rdfentry_",
"rdfslot_"});
unsigned long long ULong64_t
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
1-D histogram with a float per channel (see TH1 documentation)
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
static uint64_t sum(uint64_t i)