25 void fill_tree(
const char *filename,
const char *treeName)
27 TFile f(filename,
"RECREATE");
28 TTree t(treeName, treeName);
33 for (
int i = 0; i < 10; ++i) {
47 auto fileName =
"tdf001_introduction.root";
48 auto treeName =
"myTree";
49 fill_tree(fileName, treeName);
65 auto cutb1 = [](
double b1) {
return b1 < 5.; };
66 auto cutb1b2 = [](
int b2,
double b1) {
return b2 % 2 && b1 < 4.; };
72 auto entries1 = d.
Filter(cutb1)
73 .Filter(cutb1b2, {
"b2",
"b1"})
76 std::cout << *entries1 <<
" entries passed all filters" << std::endl;
81 auto entries2 = d.Filter(
"b1 < 5.").Count();
82 std::cout << *entries2 <<
" entries passed the string filter" << std::endl;
87 auto b1b2_cut = d.Filter(cutb1b2, {
"b2",
"b1"});
88 auto minVal = b1b2_cut.Min();
89 auto maxVal = b1b2_cut.Max();
90 auto meanVal = b1b2_cut.Mean();
91 auto nonDefmeanVal = b1b2_cut.Mean(
"b2");
92 std::cout <<
"The mean is always included between the min and the max: " << *minVal <<
" <= " << *meanVal
93 <<
" <= " << *maxVal << std::endl;
99 auto b1_cut = d.Filter(cutb1);
100 auto b1List = b1_cut.Take<
double>();
101 auto b1Vec = b1_cut.Take<double, std::vector<double>>();
103 std::cout <<
"Selected b1 entries" << std::endl;
104 for (
auto b1_entry : *b1List) std::cout << b1_entry <<
" ";
105 std::cout << std::endl;
107 std::cout <<
"The type of b1Vec is" << b1VecCl->GetName() << std::endl;
114 auto hist = d.Filter(cutb1).Histo1D();
115 std::cout <<
"Filled h " << hist->GetEntries() <<
" times, mean: " << hist->GetMean() << std::endl;
121 TH1F h(
"h",
"h", 12, -1, 11);
122 d.Filter([](
int b2) {
return b2 % 2 == 0; }, {
"b2"}).Foreach([&
h](
double b1) {
h.
Fill(b1); });
124 std::cout <<
"Filled h with " <<
h.
GetEntries() <<
" entries" << std::endl;
133 auto cutb1_result = d.Filter(cutb1);
134 auto cutb1b2_result = d.Filter(cutb1b2, {
"b2",
"b1"});
135 auto cutb1_cutb1b2_result = cutb1_result.Filter(cutb1b2, {
"b2",
"b1"});
137 auto evts_cutb1_result = cutb1_result.Count();
138 auto evts_cutb1b2_result = cutb1b2_result.Count();
139 auto evts_cutb1_cutb1b2_result = cutb1_cutb1b2_result.Count();
141 std::cout <<
"Events passing cutb1: " << *evts_cutb1_result << std::endl
142 <<
"Events passing cutb1b2: " << *evts_cutb1b2_result << std::endl
143 <<
"Events passing both: " << *evts_cutb1_cutb1b2_result << std::endl;
158 auto entries_sum = d.Define(
"sum", [](
double b1,
int b2) {
return b2 + b1; }, {
"b1",
"b2"})
159 .Filter([](
double sum) {
return sum > 4.2; }, {
"sum"})
161 std::cout << *entries_sum << std::endl;
166 auto entries_sum2 = d.Define(
"sum",
"b1 + b2").Filter(
"sum > 4.2").Count();
167 std::cout << *entries_sum2 << std::endl;
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
static long int sum(long int i)
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
tomato 1-D histogram with a float per channel (see TH1 documentation)}
TInterface< TFilterBase > Filter(F f, const ColumnNames_t &bn={}, std::string_view name="")
Append a filter to the call graph.
virtual Double_t GetEntries() const
Return the current number of entries.
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.
ROOT's TDataFrame offers a high level interface for analyses of data stored in TTrees.
A TTree object has a header with a name and a title.
int main(int argc, char **argv)