Hello,
For a while now I have made much use of the behaviour that if I had two vector branches in a TTree, I could do TTreeFormula-type access of an element of the first branch with index corresponding to the value of a second branch. E.g. I could do: branch1[branch2] and if branch2’s value was always a valid index of branch1, I would get what I wanted. E.g.:
branch1 = {2,4,6,8};
branch2 = {0,0,2,3};
doing: Scan(“branch1[branch2]”)
would give: {2,2,6,8} as the returned values for each iteration in that entry.
I wanted to now do a similar thing but where branch1 was a vector of vectors. The behaviour seems to be what I would want, but I get an error message from ROOT:
Error in TArrayI::At: index 2 out of bounds (size: 2, this: 0x4fc9ed0)
Here’s a minimal reproducer:
{
TTree t("t","t");
std::vector<std::vector<int>>* v1 = new std::vector<std::vector<int>>;
v1->resize(2); v1->at(0).resize(2,1); v1->at(1).resize(2,3);
//so v1 = {{1,1},{3,3}}
std::vector<int>* v2 = new std::vector<int>(3,1);
//so v2 = {1,1,1}
t.Branch("v1",&v1);t.Branch("v2",&v2);t.Fill();
t.Scan("v1[v2][0]","Iteration$==0"); //this produces the desired result of '3' but with an error as above
}
Is this way of using the value of one branch as the index of another erroneous in this example? I need to make the error go away because it is flooding my log files when I process a large TTree with this sort of formula
Just to say, this error appears when the v1 (vector of vectors) is of a smaller size than v2 (the vector of indices).
Thank you
Will