Retrieve tree value

Hi,

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”);
returnM=mt->GetV1();
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”
(Double_t)0.00000000000000000e+00

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.

Nidhi

Hy Nidhi,

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

http://root.cern.ch/phpBB2/viewtopic.php?t=4609

Have a nice day,

Joa.

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!!

Rene

Thanks, that works beautifully.