Operations on LorentzVectors saved to a TTree

Dear all,

I’m running intro trouble when trying to save objects of type “PtEtaPhiEVector” to a TTree, and when performing operations (assignments, sums) on those objects.

What I’m doing:

import ROOT as R
out_tree = R.TTree("t", "t")

vec = R.PtEtaPhiEVector()
out_tree.Branch("vec", vec)

/* // 1) This works like a charm
vec.SetCoordinates(50, 0, 0, 50)

// 2) This doesn't work:
v1 = R.PtEtaPhiEVector(25, 0, 0, 25)
v2 = R.PtEtaPhiEVector(25, 0, 0, 25)
vec = v1 + v2


In the first case, I fill the vector by calling a method, and it works fine: the output tree is filled with the correct values.

In the second case, I call the assignment operator: in the output tree, the coordinates for “vec” are nonsensical…

Is there a workaround in PyROOT? One solution is to create a temporary vector “temp = v1 + v2”, then assign its coordinates to “vec”, but that’s not quite practical…



the python-side assignment is a reference assignment, not a C++ operator= (this is a language thing, not a bindings thing). Call the latter explicitly:vec.__assign__(v1 + v2)to modify the original ‘vec’ object.


Thanks! That’s what I thought, but it wasn’t clear to me how to call the actual operator explicitly…