class TVector3: public TObject

The Physics Vector package 
-*                    ==========================                       
-* The Physics Vector package consists of five classes:                
-*   - TVector2                                                        
-*   - TVector3                                                        
-*   - TRotation                                                       
-*   - TLorentzVector                                                  
-*   - TLorentzRotation                                                
-* It is a combination of CLHEPs Vector package written by             
-* Leif Lonnblad, Andreas Nilsson and Evgueni Tcherniaev               
-* and a ROOT package written by Pasha Murat.                          
-* for CLHEP see:             


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 memberfunctions SetX(), SetY(), SetZ() and SetXYZ() allow to set the components:

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

Noncartesian 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 noncartesian 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);


Rotation around axes
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:

  TRotation 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.

Function Members (Methods)

voidTObject::AbstractMethod(const char* method) const
Double_tAngle(const TVector3&) const
virtual voidTObject::AppendPad(Option_t* option = "")
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTObject::Clear(Option_t* = "")
virtual TObject*TObject::Clone(const char* newname = "") const
virtual Int_tTObject::Compare(const TObject* obj) const
virtual voidTObject::Copy(TObject& object) const
Double_tCosTheta() const
TVector3Cross(const TVector3&) const
virtual voidTObject::Delete(Option_t* option = "")MENU
Double_tDeltaPhi(const TVector3&) const
Double_tDeltaR(const TVector3&) const
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
Double_tDot(const TVector3&) const
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
Double_tDrEtaPhi(const TVector3&) const
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
Double_tEta() const
TVector2EtaPhiVector() const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual const char*TObject::GetIconName() const
virtual const char*TObject::GetName() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual const char*TObject::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
voidGetXYZ(Double_t* carray) const
voidGetXYZ(Float_t* carray) const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTObject::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTObject::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTObject::ls(Option_t* option = "") const
Double_tMag() const
Double_tMag2() const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
Bool_toperator!=(const TVector3&) const
Double_toperator()(int) const
TVector3&operator*=(const TRotation&)
TVector3&operator+=(const TVector3&)
TVector3operator-() const
TVector3&operator-=(const TVector3&)
TVector3&operator=(const TVector3&)
Bool_toperator==(const TVector3&) const
Double_toperator[](int) const
TVector3Orthogonal() const
virtual voidTObject::Paint(Option_t* option = "")
Double_tPerp() const
Double_tPerp(const TVector3&) const
Double_tPerp2() const
Double_tPerp2(const TVector3&) const
Double_tPhi() const
virtual voidTObject::Pop()
virtual voidPrint(Option_t* option = "") const
Double_tPseudoRapidity() const
Double_tPt() const
Double_tPt(const TVector3&) const
Double_tPx() const
Double_tPy() const
Double_tPz() const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
voidRotate(Double_t, const TVector3&)
voidRotateUz(const TVector3&)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
voidSetMagThetaPhi(Double_t mag, Double_t theta, Double_t phi)
static voidTObject::SetObjectStat(Bool_t stat)
voidSetPtEtaPhi(Double_t pt, Double_t eta, Double_t phi)
voidSetPtThetaPhi(Double_t pt, Double_t theta, Double_t phi)
virtual voidTObject::SetUniqueID(UInt_t uid)
voidSetXYZ(Double_t x, Double_t y, Double_t z)
virtual voidShowMembers(TMemberInspector& insp) const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
Double_tTheta() const
TVector3&Transform(const TRotation&)
TVector3(const Double_t*)
TVector3(const Float_t*)
TVector3(const TVector3&)
TVector3(Double_t x, Double_t y, Double_t z)
TVector3Unit() const
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
Double_tx() const
Double_tX() const
TVector2XYvector() const
Double_ty() const
Double_tY() const
Double_tz() const
Double_tZ() const
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const

Data Members

static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie

Class Charts

Inheritance Chart:

Function documentation

TVector3(const TVector3& )
TVector3(Double_t x, Double_t y, Double_t z)
TVector3(const Double_t* )
TVector3(const Float_t* )
TVector3 & Transform(const TRotation& )
transform this vector with a TRotation
Double_t Angle(const TVector3& ) const
 return the angle w.r.t. another 3-vector
Double_t Mag() const
 return the magnitude (rho in spherical coordinate system)
Double_t Perp() const
return the transverse component  (R in cylindrical coordinate system)
Double_t Perp(const TVector3& ) const
return the transverse component (R in cylindrical coordinate system)
Double_t Phi() const
return the  azimuth angle. returns phi from -pi to pi
Double_t Theta() const
return the polar angle
TVector3 Unit() const
 return unit vector parallel to this.
void RotateX(Double_t )
rotate vector around X
void RotateY(Double_t )
rotate vector around Y
void RotateZ(Double_t )
rotate vector around Z
void Rotate(Double_t , const TVector3& )
rotate vector
void RotateUz(const TVector3& )
 NewUzVector must be normalized !
Double_t PseudoRapidity() const
Double_t m = Mag();
return 0.5*log( (m+fZ)/(m-fZ) );
 guard against Pt=0
void SetPtEtaPhi(Double_t pt, Double_t eta, Double_t phi)
set Pt, Eta and Phi
void SetPtThetaPhi(Double_t pt, Double_t theta, Double_t phi)
set Pt, Theta and Phi
void SetTheta(Double_t )
 Set theta keeping mag and phi constant (BaBar).
void SetPhi(Double_t )
 Set phi keeping mag and theta constant (BaBar).
Double_t DeltaR(const TVector3& ) const
return deltaR with respect to v
void SetMagThetaPhi(Double_t mag, Double_t theta, Double_t phi)
setter with mag, theta, phi
void Streamer(TBuffer& )
 Stream an object of class TVector3.
void Print(Option_t* option = "") const
print vector parameters
Double_t & operator[](int )
{ return operator()(i); }
Double_t operator[](int ) const
{ return operator()(i); }
Double_t x() const
{ return fX; }
Double_t y() const
{ return fY; }
Double_t z() const
{ return fZ; }
Double_t X() const
{ return fX; }
Double_t Y() const
{ return fY; }
Double_t Z() const
{ return fZ; }
Double_t Px() const
{ return fX; }
Double_t Py() const
{ return fY; }
Double_t Pz() const
{ return fZ; }
void SetX(Double_t )
{ fX = xx; }
void SetY(Double_t )
{ fY = yy; }
void SetZ(Double_t )
{ fZ = zz; }
void SetXYZ(Double_t x, Double_t y, Double_t z)
void GetXYZ(Double_t* carray) const
void GetXYZ(Float_t* carray) const
Double_t Dot(const TVector3& ) const
TVector3 Cross(const TVector3& ) const
Double_t Mag2() const
{ return fX*fX + fY*fY + fZ*fZ; }
TVector3 Orthogonal() const
Double_t Perp2() const
{ return fX*fX + fY*fY; }
Double_t Pt() const
{ return Perp(); }
Double_t Perp2(const TVector3& ) const
Double_t Pt(const TVector3& ) const
Double_t CosTheta() const
void SetMag(Double_t )
void SetPerp(Double_t )
Double_t DeltaPhi(const TVector3& ) const
Double_t Eta() const
Double_t DrEtaPhi(const TVector3& ) const
TVector2 EtaPhiVector() const
TVector2 XYvector() const