we have found a very strange issue when using the TTree Draw/Scan/Projection functions on vectors of vectors.
In our analysis, we consider large jets that are made up of smaller jets. To represent the kinematics of these small jets in the Tree, we use vectors of vectors, specifically
Where subjet_pt[0/1/2] are the vectors of the pt of subjets in the first, second, third large jet.
For each event, one of these large jets is "tagged" and we store the index of this tagged jet in a branch.
The issue appears when we try to draw/scan the subjet_pt of the tagged jet (or its length): if we call
we get wrong results, only for events where tagged_index is != 0. In particular, most of the times subjet_pt[tagged_index] contains more entries than it should. The additional entries are printed as empty
The issue doesn't appear when we pass by hand the index of the jet:
In this case the column corresponding to subjet_pt[tagged_index] is wrong, while the one corresponding to subjet_pt is correct.
We attach a code which replicates the issue.
In this code we build a tree with four branches:
- subjets_pt which is a vector< vector<int>> containing the pt of the large jets components (filled with meaningless values)
- tagged_index: the index of the tagged jet (component_pt[tagged_index] is then vector of the pt of the subjets inside the tagged jet);
- nsubjets: is the number of subjets of the tagged jet, to be used as a cross check
- njets is the number of large jets
Within ROOT, this can be run with
and creates a file named AFile.root with a tree named myTree
Several checks can be performed:
will show that the number of entries of the subjets_pt[tagged_index] column is equal to nsubjets only when tagged_index is zero.
will show that, when we request explicitly the second element to be tagged (tagged_index == 1) and access explicitly the second element (subjet_pt), the results is correct.
In summary, everything works well when we pass explicitly the index of the large jet we want to access (subjets_pt, subjets_pt and so on); the problems appear when we pass an integer stored in a branch of the same tree.
In particular, it seems that Length$(subjets_pt[tagged_index]) is equal to Length$(subjets_pt) regardless the actual value of tagged_index. Only the size is wrong: the actual vector seems correct (with blank entries when the actual size is smaller, and "truncated" when the actual size is bigger). Everything works fine when we pass the index by hand.