Physics vectors
ROOT provides several packes for physics vectors:
Generic 2D, 3D and 4D vectors (GenVectors)
Generic 2D, 3D and 4D vectors (GenVectors) represent vectors and their operations and transformations, such as rotations and Lorentz transformations. The 2D and 3D space are used to describe the geometry vectors and points, while the 4D spacetime is used for physics vectors representing relativistic particles.
In contrast to the ROOT physics libraries, the GenVector package provides class templates for modeling the vectors.
Every class, function, manipulator, or other symbol defined in the GenVector package, is in the ROOT::Math namespace.
Topical Manual
For the GenVector package, a Topical Manuals is available at Topical Manuals  Genvectors.
It contains indepth information about the GenVector package.
GenVector classes and vector class templates
The vector class templates are provided to represent vectors (in the physics sense) in 2, 3, and Minkowski space 4 dimensions.
Each vector template class uses as its only parameter the coordinate system.
Every vector class publishes a typedef for CoordinateType
, which allows to specify the coordinate system , as well as a typedef for Scalar
(which will match the Scalar
type for the coordinate system).
The vector classes are comparable (operator ==
and operator !=
for the objects or the identical class (including the coordinate system used). Checks for the
equivalence of two vectors in different coordinate systems can be done by converting one to the system of the other.
None of the vector classes have methods to rotate a vector. To rotate a vector, you first have to instantiate the desired rotation object, and then apply it to the vector.
The following GenVector classes and class templates are available:

DisplacementVector3D: Describing a generic displacement vector in 3 dimensions.

PositionVector3D: Describing a generic position vector (point) in 3 dimensions.

LorentzVector: Describing a generic LorentzVector in the 4D spacetime, using the specified coordinate system for the spatial vector part.

DisplacementVector2D: Describing a generic displacement vector in 2 dimensions.

PositionVector2D: Describing a generic position vector (point) in 2 dimensions.

Rotation3D: Class with the (3D) rotation, represented by a 3x3 orthogonal matrix.

AxisAngle: Describing a rotation, represented with a direction axis (3D Vector), and an angle of rotation around that axis.

EulerAngles: Describing a rotation as three angles (Euler angles).

Quaternion: Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).

RotationX: Rotation class representing a 3D rotation about the X axis by the angle of rotation.

RotationY: Rotation class representing a 3D rotation about the Y axis by the angle of rotation.

RotationZ: Rotation class representing a 3D rotation about the Z axis by the angle of rotation.

LorentzRotation: Lorentz transformation class with the (4D) transformation represented by a 4x4 orthosymplectic matrix.

Boost: Lorentz boost class with the (4D) transformation represented internally by a 4x4 orthosymplectic matrix.

BoostX: Representing a Lorentz Boost along the X axis, by beta.

BoostY: Class representing a Lorentz Boost along the Y axis, by beta.

BoostZ: Class representing a Lorentz Boost along the Z axis, by beta.
Coordinate systems
The vector classes are based on a generic type of coordinate system, expressed as a template parameter of the class. The following classes exist to describe the various coordinates systems:
2D coordinate system

ROOT::Math::Cartesian2D: 2D cartesian coordinate system (
x
,y
coordinates). 
ROOT::Math::Polar2D: A polar 2D coordinate system based on
r
andphi
.phi
is restricted to the range (PI,PI).
3D coordinate systems

ROOT::Math::Cartesian3D: 3D cartesian coordinate system (
x
,y
,z
coordinates). 
ROOT::Math::Polar3D: 3D polar coordinate system (
r
,theta
,phi
coordinates). 
ROOT::Math::Cylindrical3D: Cylindrical coordinate system based on
rho
,z
andphi
. 
ROOT::Math::CylindricalEta3D6: Cylindrical coordinate system based on
eta
(pseudorapidity) instead ofz
.
4D coordinate systems

ROOT::Math::PxPyPzE4D: 4D cartesian coordinate system (
x
,y
,z
,t
coordinates) or momentumenergy vectors stored as (Px
,Py
,Pz
,E
). 
ROOT::Math::PxPyPzM4D: 4D coordinate system or momentumenergy vectors stored as (
Px
,Py
,Pz
,M
). 
ROOT::Math::PtEtaPhiE4D: 4D cylindrical coordinate system using
Pt
,Phi
,Eta
andE
(orrho
,phi
,eta
,T
). The metric used is (,,,+). 
ROOT::Math::PtEtaPhiM4D: 4D cylindrical coordinate system using
Pt
,Phi
,Eta
andM
(mass). The metric used is (,,,+).
Transformations
The transformations are modeled using simple, nontemplate classes, using double
as the scalar type to avoid too large numerical errors.
The transformations are grouped as follows:
 rotations (3 dimensions)
 Lorentz transformations
 Poincare transformations (combinations of translation and rotation)
Each group has several members, which may model physically equivalent transformations but with different internal representations. Transformation classes can
operate on all type of vectors by using the ()
operator or the *
operator. You can combine transformations with the *
operator.
The available transformations are:
 3D rotation classes:
 Rotation described by a 3x3 matrix (ROOT::Math::Rotation3D).
 Rotation described by Euler angles (ROOT::Math::EulerAngles).
 Rotation described by a direction axis and an angle (ROOT::Math::AxisAngle).
 Rotation described by a quaternion (ROOT::Math::Quaternion).
 Optimized rotation around x (ROOT::Math::RotationX), y (ROOT::Math::RotationY) and z (ROOT::Math::RotationZ) and described by just one angle.
 3D transformation: the transformations are defined as a composition between a rotation and a translation using the class ROOT::Math::Transform3D. Note that transformations act differently on vectors and points. Vectors only rotate. When applying a transformation (rotation and translation) on a vector, only the rotation operates while the translation has no effect. The ROOT::Math::Transform3D class interface is similar to the one used in the CLHEP Geometry package.
 Lorentz rotation:
 Generic Lorentz rotation described by a 4x4 matrix containing a 3D rotation part and a boost part (ROOT::Math::LorentzRotation).
 A pure boost in an arbitrary direction and described by a 4x4 symmetric matrix or 10 numbers (ROOT::Math::Boost).
 Boost along the axis: x(ROOT::Math::BoostX)), y(ROOT::Math::BoostY)) and z(ROOT::Math::BoostZ)).
Example: 3D vector classes
The following typedefdeclarations are available for the different instantiations of ROOT::Math::DisplacementVector3D:
 ROOT::Math::XYZVector: Vector based on x, y, z coordinates (Cartesian) in double precision.
 ROOT::Math::XYZVectorF: Vector based on x, y, z coordinates (Cartesian) in float precision.
 ROOT::Math::Polar3DVector: Vector based on r, theta, phi coordinates (polar) in double precision.
 ROOT::Math::Polar3DVectorF: Vector based on r, theta, phi coordinates (polar) in float precision.
 ROOT::Math::RhoZPhiVector: Vector based on rho, z, phi coordinates (cylindrical) in double precision.
 ROOT::Math::RhoZPhiVectorF: Vector based on rho, z, phi coordinates (cylindrical) in float precision.
 ROOT::Math::RhoEtaPhiVector: Vector based on rho, eta, phi coordinates (cylindrical using eta instead of z) in double precision.
 ROOT::Math::RhoEtaPhiVectorF: Vector based on rho, eta, phi coordinates (cylindrical using eta instead of z) in float precision.
Constructors and assignment
The following declarations are available:
Note that each vector type is constructed by passing its coordinate representation. So a XYZVector(1,2,3)
is different
from a Polar3DVector(1,2,3)
.
In addition, you can construct the vector classes by any vector, which implements
the accessors x()
, y()
and z()
. This can be another 3D vector, based on a different coordinate system type. It can be
even any vector of a different package, like the CLHEP HepThreeVector
that implements the required signature.
Example
Coordinate accessors
All coordinate accessors are available through ROOT::Math::DisplacementVector3D:
Examples
In addition, you can retrieve all the three vector coordinates with the GetCoordinates()
method:
Setter methods
You can set the three coordinates via:
Single coordinate setter methods are available for the basic vector coordinates, like SetX()
for a ROOT::Math::XYZVector or SetR()
for a polar vector. Therefore, applying a SetX()?
on a polar vector does not compile.
There are also setter methods from C arrays or iterators.
Examples
Arithmetic operations
The following operations are possible between vector classes, even for different coordinate system types:
(v1, v2 are any type of ROOT::Math::DisplacementVector3D, v3 is the same type of v1; a is a scalar value)
Comparison
You can compare v1 and v2 of the same type (same coordinate system and same scalar type):
Dot and cross product
Use the Dot()
method for the dot product and the Cross()
method for the cross product, with any vector (q)
implementing x()
, y()
and z()
.
Examples
Note
The
*
operator for the multiplication between two vectors is not supported, because it is ambiguous.
Other methods
Returning a unit vector.
Example: 3D point classes
The following typedefdeclarations are available for the different instantiations of ROOT::Math::PositionVector3D:
 ROOT::Math::XYZPoint: Point based on x, y, z coordinates (Cartesian) in double precision.
 ROOT::Math::XYZPointF: Point based on x, y, z coordinates (Cartesian) in float precision.
 ROOT::Math::Polar3DPoint: Point based on r, theta, phi coordinates (polar) in double precision.
 ROOT::Math::Polar3DPointF: Point based on r, theta, phi coordinates (polar) in float precision.
 ROOT::Math::RhoZPhiPoint: Point based on rho, z, phi coordinates (cylindrical using z) in double precision.
 ROOT::Math::RhoZPhiPointF: Point based on rho, z, phi coordinates (cylindrical using z) in float precision.
 ROOT::Math::RhoEtaPhiPoint: Point based on rho, eta, phi coordinates (cylindrical using eta instead of z) in double precision.
 ROOT::Math::RhoEtaPhiPointF: Point based on rho, eta, phi coordinates (cylindrical using eta instead of z) in float precision.
Constructors and assignment
The following declarations are available:
Note that each point type is constructed by passing its coordinate representation. So a XYZPoint(1,2,3)
is different
from a Polar3DPoint(1,2,3)
.
In addition, you can construct the point classes by any vector, which implements the accessors x()
, y()
and z()
. This can be another 3D point based on a different coordinate system type or even any
vector of a different package, like the CLHEP HepThreePoint
that implements the required signatures.
Examples
Coordinate accessors and setter methods
The point classes use the same getter and setter methods as the vector classes, see → Example: 3D vector classes.
Pointvector operations
The following operations are possible between points and vector classes:
(p1, p2 and p3 are instantiations of ROOT::Math::PositionVector3D objects with p1 and p3 of the same type; v1 and v2 are ROOT::Math::DisplacementVector3D objects).
Note
The addition between two points is NOT possible and the difference between points returns a vector.
Other operations
As for vectors, the following operations are allowed for points:
 comparison of points,
 scaling and division of points with a scalar,
 dot and cross product with any type of vector.
Example: LorentzVector classes
The following typedefdeclarations are available for the different instantiations of ROOT::Math::LorentzVector:
 ROOT::Math::XYZTVector: Vector based on x, y, z, t coordinates (Cartesian) in double precision.
 ROOT::Math::XYZTVectorF: Vector based on x, y, z, t coordinates (Cartesian) in float precision.
 ROOT::Math::PtEtaPhiEVector: Vector based on pt(rho), eta, phi and E(t) coordinates in double precision.
 ROOT::Math::PtEtaPhiMVector: Vector based on pt(rho), eta, phi and M(t) coordinates in double precision.
 ROOT::Math::PxPyPzMVector: Vector based on px, py, pz and M(mass) coordinates in double precision.
The metric used for all ROOT::Math::LorentzVector classes is (,,,+).
Constructors and assignment
The following declarations are available:
Note that each type of vector is constructed by passing its coordinate representation. So a XYZTVector(1,2,3,4)
is
different from a PtEtaPhiEVector(1,2,3,4)
.
In addition, you can construct the vector classes by any vector, which implements the accessors x()
, y()
, z()
and t()
.
This can be another ROOT::Math::LorentzVector based on a different coordinate system or any vector of a different
package, like the CLHEP HepLorentzVector
that implements the required signature.
Examples
Coordinate accessors
The coordinate accessors are available through the interface of ROOT::Math::LorentzVector.
Examples
In addition, you can retrieve all four vector coordinates with the GetCoordinates()
method:
Setter methods
You can set the four coordinates via:
Single coordinate setter methods are available for the basic vector coordinates, like SetX()
for a XYZTVector
or SetPt()
for a PtEtaPhiEVector
. Therefore, applying a SetX()
on a nonCartesian vector does not compile.
There are also setter methods from C arrays or iterators.
Arithmetic operations
The following operations are possible between Lorentz vectors classes, even for different coordinate system types:
(v and w are two Lorentz vectors of the same type, q is a generic Lorentz vector implementing x()
, y()
, z()
and t()
, and a is a generic scalar type: double, float, int, etc.) .
Comparison
The following comparisons are possible:
Other methods
There are several other methods available:
Example: Vector transformations
The transformation classes are grouped as follows:
 3D rotations,
 Lorentz transformations,
 Poincaré transformations, which are translation/rotation combinations.
Each group has several members which may model physically equivalent transformations but with different internal representations. All the classes are nontemplate and use double precision as the scalar type.
3D rotations:
 ROOT::Math::Rotation3D: Rotation described by a 3x3 matrix of doubles.
 ROOT::Math::EulerAngles: Rotation described by the three Euler angles (phi, theta and psi) following the GoldStein definition.
 ROOT::Math::RotationZYX: Rotation described by three angles defining a rotation first along the Z axis, then along the rotated Y’ axis and then along the rotated X’’ axis.
 ROOT::Math::AxisAngle: Rotation described by a vector (axis) and an angle.
 ROOT::Math::Quaternion: Rotation described by a quaternion (4 numbers).
 ROOT::Math::RotationX: Specialized rotation along the X axis.
 ROOT::Math::RotationY: Specialized rotation along the Y axis.
 ROOT::Math::RotationZ: Specialized rotation along the Z axis.
Lorentz rotations and boosts:
 ROOT::Math::LorentzRotation: 4D rotation (3D rotation plus a boost) described by a 4x4 matrix.
 ROOT::Math::Boost: A Lorentz boost in an arbitrary direction and described by a 4x4 symmetric matrix (10 numbers).
 ROOT::Math::BoostX: A boost in the X axis direction.
 ROOT::Math::BoostY: A boost in the Y axis direction.
 ROOT::Math::BoostZ: A boost in the Z axis direction.
3D transformations (rotations and translations):
 ROOT::Math::Transform3D: Rotations and then translations described by a 3x4 matrix (12 double numbers).
 ROOT::Math::Translation3D: Only translations described by a 3D vector.
Constructors
All rotations and transformations can be constructed by default, giving the identity transformation. All rotations can be constructed by taking a number of scalar arguments, which match with the number and the order of components.
Examples
In addition, all rotations and transformations, other than the axial rotations, and transformations can be constructed
from (begin
, end
) iterators or from pointers that behave like iterators.
Examples
All rotations, except the axial rotations, can be constructed and assigned from any other type of rotation (including the axial):
Examples
ROOT::Math::Transform3D (rotation and translation) can be constructed from a rotation and a translation vector:
Examples
Operations
You can apply all transformations to vectors and points by using the operator or the ()
operator.
Examples
You can combine transformations using the *
operator . You can combine rotation, translation, and Transform3D
classes with the *
operator . The result of a combination of a rotation and a translation will be a Transform3D class.
**Note **
Rotations are not commutative, so the order is important.
Example
You can combine rotations of different types, like Rotation3D
with any other type of rotations. The product of two
different axial rotations returns a Rotation3D
.
Example
It is also possible to invert all the transformation or return their inverse.
Example
All the presented operations can also be applied to all transformation classes.
SetGetComponents and GetComponents methods
You can use the SetGetComponents()
and SetComponents()
methods to retrieve all the scalar values on which the transformation is based.
Examples
You can use the GetComponents()
and SetComponents()
methods with a signature based on iterators or by using any foreign
matrix, which implements the operator(i,j) or a different signature depending on the transformation.
Example: Connection to linear algebra classes
You can use the vector and rotation classes together with the linear algebra classes and to set and get the contents of any 3D or 4D vector from a linear algebra vector class, which implements an iterator or something which behaves like an iterator.
For example, a pointer to a C array (double*
) behaves like an iterator. It is then assumed that the coordinates, like (x,y,z)
are stored contiguously.
To fill a linear algebra vector from a 3D or 4D vector with GetCoordinates()
, you can get the internal coordinate
data.
or using TVectorD
:
For transformations, constructors and methods to set/get components exist with linear algebra matrices. Prerequisite is that the matrix data is stored, for example, in the case of a Lorentz rotation, from (0,0) thru (3,3).
Example: Connection to other vector classes
You can construct and assign the 3D and 4D vectors of the GenVector package from any vector that meets the following requirements:
 for 3D vectors implementing the
x()
,y()
andz()
methods,  for Lorentz vectors implementing the
x()
,y()
,z()
andt()
methods.
Example
Physics vector package
The physics vector package is a combination of CLHEPs vector package written by Leif Lonnblad, Andreas Nilsson and Evgueni Tcherniaev (→ see https://www.cern.ch/clhep/) and a ROOT package written by Pasha Murat.
There are the following classes in the physics vector package, which are described in detail in the Reference Guide:

TVector2: A general twovector class that can be used for the description of vectors in 2D.

TVector3: A general threevector class that can be used for the description of vectors in 3D.

TRotation: Describes a rotation of objects of the
TVector3
class. 
TLorentzVector: A general fourvector classthat can be used either for the description of position and time (x, y, z, t) or momentum and energy (px, py, pz, E).
TLorentzVector
is a legacy class. 
TLorentzRotation: Describes Lorentz transformations including Lorentz boosts and rotations.