TBranch with TLeaf containing vectors

So far I’ve been writing doubles to TBranches in the following way:

Double_t startVector[8];

However I would like now the individual TLeaves to contain a std::vector<Double_t>.

std::vector <Double_t> > startVector[8];

doesn’t seem to work.


You have two choices. If you want to keep the naming of the leaf, use

std::vector <Double_t> > startVector(8); // Note the parenthesis and not a square bracket (you want a vector of 8 element and not an array of 8 vectors.
tree->Branch("startVector",  & (startVector[0]) ,"xEnd:yEnd:zEnd:pxEnd:pyEnd:pzEnd:tEnd:eEnd"); // you need to pass the starting address of the content of the vector

or if you want to simplify, you can use:

std::vector <Double_t> > startVector; // Here the initiall sizing of the vector might be optional depending on how the rest of your code uses it.
tree->Branch("startVector",  &startVector);