18void fill_tree(
const char *treeName,
const char *fileName)
22 d.Define(
"b1", [&i]() {
return (
double)i; })
29 .Snapshot(treeName, fileName);
36 auto fileName =
"df001_introduction.root";
37 auto treeName =
"myTree";
38 fill_tree(treeName, fileName);
54 auto cutb1 = [](
double b1) {
return b1 < 5.; };
55 auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
61 auto entries1 =
d.Filter(cutb1)
62 .Filter(cutb1b2, {
"b2",
"b1"})
65 std::cout << *entries1 <<
" entries passed all filters" << std::endl;
70 auto entries2 =
d.Filter(
"b1 < 5.").Count();
71 std::cout << *entries2 <<
" entries passed the string filter" << std::endl;
76 auto b1b2_cut =
d.Filter(cutb1b2, {
"b2",
"b1"});
77 auto minVal = b1b2_cut.Min();
78 auto maxVal = b1b2_cut.Max();
79 auto meanVal = b1b2_cut.Mean();
80 auto nonDefmeanVal = b1b2_cut.Mean(
"b2");
81 std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *meanVal
82 <<
" <= " << *maxVal << std::endl;
88 auto b1_cut =
d.Filter(cutb1);
89 auto b1Vec = b1_cut.Take<
double>();
90 auto b1List = b1_cut.Take<
double, std::list<double>>();
92 std::cout <<
"Selected b1 entries" << std::endl;
93 for (
auto b1_entry : *b1List)
94 std::cout << b1_entry <<
" ";
95 std::cout << std::endl;
97 std::cout <<
"The type of b1Vec is " << b1VecCl->GetName() << std::endl;
104 auto hist =
d.Filter(cutb1).Histo1D();
105 std::cout <<
"Filled h " << hist->GetEntries() <<
" times, mean: " << hist->GetMean() << std::endl;
111 TH1F h(
"h",
"h", 12, -1, 11);
112 d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.Fill(b1); });
114 std::cout <<
"Filled h with " <<
h.GetEntries() <<
" entries" << std::endl;
123 auto cutb1_result =
d.Filter(cutb1);
124 auto cutb1b2_result =
d.Filter(cutb1b2, {
"b2",
"b1"});
125 auto cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2, {
"b2",
"b1"});
127 auto evts_cutb1_result = cutb1_result.Count();
128 auto evts_cutb1b2_result = cutb1b2_result.Count();
129 auto evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count();
131 std::cout <<
"Events passing cutb1: " << *evts_cutb1_result << std::endl
132 <<
"Events passing cutb1b2: " << *evts_cutb1b2_result << std::endl
133 <<
"Events passing both: " << *evts_cutb1_cutb1b2_result << std::endl;
148 auto entries_sum =
d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
151 std::cout << *entries_sum << std::endl;
156 auto entries_sum2 =
d.Define(
"sum2",
"b1 + b2").Filter(
"sum2 > 4.2").Count();
157 std::cout << *entries_sum2 << std::endl;
164 auto printEntrySlot = [](
ULong64_t iEntry,
unsigned int slot) {
165 std::cout <<
"Entry: " << iEntry <<
" Slot: " << slot << std::endl;
167 d.Foreach(printEntrySlot, {
"rdfentry_",
"rdfslot_"});
unsigned long long ULong64_t
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
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 long int sum(long int i)