Problem retreaving leaf from TBranch with GetLeaf

Hi,

I have a TFile containing a TTree with some TBranches. I want to plot a TLeaf in one of the branches and do like this:

TFile *f = new TFile("file.root)
TTree t = (TTree)f->Get(“Physics”)
TBranch b = (TBranch)t->GetBranch(“Detector1”)
(b->GetLeaf(“Variable”))->GetValue(0)

but GetLeaf return a null pointer. This is not the case if I plot a variable in the tree. That is, if I use GetLeaf directly on the top level tree. Why is this? Isnt it possible to use GetLeaf on a TBranch like this?

regards
Peter

Hi Peter,
if b->GetLeaf(“Variable”) return null pointer, leaf “Variable” does not exist …
if b->GetLeaf(“Variable”)->GetValue() return (const Double_t)0.0 you forgot t->GetEntry(123) (or b->GetEntry(123) )

Jan

Hi Jan,

the variable exists, Im sure. When I try to retrieve the leaf from the sub-branch I get the error
root [18] (b->GetLeaf(“unpackError”))->GetValue(0)
Error: illegal pointer to class object b->GetLeaf(“unpackError”) 0x0 150 (tmpfile):1:

but when I do the same thing with a variable directly under the top-tree it works… so, whats the difference between: (where f is an open root file)
1)
TTree t = (TTree)f->Get(“Physics”)
t->GetEntry(0)
(t->GetLeaf(“somevariable”))->GetValue(0)

and
2)
TBranch b = (TBranch)t->Get(“Detector”)
b->GetEntry(0)
(b->GetLeaf(“someothervariable”))->GetValue(0)

just to not confuse anyone, I dont mean to extract the same variable in the two cases above… I just wonder why the first procedure works but not the second

thanks!

[quote=“musinsky”]Hi Peter,
if b->GetLeaf(“Variable”) return null pointer, leaf “Variable” does not exist …
if b->GetLeaf(“Variable”)->GetValue() return (const Double_t)0.0 you forgot t->GetEntry(123) (or b->GetEntry(123) )

Jan[/quote]

[quote]TBranch b = (TBranch)t->Get(“Detector”)
b->GetEntry(0)
(b->GetLeaf(“someothervariable”))->GetValue(0) [/quote]try this:

name “someothervariable” must be in this list (maybe in other sub-branch?)
or try this:

Jan