This tutorial shows how to write out datasets in ROOT formatusing the TDataFrame.
5 def fill_tree(treeName, fileName):
6 tdf = ROOT.ROOT.Experimental.TDataFrame(10000)
7 tdf.Define(
"b1",
"(int) tdfentry_")\
8 .Define(
"b2",
"(float) tdfentry_ * tdfentry_").Snapshot(treeName, fileName)
11 fileName =
"tdf007_snapshot_py.root"
12 outFileName =
"tdf007_snapshot_output_py.root"
13 outFileNameAllColumns =
"tdf007_snapshot_output_allColumns_py.root"
15 fill_tree(treeName, fileName)
18 TDF = ROOT.ROOT.Experimental.TDataFrame
19 d = TDF(treeName, fileName)
23 d_cut = d.Filter(
"b1 % 2 == 0")
28 std::vector<float> getVector (float b2)
31 for (int i = 0; i < 3; i++) v.push_back(b2*i);
35 ROOT.gInterpreter.Declare(getVector_code)
37 d2 = d_cut.Define(
"b1_square",
"b1 * b1") \
38 .Define(
"b2_vector",
"getVector( b2 )")
46 branchList = ROOT.vector(
'string')()
47 for branchName
in [
"b1",
"b1_square",
"b2_vector"]:
48 branchList.push_back(branchName)
49 d2.Snapshot(treeName, outFileName, branchList)
52 f1 = ROOT.TFile(outFileName)
54 print(
"These are the columns b1, b1_square and b2_vector:")
55 for branch
in t.GetListOfBranches():
56 print(
"Branch: %s" %branch.GetName())
63 d2.Snapshot(treeName, outFileNameAllColumns)
66 f2 = ROOT.TFile(outFileNameAllColumns)
68 print(
"These are all the columns available to this tdf:")
69 for branch
in t.GetListOfBranches():
70 print(
"Branch: %s" %branch.GetName())
78 branchList.push_back(
"b1_square")
79 snapshot_tdf = d2.Snapshot(treeName, outFileName, branchList);
80 h = snapshot_tdf.Histo1D(
"b1_square")
- Date
- April 2017
- Author
- Danilo Piparo
Definition in file tdf007_snapshot.py.