PyROOT and operator overloading?


I’m confused why this doesn’t work:

[code]In [5]: a = ROOT.TVector3(1, 2, 3)

In [6]: b = ROOT.TVector3(4, 5, 6)

In [7]: a-b

TypeError Traceback (most recent call last)

/home/elliottb/workspace/mycroot/ in ()

TypeError: unsupported operand type(s) for -: ‘TVector3’ and ‘TVector3’

In [8]: a -= b

In [9]: a.Print()
TVector3 A 3D physics vector (x,y,z)=(-3.000000,-3.000000,-3.000000) (rho,theta,phi)=(5.196152,125.264390,-135.000000)

I’ve been dealing with this for a while. Mostly been working around, but I’m thinking that I should probably post it here.

Is there something I’m not understanding about python?



mapping C++ global operator overloading is a relative recent feature (there is, after all no such thing in python). Which version of ROOT are you using?


Sorry that I never got back on this. I just realized that this now seems to work with ROOT 5.28. (at least with TVector3’s) Very nice!