void fill_tree(const char *treeName, const char *fileName)
{
d.Define(
"b1", [&
i]() {
return i; })
return j;
})
}
{
auto fileName = "df007_snapshot.root";
auto outFileName = "df007_snapshot_output.root";
auto outFileNameAllColumns = "df007_snapshot_output_allColumns.root";
auto treeName = "myTree";
fill_tree(treeName, fileName);
auto d_cut =
d.Filter(
"b1 % 2 == 0");
auto d2 = d_cut.Define("b1_square", "b1 * b1")
.Define("b2_vector",
[](float b2) {
for (
int i = 0;
i < 3;
i++)
},
{"b2"});
d2.Snapshot(treeName, outFileName, {"b1", "b1_square", "b2_vector"});
std::cout << "These are the columns b1, b1_square and b2_vector:" << std::endl;
for (auto branch : *t->GetListOfBranches()) {
std::cout << "Branch: " << branch->GetName() << std::endl;
}
d2.Snapshot(treeName, outFileNameAllColumns);
TFile f2(outFileNameAllColumns);
t = f2.Get<
TTree>(treeName);
std::cout << "These are all the columns available to this dataframe:" << std::endl;
for (auto branch : *t->GetListOfBranches()) {
std::cout << "Branch: " << branch->GetName() << std::endl;
}
f2.Close();
auto snapshot_df = d2.Snapshot<int>(treeName, outFileName, {"b1_square"});
auto h = snapshot_df->Histo1D();
return 0;
}
RInterface< Proxied, DS_t > Define(std::string_view name, F expression, const ColumnNames_t &columns={})
Define a new column.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
A TTree represents a columnar dataset.
RResultPtr< RInterface< RLoopManager > > Snapshot(std::string_view treename, std::string_view filename, const ColumnNames_t &columnList, const RSnapshotOptions &options=RSnapshotOptions())
Save selected columns to disk, in a new TTree treename in file filename.