Basic RDataFrame usage.
This tutorial illustrates the basic features of the RDataFrame class, a utility which allows to interact with data stored in TTrees following a functional-chain like approach.
{
}
{
auto fileName = "df001_introduction.root";
auto cutb1 = [](
double b1) {
return b1 < 5.; };
auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
.Count();
std::cout << *
entries1 <<
" entries passed all filters" << std::endl;
std::cout << *
entries2 <<
" entries passed the string filter" << std::endl;
std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *
meanVal
<< " <= " << *maxVal << std::endl;
std::cout << "Selected b1 entries" << std::endl;
std::cout << std::endl;
std::cout <<
"The type of b1Vec is " <<
b1VecCl->GetName() << std::endl;
auto hist =
d.Filter(
cutb1).Histo1D();
std::cout << "Filled h " << hist->GetEntries() << " times, mean: " << hist->GetMean() << std::endl;
TH1F h(
"h",
"h", 12, -1, 11);
d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.Fill(b1); });
std::cout <<
"Filled h with " <<
h.GetEntries() <<
" entries" << std::endl;
auto entries_sum =
d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
.Count();
auto entries_sum2 =
d.Define(
"sum2",
"b1 + b2").Filter(
"sum2 > 4.2").Count();
std::cout <<
"Entry: " <<
iEntry <<
" Slot: " <<
slot << std::endl;
};
return 0;
}
unsigned long long ULong64_t
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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)
2 entries passed all filters
5 entries passed the string filter
The mean is always included between the min and the max: 1 <= 2 <= 3
Selected b1 entries
0 1 2 3 4
The type of b1Vec is vector<double>
Filled h 5 times, mean: 2
Filled h with 5 entries
Events passing cutb1: 5
Events passing cutb1b2: 2
Events passing both: 2
8
8
Entry: 0 Slot: 0
Entry: 1 Slot: 0
Entry: 2 Slot: 0
Entry: 3 Slot: 0
Entry: 4 Slot: 0
Entry: 5 Slot: 0
Entry: 6 Slot: 0
Entry: 7 Slot: 0
Entry: 8 Slot: 0
Entry: 9 Slot: 0
(int) 0
- Date
- December 2016
- Author
- Enrico Guiraud (CERN)
Definition in file df001_introduction.C.