17 void fill_tree(
const char *treeName,
const char *fileName)
21 d.Define(
"b1", [&i]() {
return (
double)i; })
28 .Snapshot(treeName, fileName);
35 auto fileName =
"df001_introduction.root";
36 auto treeName =
"myTree";
37 fill_tree(treeName, fileName);
53 auto cutb1 = [](
double b1) {
return b1 < 5.; };
54 auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
60 auto entries1 =
d.Filter(cutb1)
61 .Filter(cutb1b2, {
"b2",
"b1"})
64 std::cout << *entries1 <<
" entries passed all filters" << std::endl;
69 auto entries2 =
d.Filter(
"b1 < 5.").Count();
70 std::cout << *entries2 <<
" entries passed the string filter" << std::endl;
75 auto b1b2_cut =
d.Filter(cutb1b2, {
"b2",
"b1"});
76 auto minVal = b1b2_cut.Min();
77 auto maxVal = b1b2_cut.Max();
78 auto meanVal = b1b2_cut.Mean();
79 auto nonDefmeanVal = b1b2_cut.Mean(
"b2");
80 std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *meanVal
81 <<
" <= " << *maxVal << std::endl;
87 auto b1_cut =
d.Filter(cutb1);
88 auto b1Vec = b1_cut.Take<
double>();
89 auto b1List = b1_cut.Take<double, std::list<double>>();
91 std::cout <<
"Selected b1 entries" << std::endl;
92 for (
auto b1_entry : *b1List)
93 std::cout << b1_entry <<
" ";
94 std::cout << std::endl;
96 std::cout <<
"The type of b1Vec is " << b1VecCl->GetName() << std::endl;
103 auto hist =
d.Filter(cutb1).Histo1D();
104 std::cout <<
"Filled h " << hist->GetEntries() <<
" times, mean: " << hist->GetMean() << std::endl;
110 TH1F h(
"h",
"h", 12, -1, 11);
111 d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.Fill(b1); });
113 std::cout <<
"Filled h with " <<
h.GetEntries() <<
" entries" << std::endl;
122 auto cutb1_result =
d.Filter(cutb1);
123 auto cutb1b2_result =
d.Filter(cutb1b2, {
"b2",
"b1"});
124 auto cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2, {
"b2",
"b1"});
126 auto evts_cutb1_result = cutb1_result.Count();
127 auto evts_cutb1b2_result = cutb1b2_result.Count();
128 auto evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count();
130 std::cout <<
"Events passing cutb1: " << *evts_cutb1_result << std::endl
131 <<
"Events passing cutb1b2: " << *evts_cutb1b2_result << std::endl
132 <<
"Events passing both: " << *evts_cutb1_cutb1b2_result << std::endl;
147 auto entries_sum =
d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
148 .
Filter([](
double sum) {
return sum > 4.2; }, {
"sum"})
150 std::cout << *entries_sum << std::endl;
155 auto entries_sum2 =
d.Define(
"sum2",
"b1 + b2").Filter(
"sum2 > 4.2").Count();
156 std::cout << *entries_sum2 << std::endl;
163 auto printEntrySlot = [](
ULong64_t iEntry,
unsigned int slot) {
164 std::cout <<
"Entry: " << iEntry <<
" Slot: " << slot << std::endl;
166 d.Foreach(printEntrySlot, {
"tdfentry_",
"tdfslot_"});
static long int sum(long int i)
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.
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV's and other data formats.
unsigned long long ULong64_t
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.