XYZVector constructor based on C array

Hi,

Is there a reason why ROOT::Math::XYZVector doesn’t have a constructor such as:
XYZVector(const double* arr)?

TVector3 has it.
DD4hep Vector3D has it.
And If I am not mistaken CLHEP Geom library also should have it.

Sure one can always do:
XYZVector(arr[0], arr[1], arr[2]), but it way more uglier if it happens all over the code.

or in my particular case I am forced to do one of the following:

const double* arr = hit->getPosition();
XYZVector vec = XYZVector(arr[0], arr[1], arr[2])

or

XYZVector vec = XYZVector(hit->getPosition()[0], hit->getPosition()[1], hit->getPosition()[2])

which makes code even more uglier or creates a lot of temporary variables that are needed just to pass the array to the XYZVector.

cheers,
Bohdan

I also have not found the constructor you look for but you can break up in a single line or call a method and use

double d[3] = {1.,2.,3.};
XYZVector v;
v.SetCoordinates(d);

Or from a vector
v.SetCoordinate(d.begin(),d.end())

Maybe it’s not as good as having a constructor from array or vectors but you can inline an external function to construct , assign and return ( move) maybe?

1 Like

I ll ping it to possibly bring it back to life

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