This tutorial shows how to express the concept of ranges when working with the RDataFrame.
void fill_tree(const char *treeName, const char *fileName)
{
int i(0);
d.Define(
"b1", [&i]() {
return i; })
.Define("b2",
[&i]() {
float j = i * i;
++i;
return j;
})
.Snapshot(treeName, fileName);
}
{
auto fileName = "df006_ranges.root";
auto treeName = "myTree";
fill_tree(treeName, fileName);
auto d_0_30 =
d.Range(0, 30);
auto c_0_30 = d_0_30.Count();
auto d_15_end =
d.Range(15, 0);
auto c_15_end = d_15_end.Count();
auto d_15_end_3 =
d.Range(15, 0, 3);
auto c_15_end_3 = d_15_end_3.Count();
auto d_0_50 =
d.Range(0, 50);
auto c_0_50_odd_b1 = d_0_50.Filter("1 == b1 % 2").Count();
auto c_0_3_after_even_b1 =
d.Filter(
"0 == b1 % 2").Range(0, 3).Count();
cout << "Usage of ranges:\n"
<< " - All entries: " << *c_all << endl
<< " - Entries from 0 to 30: " << *c_0_30 << endl
<< " - Entries from 15 onwards: " << *c_15_end << endl
<< " - Entries from 15 onwards in steps of 3: " << *c_15_end_3 << endl
<< " - Entries from 0 to 50, odd only: " << *c_0_50_odd_b1 << endl
<< " - First three entries of all even entries: " << *c_0_3_after_even_b1 << endl;
return 0;
}
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Usage of ranges:
- All entries: 100
- Entries from 0 to 30: 30
- Entries from 15 onwards: 85
- Entries from 15 onwards in steps of 3: 28
- Entries from 0 to 50, odd only: 25
- First three entries of all even entries: 3
(int) 0
- Date
- March 2017
- Author
- Danilo Piparo
Definition in file df006_ranges.C.