这对我来说是用在平线上的指数计算。
>>>from ROOT import *
>>>vec1 = std.vector( double )()
>>>vec2 = std.vector( double )()
>>>vec_vec = std.vector(std.vector( double ))()
>>>for i in range(3):
>>> vec1.push_back(i)
>>>for i in range(5):
>>> vec2.push_back(i)
>>>vec_vec.push_back(vec1)
>>>vec_vec.push_back(vec2)
>>>len(vec_vec)
2
>>>len(vec_vec[0])
3
>>>len(vec_vec[1])
5
>>>vec_vec[1][2]
2.0
在你的例子中,错误说:
TypeError: vector<vector<float> > object is unindexable
在打电话给构造者(类型)之后,你有不同的类型表明记忆空间的分配者正在工作。
>>>type(vec1)
<class ROOT.vector<double,allocator<double> > >
>>>type(vec_vec)
<class ROOT.vector<vector<double,allocator<double> >,allocator<vector<double,allocator<double> > > > >
To import such vectors from a TTree use setBranchAddress like in this example:
>>>tree = file.Get( tree )
>>>tree.SetBranchAddress("nested",vec_vec)
>>>N = tree.GetEntries()
>>>for i in range(N):
>>> vec_vec.clear()
>>> tree.GetEntry(i)
>>> print vec_vec[0][0]
Also note that this may be significantly faster after using
>>>tree.setBranchStatus( * ,0)
>>>tree.setBranchStatus( nested ,1)