TBranch with TLeaf containing vectors

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

Double_t startVector[8];
tree->Branch("startVector",startVector,"xEnd/D:yEnd/D:zEnd/D:pxEnd/D:pyEnd/D:pzEnd/D:tEnd/D:eEnd/D");

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

std::vector <Double_t> > startVector[8];
tree->Branch("startVector",startVector,"xEnd:yEnd:zEnd:pxEnd:pyEnd:pzEnd:tEnd:eEnd");

doesn’t seem to work.

Hi,

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);

Cheers,
Philippe.