Unable to add a TGLVector3 to a TGLVertex3 in a loop in PyROOT

Hi,

I’m trying to add a TGLVector3 to a TGLVertex3 in PyROOT:

    scatteringPoint = TGLVertex3(2., 3., 0.2)
    vectorAfterScattering = TVector3(1, 2, 3)
    vertexEnd = scatteringPoint + TGLVector3(vectorAfterScattering.X(), vectorAfterScattering.Y(), vectorAfterScattering.Z())

It works on its own, but as soon as I put it in a loop like this:

import ROOT
from ROOT import *

def scattering():
    scatteringPoint = TGLVertex3(2., 3., 0.2)
    vectorAfterScattering = TVector3(1, 2, 3)
    vertexEnd = scatteringPoint + TGLVector3(vectorAfterScattering.X(), vectorAfterScattering.Y(), vectorAfterScattering.Z())


def main():
    for k in range(10):
        print("---Iteration #%i---" % (k+1))
        scattering()

if __name__ == "__main__":
    main()

, it works fine in the first iteration and then breaks with

---Iteration #1---
---Iteration #2---
Traceback (most recent call last):
  File "model_3d_v03_problem.py", line 18, in <module>
    main()
  File "model_3d_v03_problem.py", line 15, in main
    scattering()
  File "model_3d_v03_problem.py", line 9, in scattering
    vertexEnd = scatteringPoint + TGLVector3(vectorAfterScattering.X(), vectorAfterScattering.Y(), vectorAfterScattering.Z())
TypeError: TGLVertex3 ::operator+(const TGLVertex3& vertex1, const TGLVector3& vertex2) =>
    could not convert argument 2

Why? And why it worked first time?

In C++, however, this works fine: the following excerpt:

void model_3d_v03_problem()
{
        for (int k=0; k<10; k++)
        {
                printf("---Iteration #%i---\n", k+1);
                TGLVertex3 scatteringPoint(2., 3., 0.2);
                TVector3 vectorAfterScattering(1, 2, 3);
                TGLVertex3 vertexEnd(scatteringPoint + TGLVector3(vectorAfterScattering.X(), vectorAfterScattering.Y(), vectorAfterScattering.Z()));
                printf("\tThis second point: (x,y,z) = (%.2f,%.2f,%.2f)\n", vertexEnd.X(), vertexEnd.Y(), vertexEnd.Z());
        }
}

returns good numbers for all ten iterations.


ROOT Version: 6.14.04
Platform: x86_64-slc6
Compiler: gcc484
Python: 2.7.4


Hi @yus,

I was able to reproduce the issue, it indeed looks like a bug. I opened a ticket to follow it:

https://sft.its.cern.ch/jira/browse/ROOT-10166

Enric

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.