TVector3 - operator syntax?

Hello,

Can anyone spot what I’m doing wrong here?:

#!/usr/bin/env python

from ROOT import TVector3

a = TVector3(1, 2, 3)
b = TVector3(4, 5, 6)

c = b - a

When run, I get:

Traceback (most recent call last):
  File "test2.py", line 8, in <module>
    c = b - a
TypeError: TVector3 TVector3::operator-() =>
    takes at most 0 arguments (1 given)

(Edited from earlier post for clarity)

Cheers,
Matthew Lockner

Hi,

Does this work in Cint?

Cheers,
Charles

simple to try ::slight_smile:

root [1] TVector3 a(1,2,3) root [2] TVector3 b(4,5,6) root [3] TVector3 c=b-a root [4] c.Print() TVector3 A 3D physics vector (x,y,z)=(3.000000,3.000000,3.000000) (rho,theta,phi)=(5.196152,54.735610,45.000000) root [5]

Rene

Hi,

the operator-() for the TVector is a globally overloaded function, which I currently have no clear idea on how to associate with the class (that is, how to find them in the dictionary; python does make the overload itself possible).

Cheers,
Wim

[quote=“wlav”]Hi,

the operator-() for the TVector is a globally overloaded function, which I currently have no clear idea on how to associate with the class (that is, how to find them in the dictionary; python does make the overload itself possible).

Cheers,
Wim[/quote]

Globally defined where? I don’t really know enough about Python-C interfacing to look into this deeply, but I can keep an eye peeled should I ever come across a good workaround. (I plan to start using PyROOT wherever possible, so I will likely revisit this over time. I do find that defining a “minus(a, b)” function in Python will work as expected with the obvious implementation).

Hi,

the C++ definition is in include/TVectorT.h. They get into the dictionary as global functions, which can be found and parsed by name, but doing so is extremely slow (n^2).

Cheers,
Wim

[quote=“wlav”]Hi,

the C++ definition is in include/TVectorT.h. They get into the dictionary as global functions, which can be found and parsed by name, but doing so is extremely slow (n^2).

Cheers,
Wim[/quote]

Greetings,

Is this it?

Hi,

yes, and then an instantiation of it in the dictionary.

Cheers,
Wim

[quote=“wlav”]Hi,

yes, and then an instantiation of it in the dictionary.

Cheers,
Wim[/quote]

Greetings,

Please explain what “dictionary” means in this context. Does this refer to CINT?

Hi,

yes, and is what is used to provide the bindings. PyROOT uses a list (hashtable, really) of global functions to find them on request, but here something different is needed: given the class, what are the global overloads defined for it. I haven’t found an easy way to do so, other than searching the full list, which turns into a double loop (n^2) that way.

Cheers,
Wim

[quote=“wlav”]Hi,

yes, and is what is used to provide the bindings. PyROOT uses a list (hashtable, really) of global functions to find them on request, but here something different is needed: given the class, what are the global overloads defined for it. I haven’t found an easy way to do so, other than searching the full list, which turns into a double loop (n^2) that way.

Cheers,
Wim[/quote]

Another hashtable mapping classes to names/pointers of global overloaded functions, maybe?

(Please pardon the armchair programming, it sounds like it would take an outsider some measure of involved study to resolve).

M. Lockner

Actually, is there any sort of documentation of the PyROOT internals floating around anywhere? I’m keen enough on the tool that I think I’d like to learn at least a little about its inner workings. It’s proven impressively complete and stable thus far.

M. Lockner

Hi,

yes, except that it would be n^2 to build if not done on loading, so no gain there. There should be a better way, since CINT can find it, but not all functionality is readily accessible.

There’s an open savannah on this one; won’t be forgotten. Problem is that the experiment startup (I’m a member of ATLAS) currently has priority (that, and recovery from surgery: I’m not even armchair programming, it’s bedside).

Cheers,
Wim

[quote=“wlav”]Hi,

yes, and is what is used to provide the bindings. PyROOT uses a list (hashtable, really) of global functions to find them on request, but here something different is needed: given the class, what are the global overloads defined for it. I haven’t found an easy way to do so, other than searching the full list, which turns into a double loop (n^2) that way.

Cheers,
Wim[/quote]

Why not just mandate that the C++ base consider bindings and implement global operator overloads as (inlined?) wrappers to class methods. IMO, they should be named to eliminate any ambiguity, anyway. Personally, I could use a TVector3.Scale method in PyROOT…

Or, just start specific Pythonification of a few classes? :smiley:

Hi,

such a coding convention still wouldn’t work as most of these binary operators would at that point be friends or using. Neither is properly propagated through the dictionary at this point in time.

Cheers,
Wim

Wim,

As explained in another thread, TVector3 has nothing to do with TVectorT.
TVector3, TLorenztVector are physics objects describing things such as a particle position, momentum, 4 vectors, while TVectorT is a container for basic types.

Rene