20void fill_tree(
const char *treeName,
const char *fileName)
24 d.Define(
"b1", [&i]() {
return (
double)i; })
31 .Snapshot(treeName, fileName);
38 auto fileName =
"df001_introduction.root";
39 auto treeName =
"myTree";
40 fill_tree(treeName, fileName);
58 auto cutb1 = [](
double b1) {
return b1 < 5.; };
59 auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
65 auto entries1 =
d.Filter(cutb1)
66 .Filter(cutb1b2, {
"b2",
"b1"})
69 std::cout << *entries1 <<
" entries passed all filters" << std::endl;
74 auto entries2 =
d.Filter(
"b1 < 5.").Count();
75 std::cout << *entries2 <<
" entries passed the string filter" << std::endl;
80 auto b1b2_cut =
d.Filter(cutb1b2, {
"b2",
"b1"});
81 auto minVal = b1b2_cut.Min();
82 auto maxVal = b1b2_cut.Max();
83 auto meanVal = b1b2_cut.Mean();
84 auto nonDefmeanVal = b1b2_cut.Mean(
"b2");
85 std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *meanVal
86 <<
" <= " << *maxVal << std::endl;
92 auto b1_cut =
d.Filter(cutb1);
93 auto b1Vec = b1_cut.Take<
double>();
94 auto b1List = b1_cut.Take<
double, std::list<double>>();
96 std::cout <<
"Selected b1 entries" << std::endl;
97 for (
auto b1_entry : *b1List)
98 std::cout << b1_entry <<
" ";
99 std::cout << std::endl;
101 std::cout <<
"The type of b1Vec is " << b1VecCl->GetName() << std::endl;
108 auto hist =
d.Filter(cutb1).Histo1D();
109 std::cout <<
"Filled h " << hist->GetEntries() <<
" times, mean: " << hist->GetMean() << std::endl;
115 TH1F h(
"h",
"h", 12, -1, 11);
116 d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.Fill(b1); });
118 std::cout <<
"Filled h with " <<
h.GetEntries() <<
" entries" << std::endl;
127 auto cutb1_result =
d.Filter(cutb1);
128 auto cutb1b2_result =
d.Filter(cutb1b2, {
"b2",
"b1"});
129 auto cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2, {
"b2",
"b1"});
131 auto evts_cutb1_result = cutb1_result.Count();
132 auto evts_cutb1b2_result = cutb1b2_result.Count();
133 auto evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count();
135 std::cout <<
"Events passing cutb1: " << *evts_cutb1_result << std::endl
136 <<
"Events passing cutb1b2: " << *evts_cutb1b2_result << std::endl
137 <<
"Events passing both: " << *evts_cutb1_cutb1b2_result << std::endl;
152 auto entries_sum =
d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
155 std::cout << *entries_sum << std::endl;
160 auto entries_sum2 =
d.Define(
"sum2",
"b1 + b2").Filter(
"sum2 > 4.2").Count();
161 std::cout << *entries_sum2 << std::endl;
168 auto printEntrySlot = [](
ULong64_t iEntry,
unsigned int slot) {
169 std::cout <<
"Entry: " << iEntry <<
" Slot: " << slot << std::endl;
171 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)