Converting SVector <> GenVector

I have an application where I need to convert between SVector<3> objects (for matrix algebra) and GenVector XYZVector objects (for geometric functions). I am currently doing that ‘by hand’, ie
using ROOT::Math::XYZVector;
typedef ROOT::Math::SVector<double,3> SVector3;
XYZVector gv1, gv2;
SVector3 sv1, sv2;

sv1 = SVector3(gv1.X(), gv1.Y(), gv1.Z());
gv2 = XYZVector(sv2[0],sv2[1],sv2[2]);
Is there a more elegant (less error-prone) way to perform these cross-constructions?
thanks, Dave

_ROOT Version:6.18
_Platform:macos Catalina

Hello Dave,

Unfortunately now it is not possible, three is not a different constructor taking a vector such as SVector. It was forseen, see line 118 of
but never enabled, probably because in the past there were some issues with the CINT template code.

Now that you are asking, if you need it, I could re-enable that code



Hi Lorenzo,
Thanks for your response. I had a vague recollection of this being supported or at least documented in earlier code, I’m glad to see I wasn’t completely wrong. I think it would be useful to have this functionality, it will result in cleaner, less fragile user code covering a legitimate and common use case. I suggest throwing if the dimensions don’t match exactly. What about the other direction? Could GenVector support operator []? That would allow cross-construction of SVector.


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