Skip to content
Snippets Groups Projects
Commit 834b0476 authored by Lorenzo Moneta's avatar Lorenzo Moneta
Browse files

Transform documentation files from html to markdown

parent 2caf2abd
Branches
Tags
No related merge requests found
Showing with 934 additions and 7 deletions
/** /**
The Histogram library is documented in the class TH1.
\defgroup Hist Histogram Library \defgroup Hist Histogram Library
The Histogram library is documented in the class TH1. */
*/
\ No newline at end of file
/** /**
\defgroup Math Math The %ROOT Mathematical Libraries.
See the \subpage MathPage "Mathematical Libraries" description page.
The %ROOT Mathematical library.
See the \subpage MathPage "Math" libraries description page. \defgroup Math Math
\page MathPage The %ROOT Mathematical Libraries \page MathPage The ROOT Mathematical Libraries
The %ROOT Mathematical libraries consist of the following components: The %ROOT Mathematical libraries consist of the following components:
......
/**
\page Vector Generic Vector for 2, 3 and 4 Dimensions
**GenVector**, is a new package intended to prepresent vectors and their operations and transformations, such as rotations and Lorentz transformations, in 2, 3 and 4 dimensions. The 2D and 3D space are used to describe the geometry vectors and points, while the 4D space-time is used for physics vectors representing relativistic particles.
These 2D,3D and 4D vectors are different from vectors of the Linear Algebra package which describe generic N-dimensional vectors. Similar functionality is currently provided by the CLHEP [Vector](http://proj-clhep.web.cern.ch/proj-clhep/manual/UserGuide/VectorDefs/index.html) and [Geometry](http://www.hep.phy.cam.ac.uk/lhcb/doc/CLHEP/1.9.1.2/html/namespaceHepGeom.html) packages and the %ROOT [Physics Vector](http://root.cern.ch/root/html/PHYSICS_Index.html) classes (Tvector2, TVector3 and TLorentzVector). It is also re-uses concepts and ideas from the CMS [Common Vector package](http://lcgapp.cern.ch/doxygen/SEAL/snapshot/html/dir_000007.html).
In contrast to CLHEP or the %ROOT physics libraries, GenVector provides class templates for modelling the vectors. There is a user-controlled freedom on how the vector is internally represented. This is expressed by a choice of coordinate system which is supplied as a template prameter when the vector is constructed. Furthermore each coordinate system is itself a template, so that the user can specify the underlying scalar type.
In more detail, the main characteristics of GenVector are:
* #### Optimal runtime performances
We try to minimize any overhead in the run-time performances. We have deliberatly avoided to have any virtual function and even virtual destructors in the classes and have inlined as much as possible all the functions. For this reason, we have chosen to use template classes to implement the GenVector concepts instead of abstract or base classes and virtual functions.
* #### Points and Vector concept
Mathematically vectors and points are two distinct concepts. They have different transformations, like vectors only rotate while points rotate and translate. You can add two vectors but not two points and the difference between two points is a vector. We then distinguish for the 2 and 3 dimensional case, between points and vectors, modeling them with different classes:
* ROOT::Math::DisplacementVector3D and ROOT::Math::DisplacementVector2D template classes describing 3 and 2 component direction and magnitude vectors, not rooted at any particular point;
* ROOT::Math::PositionVector3D template and ROOT::Math::PositionVector3D class modeling the points in 3 and 2 dimensions
For the 4D space-time vectors, we use the same class to model them, ROOT::Math::LorentzVector, since we have recognized a limited needs for modeling the functionality of a 4D point.
* #### Generic Coordinate System
The vector classes are based on a generic type of coordinate system, expressed as a template parameter of the class. Various classes exist to describe the various coordinates systems:
* **2D coordinate system** classes:
* ROOT::Math::Cartesian2D, based on _(x,y)_;
* ROOT::Math::Polar2D, based on _(r, phi)_;
* **3D coordinate system** classes:
* ROOT::Math::Cartesian3D, based on _(x,y,z)_;
* ROOT::Math::Polar3D, based on _(r, theta, phi)_;
* ROOT::Math::Cylindrical3D, based on _(rho, z, phi)_
* ROOT::Math::CylindricalEta3D, based on _(rho, eta, phi)_, where eta is the pseudo-rapidity;
* **4D coordinate system** classes:
* ROOT::Math::PxPyPzE4D, based on based on _(px,py,pz,E)_;
* ROOT::Math::PxPyPzM4D, based on based on _(px,py,pz,M)_;
* ROOT::Math::PtEtaPhiE4D, based on based on _(pt,eta,phi,E)_;
* ROOT::Math::PtEtaPhiM4D, based on based on _(pt,eta,phi,M)_;The angle _theta_ is defined between [0,PI] and _phi_ between [-PI,PI]. The angles are expressed in radians.
Users can define the Vectors according to the coordinate type which is most efficient for their use. Transformations between the various coordinate systems are available through copy constructors or the assignment _(=)_ operator.
For maximum flexibility and minimize in some use case memory allocation, the coordinate system classes are templated on the scalar type. To avoid exposing templated parameter to the users, typedefs are defined for all types of vectors based an double's.
See the \ref Vector3DPage "3D Vector", \ref Point3DPage "3D Point", \ref Vector2DPage "2D Vector and Point", and \ref LorentzVectorPage "LorentzVector" classes for all the possible types of vector classes which can be constructed by the user with the available coordinate system types.
* #### Coordinate System Tag
The 2D and 3D points and vector classes can be associated to a tag defining the coordinate system. This can be used to distinguish between vectors of different coordinate systems like global or local vectors. The coordinate system tag is a template parameter of the ROOT::Math::DisplacementVector3D (and ROOT::Math::DisplacementVector2D) and ROOT::Math::PositionVector3D (and ROOT::Math::PositionVector2D) classes. A default tag, ROOT::Math::DefaultCoordinateSystemTag, exists for users who don't need this functionality.
* ### Transformations
The transformations are modeled using simple (non-template) classes, using double as the scalar type to avoid too large numerical errors. The transformations are grouped in Rotations (in 3 dimensions), Lorentz transformations and Poincarre transformations, which are Translation/Rotation combinations. Each group has several members which may model physically equivalent trasformations but with different internal representations. Transformation classes can operate on all type of vectors using the _operator()_ or the _operator *_ and the transformations can also be combined via the _operator *_. In more detail the transformations available are:
* #### 3D Rotations classes
* Rotation described by a 3x3 matrix (ROOT::Math::Rotation3D)
* Rotation described by Euler angles, Goldstein representation, (ROOT::Math::EulerAngles)
* Rotation described by 3-2-1 Euler angles (ROOT::Math::RotationZYX)
* Rotation described by a direction axis and an angle (ROOT::Math::AxisAngle)
* Rotation described by a quaternion (ROOT::Math::Quaternion)
* Optimized rotation around the x (ROOT::Math::RotationX), y (ROOT::Math::RotationY) and z (ROOT::Math::RotationZ) axis and described by just one angle.
* #### 3D Transformation
We describe the transformations defined as a composition between a rotation and a translation using the class ROOT::Math::Transform3D. It is important to note that transformations act differently on Vectors and Points. The Vectors only rotate, therefore when applying a transfomation (rotation + translation) on a Vector, only the rotation operates while the translation has no effect. The interface for Transformations is similar to the one used in the CLHEP Geometry package (class [Transform3D](http://www.hep.phy.cam.ac.uk/lhcb/doc/CLHEP/1.9.1.2/html/classHepGeom_1_1Transform3D.html)).
A class, ROOT::Math::Translation3D. describe transformations consisting of only a translation. Translation can be applied only on Points, applying them on Vector objects has no effect. The Translation3D class can be combined with both ROOT::Math::Rotation3D and ROOT::Math::Transform3D using the _operator *_ to obtain a new transformation as an instance of a Transform3D class.
* #### Lorentz Rotation
* Generic Lorentz Rotation described by a 4x4 matrix containing a 3D rotation part and a boost part (class ROOT::Math::LorentzRotation)
* A pure boost in an arbitrary direction and described by a 4x4 symmetric matrix or 10 numbers (class ROOT::Math::Boost)
* Boost along the x (ROOT::Math::BoostX), y (ROOT::Math::BoostY) and z (ROOT::Math::BoostZ) axis.
Other main characteristics of the GenVector classes are:
* #### Minimal Vector classes interface
We have tried to keep the interface to a minimal level:
* We try to avoid methods providing the same functionality but with different names ( like getX() and x() ).
* we minimize the number of setter methods, avoiding methods which can be ambigous and set the Vector classes in an inconsistent state. We provide only methods which set all the coordinates at the same time or set only the coordinates on which the vector is based, for example SetX() for a cartesian vector. We then enforce the use of transformations as rotations or translations (additions) for modifying the vector contents.
* The majority of the functionality, which is present in the CLHEP package, involving operations on two vectors, is moved in separated helper functions (see ROOT::Math::VectorUtil). This has the advantage that the basic interface will remain more stable with time while additional functions can be added easily.
* #### Naming Convention
As part of %ROOT, the GenVector package adheres to the prescribed ROOT naming convention, with some (approved) exceptions, as described here:
* Every class and function is in the _ROOT::Math_ namespace
* Member function names starts with upper-case letter, apart some exceptions (see later CLHEP compatibility)
* #### Compatibility with CLHEP Vector classes
* For backward compatibility with CLHEP the Vector classes can be constructed easly from a CLHEP HepVector or HepLorentzVector, by using a template constructor, which requires only that the classes implement the accessors x(), y() and z() (and t() for the 4D).
* we have decided to provide Vector member function with the same naming convention as CLHEP for the most used functions like _x()_, _y()_ and _z()_.
* ### Connection to Linear Algebra package
In some use cases, like in track reconstruction, it is needed to use the content of the vector and rotation classes in conjunction with linear algebra operations. We prefer to avoid any direct dependency to any Linear algebra package. However, we provide some hooks to convert to and from Linear Algebra classes.
* The vector and the transformation classes have methods which allow to get and set their data members (like SetCoordinates and GetCoordinates ) passing either a generic iterator or a pointer to a contigous set of data, like a C array. This allows a easy connection with linear algebra package which allows creation of matrices using C arrays (like the %ROOT TMatrix classes) or iterators ( SMatrix classes )
* Multiplication between Linear Algebra matrix and GenVector Vectors is possible by using the template free functions ROOT::Math::VectorUtil::Mult. This works for any Linear Algebra matrix which implement the _operator(i,j)_ and with first matrix element at _i=j=0_.
## Example of Usage
* \ref Vector3DPage
* \ref Point3DPage
* \ref LorentzVectorPage
* \ref TransformPage
* ROOT::Math::VectorUtil (Helper functions)
* \ref ExtUsagePage
## Packaging
This GenVector package is part of the \ref index and it can be built as an independent package. A tar file can be downloaded from [here](../GenVector.tar.gz).
## Additional Documentation
A more detailed description of all the GenVector classes is available in this [document](http://seal.cern.ch/documents/mathlib/GenVector.pdf).
## References
1. CLHEP Vector package ([User guide](http://proj-clhep.web.cern.ch/proj-clhep/manual/UserGuide/VectorDefs/index.html) and [reference doc](http://www.hep.phy.cam.ac.uk/lhcb/doc/CLHEP/1.9.1.2/html/dir_000027.html))
2. [CLHEP Geometry package](http://www.hep.phy.cam.ac.uk/lhcb/doc/CLHEP/1.9.1.2/html/namespaceH)
3. [%ROOT Physics Vector classes](http://root.cern.ch/root/html/PHYSICS_Index.html)
4. [CMS Vector package](http://lcgapp.cern.ch/doxygen/SEAL/snapshot/html/dir_000007.html)
* * *
*/
// Point3d doxygen page
/**
\page Point3DPage Point3D Classes
To avoid exposing templated parameter to the users, typedefs are defined for all types of vectors based an double's and float's. To use them, one must include the header file _Math/Point3D.h_. The following typedef's, defined in the header file _Math/Point3Dfwd.h_, are available for the different instantiations of the template class 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:
<pre> XYZPoint p1; // create an empty vector (x = 0, y = 0, z = 0)
XYZPoint p2( 1,2,3); // create a vector with x=1, y = 2, z = 3;
Polar3DPoint p3( 1, PI/2, PI); // create a vector with r = 1, theta = PI/2 and phi=PI
RhoEtaPHiPoint p4( 1, 2, PI) // create a vector with rho= 1, eta = 2, phi = PI
</pre>
Note that each type of vector is constructed by passing its coordinates representations, so a XYZPoint(1,2,3) is different from a Polar3DPoint(1,2,3).
In addition the Point classes can be constructed by any vector, which implements the accessors x(), y() and z(). This con be another Point3D based on a different coordinate system types or even any vector of a different package, like the CLHEP HepThreePoint that implements the required signatures.
<pre> XYZPoint p1(1,2,3);
RhoEtaPHiPoint r2(v1);
CLHEP::HepThreePoint q(1,2,3);
XYZPoint p3(q)
</pre>
#### Coordinate Accessors and Setter Methods
For the Points classes we have the same getter and setter methods as for the Vector classes. See the examples for the \ref Vector3DPage.
#### Point-Vector Operations
The following operations are possible between points and vector classes: ( p1 ,p2 and p3 are instantiations of the ROOT::Math::PositionVector3D class, p1 and p3 of the same type v1 and v2 are a ROOT::Math::DisplacementVector3D class )
<pre>p1 += v1;
p1 -= v1;
p3 = p1 + v1; // p1 and p3 are the same type
p3 = v1 + p1; // p3 is based on the same coordinate system as v1
p3 = p1 - v1;
p3 = v1 - p1;
v2 = p1 - p2; // difference between points returns a vector v2 based on the same coordinate system as p1
</pre>
Note that additions between two points is NOT possible and the difference between points returns a vector.
#### Other Operations
Exactly as for the 3D Vectors, the following operations are allowed:
* comparison of points
* scaling and division of points with a scalar
* dot and cross product with any type of vector
*/
// Rotation and transformation doxygen page
/**
\page TransformPage Vector Transformations
Transformations classes are grouped in Rotations (in 3 dimensions), Lorentz transformations and Poincarre transformations, which are Translation/Rotation combinations. Each group has several members which may model physically equivalent trasformations but with different internal representations.
All the classes are non-template and use double precision as the scalar type The following types of transformation classes are defined:
* 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](http://mathworld.wolfram.com/EulerAngles.html).
* 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
* 3D Transformations (Rotations + Translations)
* ROOT::Math::Translation3D, (only translation) described by a 3D Vector
* ROOT::Math::Transform3D, (rotations and then translation) described by a 3x4 matrix (12 numbers)
* Lorentz Rotations and Boost
* 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 symmetrix 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
#### Constructors
All rotations and transformations are default constructible (giving the identity transformation). All rotations are constructible taking a number of scalar argumnts matching the number (and order of components)
<pre>Rotation3D rI; // create a summy rotation (Identity matrix)
RotationX rX(M_PI); // create a rotationX with an angle PI
EulerAngles rE(phi, theta, psi); // create a Euler rotation with phi,theta,psi angles
XYZVector u(ux,uy,uz);
AxisAngle rA(u, delta); // create a rotation based on direction u with delta angle
</pre>
In addition, all rotations and transformations (other than the axial rotations) and transformations are constructible from (begin,end) iterators or from pointers whicih behave like iterators.
<pre>double data[9];
Rotation3D r(data, data+9); // create a rotation from a rotation matrix
std::vector <double>w(12);
Transform3D t(w.begin(),w.end()); // create a Transform3D from the content of a std::vector</double> </pre>
All rotations, except the axial rotations, are constructible and assigned from any other type of rotation (including the axial):
<pre>Rotation3D r(ROOT::Math::RotationX(PI)); // create a rotation 3D from a rotation along X axis of angle PI
EulerAngles r2(r); // construct an Euler Rotation from A Rotation3D
AxisAngle r3; r3 = r2; // assign an Axis Rotation from an Euler Rotation;
</pre>
Transform3D (rotation + translation) can be constructed from a rotation and a translation vector
<pre>Rotation3D r; XYZVector v;
Transform3D t1(r,v); // construct from rotation and then translation
Transform3D t2(v,r); // construct inverse from first translation then rotation
Transform3D t3(r); // construct from only a rotation (zero translation)
Transform3D t4(v); // construct from only translation (identity rotation)
</pre>
#### Operations
All transformations can be applied to vector and points using the _operator *_ or using the _operator()_
<pre>XYZVector v1(...);
Rotation3D r(...);
XYZVector v2 = r*v1; // rotate vector v1 using r
v2 = r(v1) // equivalent
</pre>
Transformations can be combined using the operator * . Note that the rotations are not commutative ans therefore the order is important
<pre>Rotation3D r1(...);
Rotation3D r2(...);
Rotation3D r3 = r2*r1; // obtain a combine rotation r3 by applying first r1 then r2
</pre>
We can combine rotations of different types, like Rotation3D with any other type of rotations. The product of two different axial rotations return a Rotation3D:
<pre>RotationX rx(1.);
RotationY ry(2.);
Rotation3D r = ry * rx; // rotation along X and then Y axis
</pre>
It is also possible to invert all the transformation or return the inverse of a transformation
<pre>Rotation3D r1(...);
r1.Invert(); // invert the rotation modifying its content
Rotation3D r2 =r1.Inverse(); // return the inverse in a new rotation class
</pre>
We have used rotation as examples, but all these operations can be applied to all the transformation classes. Rotation3D, Transform3D and Translation3D classes can all be combined via the _operator *_.
<pre>Rotation3D r(AxisAngle(phi,ux,uy,uz)); // rotation of an angle phi around u.
Translation3D d(dx,dy,dz); // translation of a vector d
Transform3D t1 = d * r; // transformation obtained applying first the rotation
Transform3D t2 = r * d; // transformation obtained applying first the translation
</pre>
#### Set/GetComponents methods
Common methods to all the transformations are the Get and SetComponents. They can be used to retrieve all the scalar values on which the trasformation is based. They can be used with a signature based iterators or by using any foreign matrix which implements the _operator(i,j)_ or a different signatures depending on the transformation type.
<pre>RotationX rx; rx.SetComponents(1.) // set agle of the X rotation
double d[9] = {........}
Rotation3D r; r.SetComponents(d,d+9); // set 9 components of 3D rotation
double d[16];
LorentzRotation lr;
lr.GetComponents( d, d+16); // get 16 components of a LorentzRotation
TMatrixD(3,4) m;
Transform3D t; t.GetComponens(m); // fill matrix of size 3x4 with components of the transform3D t
</pre>
For more detailed documentation on all methods see the reference doc for the specific transformation class.
*/
/**
\page Vector3DPage Vector3D Classes
To avoid exposing templated parameter to the users, typedefs are defined for all types of vectors based an double's and float's. To use them, one must include the header file _Math/Vector3D.h_. The following typedef's, defined in the header file _Math/Vector3Dfwd.h_, are available for the different instantiations of the template class 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:
<pre> XYZVector v1; // create an empty vector (x = 0, y = 0, z = 0)
XYZVector v2( 1,2,3); // create a vector with x=1, y = 2, z = 3;
Polar3DVector v3( 1, PI/2, PI); // create a vector with r = 1, theta = PI/2 and phi=PI
RhoEtaPHiVector v4( 1, 2, PI) // create a vector with rho= 1, eta = 2, phi = PI
</pre>
Note that each type of vector is constructed by passing its coordinates representations, so a XYZVector(1,2,3) is different from a Polar3DVector(1,2,3).
In addition the Vector classes can be constructed by any vector, which implements the accessors x(), y() and z(). This con be another Vector3D based on a different coordinate system types or even any vector of a different package, like the CLHEP HepThreeVector that implements the required signatures.
<pre> XYZVector v1(1,2,3);
RhoEtaPhiVector r2(v1);
CLHEP::HepThreeVector q(1,2,3);
XYZVector v3(q)
</pre>
#### Coordinate Accessors
All the same coordinate accessors are available through the interface of the class ROOT::Math::DisplacementVector3D. For example:
<pre>v1.X(); v1.X(); v1.Z() // returns cartesian components for the cartesian vector v1
v1.Rho(); v1.Eta(); v1.Phi() // returns cylindrical components for the cartesian vector v1
r2.X(); r2.Y(); r2.Z() // returns cartesian components for the cylindrical vector r2
</pre>
In addition, all the 3 coordinates of the vector can be retrieved with the GetCoordinates method:
<pre>double d[3];
v1.GetCoordinates(d); // fill d array with (x,y,z) components of v1
r2.GetCoordinates(d); // fill d array with (r,eta,phi) components of r2
std::vector <double>vc(3);
v1.GetCoordinates(vc.begin(),vc.end()); // fill std::vector with (x,y,z) components of v1</double> </pre>
To get more information on all the coordinate accessors see the reference documentation of ROOT::Math::DisplacementVector3D.
#### Setter Methods
One can set only all the three coordinates via:
<pre>v1.SetCoordinates(c1,c2,c3); // sets the (x,y,z) for a XYZVector
r2.SetCoordinates(c1,c2,c3); // sets r,theta,phi for a Polar3DVector
r2.SetXYZ(x,y,z); // sets the three cartesian components for the Polar3DVector
</pre>
Single coordinate setter methods are available for the basic vector coordinates, like SetX() for a XYZVector or SetR() for a polar vector. Attempting to do a SetX() on a polar vector will not compile.
<pre>XYZVector v1; v1.SetX(1) // OK setting x for a Cartesian vector
Polar3DVector v2; v2.SetX(1) // ERROR: cannot set X for a Polar vector. Method will not compile
v2.SetR(1) // OK setting r for a Polar vector
</pre>
In addition there are setter methods from C arrays or iterators.
<pre>double d[3] = {1.,2.,3.};
XYZVector v;
v.SetCoordinates(d); // set (x,y,z) components of v using values from d
</pre>
or for example from an std::vector using the iterator
<pre>std::vector <double>w(3);
v.SetCoordinates(w.begin(),w.end()); // set (x,y,z) components of v using values from w</double> </pre>
#### Arithmetic Operations
The following operations are possible between Vector classes, even of different coordinate system types: ( v1,v2 are any type of ROOT::Math::DisplacementVector3D classes, v3 is the same type of v1; _a_ is a scalar value)
<pre>v1 += v2;
v1 -= v2;
v1 = - v2;
v1 *= a;
v1 /= a;
v2 = a * v1;
v2 = v1 / a;
v2 = v1 * a;
v3 = v1 + v2;
v3 = v1 - v2;
</pre>
#### Comparison
For v1 and v2 of the same type (same coordinate system and same scalar type):
<pre>v1 == v2;
v1 != v2;
</pre>
#### Dot and Cross Product
We support the dot and cross products, through the Dot() and Cross() method, with any Vector (q) implementing x(), y() and z()
<pre>XYZVector v1(x,y,z);
double s = v1.Dot(q);
XYZVector v2 = v1.Cross(q);
</pre>
Note that the multiplication between two vectors using the operator * is not supported because is ambiguous.
#### Other Methods
<pre>XYZVector u = v1.Unit(); // return unit vector parallel to v1
</pre>
*/
// Vector2d doxygen page
/**
\page Vector2DPage 2D Point and Vector Classes
Similar to the \ref Vector3DPage and \ref Point3DPage , typedefs are defined to avoid exposing templated parameter to the users, for all 2D vectors based an double's and float's. To use them, one must include the header file _Math/Vector2D.h_ or _Math/Point2D.h_. The following typedef's, defined in the header file _Math/Vector2Dfwd.h_, are available for the different instantiations of the template class ROOT::Math::DisplacementVector2D:
* ROOT::Math::XYVector vector based on x,y coordinates (cartesian) in double precision
* ROOT::Math::XYVectorF vector based on x,y coordinates (cartesian) in float precision
* ROOT::Math::Polar2DVector vector based on r,phi coordinates (polar) in double precision
* ROOT::Math::Polar2DVectorF vector based on r,phi coordinates (polar) in float precision
The typedef's, defined in the header file _Math/Point2Dfwd.h_, available for the different instantiations of the template class ROOT::Math::PoistionVector2D are:
* ROOT::Math::XYPoint vector based on x,y coordinates (cartesian) in double precision
* ROOT::Math::XYPointF vector based on x,y coordinates (cartesian) in float precision
* ROOT::Math::Polar2DPoint vector based on r,phi coordinates (polar) in double precision
* ROOT::Math::Polar2DPointF vector based on r,phi coordinates (polar) in float precision
Similar constructs, functions and operations available for the 3D vectors and points (see \ref Vector3DPage and \ref Point3DPage ) are available also for the 2D vector and points. No transformations or rotation classes are available for the 2D vectors.
*/
// example on using with exteral classes (doxygen page)
/**
\page ExtUsagePage Examples with External Packages
### Connection to Linear Algebra classes
It is possible to use the Vector and Rotation classes together with the Linear Algebra classes. It is possible to set and get the contents of any 3D or 4D Vector from a Linear Agebra 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) will be stored contiguosly.
<pre>TVectorD r2(N) // %ROOT Linear Algebra Vector containing many vectors
XYZVector v2;
v2.SetCoordinates(&r2[INDEX],&r2[index]+3); // construct vector from x=r[INDEX], y=r[INDEX+1], z=r[INDEX+2]
</pre>
To fill a Linear Algebra Vector from a 3D or 4D Vector, with GetCoordinates() one can get the internal coordinate data.
<pre>HepVector c(3); // CLHEP Linear algebra vector
v2.GetCoordinates(&c[0],&c[index]+3 ) // fill HepVector c with c[0] = x, c[1] = y , c[2] = z
</pre>
Or using TVectorD
<pre>double * data[3];
v2.GetCoordinates(data,data+3);
TVectorD r1(3,data); // create a new Linear Algebra vector copying the data
</pre>
In the case of transformations, constructor and method to set/get components exist with Linear Algebra matrices. The requisite is that the matrix data are stored, for example in the cse of a LorentzRotation, from (0,0) thru (3,3)
<pre>TMatrixD(4,4) m;
LorentzRotation r(m) // create LorentzRotation from matrix m
r.GetComponents(m) // fill matrix m with LorentzRotation components
</pre>
### Connection to Other Vector classes
The 3D and 4D vectors of the GenVector package can be constructed and assigned from any Vector, which satisfies the following requisites:
* for 3D Vectors and Points must implement the x(), y() ans z() methods
* for LorentzVectors must implement the x(), y(), z() and t() methods.
<pre>CLHEP::Hep3Vector hv;
XYZVector v1(hv); // create 3D Vector from CLHEP 3D Vector
HepGeom::Point3D <double>hp;
XYZPoint p1(hp); // create a 3D Point from CLHEP geom Point
CLHEP::HepLorentzVector hq;
XYZTVector q(hq); // create a LorentzVector from CLHEP L.V.</double> </pre>
*/
/**
\defgroup MathCore MathCore
The Core Mathematical Library of %ROOT. See the \ref MathCorePage description page.
\ingroup Math
\page MathCorePage MathCore Library
**MathCore** provides a collection of functions and C++ classes for HEP numerical computing. This library provides only the basic mathematical functions and algorithms and not all the functionality required by the HEP community. More advanced mathematical functionalities is provided by the \ref MathMore. The current set includes classes and functions for:
* \ref SpecFunc "Basic special functions" used in HEP like the gamma, beta and error function;
* \ref StatFunc : mathematical functions used in statistics, such as the probability density functions and the cumulative distributions functions (lower and upper integral of the pdf's) for continuous and discrete distributions.;
* \ref CppFunctions :
* \ref GenFunc, including helper class to wrap free (static) and non-static member functions
* \ref ParamFunc
* Numerical algorithms: user classes with (in some cases) basic implementations for:
* \ref Integration
* \ref Deriv
* \ref RootFinders
* \ref Min1D and \ref MultiMin
* \ref Fit :classes for fitting and parameter estimation from a given data set.
Note that in this latest release the \ref Vector "GenVector" (physics and geometry vectors for 2,3 and 4 dimensions with their transformations) is not anymore part of MathCore, but is built as a separate library.
MathCore contains instead now classes which were originally part of _libCore_. These include:
* [**<tt>TMath</tt>**](http://root.cern.ch/root/htmldoc/math/mathcore/TMath.html): namespace with mathematical functions and basic function algorithms.
* [**<tt>TComplex</tt>**](http://root.cern.ch/root/htmldoc/TComplex.html): class for complex numbers.
* Random classes: base class [**<tt>TRandom</tt>**](http://root.cern.ch/root/htmldoc/TRandom.html) and the derived classes [<tt>TRandom1</tt>](http://root.cern.ch/root/htmldoc/TRandom1.html), [<tt>TRandom2</tt>](http://root.cern.ch/root/htmldoc/TRandom2.html) and [<tt>TRandom3</tt>](http://root.cern.ch/root/htmldoc/TRandom.html)), implementing the pseudo-random number generators.
MathCore and its CINT dictionary is normally built by default in %ROOT. Alternatively MathCore can be built as a stand-alone library (excluding classes like <tt>TComplex</tt> or <tt>TRandom</tt>
having a direct dependency of %ROOT _libCore_), downloading the current version from [here](../MathCore.tar.gz). Note, that the stand-alone library, in contrast to the one distributed by %ROOT, **does
not** contain the dictionary information and therefore cannot be used interactively. To build the stand-alone MathCore library run first the _configure_ script and then _make_. Do _configure --help_
to see options available in configuring, like defining the installation directory. Run also _make install_ to install the library and include files and _make check_ to build the tests.
*/
/**
\defgroup MathMore MathMore
The Mathematical library providing some advanced functionality and based on GSL. See the \ref MathMorePage page.
\ingroup Math
\page MathMorePage MathMore Library
**MathMore** provides an advanced collection of functions and C++ classes for HEP numerical computing. This is an extension of the functionality provided by the \ref MathCore. The current set includes classes and functions for:
* \ref SpecFunc, with all the major functions (Bessel functions, Legendre polynomial, etc..)
* \ref StatFunc, Mathematical functions used in statistics such as probability density functions, cumulative distributions functions and their inverse (quantiles).
* Numerical algorithms:
* \ref Integration
* \ref MCIntegration
* \ref Deriv
* \ref RootFinders
* \ref Min1D
* \ref MultiMin
* \ref Interpolation
* \ref FuncApprox, based on Chebyshev polynomials
* \ref Random
The mathematical functions are implemented as a set of free functions in the namespace \em ROOT::Math. The naming used for the special functions is the same proposed for the C++ standard (see C++ standard extension [proposal document](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1687.pdf)). The MathMore library is implemented wrapping in C++ the GNU Scientific Library ([GSL](http://www.gnu.org/software/gsl)).
To build MathMore you need to have first GSL installed somewhere in your system. A version of GSL larger or equal 1.8 is required. A tar file of GSL can be downloaded from the [GSL Web site](http://www.gnu.org/software/gsl/#downloading), or (for version 1.8) from [here](http://seal.web.cern.ch/seal/MathLibs/gsl-1.8.tar.gz). Windows binaries, compiled using Visual Studio 7.1 can be downloaded from [this location](http://seal.web.cern.ch/seal/MathLibs/GSL-1.8.zip).
MathMore (and its %ROOT CINT dictionary) can be built within %ROOT whenever a GSL library is found in the system. Optionally the GSL library and header file location can be specified in the %ROOT configure script with _configure --with-gsl-incdir=... --with-gsl-libdir=..._
MathMore can be built also a stand-alone library (without requiring %ROOT) downloding the tar file from the Web. Note that in this case the library will **NOT** contain the dictionary information and therefore cannot be used interactivly.
The current standalone version of MathMore can be downloaded [here](../MathMore.tar.gz).
To build the library run first the script _configure --with-gsl="gsl_dir_location"_ and then _make_. Do _configure --help_ to see options available in configuring, like defining the installation directory. Run also _make install_ to install the library and include files and _make check_ to build the tests.
The source code is distributed under the GNU General Public License.
*/
/**
\page Minuit2Page Minuit2
The **Minuit2** library is a new object-oriented implementation, written in C++, of the popular MINUIT minimization package. These new version provides basically all the functionality present in the old Fortran version, with almost equivalent numerical accuracy and computational performances. Furthermore, it contains new functionality, like the possibility to set single side parameter limits or the FUMILI algorithm, which is an optimized method for least square and log likelihood minimizations. The package has been originally developed by M. Winkler and F. James. More information on the new C++ version can be found on the [MINUIT Web Site](http://www.cern.ch/minuit).
Minuit2, originally developed in the SEAL project, is now distributed within %ROOT. The API has been then changed in this new version to follow the %ROOT coding convention (function names starting with capital letters) and the classes have been moved inside the namespace _ROOT::Minuit2_. In addition, the %ROOT distribution contains classes needed to integrate Minuit2 in the %ROOT framework.
A new class has been introduced, ROOT::Minuit2::Minuit2Minimizer, which implements the interface ROOT::Math::Minimizer. Within %ROOT, it can be instantiates also using the %ROOT plug-in manager. This class provides a convenient entry point for using Minuit2\. An example of using this interface is the %ROOT tutorial _tutorials/fit/NumericalMinimization.C_ or the Minuit2 test program [<tt>testMinimize.cxx</tt>](http://root.cern.ch/viewvc/trunk/math/minuit2/test/testMinimize.cxx?view=markup).
A standalone version of Minuit2 (indipendent of %ROOT) can be downloaded from [here](../Minuit2.tar.gz). It does not contain the %ROOT interface and it is therefore totally independent of external packages and can be simply build using the _configure_ script and then _make_. Example tests are provided in the directory _test/MnSim_ and _test/MnTutorial_ and they can be built with the _make check_ command.
The [Minuit2 User Guide](https://root.cern.ch/root/htmldoc/guides/minuit2/Minuit2.html) provides all the information needed for using directly (without add-on packages like %ROOT) Minuit2.
## References
1. F. James, _Fortran MINUIT Reference Manual_ ([html](http://wwwasdoc.web.cern.ch/wwwasdoc/minuit/minmain.html));
2. F. James and M. Winkler, _C++ MINUIT User's Guide_ ([html](https://root.cern.ch/root/htmldoc/guides/minuit2/Minuit2.html) and [pdf](https://root.cern.ch/root/htmldoc/guides/minuit2/Minuit2.pdf));
3. F. James, _Minuit Tutorial on Function Minimization_ ([pdf](http://seal.cern.ch/documents/minuit/mntutorial.pdf));
4. F. James, _The Interpretation of Errors in Minuit_ ([pdf](http://seal.cern.ch/documents/minuit/mnerror.pdf));
*/
// Matrix and Vector Functions doc
/**
\page MatVecFunctions Matrix and Vector Operators and Functions
## Matrix and Vector Operators
The ROOT::Math::SVector and ROOT::Math::SMatrix classes defines the following operators described below. The _m1,m2,m3_ are vectors or matrices of the same type (and size) and _a_ is a scalar value:
<pre>m1 == m2 _// returns whether m1 is equal to m2 (element by element comparison)_
m1 != m2 _// returns whether m1 is NOT equal to m2 (element by element comparison)_
m1 < m2 _// returns whether m1 is less than m2 (element wise comparison)_
m1 > m2 _// returns whether m1 is greater than m2 (element wise comparison)_
_// in the following m1 and m3 can be general and m2 symmetric, but not vice-versa_
m1 += m2 _// add m2 to m1_
m1 -= m2 _// subtract m2 to m1_
m3 = m1 + m2 _// addition_
m1 - m2 _// subtraction_
_// Multiplication and division via a scalar value a_
m3 = a*m1; m3 = m1*a; m3 = m1/a;
</pre>
### Vector-Vector multiplication
The _operator *_ defines an element by element multiplication between vectors. For the standard vector-vector multiplication, \f$ a = v^T v \f$, (dot product) one must use the ROOT::Math::Dot function. In addition, the Cross (only for vector sizes of 3), ROOT::Math::Cross, and the Tensor product, ROOT::Math::TensorProd, are defined.
### Matrix - Vector multiplication
The _operator *_ defines the matrix-vector multiplication, \f$ y_i = \sum_{j} M_{ij} x_j\f$:
<pre>_// M is a N1xN2 matrix, x is a N2 size vector, y is a N1 size vector_
y = M * x
</pre>
It compiles only if the matrix and the vectors have the right sizes.
**Matrix - Matrix multiplication** The _operator *_ defines the matrix-matrix multiplication, \f$ C_{ij} = \sum_{k} A_{ik} B_{kj}\f$:
<pre>_// A is a N1xN2 matrix, B is a N2xN3 matrix and C is a N1xN3 matrix_
C = A * B
</pre>
The operation compiles only if the matrices have the right size. In the case that A and B are symmetric matrices, C is a general one, since their product is not guaranteed to be symmetric.
### Matrix and Vector Functions
The most used matrix functions are:
* **ROOT::Math::Transpose**(M) : return the transpose matrix, \f$ M^T \f$
* **ROOT::Math::Similarity**( v, M) : returns the scalar value resulting from the matrix- vector product \f$ v^T M v \f$
* **ROOT::Math::Similarity**( U, M) : returns the matrix resulting from the product \f$ U M U^T \f$. If M is symmetric, the returned resulting matrix is also symmetric
* **ROOT::Math::SimilarityT**( U, M) : returns the matrix resulting from the product \f$ U^T M U \f$. If M is symmetric, the returned resulting matrix is also symmetric
See \ref MatrixFunctions for the documentation of all existing matrix functions in the package.
The major Vector functions are:
* **ROOT::Math::Dot**( v1, v2) : returns the scalar value resulting from the vector dot product
* **ROOT::Math::Cross**( v1, v2) : returns the vector cross product for two vectors of size 3\. Note that the Cross product is not defined for other vector sizes
* **ROOT::Math::Unit**( v) : returns unit vector. One can use also the _v.Unit()_ method.
* **ROOT::Math::TensorProd**(v1,v2) : returns a general matrix M of size N1xN2 resulting from the [Tensor Product](http://en.wikipedia.org/wiki/Tensor_product) between the vector v1 of size N1) and v2 of size N2
See \ref VectFunction for the list and documentation of all of them.
### Matrix and Vector I/O
One can print (or write in an output stream) Vectors (and also Matrices) using the Print method or the << operator, like:
<pre>v.Print(std::cout);
std::cout << v << std::endl;
</pre>
In the ROOT distribution, the CINT dictionary is generated for SMatrix and SVector for double types and sizes up to 5\. This allows the storage of them in a ROOT file.
*/
*/
// top doc Doxygen page for smatrix
/**
\page SMatrixPage SMatrix Package
@b SMatrix is a C++ package for high performance vector and matrix computations. It can be used only in problems when the size of the matrices is known at compile time, like in the tracking reconstruction of HEP experiments. It is based on a C++ technique, called expression templates, to achieve an high level optimization. The C++ templates can be used to implement vector and matrix expressions such that these expressions can be transformed at compile time to code which is equivalent to hand optimized code in a low-level language like FORTRAN or C (see for example ref. 1)
The SMatrix has been developed initially by T. Glebe of the Max-Planck-Institut, Heidelberg, as part of the HeraB analysis framework. A subset of the original package has been now incorporated in the %ROOT distribution, with the aim to provide to the LHC experiments a stand-alone and high performant matrix package for reconstruction. The API of the current package differs from the original one, in order to be compliant to the %ROOT coding conventions.
SMatrix contains generic \ref SMatrixSVector to describe matrix and vector of arbitrary dimensions and of arbitrary type. The classes are templated on the scalar type and on the size of the matrix (number of rows and columns) or the vector. Therefore, the size has to be known at compile time. Since the release 5.10, SMatrix supports symmetric matrices using a storage class (ROOT::Math::MatRepSym) which contains only the N*(N+1)/2 independent element of a NxN symmetric matrix.
It is not in the mandate of this package to provide a complete linear algebra functionality for these classes. What is provided are basic \ref MatrixFunctions and \ref VectFunction, such as the matrix-matrix, matrix-vector, vector-vector operations, plus some extra functionality for square matrices, like inversion, which is based on the optimized Cramer method for squared matrices of size up to 6x6, and determinant calculation.
For a more detailed descriptions and usage examples see:
* \ref SVectorDoc
* \ref SMatrixDoc
* \ref MatVecFunctions
The SMatrix package contains only header files. Normally one does not need to build any library. In the %ROOT distribution a library, _libSmatrix_ is produced with the C++ dictionary information for vectors, symmetric and squared matrices for double, float types up to dimension 7.
The current version of SMatrix can be downloaded from [here](../SMatrix.tar.gz). If you want to install the header files or run the test _configure_ script and then _make install_ or _make check_ to build the tests. No dictionary library is built in this case.
## References
1. T. Veldhuizen, [_Expression Templates_](http://osl.iu.edu/~tveldhui/papers/Expression-Templates/exprtmpl.html), C++ Report, 1995.
2. T. Glebe, _SMatrix - A high performance library for Vector/Matrix calculation and Vertexing_, HERA-B Software Note 01-134, December 2, 2003 ([pdf](http://seal.web.cern.ch/seal/documents/mathlib/smatrix_herab.pdf))
3. L. Moneta, %ROOT Math proposal for Linear Algebra, [presentation](http://seal.cern.ch/documents/mathlib/aa_matrix_nov05.pdf) at the LCG Application Area meeting, November 23, 2005
* * *
@authors the %ROOT Math Library Team, T. Glebe (original SMatrix author) and J. Palacios (LHCb)
*/
// SMatrix example of usage
/**
\page SMatrixDoc SMatrix Class Properties
The template ROOT::Math::SMatrix class has 4 template parameters which define, at compile time, its properties. These are:
* type of the contained elements, T, for example _float_ or _double_;
* number of rows;
* number of columns;
* representation type (\ref MatRep). This is a class describing the underlined storage model of the Matrix. Presently exists only two types of this class:
1. ROOT::Math::MatRepStd for a general nrows x ncols matrix. This class is itself a template on the contained type T, the number of rows and the number of columns. Its data member is an array T[nrows*ncols] containing the matrix data. The data are stored in the row-major C convention. For example, for a matrix, M, of size 3x3, the data \f$ \left[a_0,a_1,a_2,.......,a_7,a_8 \right] \f$ are stored in the following order: \f[ M = \left( \begin{array}{ccc} a_0 & a_1 & a_2 \\ a_3 & a_4 & a_5 \\ a_6 & a_7 & a_8 \end{array} \right) \f]
2. ROOT::Math::MatRepSym for a symmetric matrix of size NxN. This class is a template on the contained type and on the symmetric matrix size, N. It has as data member an array of type T of size N*(N+1)/2, containing the lower diagonal block of the matrix. The order follows the lower diagonal block, still in a row-major convention. For example for a symmetric 3x3 matrix the order of the 6 elements \f$ \left[a_0,a_1.....a_5 \right]\f$ is: \f[ M = \left( \begin{array}{ccc} a_0 & a_1 & a_3 \\ a_1 & a_2 & a_4 \\ a_3 & a_4 & a_5 \end{array} \right) \f]
### Creating a matrix
The following constructors are available to create a matrix:
* Default constructor for a zero matrix (all elements equal to zero).
* Constructor of an identity matrix.
* Copy constructor (and assignment) for a matrix with the same representation, or from a different one when possible, for example from a symmetric to a general matrix.
* Constructor (and assignment) from a matrix expression, like D = A*B + C. Due to the expression template technique, no temporary objects are created in this operation. In the case of an operation like A = A*B + C, a temporary object is needed and it is created automatically to store the intermediary result in order to preserve the validity of this operation.
* Constructor from a generic STL-like iterator copying the data referred by the iterator, following its order. It is both possible to specify the _begin_ and _end_ of the iterator or the _begin_ and the size. In case of a symmetric matrix, it is required only the triangular block and the user can specify whether giving a block representing the lower (default case) or the upper diagonal part.
* Constructor of a symmetric matrix NxN passing a ROOT::Math::SVector with dimension N*(N+1)/2 containing the lower (or upper) block data elements.
Here are some examples on how to create a matrix. We use _typedef's_ in the following examples to avoid the full C++ names for the matrix classes. Notice that for a general matrix the representation has the default value, ROOT::Math::MatRepStd, and it is not needed to be specified. Furtheremore, for a general square matrix, the number of column may be as well omitted.
<pre>_// typedef definitions used in the following declarations_
typedef ROOT::Math::SMatrix<double,3> SMatrix33;
typedef ROOT::Math::SMatrix<double,2> SMatrix22;
typedef ROOT::Math::SMatrix<double,3,3,ROOT::Math::MatRepSym<double,3> > SMatrixSym3;
typedef ROOT::Math::SVector>double,2> SVector2;
typedef ROOT::Math::SVector>double,3> SVector3;
typedef ROOT::Math::SVector>double,6> SVector6;
SMatrix33 m0; _// create a zero 3x3 matrix_
_// create an 3x3 identity matrix_
SMatrix33 i = ROOT::Math::SMatrixIdentity();
double a[9] = {1,2,3,4,5,6,7,8,9}; _// input matrix data_
SMatrix33 m(a,9); _// create a matrix using the a[] data_
_// this will produce the 3x3 matrix
// ( 1 2 3
// 4 5 6
// 7 8 9 )_
</pre>
Example to create a symmetric matrix from an _std::vector_:
<pre>std::vector<double> v(6);
for (int i = 0; i<6; ++i) v[i] = double(i+1);
SMatrixSym3 s(v.begin(),v.end())
_// this will produce the symmetric matrix
// ( 1 2 4
// 2 3 5
// 4 5 6 )_
_// create a a general matrix from a symmetric matrix. The opposite will not compile_
SMatrix33 m2 = s;
</pre>
Example to create a symmetric matrix from a ROOT::Math::SVector contining the lower/upper data block:
<pre>ROOT::Math::SVectorr<double, 6> v(1,2,3,4,5,6);
SMatrixSym3 s1(v); // lower block (default)
// this will produce the symmetric matrix
// ( 1 2 4
// 2 3 5
// 4 5 6 )
SMatrixSym3 s2(v,false); // upper block
// this will produce the symmetric matrix
// ( 1 2 3
// 2 4 5
// 3 5 6 )
</pre>
### Accessing and Setting Methods
The matrix elements can be set using the _operator()(irow,icol)_, where irow and icol are the row and column indexes or by using the iterator interface. Notice that the indexes start from zero and not from one as in FORTRAN. All the matrix elements can be set also by using the ROOT::Math::SetElements function passing a generic iterator.
The elements can be accessed by these same methods and also by using the ROOT::Math::SMatrix::apply function. The _apply(i)_ function has exactly the same behavior for general and symmetric matrices, in contrast to the iterator access methods which behave differently (it follows the data order).
<pre>SMatrix33 m;
m(0,0) = 1; _ // set the element in first row and first column_
*(m.**begin**()+1) = 2; _// set the second element (0,1)_
double d[9]={1,2,3,4,5,6,7,8,9};
m.SetElements(d,d+9); _// set the d[] values in m_
double x = m(2,1); _// return the element in third row and first column_
x = m.**apply**(7); _// return the 8-th element (row=2,col=1)_
x = *(m.**begin**()+7); _// return the 8-th element (row=2,col=1)_
_// symmetric matrices (note the difference in behavior between apply and the iterators)_
x = *(m.**begin**()+4) _// return the element (row=2,col=1)._
x = m.**apply**(7); _// returns again the (row=2,col=1) element_
</pre>
There are methods to place and/or retrieve ROOT::Math::SVector objects as rows or columns in (from) a matrix. In addition one can put (get) a sub-matrix as another ROOT::Math::SMatrix object in a matrix. If the size of the the sub-vector or sub-matrix are larger than the matrix size a static assert ( a compilation error) is produced. The non-const methods are:
<pre>
SMatrix33 m;
SVector2 v2(1,2);
_// place a vector of size 2 in the first row starting from element (0,1) : m(0,1) = v2[0]_
m.**Place_in_row**(v2,0,1);
_// place the vector in the second column from (0,1) : m(0,1) = v2[0] _
m.**Place in_col**(v2,0,1);
SMatrix22 m2;
_// place the sub-matrix m2 in m starting from the element (1,1) : m(1,1) = m2(0,0) _
m.**Place_at**(m2,1,1);
SVector3 v3(1,2,3);
_// set v3 as the diagonal elements of m : m(i,i) = v3[i] for i=0,1,2_
m.**SetDiagonal**(v3) </pre>
The const methods retrieving contents (getting slices of a matrix) are:
<pre>a = {1,2,3,4,5,6,7,8,9};
SMatrix33 m(a,a+9);
SVector3 irow = m.**Row**(0); _// return as vector the first matrix row_
SVector3 jcol = m.**Col**(1); _// return as vector the second matrix column_
_// return a slice of the first row from element (0,1) : r2[0] = m(0,1); r2[1] = m(0,2)_
SVector2 r2 = m.**SubRow**<SVector2> (0,1);
_// return a slice of the second column from element (0,1) : c2[0] = m(0,1); c2[1] = m(1,1);_
SVector2 c2 = m.**SubCol**<SVector2> (1,0);
_// return a sub-matrix 2x2 with the upper left corner at the values (1,1)_
SMatrix22 subM = m.**Sub**<SMatrix22> (1,1);
_// return the diagonal element in a SVector_
SVector3 diag = m.**Diagonal**();
_// return the upper(lower) block of the matrix m_
SVector6 vub = m.**UpperBlock**(); _// vub = [ 1, 2, 3, 5, 6, 9 ]_
SVector6 vlb = m.**LowerBlock**(); _// vlb = [ 1, 4, 5, 7, 8, 9 ]_
</pre>
### Linear Algebra Functions
Only limited linear algebra functionality is available for SMatrix. It is possible for squared matrices NxN, to find the inverse or to calculate the determinant. Different inversion algorithms are used if the matrix is smaller than 6x6 or if it is symmetric. In the case of a small matrix, a faster direct inversion is used. For a large (N > 6) symmetric matrix the Bunch-Kaufman diagonal pivoting method is used while for a large (N > 6) general matrix an LU factorization is performed using the same algorithm as in the CERNLIB routine [dinv](http://wwwasdoc.web.cern.ch/wwwasdoc/shortwrupsdir/f010/top.html).
<pre>_// Invert a NxN matrix. The inverted matrix replace the existing one and returns if the result is successful_
bool ret = m.**Invert**()
_// return the inverse matrix of m. If the inversion fails ifail is different than zero_
int ifail = 0;
mInv = m.**Inverse**(ifail);
</pre>
The determinant of a square matrix can be obtained as follows:
<pre>double det;
_// calculate the determinant modyfing the matrix content. Returns if the calculation was successful_
bool ret = m.**Det**(det);
_// calculate the determinant using a temporary matrix but preserving the matrix content_
bool ret = n.**Det2**(det);
</pre>
For additional Matrix functionality see the \ref MatVecFunctions page
*/
// SVector example of usage
/** \page SVectorDoc SVector Class Properties
The template ROOT::Math::SVector class has 2 template parameters which define, at compile time, its properties. These are:
* type of the contained elements, for example _float_ or double.
* size of the vector.
### Creating a Vector
The following constructors are available to create a vector:
* Default constructor for a zero vector (all elements equal to zero)
* Constructor (and assignment) from a vector expression, like v = p*q + w. Due to the expression template technique, no temporary objects are created in this operation.
* Construct a vector passing directly the elements. This is possible only for vector up to size 10\.
* Constructor from an iterator copying the data refered by the iterator. It is possible to specify the _begin_ and _end_ of the iterator or the _begin_ and the size. Note that for the Vector the iterator is not generic and must be of type _T*,_ where T is the type of the contained elements.
Here are some examples on how to create a vector. In the following we assume that we are using the namespace ROOT::Math.
<pre>
SVector>double,N> v; _// create a vector of size N, v[i]=0_
SVector>double,3> v(1,2,3); _// create a vector of size 3, v[0]=1,v[1]=2,v[2]=3_
double a[9] = {1,2,3,4,5,6,7,8,9}; _// input data_
SVector>double,9> v(a,9); _// create a vector using the a[] data_
</pre>
### Accessing and Setting Methods
The single vector elements can be set or retrieved using the _operator[i]_ , _operator(i)_ or the iterator interface. Notice that the index starts from zero and not from one as in FORTRAN. Also no check is performed on the passed index. Furthermore, all the matrix elements can be set also by using the ROOT::SVector::SetElements function passing a generic iterator. The elements can be accessed also by using the ROOT::Math::SVector::apply(i) function.
<pre>
v[0] = 1; _ // set the first element _
v(1) = 2; _ // set the second element _
*(v.**begin**()+3) = 3; _// set the third element_
_// set vector elements from a std::vector<double>::iterator</double>_
std::vector <double>w(3);
v.SetElements(w.begin(),w.end());
double x = m(i); _// return the i-th element_
x = m.**apply**(i); _// return the i-th element_
x = *(m.**begin**()+i); _// return the i-th element
</pre>
In addition there are methods to place a sub-vector in a vector. If the size of the the sub-vector is larger than the vector size a static assert ( a compilation error) is produced.
<pre>
SVector>double,N> v;
SVector>double,M> w; _// M <= N otherwise a compilation error is obtained later _
_// place a vector of size M starting from element ioff, v[ioff + i] = w[i]_
v.**Place_at**(w,ioff);
_// return a sub-vector of size M starting from v[ioff]: w[i] = v[ioff + i]_
w = v.Sub < SVector>double,M> > (ioff);
</pre>
For additional Vector functionality see the \ref MatVecFunctions page
*/
/** /**
Universal Non Uniform Random number generator for generating non uniform pseudo-random numbers
\defgroup Unuran Unuran \defgroup Unuran Unuran
\ingroup Math \ingroup Math
UNU.RAN, (Universal Non Uniform Random number generator for generating non uniform pseudo-random numbers) UNU.RAN, (Universal Non Uniform Random number generator for generating non uniform pseudo-random numbers)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment