import ROOT
def fill_tree(treeName, fileName):
df.Define("b1", "(int) rdfentry_")\
.Define("b2", "(float) rdfentry_ * rdfentry_").Snapshot(treeName, fileName)
fileName = "df007_snapshot_py.root"
outFileName = "df007_snapshot_output_py.root"
outFileNameAllColumns = "df007_snapshot_output_allColumns_py.root"
treeName = "myTree"
fill_tree(treeName, fileName)
d_cut = d.Filter("b1 % 2 == 0")
getVector_code ='''
std::vector<float> getVector (float b2)
{
std::vector<float> v;
for (int i = 0; i < 3; i++) v.push_back(b2*i);
return v;
}
'''
ROOT.gInterpreter.Declare(getVector_code)
d2 = d_cut.Define("b1_square", "b1 * b1") \
.Define("b2_vector", "getVector( b2 )")
d2.Snapshot(treeName, outFileName, \
["b1", "b1_square", "b2_vector"])
f1 = ROOT.TFile(outFileName)
t = f1[treeName]
print("These are the columns b1, b1_square and b2_vector:")
for branch in t.GetListOfBranches():
print("Branch: %s" %branch.GetName())
f1.Close()
d2.Snapshot(treeName, outFileNameAllColumns)
f2 = ROOT.TFile(outFileNameAllColumns)
t = f2[treeName]
print("These are all the columns available to this dataframe:")
for branch in t.GetListOfBranches():
print("Branch: %s" %branch.GetName())
f2.Close()
snapshot_df = d2.Snapshot(treeName, outFileName, ["b1_square"]);
h = snapshot_df.Histo1D("b1_square")
c = ROOT.TCanvas()
h.Draw()
c.SaveAs("df007_snapshot.png")
print("Saved figure to df007_snapshot.png")
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...