13 def fill_tree(treeName, fileName):
14 tdf = ROOT.ROOT.Experimental.TDataFrame(10000)
15 tdf.Define(
"b1",
"(int) tdfentry_")\
16 .Define(
"b2",
"(float) tdfentry_ * tdfentry_").Snapshot(treeName, fileName)
19 fileName =
"tdf007_snapshot_py.root" 20 outFileName =
"tdf007_snapshot_output_py.root" 21 outFileNameAllColumns =
"tdf007_snapshot_output_allColumns_py.root" 23 fill_tree(treeName, fileName)
26 TDF = ROOT.ROOT.Experimental.TDataFrame
27 d = TDF(treeName, fileName)
31 d_cut = d.Filter(
"b1 % 2 == 0")
36 std::vector<float> getVector (float b2) 39 for (int i = 0; i < 3; i++) v.push_back(b2*i); 43 ROOT.gInterpreter.Declare(getVector_code)
45 d2 = d_cut.Define(
"b1_square",
"b1 * b1") \
46 .Define(
"b2_vector",
"getVector( b2 )")
54 branchList = ROOT.vector(
'string')()
55 for branchName
in [
"b1",
"b1_square",
"b2_vector"]:
56 branchList.push_back(branchName)
57 d2.Snapshot(treeName, outFileName, branchList)
60 f1 = ROOT.TFile(outFileName)
62 print(
"These are the columns b1, b1_square and b2_vector:")
63 for branch
in t.GetListOfBranches():
64 print(
"Branch: %s" %branch.GetName())
71 d2.Snapshot(treeName, outFileNameAllColumns)
74 f2 = ROOT.TFile(outFileNameAllColumns)
76 print(
"These are all the columns available to this tdf:")
77 for branch
in t.GetListOfBranches():
78 print(
"Branch: %s" %branch.GetName())
86 branchList.push_back(
"b1_square")
87 snapshot_tdf = d2.Snapshot(treeName, outFileName, branchList);
88 h = snapshot_tdf.Histo1D(
"b1_square")