Hi Noel,
thank you very much for the example (which works like a charm!) and the clarifications. I tried to modify your program to adapt it to my needs, but I did not quite succeed, so I was trying to figure out what I might be doing wrong before posting another question. So, here is how I modified the program:
import rootpy
rootpy.log.basic_config_colorized()
from rootpy.tree import Tree, TreeModel
from
rootpy.io import root_open as ropen
from rootpy.types import IntCol, ObjectCol
import rootpy.compiled as C
from random import gauss
# alternatively you can ROOT.gSystem.Load() your library
import ROOT
ROOT.gSystem.Load("Delphes_C")
# define the model
class Event(TreeModel):
event_number = IntCol()
thingy = ObjectCol(ROOT.Delphes)
f = ropen("test.root", "recreate")
tree = Tree("test", model=Event)
# fill the tree
for i in xrange(20):
tree.event_number = i
tree.thingy.Track_size = 1
tree.fill()
tree.write()
f.close()
# now to read the same tree
with ropen("test.root") as f:
tree = f.test
for event in tree:
thing = event.thingy
print event.event_number, thing.Track_size
Why is this not working? I loaded my own (rather Delphes') class definitions by
1) opening the file mymain.root generated by Delphes in root and TBrowser,
2) generating Delphes.C and Delphes.h by the MakeClass command,
3) precompiling the code with "echo .L Delpges.C++ | root -b".
Pyroot seems to recognize the new class, but filling the tree with "tree.thingy.Track_size = 1" seems to have no effect (output is thing.Track_size --> 0). Any ideas? For ease of inspection, I am attaching
1) the code,
2) Delphes.C,
3) Delphes.h.
I am using Python 2.7.1., Root 5.28 and the most recent pyroot (updated this morning via git).
Best,
Akin