This tutorial shows how to write out datasets in ROOT formatusing the TDataFrame
void fill_tree(const char *filename, const char *treeName)
{
TFile f(filename,
"RECREATE");
TTree t(treeName, treeName);
int b1;
float b2;
t.Branch("b1", &b1);
t.Branch("b2", &b2);
for (int i = 0; i < 10000; ++i) {
b1 = i;
b2 = i * i;
t.Fill();
}
return;
}
{
auto fileName = "tdf007_snapshot.root";
auto outFileName = "tdf007_snapshot_output.root";
auto outFileNameAllColumns = "tdf007_snapshot_output_allColumns.root";
auto treeName = "myTree";
fill_tree(fileName, treeName);
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++) v.push_back(b2*i);
},
{"b2"});
d2.Snapshot(treeName, outFileName, {"b1", "b1_square", "b2_vector"});
f1.GetObject(treeName, t);
std::cout << "These are the columns b1, b1_square and b2_vector:" << std::endl;
std::cout <<
"Branch: " << branch->
GetName() << std::endl;
}
d2.Snapshot(treeName, outFileNameAllColumns);
f2.GetObject(treeName, t);
std::cout << "These are all the columns available to this tdf:" << std::endl;
std::cout << "Branch: " << branch->GetName() << std::endl;
}
auto snapshot_tdf = d2.Snapshot<int>(treeName, outFileName, {"b1_square"});
auto h = snapshot_tdf.Histo1D();
h->Draw();
return 0;
}
- Date
- April 2017
- Author
- Danilo Piparo
Definition in file tdf007_snapshot.C.