Error loading Info from event branch in python

Issue #265 resolved
Laurie Nevay created an issue

Following instructions: http://www.pp.rhul.ac.uk/bdsim/manual-develop/output_analysis.html#looping-over-events

I should be able to do:

> d = pybdsim.Data.Load("data.root")
> eventTree = d.GetEventTree()
> for event in eventTree:
   .... print event.Info.duration

but I get the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-8fd0cc31bbb6> in <module>()
      1 for event in eventTree:
----> 2     print event.Info.index
      3

AttributeError: 'ROOT.MethodProxy' object has no attribute 'index'

Whereas for any primary or sampler branch this works fine - such as event.Primary.x.

I suspect something to do with the way the Info structure is setup in the Event class in analysis.

Comments (1)

  1. Laurie Nevay reporter

    This was found to be because the TObject class has a function called Info. Only when using python iteration like this do you get the function instead of the object.

    To avoid this, we have changed Info to Summary in the output for the next release (backwards compatible of course).

    To overcome this with files with Info in the Event tree, you need to loop over it manually with GetEntry(n) on the tree and look at your Info object directly.

    d = pybdsim.Data.Load("data.root")
    event = d.GetEvent()
    eventTree = d.GetEventTree()
    for i in range(eventTree.GetEntries()):
        eventTree.GetEntry(i)
        print event.Info.duration
    

    works!

  2. Log in to comment