13 void fill_tree(const char *filename, const char *treeName) 15 TFile f(filename, "RECREATE"); 16 TTree t(treeName, treeName); 21 for (int i = 0; i < 10000; ++i) { 33 fileName =
"tdf007_snapshot_py.root" 34 outFileName =
"tdf007_snapshot_output_py.root" 35 outFileNameAllColumns =
"tdf007_snapshot_output_allColumns_py.root" 37 ROOT.gInterpreter.Declare(fill_tree_code)
38 ROOT.fill_tree(fileName, treeName)
41 TDF = ROOT.ROOT.Experimental.TDataFrame
42 d = TDF(treeName, fileName)
46 d_cut = d.Filter(
"b1 % 2 == 0")
51 std::vector<float> getVector (float b2) 54 for (int i = 0; i < 3; i++) v.push_back(b2*i); 58 ROOT.gInterpreter.Declare(getVector_code)
60 d2 = d_cut.Define(
"b1_square",
"b1 * b1") \
61 .Define(
"b2_vector",
"getVector( b2 )")
69 branchList = ROOT.vector(
'string')()
70 for branchName
in [
"b1",
"b1_square",
"b2_vector"]:
71 branchList.push_back(branchName)
72 d2.Snapshot(treeName, outFileName, branchList)
75 f1 = ROOT.TFile(outFileName)
77 print(
"These are the columns b1, b1_square and b2_vector:")
78 for branch
in t.GetListOfBranches():
79 print(
"Branch: %s" %branch.GetName())
86 d2.Snapshot(treeName, outFileNameAllColumns)
89 f2 = ROOT.TFile(outFileNameAllColumns)
91 print(
"These are all the columns available to this tdf:")
92 for branch
in t.GetListOfBranches():
93 print(
"Branch: %s" %branch.GetName())
101 branchList.push_back(
"b1_square")
102 snapshot_tdf = d2.Snapshot(treeName, outFileName, branchList);
103 h = snapshot_tdf.Histo1D(
"b1_square")