Using TTreeFormual to access a vector in a TTree

Hi ROOT folks,

I have the following problem: given a TTree object containing a branch beeing a std::vector I try to access its elements using

TTreeFormula * form = new TTreeFormula(“form”, “myBranch”, tree);
tree->GetEntry(0);
cout << "instance 0: " << form->EvalInstance(0) << endl;
cout << "instance 1: " << form->EvalInstance(1) << endl;
cout << "instance 2: " << form->EvalInstance(2) << endl;
cout << "instance 3: " << form->EvalInstance(3) << endl;

While the branch “myBranch” has in entry 0 more than 2 elements in the vector (checked with tree->Scan()), only the first two get evaluated correctly, the rest is evaluated to zero. Is this a bug, any feature I don’t know or am I simply misunderstanding the way the TTreeFormual can be used.

Thank you very much for your help!!

Cheers,
Andi

Hi ROOTers,

is there anybody to know an answer to my question?

Thanks!
Cheers,
Andi

Hi Andi,

You must call form->GetNdata() in order to properly initialize the internal sizes (and use the result to know how many element to loop for).

Cheers,
Philippe.

Hi Philippe,

thank you very much! This solves my problem.

Cheers,
Andi