Editing single tree entries on the fly

Hello,
I was wondering if it’s possible to edit a single entry of one branch of a tree on the fly, without it affecting other entries. Here’s a sample of what I’m trying to accomplish:

def scale(t):
  t.SomeVariable *= 1.5

for i in xrange(tree.GetEntries()):
  tree.GetEntry(i)
  scale(tree)
  # do something with tree.SomeVariable
  print tree.SomeVariable

I tried the above code, but the problem is once I do t.SomeVariable *= 1.5, tree.SomeVariable no longer changes value as I loop over all entries. Eg., suppose SomeVariable has values 2, 4, 6, 8 for the 4 first events, then the output of the above macro will be:

3
4.5
6.75
10.125

instead of what I would like it to be:

3
6
9
12

Ideas?

Hi,

tree.SomeVariable works because SomeVariable is not a member of the python object tree, and then a hook kicks in to lookup the variable from the C++ Tree. Once you did *=, which has an assignment, SomeVariable will be a data member of the python object tree, and so the hook is no longer called.

You’ll have to save tree.SomeVariable in a local variable before doing =. Note that that local variable may be assigned to the tree if you want, so you could use e.g. tree.ScaledSomeVariable = 1.5tree.SomeVariable and then use each as appropriate downstream.

Cheers,
Wim