183 TVector3 & TVector3::operator *= (
const TRotation & m){
184 return *
this = m * (*this);
190 TVector3 & TVector3::Transform(
const TRotation & m) {
191 return *
this = m * (*this);
197 Double_t TVector3::Angle(
const TVector3 & q)
const
199 Double_t ptot2 = Mag2()*q.Mag2();
203 Double_t arg = Dot(q)/TMath::Sqrt(ptot2);
204 if(arg > 1.0) arg = 1.0;
205 if(arg < -1.0) arg = -1.0;
206 return TMath::ACos(arg);
213 Double_t TVector3::Perp()
const
215 return TMath::Sqrt(Perp2());
222 Double_t TVector3::Perp(
const TVector3 & p)
const
224 return TMath::Sqrt(Perp2(p));
230 Double_t TVector3::Phi()
const
232 return fX == 0.0 && fY == 0.0 ? 0.0 : TMath::ATan2(fY,fX);
238 Double_t TVector3::Theta()
const
240 return fX == 0.0 && fY == 0.0 && fZ == 0.0 ? 0.0 : TMath::ATan2(Perp(),fZ);
246 TVector3 TVector3::Unit()
const
248 Double_t tot2 = Mag2();
249 Double_t tot = (tot2 > 0) ? 1.0/TMath::Sqrt(tot2) : 1.0;
250 TVector3 p(fX*tot,fY*tot,fZ*tot);
257 void TVector3::RotateX(Double_t angle) {
258 Double_t s = TMath::Sin(angle);
259 Double_t c = TMath::Cos(angle);
268 void TVector3::RotateY(Double_t angle) {
269 Double_t s = TMath::Sin(angle);
270 Double_t c = TMath::Cos(angle);
279 void TVector3::RotateZ(Double_t angle) {
280 Double_t s = TMath::Sin(angle);
281 Double_t c = TMath::Cos(angle);
290 void TVector3::Rotate(Double_t angle,
const TVector3 & axis){
292 trans.Rotate(angle, axis);
299 void TVector3::RotateUz(
const TVector3& NewUzVector) {
300 Double_t u1 = NewUzVector.fX;
301 Double_t u2 = NewUzVector.fY;
302 Double_t u3 = NewUzVector.fZ;
303 Double_t up = u1*u1 + u2*u2;
306 up = TMath::Sqrt(up);
307 Double_t px = fX, py = fY, pz = fZ;
308 fX = (u1*u3*px - u2*py + u1*up*pz)/up;
309 fY = (u2*u3*px + u1*py + u2*up*pz)/up;
310 fZ = (u3*u3*px - px + u3*up*pz)/up;
311 }
else if (u3 < 0.) { fX = -fX; fZ = -fZ; }
320 Double_t TVector3::PseudoRapidity()
const {
321 double cosTheta = CosTheta();
322 if (cosTheta*cosTheta < 1)
return -0.5* TMath::Log( (1.0-cosTheta)/(1.0+cosTheta) );
323 if (fZ == 0)
return 0;
325 if (fZ > 0)
return 10e10;
332 void TVector3::SetPtEtaPhi(Double_t pt, Double_t eta, Double_t phi) {
333 Double_t apt = TMath::Abs(pt);
334 SetXYZ(apt*TMath::Cos(phi), apt*TMath::Sin(phi), apt/TMath::Tan(2.0*TMath::ATan(TMath::Exp(-eta))) );
340 void TVector3::SetPtThetaPhi(Double_t pt, Double_t theta, Double_t phi) {
341 fX = pt * TMath::Cos(phi);
342 fY = pt * TMath::Sin(phi);
343 Double_t tanTheta = TMath::Tan(theta);
344 fZ = tanTheta ? pt / tanTheta : 0;
350 void TVector3::SetTheta(Double_t th)
354 SetX(ma*TMath::Sin(th)*TMath::Cos(ph));
355 SetY(ma*TMath::Sin(th)*TMath::Sin(ph));
356 SetZ(ma*TMath::Cos(th));
362 void TVector3::SetPhi(Double_t ph)
364 Double_t xy = Perp();
365 SetX(xy*TMath::Cos(ph));
366 SetY(xy*TMath::Sin(ph));
372 Double_t TVector3::DeltaR(
const TVector3 & v)
const
374 Double_t deta = Eta()-v.Eta();
375 Double_t dphi = TVector2::Phi_mpi_pi(Phi()-v.Phi());
376 return TMath::Sqrt( deta*deta+dphi*dphi );
382 void TVector3::SetMagThetaPhi(Double_t mag, Double_t theta, Double_t phi)
384 Double_t amag = TMath::Abs(mag);
385 fX = amag * TMath::Sin(theta) * TMath::Cos(phi);
386 fY = amag * TMath::Sin(theta) * TMath::Sin(phi);
387 fZ = amag * TMath::Cos(theta);
393 void TVector3::Streamer(TBuffer &R__b)
395 if (R__b.IsReading()) {
397 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
399 R__b.ReadClassBuffer(TVector3::Class(),
this, R__v, R__s, R__c);
403 if (R__v < 2) TObject::Streamer(R__b);
407 R__b.CheckByteCount(R__s, R__c, TVector3::IsA());
411 R__b.WriteClassBuffer(TVector3::Class(),
this);
418 TVector3 operator + (
const TVector3 & a,
const TVector3 & b) {
419 return TVector3(a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
425 TVector3 operator - (
const TVector3 & a,
const TVector3 & b) {
426 return TVector3(a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
432 TVector3 operator * (
const TVector3 & p, Double_t a) {
433 return TVector3(a*p.X(), a*p.Y(), a*p.Z());
439 TVector3 operator * (Double_t a,
const TVector3 & p) {
440 return TVector3(a*p.X(), a*p.Y(), a*p.Z());
444 Double_t operator * (
const TVector3 & a,
const TVector3 & b) {
451 TVector3 operator * (
const TMatrix & m,
const TVector3 & v ) {
452 return TVector3( m(0,0)*v.X()+m(0,1)*v.Y()+m(0,2)*v.Z(),
453 m(1,0)*v.X()+m(1,1)*v.Y()+m(1,2)*v.Z(),
454 m(2,0)*v.X()+m(2,1)*v.Y()+m(2,2)*v.Z());
460 void TVector3::Print(Option_t*)
const
462 Printf(
"%s %s (x,y,z)=(%f,%f,%f) (rho,theta,phi)=(%f,%f,%f)",GetName(),GetTitle(),X(),Y(),Z(),
463 Mag(),Theta()*TMath::RadToDeg(),Phi()*TMath::RadToDeg());