Dear all,
I’m trying to read .root file (array-1-0.root (105.3 KB) ) which contain 1 vector<double> and 2 double variable branches, by PyROOT.
My python script is :
import sys
import os
import ROOT as rt
from ROOT import gROOT as grt
from ROOT.VecOps import RVec
from sklearn.decomposition import PCA
import pandas
import numpy as np
#variables = ["vector0", "vector1"]
if __name__ == "__main__":
for filename, label in [["array-1-0.root", "signal"]]:
print(">>> Extract the training and testing events for {} from the {} dataset.".format(label, filename))
fullpath = os.path.dirname(filename)+filename
df = rt.RDataFrame("test", fullpath) # getting tree
vec1 = df.AsNumpy(columns=["vector"]) # test to get "vector", vector<double> branch
vec4 = rt.VecOps.RVec('double')(vec1) # does not work
# Output test
print("Test. {}".format(vec4))
And I’d like to read my vector<double> object at branch (in the file) and convert it to numpy array.
At first I simply tried like vec1=file.AsNumpy(columns=["vector"])
.
In my script, the output of print(“{}”.format(vec1)) is :
{‘vector’: ndarray([<cppyy.gbl.ROOT.VecOps.RVec object at 0x7fca7e5d0540>,
<cppyy.gbl.ROOT.VecOps.RVec object at 0x7fca7e5d0568>,
<cppyy.gbl.ROOT.VecOps.RVec object at 0x7fca7e5d0590>,
<cppyy.gbl.ROOT.VecOps.RVec object at 0x7fca7e5d05b8>,
…
Then how can I take a vector and convert it to numpy array?
Thank you.
Best regards,
KH Kim
ROOT Version: 6.22/09
Platform: WSL Ubuntu 18.04
Compiler: (Not exactly know what, but I run python script.)