Logo ROOT   6.13/01
Reference Guide
List of all members | Public Types | Public Member Functions | Private Attributes | Friends | List of all members
TVector3 Class Reference

TVector3 is a general three vector class, which can be used for the description of different vectors in 3D.

Declaration / Access to the components

TVector3 has been implemented as a vector of three Double_t variables, representing the cartesian coordinates. By default all components are initialized to zero:

TVector3 v1; // v1 = (0,0,0)
TVector3 v3(1,2,3); // v3 = (1,2,3)
TVector3 v4(v2); // v4 = v2

It is also possible (but not recommended) to initialize a TVector3 with a Double_t or Float_t C array.

You can get the basic components either by name or by index using operator():

xx = v1.X(); or xx = v1(0);
yy = v1.Y(); yy = v1(1);
zz = v1.Z(); zz = v1(2);

The member functions SetX(), SetY(), SetZ() and SetXYZ() allow to set the components:

v1.SetX(1.); v1.SetY(2.); v1.SetZ(3.);
v1.SetXYZ(1.,2.,3.);

Non-cartesian coordinates

To get information on the TVector3 in spherical (rho,phi,theta) or cylindrical (z,r,theta) coordinates, the

the member functions Mag() (=magnitude=rho in spherical coordinates), Mag2(), Theta(), CosTheta(), Phi(), Perp() (the transverse component=r in cylindrical coordinates), Perp2() can be used:

Double_t m = v.Mag(); // get magnitude (=rho=Sqrt(x*x+y*y+z*z)))
Double_t m2 = v.Mag2(); // get magnitude squared
Double_t t = v.Theta(); // get polar angle
Double_t ct = v.CosTheta(); // get cos of theta
Double_t p = v.Phi(); // get azimuth angle
Double_t pp = v.Perp(); // get transverse component
Double_t pp2= v.Perp2(); // get transvers component squared

It is also possible to get the transverse component with respect to another vector:

Double_t ppv1 = v.Perp(v1);
Double_t pp2v1 = v.Perp2(v1);

The pseudo-rapidity ( eta=-ln (tan (theta/2)) ) can be obtained by Eta() or PseudoRapidity():

Double_t eta = v.PseudoRapidity();

There are set functions to change one of the non-cartesian coordinates:

v.SetTheta(.5); // keeping rho and phi
v.SetPhi(.8); // keeping rho and theta
v.SetMag(10.); // keeping theta and phi
v.SetPerp(3.); // keeping z and phi

Arithmetic / Comparison

The TVector3 class provides the operators to add, subtract, scale and compare vectors:

v3 = -v1;
v1 = v2+v3;
v1 += v3;
v1 = v1 - v3
v1 -= v3;
v1 *= 10;
v1 = 5*v2;
if (v1==v2) {...}
if (v1!=v2) {...}

Related Vectors

v2 = v1.Unit(); // get unit vector parallel to v1
v2 = v1.Orthogonal(); // get vector orthogonal to v1

Scalar and vector products

s = v1.Dot(v2); // scalar product
s = v1 * v2; // scalar product
v = v1.Cross(v2); // vector product

Angle between two vectors

Double_t a = v1.Angle(v2);

Rotations

Rotation around axes

v.RotateX(.5);
v.RotateZ(angle);

Rotation around a vector

v1.Rotate(TMath::Pi()/4, v2); // rotation around v2

Rotation by TRotation

TVector3 objects can be rotated by objects of the TRotation class using the Transform() member functions,

the operator *= or the operator * of the TRotation class:

...
v1.transform(m);
v1 = m*v1;
v1 *= m; // Attention v1 = m*v1

Transformation from rotated frame

TVector3 direction = v.Unit()
v1.RotateUz(direction); // direction must be TVector3 of unit length

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.

Definition at line 22 of file TVector3.h.

Public Types

typedef Double_t Scalar
 

Public Member Functions

 TVector3 ()
 Constructors. More...
 
 TVector3 (Double_t x, Double_t y, Double_t z)
 
 TVector3 (const Double_t *)
 
 TVector3 (const Float_t *)
 
 TVector3 (const TVector3 &)
 
virtual ~TVector3 ()
 
Double_t Angle (const TVector3 &) const
 Return the angle w.r.t. another 3-vector. More...
 
Double_t CosTheta () const
 
TVector3 Cross (const TVector3 &) const
 
Double_t DeltaPhi (const TVector3 &) const
 
Double_t DeltaR (const TVector3 &) const
 Return deltaR with respect to v. More...
 
Double_t Dot (const TVector3 &) const
 
Double_t DrEtaPhi (const TVector3 &) const
 
Double_t Eta () const
 
TVector2 EtaPhiVector () const
 
void GetXYZ (Double_t *carray) const
 
void GetXYZ (Float_t *carray) const
 
Double_t Mag () const
 
Double_t Mag2 () const
 
Bool_t operator!= (const TVector3 &) const
 
Double_t operator() (int) const
 
Double_t & operator() (int)
 
TVector3operator*= (Double_t)
 
TVector3operator*= (const TRotation &)
 Multiplication operator. More...
 
TVector3operator+= (const TVector3 &)
 
TVector3 operator- () const
 
TVector3operator-= (const TVector3 &)
 
TVector3operator= (const TVector3 &)
 
Bool_t operator== (const TVector3 &) const
 
Double_t operator[] (int) const
 
Double_t & operator[] (int)
 
TVector3 Orthogonal () const
 
Double_t Perp () const
 Return the transverse component (R in cylindrical coordinate system) More...
 
Double_t Perp (const TVector3 &) const
 Return the transverse component (R in cylindrical coordinate system) More...
 
Double_t Perp2 () const
 
Double_t Perp2 (const TVector3 &) const
 
Double_t Phi () const
 Return the azimuth angle. Returns phi from -pi to pi. More...
 
void Print (Option_t *option="") const
 Print vector parameters. More...
 
Double_t PseudoRapidity () const
 Double_t m = Mag(); return 0.5*log( (m+fZ)/(m-fZ) ); guard against Pt=0. More...
 
Double_t Pt () const
 
Double_t Pt (const TVector3 &) const
 
Double_t Px () const
 
Double_t Py () const
 
Double_t Pz () const
 
void Rotate (Double_t, const TVector3 &)
 Rotate vector. More...
 
void RotateUz (const TVector3 &)
 NewUzVector must be normalized ! More...
 
void RotateX (Double_t)
 Rotate vector around X. More...
 
void RotateY (Double_t)
 Rotate vector around Y. More...
 
void RotateZ (Double_t)
 Rotate vector around Z. More...
 
void SetMag (Double_t)
 
void SetMagThetaPhi (Double_t mag, Double_t theta, Double_t phi)
 Setter with mag, theta, phi. More...
 
void SetPerp (Double_t)
 
void SetPhi (Double_t)
 Set phi keeping mag and theta constant (BaBar). More...
 
void SetPtEtaPhi (Double_t pt, Double_t eta, Double_t phi)
 Set Pt, Eta and Phi. More...
 
void SetPtThetaPhi (Double_t pt, Double_t theta, Double_t phi)
 Set Pt, Theta and Phi. More...
 
void SetTheta (Double_t)
 Set theta keeping mag and phi constant (BaBar). More...
 
void SetX (Double_t)
 
void SetXYZ (Double_t x, Double_t y, Double_t z)
 
void SetY (Double_t)
 
void SetZ (Double_t)
 
Double_t Theta () const
 Return the polar angle. More...
 
TVector3Transform (const TRotation &)
 Transform this vector with a TRotation. More...
 
TVector3 Unit () const
 Return unit vector parallel to this. More...
 
Double_t x () const
 
Double_t X () const
 
TVector2 XYvector () const
 
Double_t y () const
 
Double_t Y () const
 
Double_t z () const
 
Double_t Z () const
 

Private Attributes

Double_t fX
 
Double_t fY
 
Double_t fZ
 

Friends

class TLorentzVector
 

#include <TVector3.h>

Inheritance diagram for TVector3:
[legend]

Member Typedef Documentation

◆ Scalar

typedef Double_t TVector3::Scalar

Definition at line 26 of file TVector3.h.

Constructor & Destructor Documentation

◆ TVector3() [1/5]

TVector3::TVector3 ( )
inline

Constructors.

Definition at line 247 of file TVector3.h.

◆ TVector3() [2/5]

TVector3::TVector3 ( Double_t  x,
Double_t  y,
Double_t  z 
)
inline

Definition at line 253 of file TVector3.h.

◆ TVector3() [3/5]

TVector3::TVector3 ( const Double_t *  x0)
inline

Definition at line 256 of file TVector3.h.

◆ TVector3() [4/5]

TVector3::TVector3 ( const Float_t *  x0)
inline

Definition at line 259 of file TVector3.h.

◆ TVector3() [5/5]

TVector3::TVector3 ( const TVector3 p)
inline

Definition at line 250 of file TVector3.h.

◆ ~TVector3()

virtual TVector3::~TVector3 ( )
inlinevirtual

Definition at line 40 of file TVector3.h.

Member Function Documentation

◆ Angle()

Double_t TVector3::Angle ( const TVector3 q) const

Return the angle w.r.t. another 3-vector.

Definition at line 197 of file TVector3.cxx.

◆ CosTheta()

Double_t TVector3::CosTheta ( ) const
inline

Definition at line 371 of file TVector3.h.

◆ Cross()

TVector3 TVector3::Cross ( const TVector3 p) const
inline

Definition at line 335 of file TVector3.h.

◆ DeltaPhi()

Double_t TVector3::DeltaPhi ( const TVector3 v) const
inline

Definition at line 396 of file TVector3.h.

◆ DeltaR()

Double_t TVector3::DeltaR ( const TVector3 v) const

Return deltaR with respect to v.

Definition at line 372 of file TVector3.cxx.

◆ Dot()

Double_t TVector3::Dot ( const TVector3 p) const
inline

Definition at line 331 of file TVector3.h.

◆ DrEtaPhi()

Double_t TVector3::DrEtaPhi ( const TVector3 v) const
inline

Definition at line 404 of file TVector3.h.

◆ Eta()

Double_t TVector3::Eta ( ) const
inline

Definition at line 400 of file TVector3.h.

◆ EtaPhiVector()

TVector2 TVector3::EtaPhiVector ( ) const
inline

Definition at line 409 of file TVector3.h.

◆ GetXYZ() [1/2]

void TVector3::GetXYZ ( Double_t *  carray) const
inline

Definition at line 233 of file TVector3.h.

◆ GetXYZ() [2/2]

void TVector3::GetXYZ ( Float_t *  carray) const
inline

Definition at line 239 of file TVector3.h.

◆ Mag()

Double_t TVector3::Mag ( ) const
inline

Definition at line 86 of file TVector3.h.

◆ Mag2()

Double_t TVector3::Mag2 ( ) const
inline

Definition at line 339 of file TVector3.h.

◆ operator!=()

Bool_t TVector3::operator!= ( const TVector3 v) const
inline

Definition at line 302 of file TVector3.h.

◆ operator()() [1/2]

Double_t TVector3::operator() ( int  i) const
inline

Definition at line 263 of file TVector3.h.

◆ operator()() [2/2]

Double_t & TVector3::operator() ( int  i)
inline

Definition at line 277 of file TVector3.h.

◆ operator*=() [1/2]

TVector3 & TVector3::operator*= ( Double_t  a)
inline

Definition at line 324 of file TVector3.h.

◆ operator*=() [2/2]

TVector3 & TVector3::operator*= ( const TRotation m)

Multiplication operator.

Definition at line 183 of file TVector3.cxx.

◆ operator+=()

TVector3 & TVector3::operator+= ( const TVector3 p)
inline

Definition at line 306 of file TVector3.h.

◆ operator-()

TVector3 TVector3::operator- ( ) const
inline

Definition at line 320 of file TVector3.h.

◆ operator-=()

TVector3 & TVector3::operator-= ( const TVector3 p)
inline

Definition at line 313 of file TVector3.h.

◆ operator=()

TVector3 & TVector3::operator= ( const TVector3 p)
inline

Definition at line 291 of file TVector3.h.

◆ operator==()

Bool_t TVector3::operator== ( const TVector3 v) const
inline

Definition at line 298 of file TVector3.h.

◆ operator[]() [1/2]

Double_t TVector3::operator[] ( int  i) const
inline

Definition at line 211 of file TVector3.h.

◆ operator[]() [2/2]

Double_t & TVector3::operator[] ( int  i)
inline

Definition at line 210 of file TVector3.h.

◆ Orthogonal()

TVector3 TVector3::Orthogonal ( ) const
inline

Definition at line 342 of file TVector3.h.

◆ Perp() [1/2]

Double_t TVector3::Perp ( ) const

Return the transverse component (R in cylindrical coordinate system)

Definition at line 213 of file TVector3.cxx.

◆ Perp() [2/2]

Double_t TVector3::Perp ( const TVector3 p) const

Return the transverse component (R in cylindrical coordinate system)

Definition at line 222 of file TVector3.cxx.

◆ Perp2() [1/2]

Double_t TVector3::Perp2 ( ) const
inline

Definition at line 353 of file TVector3.h.

◆ Perp2() [2/2]

Double_t TVector3::Perp2 ( const TVector3 p) const
inline

Definition at line 358 of file TVector3.h.

◆ Phi()

Double_t TVector3::Phi ( ) const

Return the azimuth angle. Returns phi from -pi to pi.

Definition at line 230 of file TVector3.cxx.

◆ Print()

void TVector3::Print ( Option_t *  option = "") const

Print vector parameters.

Definition at line 460 of file TVector3.cxx.

◆ PseudoRapidity()

Double_t TVector3::PseudoRapidity ( ) const

Double_t m = Mag(); return 0.5*log( (m+fZ)/(m-fZ) ); guard against Pt=0.

Definition at line 320 of file TVector3.cxx.

◆ Pt() [1/2]

Double_t TVector3::Pt ( ) const
inline

Definition at line 356 of file TVector3.h.

◆ Pt() [2/2]

Double_t TVector3::Pt ( const TVector3 p) const
inline

Definition at line 367 of file TVector3.h.

◆ Px()

Double_t TVector3::Px ( ) const
inline

Definition at line 219 of file TVector3.h.

◆ Py()

Double_t TVector3::Py ( ) const
inline

Definition at line 220 of file TVector3.h.

◆ Pz()

Double_t TVector3::Pz ( ) const
inline

Definition at line 221 of file TVector3.h.

◆ Rotate()

void TVector3::Rotate ( Double_t  angle,
const TVector3 axis 
)

Rotate vector.

Definition at line 290 of file TVector3.cxx.

◆ RotateUz()

void TVector3::RotateUz ( const TVector3 NewUzVector)

NewUzVector must be normalized !

Definition at line 299 of file TVector3.cxx.

◆ RotateX()

void TVector3::RotateX ( Double_t  angle)

Rotate vector around X.

Definition at line 257 of file TVector3.cxx.

◆ RotateY()

void TVector3::RotateY ( Double_t  angle)

Rotate vector around Y.

Definition at line 268 of file TVector3.cxx.

◆ RotateZ()

void TVector3::RotateZ ( Double_t  angle)

Rotate vector around Z.

Definition at line 279 of file TVector3.cxx.

◆ SetMag()

void TVector3::SetMag ( Double_t  ma)
inline

Definition at line 376 of file TVector3.h.

◆ SetMagThetaPhi()

void TVector3::SetMagThetaPhi ( Double_t  mag,
Double_t  theta,
Double_t  phi 
)

Setter with mag, theta, phi.

Definition at line 382 of file TVector3.cxx.

◆ SetPerp()

void TVector3::SetPerp ( Double_t  r)
inline

Definition at line 388 of file TVector3.h.

◆ SetPhi()

void TVector3::SetPhi ( Double_t  ph)

Set phi keeping mag and theta constant (BaBar).

Definition at line 362 of file TVector3.cxx.

◆ SetPtEtaPhi()

void TVector3::SetPtEtaPhi ( Double_t  pt,
Double_t  eta,
Double_t  phi 
)

Set Pt, Eta and Phi.

Definition at line 332 of file TVector3.cxx.

◆ SetPtThetaPhi()

void TVector3::SetPtThetaPhi ( Double_t  pt,
Double_t  theta,
Double_t  phi 
)

Set Pt, Theta and Phi.

Definition at line 340 of file TVector3.cxx.

◆ SetTheta()

void TVector3::SetTheta ( Double_t  th)

Set theta keeping mag and phi constant (BaBar).

Definition at line 350 of file TVector3.cxx.

◆ SetX()

void TVector3::SetX ( Double_t  xx)
inline

Definition at line 223 of file TVector3.h.

◆ SetXYZ()

void TVector3::SetXYZ ( Double_t  x,
Double_t  y,
Double_t  z 
)
inline

Definition at line 227 of file TVector3.h.

◆ SetY()

void TVector3::SetY ( Double_t  yy)
inline

Definition at line 224 of file TVector3.h.

◆ SetZ()

void TVector3::SetZ ( Double_t  zz)
inline

Definition at line 225 of file TVector3.h.

◆ Theta()

Double_t TVector3::Theta ( ) const

Return the polar angle.

Definition at line 238 of file TVector3.cxx.

◆ Transform()

TVector3 & TVector3::Transform ( const TRotation m)

Transform this vector with a TRotation.

Definition at line 190 of file TVector3.cxx.

◆ Unit()

TVector3 TVector3::Unit ( ) const

Return unit vector parallel to this.

Definition at line 246 of file TVector3.cxx.

◆ x()

Double_t TVector3::x ( ) const
inline

Definition at line 213 of file TVector3.h.

◆ X()

Double_t TVector3::X ( ) const
inline

Definition at line 216 of file TVector3.h.

◆ XYvector()

TVector2 TVector3::XYvector ( ) const
inline

Definition at line 413 of file TVector3.h.

◆ y()

Double_t TVector3::y ( ) const
inline

Definition at line 214 of file TVector3.h.

◆ Y()

Double_t TVector3::Y ( ) const
inline

Definition at line 217 of file TVector3.h.

◆ z()

Double_t TVector3::z ( ) const
inline

Definition at line 215 of file TVector3.h.

◆ Z()

Double_t TVector3::Z ( ) const
inline

Definition at line 218 of file TVector3.h.

Friends And Related Function Documentation

◆ TLorentzVector

friend class TLorentzVector
friend

Definition at line 191 of file TVector3.h.

Member Data Documentation

◆ fX

Double_t TVector3::fX
private

Definition at line 185 of file TVector3.h.

◆ fY

Double_t TVector3::fY
private

Definition at line 185 of file TVector3.h.

◆ fZ

Double_t TVector3::fZ
private

Definition at line 185 of file TVector3.h.

Libraries for TVector3:
[legend]

The documentation for this class was generated from the following files: