18 void fill_tree(
const char *filename,
const char *treeName)
20 TFile f(filename,
"RECREATE");
21 TTree t(treeName, treeName);
26 for (
int i = 0; i < 10000; ++i) {
39 auto fileName =
"tdf007_snapshot.root";
40 auto outFileName =
"tdf007_snapshot_output.root";
41 auto outFileNameAllColumns =
"tdf007_snapshot_output_allColumns.root";
42 auto treeName =
"myTree";
43 fill_tree(fileName, treeName);
50 auto d_cut = d.Filter(
"b1 % 2 == 0");
53 auto d2 = d_cut.Define(
"b1_square",
"b1 * b1")
57 for (
int i = 0; i < 3; i++) v.push_back(b2*i);
68 d2.Snapshot(treeName, outFileName, {
"b1",
"b1_square",
"b2_vector"});
73 f1.GetObject(treeName, t);
74 std::cout <<
"These are the columns b1, b1_square and b2_vector:" << std::endl;
76 std::cout <<
"Branch: " << branch->
GetName() << std::endl;
83 d2.Snapshot(treeName, outFileNameAllColumns);
86 TFile f2(outFileNameAllColumns);
87 f2.GetObject(treeName, t);
88 std::cout <<
"These are all the columns available to this tdf:" << std::endl;
90 std::cout <<
"Branch: " << branch->GetName() << std::endl;
98 auto snapshot_tdf = d2.Snapshot<
int>(treeName, outFileName, {
"b1_square"});
99 auto h = snapshot_tdf.Histo1D();
virtual const char * GetName() const
Returns name of object.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual TObjArray * GetListOfBranches()
double f2(const double *x)
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.