6To 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:
7
8* ROOT::Math::XYZVector vector based on x,y,z coordinates (cartesian) in double precision
9* ROOT::Math::XYZVectorF vector based on x,y,z coordinates (cartesian) in float precision
10* ROOT::Math::Polar3DVector vector based on r,theta,phi coordinates (polar) in double precision
11* ROOT::Math::Polar3DVectorF vector based on r,theta,phi coordinates (polar) in float precision
12* ROOT::Math::RhoZPhiVector vector based on rho, z,phi coordinates (cylindrical) in double precision
13* ROOT::Math::RhoZPhiVectorF vector based on rho, z,phi coordinates (cylindrical) in float precision
14* ROOT::Math::RhoEtaPhiVector vector based on rho,eta,phi coordinates (cylindrical using eta instead of z) in double precision
15* ROOT::Math::RhoEtaPhiVectorF vector based on rho,eta,phi coordinates (cylindrical using eta instead of z) in float precision
16
17#### Constructors and Assignment
18
19The following declarations are available:
20
21<pre> XYZVector v1; // create an empty vector (x = 0, y = 0, z = 0)
22 XYZVector v2( 1,2,3); // create a vector with x=1, y = 2, z = 3;
23 Polar3DVector v3( 1, PI/2, PI); // create a vector with r = 1, theta = PI/2 and phi=PI
24 RhoEtaPHiVector v4( 1, 2, PI) // create a vector with rho= 1, eta = 2, phi = PI
25</pre>
26
27Note 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).
28
29In 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.
30
31<pre> XYZVector v1(1,2,3);
32 RhoEtaPhiVector r2(v1);
33 CLHEP::HepThreeVector q(1,2,3);
34 XYZVector v3(q)
35</pre>
36
37#### Coordinate Accessors
38
39All the same coordinate accessors are available through the interface of the class ROOT::Math::DisplacementVector3D. For example:
40
41<pre>v1.X(); v1.X(); v1.Z() // returns cartesian components for the cartesian vector v1
42v1.Rho(); v1.Eta(); v1.Phi() // returns cylindrical components for the cartesian vector v1
43r2.X(); r2.Y(); r2.Z() // returns cartesian components for the cylindrical vector r2
44</pre>
45
46In addition, all the 3 coordinates of the vector can be retrieved with the GetCoordinates method:
47
48<pre>double d[3];
49v1.GetCoordinates(d); // fill d array with (x,y,z) components of v1
50r2.GetCoordinates(d); // fill d array with (r,eta,phi) components of r2
51std::vector <double>vc(3);
52v1.GetCoordinates(vc.begin(),vc.end()); // fill std::vector with (x,y,z) components of v1</double> </pre>
53
54To get more information on all the coordinate accessors see the reference documentation of ROOT::Math::DisplacementVector3D.
55
56#### Setter Methods
57
58One can set only all the three coordinates via:
59
60<pre>v1.SetCoordinates(c1,c2,c3); // sets the (x,y,z) for a XYZVector
61r2.SetCoordinates(c1,c2,c3); // sets r,theta,phi for a Polar3DVector
62r2.SetXYZ(x,y,z); // sets the three cartesian components for the Polar3DVector
63</pre>
64
65Single 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.
66
67<pre>XYZVector v1; v1.SetX(1) // OK setting x for a Cartesian vector
68Polar3DVector v2; v2.SetX(1) // ERROR: cannot set X for a Polar vector. Method will not compile
69v2.SetR(1) // OK setting r for a Polar vector
70</pre>
71
72In addition there are setter methods from C arrays or iterators.
73
74<pre>double d[3] = {1.,2.,3.};
75XYZVector v;
76v.SetCoordinates(d); // set (x,y,z) components of v using values from d
77</pre>
78
79or for example from an std::vector using the iterator
80
81<pre>std::vector <double>w(3);
82v.SetCoordinates(w.begin(),w.end()); // set (x,y,z) components of v using values from w</double> </pre>
83
84#### Arithmetic Operations
85
86The 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)
87
88<pre>v1 += v2;
89v1 -= v2;
90v1 = - v2;
91v1 *= a;
92v1 /= a;
93v2 = a * v1;
94v2 = v1 / a;
95v2 = v1 * a;
96v3 = v1 + v2;
97v3 = v1 - v2;
98</pre>
99
100#### Comparison
101
102For v1 and v2 of the same type (same coordinate system and same scalar type):
103
104<pre>v1 == v2;
105v1 != v2;
106</pre>
107
108#### Dot and Cross Product
109
110We support the dot and cross products, through the Dot() and Cross() method, with any Vector (q) implementing x(), y() and z()
111
112<pre>XYZVector v1(x,y,z);
113double s = v1.Dot(q);
114XYZVector v2 = v1.Cross(q);
115</pre>
116
117Note that the multiplication between two vectors using the operator * is not supported because is ambiguous.
118
119#### Other Methods
120
121<pre>XYZVector u = v1.Unit(); // return unit vector parallel to v1