1

I'm trying to get up and running using the TTreeReader approach to reading TTrees in PyROOT. As a guide, I am using the ROOT 6 Analysis Workshop (http://root.cern.ch/drupal/content/7-using-ttreereader) and its associated ROOT file (http://root.cern.ch/root/files/tutorials/mockupx.root).

from ROOT import *
fileName = "mockupx.root"
file = TFile(fileName)
tree = file.Get("MyTree")
treeReader = TTreeReader("MyTree", file)

After this, I am a bit lost. I attempt to access variable information using the TTreeReader object and it doesn't quite work:

>>> rvMissingET = TTreeReaderValue(treeReader, "missingET")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/ROOT/v6-03-01/root/lib/ROOT.py", line 198, in __call__
    result = _root.MakeRootTemplateClass( *newargs )
SystemError: error return without exception set

Where am I going wrong here?

pseyfert
  • 3,263
  • 3
  • 21
  • 47
d3pd
  • 7,935
  • 24
  • 76
  • 127

1 Answers1

2

TTreeReaderValue is a templated class, as shown in the example on the TTreeReader documentation, so you need to specify the template type.

You can do this with

rvMissingET = ROOT.TTreeReaderValue(ROOT.Double)(treeReader, "missingET")

The Python built-ins can be used for int and float types, e.g.

rvInt = ROOT.TTreeReaderValue(int)(treeReader, "intBranch")
rvFloat = ROOT.TTreeReaderValue(float)(treeReader, "floatBranch")

Also note that using TTreeReader in PyROOT is not recommended. (If you're looking for faster ntuple branch access in Python, you might look in to the Ntuple class I wrote.)

Alex
  • 9,313
  • 1
  • 39
  • 44