Retrieve tree value


I’ve a tree made of several branches. The branches contain Ion information such as Element Name, Atomic Number, Atomic Mass, etc. If I want to retrieve let say Atomic Mass given the Element Name and Atomic Number, how would I do that?

I’ve tried following method.

Double_t myMass(Int_t AA, Int_t AZ)
Double_t returnM;
TFile *mrf = TFile::Open(“mass2003tree.root”);
mt->Draw(“M”, “A==AA && Z==AZ”, “goff”);
return returnM;

Here, AA=Atomic Number and AZ=Atomic Z.

This gives me following error after I load the file and type “myMass(11, 5)” for 11B mass:
Error in TTreeFormula::Compile: Bad numerical expression : “AA”

I’m not sure how I can pass a parameter in the selection whether it’s an integer, double, or string of characters?

Any help would be great.


Hy Nidhi,

I guess this is exactly what I’m trying to do, too…

Have a nice day,


To encode the value of a variable, use the Form function as shown below

Double_t myMass(Int_t AA, Int_t AZ) { TFile *mrf = TFile::Open("mass2003tree.root"); int N = mt->Draw("M", Form("A==%d && Z==%d",AA,AZ), "goff"); return mt->GetV1(); //returns a pointer to the array of N selected values of M }
Note that TTree::GetV1 does not return a scalar, but a pointer to an array!!


Thanks, that works beautifully.