This tutorial shows how to write out datasets in ROOT formatusing the TDataFrame.
5 void fill_tree(const char *filename, const char *treeName)
7 TFile f(filename, "RECREATE");
8 TTree t(treeName, treeName);
13 for (int i = 0; i < 10000; ++i) {
25 fileName =
"tdf007_snapshot_py.root"
26 outFileName =
"tdf007_snapshot_output_py.root"
27 outFileNameAllColumns =
"tdf007_snapshot_output_allColumns_py.root"
29 ROOT.gInterpreter.Declare(fill_tree_code)
30 ROOT.fill_tree(fileName, treeName)
33 TDF = ROOT.ROOT.Experimental.TDataFrame
34 d = TDF(treeName, fileName)
38 d_cut = d.Filter(
"b1 % 2 == 0")
43 std::vector<float> getVector (float b2)
46 for (int i = 0; i < 3; i++) v.push_back(b2*i);
50 ROOT.gInterpreter.Declare(getVector_code)
52 d2 = d_cut.Define(
"b1_square",
"b1 * b1") \
53 .Define(
"b2_vector",
"getVector( b2 )")
61 branchList = ROOT.vector(
'string')()
62 for branchName
in [
"b1",
"b1_square",
"b2_vector"]:
63 branchList.push_back(branchName)
64 d2.Snapshot(treeName, outFileName, branchList)
67 f1 = ROOT.TFile(outFileName)
69 print(
"These are the columns b1, b1_square and b2_vector:")
70 for branch
in t.GetListOfBranches():
71 print(
"Branch: %s" %branch.GetName())
78 d2.Snapshot(treeName, outFileNameAllColumns)
81 f2 = ROOT.TFile(outFileNameAllColumns)
83 print(
"These are all the columns available to this tdf:")
84 for branch
in t.GetListOfBranches():
85 print(
"Branch: %s" %branch.GetName())
93 branchList.push_back(
"b1_square")
94 snapshot_tdf = d2.Snapshot(treeName, outFileName, branchList);
95 h = snapshot_tdf.Histo1D(
"b1_square")
- Date
- April 2017
- Author
- Danilo Piparo
Definition in file tdf007_snapshot.py.