Accessing variables in a TTree

Is there any way to access directly a variable stored in a tree?
I mean, imagine you have a TTree with 2 branches called px and py and you wish to call the i-th entry and then store px and py in a bidimensional array. Is it possible?

Yes, it is … They are several mechanism. You could do tree->Draw(“px:py”,"",“goff”) and the use the result of tree->GetV1() and tree->GetV2() (and you might have to call tree->SetEstimate(tree->GetEntries()).

You could write a small script:// start of my script.C double script() { myarray[fChain->GetReadEntry()][0] = px; myarray[fChain->GetReadEntry()][1] = px; };and// start of my script.h double myarray[maxentry][2]; // Or any 'smarter' container and the use[code]tree->Draw(“script.C”,"",“goff”);
Or you can make tree->MakeSelector (or MakeClass or MakeProxy) and modify the body of the generate code skeleton to suit your need …

Cheers,
Philippe.
Ps. Or … you coud even use TTreeFormula (the engine behing TTree::Draw) directly …