Meaning of RotateUz

Hello ROOTers,

I have to compute angles between vectors and may want to use the RotateUz function.

As far as I understood, we give a vector to that function, which rotates that into the Z direction…

I did that simple test

// create a vector
TVector3 A ( 1, 2, 3);
// define it as Z axis
TVector3 direction = A.Unit();
// rotate it in the new frame
A.RotateUz( direction );
// get its new coordinates
Double_t carray[3];
A.GetXYZ( carray );
cout << "x = " << carray[0] << endl;
cout << "y = " << carray[1] << endl;
cout << "z = " << carray[2] << endl;


What I got is

x = -0.628502
y = 3.21513
z = 1.80774

While I would expect the Z coordinate to be the norm of that vector thus
sqrt( 11 + 22 + 3*3 ) = 3.7416 !!!

What do I understand wrong ? Anyone may have an exemple of the use of that function ?

Thanks in advance,



I don’t tink that function can be used to compute angles between vector.
It is used for transforming a vector from a rotated frame to another.
For example, from the documentation of TVector3:

For getting the angle between two vector you can use

Double_t a = v1.Angle(v2);

Best Regards


The problem is unfortunately a bit more complicated, indeed the Angle() function computes the cosine of the angle from the scalar product, and then apply acos. Thus the angle is not between -pi and +pi.
Concerning RotationUz, if it’s effectively transform one vector from 1 frame to another, what is the meaning of the “direction” vector provided ? By applying that rotation to the “direction” vector one should get one basis vector of the new frame.

Direction represents the z’ axis of the rotated frame.
If you use as direction the vector (0,0,1), you will see that you have a unit transformation. (v’ = v)


So if I take the vector z’ and apply the rotation, I should get the z vector right ?
That’s my concern, because in my exemple I took the vector
TVector3 A ( 1, 2, 3);
as z’, and when applying the rotation to A, it was’nt aligned with z…

No, because it is not the inverse.
You will apply 2 times the same rotation.
If R is the rotation from direction z to direction z’, using RotateUz you will get the R * R rotation.


There must be then something I don’t make out …
The document says
transforms v1 from the rotated frame (z’ parallel to direction, x’ in the theta plane and y’ in the xy plane as well as perpendicular to the theta plane) to the (x,y,z) frame.

So the transformation RotationUz is F’ -> F through the R rotation right ?
If F” is defined in such a way that the A vector is the z’ axis, then R should take A to the z axis in F, right ?

It depends if you consider active or passive rotations. This is always a bit confusing.
In this case it is a passive rotation. The vector A is expressed initially in
(x’,y’,z’) and is then transformed by R in (x,y,z). But the vector itself does not rotate, it is the system that rotates.
It should probably be clarified in the documentation.


OK, I see what you mea ,

but it’ s quite confusing as I did’nt specify any frame F’ (out of the A vector) and the A vector is builld in the F frame at the beginning of my code

I am glad I found this thread: I read through but I am still confised.

If I have a vector VEC then I make a unit vector out of it U = VEC.Unit(); and then do VEC.RotateUz(U);
Should new VEC be aligned with Z? so when I do VEC.CosTheta() should it give me zero?