I haven’t looked into this for two long, but I found that using the following script I can get two different vector components for a vector. I think they should be the same in both cases

That is not the point. The thing should be the same in both cases, regardless of the units, shouldn’t it?

I set the coordinates in spherical coordinates (it doesn’t matter if in degrees or radians) write the coordinates in cartesian, set the coordinates again to the same values but using different methods (methods I believe should do the same thing) and write the cartesian coordinates again.

The point is that I’m getting different values for the cartesian coordinates, using two methods that are supposed to do the same thing, and using exactly the same values.

Am I missing something here?

I actualy think the problem is not in SetTheta but in SetPhi.

Double_t ma = Mag();
Double_t ph = Phi();//here is the call to TMath::Atan2, which
//always returns value from -pi to pi in radians. How do you think, is posiible to get yout original pi == 140.168 here???

Hi,
wait, I suppose we all agree that TVector3 v(x,y,z);
v.SetTheta(v.GetTheta()); should leave the vector unchanged, right? And so it has to be fixed.
Axel.

What shoud be fixed??? Do you think in spherical coordinates Phi can be 140 radians and theta 54 radians??? The author need to convert angles!
And if you add SetTheta(angle * DegToRad() ) or SetPhi(angle2 * DegToRad())…

Hi,
the problem stems from using theta outside its defined range. theta is only defined for [0…pi[, and by passing a value >pi, phi gets flipped: v.SetMagThetaPhi(1.,3.0,0.)
v.Print()
TVector3 A 3D physics vector (x,y,z)=(0.141120,0.000000,-0.989992) (rho,theta,phi)=(1.000000,171.887339,0.000000)
v.SetTheta(3.)
v.Print()
TVector3 A 3D physics vector (x,y,z)=(0.141120,0.000000,-0.989992) (rho,theta,phi)=(1.000000,171.887339,0.000000)
v.SetMagThetaPhi(1.,3.5,0.)
v.Print()
TVector3 A 3D physics vector (x,y,z)=(-0.350783,-0.000000,-0.936457) (rho,theta, phi)=(1.000000,159.464772,-180.000000)
v.SetTheta(3.5)
v.Print()
TVector3 A 3D physics vector (x,y,z)=(0.350783,0.000000,-0.936457) (rho,theta,phi)=(1.000000,159.464772,0.000000)
Setting MagThetaPhi and Mag, Theta, Phi should still be consistent in my point of view, and it should probably issue a warning about an out-of-range theta. I’ll come up with a patch.
Axel.