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);
56 auto cutb1 = [](
double b1) {
return b1 < 5.; };
57 auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
63 auto entries1 =
d.Filter(cutb1)
64 .Filter(cutb1b2, {
"b2",
"b1"})
67 std::cout << *entries1 <<
" entries passed all filters" << std::endl;
72 auto entries2 =
d.Filter(
"b1 < 5.").Count();
73 std::cout << *entries2 <<
" entries passed the string filter" << std::endl;
78 auto b1b2_cut =
d.Filter(cutb1b2, {
"b2",
"b1"});
79 auto minVal = b1b2_cut.Min();
80 auto maxVal = b1b2_cut.Max();
81 auto meanVal = b1b2_cut.Mean();
82 auto nonDefmeanVal = b1b2_cut.Mean(
"b2");
83 std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *meanVal
84 <<
" <= " << *maxVal << std::endl;
90 auto b1_cut =
d.Filter(cutb1);
91 auto b1Vec = b1_cut.Take<
double>();
92 auto b1List = b1_cut.Take<
double, std::list<double>>();
94 std::cout <<
"Selected b1 entries" << std::endl;
95 for (
auto b1_entry : *b1List)
96 std::cout << b1_entry <<
" ";
97 std::cout << std::endl;
99 std::cout <<
"The type of b1Vec is " << b1VecCl->GetName() << std::endl;
106 auto hist =
d.Filter(cutb1).Histo1D();
107 std::cout <<
"Filled h " << hist->GetEntries() <<
" times, mean: " << hist->GetMean() << std::endl;
113 TH1F h(
"h",
"h", 12, -1, 11);
114 d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.Fill(b1); });
116 std::cout <<
"Filled h with " <<
h.GetEntries() <<
" entries" << std::endl;
125 auto cutb1_result =
d.Filter(cutb1);
126 auto cutb1b2_result =
d.Filter(cutb1b2, {
"b2",
"b1"});
127 auto cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2, {
"b2",
"b1"});
129 auto evts_cutb1_result = cutb1_result.Count();
130 auto evts_cutb1b2_result = cutb1b2_result.Count();
131 auto evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count();
133 std::cout <<
"Events passing cutb1: " << *evts_cutb1_result << std::endl
134 <<
"Events passing cutb1b2: " << *evts_cutb1b2_result << std::endl
135 <<
"Events passing both: " << *evts_cutb1_cutb1b2_result << std::endl;
150 auto entries_sum =
d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
153 std::cout << *entries_sum << std::endl;
158 auto entries_sum2 =
d.Define(
"sum2",
"b1 + b2").Filter(
"sum2 > 4.2").Count();
159 std::cout << *entries_sum2 << std::endl;
166 auto printEntrySlot = [](
ULong64_t iEntry,
unsigned int slot) {
167 std::cout <<
"Entry: " << iEntry <<
" Slot: " << slot << std::endl;
169 d.Foreach(printEntrySlot, {
"rdfentry_",
"rdfslot_"});
unsigned long long ULong64_t
ROOT's RDataFrame offers a high level interface for analyses 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)