How to access the Tree inside TDirectory

Hello Experts,

I have a root file with a tree inside a directory:

TFile* test.root
TDirectoryFile* ana ana folder
KEY: TTree ntuple;1 Variables for selected events

Also, there is a variable called “Run” inside the tree.

I tried to access the Tree using the example from the pyRoot maual:

[code] myfile = ROOT.TFile(‘test.root’)
mychain = ROOT.gDirectory.Get(‘ana/ntuple’)
entries = mychain.GetEntriesFast()

for jentry in xrange(entries):
    ientry = mychain.LoadTree(jentry)
    if ientry< 0:
        break
    nb = mychain.GetEntry(jentry)
    if nb <= 0:
        continue
    run = mychain.Run
    print run

[/code]
But I got the error:

AttributeError: ‘TTree’ object has no attribute ‘Run’

Any suggestions?

Thanks!
Xin

Hi,

can you post the “test.root” file, so that the problem may be reproduced? Thanks.

Cheers,
Wim

Hi Wim,

Please see the attachment. Thanks!

Xin
test.root (393 KB)

Xin,

the name that the lookup reconizes is “run_” instead of “Run”. Having the mapping automatic was an old TODO … now fixed in trunk. Please use “mychain.run_” for now (which will continue to work).

Cheers,
Wim

Hi Wim,

I see. I’d better use the same name for the variables when booking them.

Thanks!

Xin