Logo ROOT  
Reference Guide
Cartesian3D.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id: 2fd203872f434b1e4e74933903abb3429494ea6f $
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT MathLib Team *
7 * & FNAL LCG ROOT Mathlib Team *
8 * *
9 * *
10 **********************************************************************/
11
12// Header file for class Cartesian3D
13//
14// Created by: Lorenzo Moneta at Mon May 30 11:16:56 2005
15// Major revamp: M. FIschler at Wed Jun 8 2005
16//
17// Last update: $ID: $
18//
19#ifndef ROOT_Math_GenVector_Cartesian3D
20#define ROOT_Math_GenVector_Cartesian3D 1
21
23
24#include "Math/Math.h"
25
26#include <limits>
27#include <cmath>
28
29#include "Math/GenVector/eta.h"
30
31namespace ROOT {
32
33namespace Math {
34
35//__________________________________________________________________________________________
36 /**
37 Class describing a 3D cartesian coordinate system
38 (x, y, z coordinates)
39
40 @ingroup GenVector
41
42 @sa Overview of the @ref GenVector "physics vector library"
43 */
44
45template <class T = double>
47
48public :
49
50 typedef T Scalar;
51
52 /**
53 Default constructor with x=y=z=0
54 */
55 Cartesian3D() : fX(0.0), fY(0.0), fZ(0.0) { }
56
57 /**
58 Constructor from x,y,z coordinates
59 */
60 Cartesian3D(Scalar xx, Scalar yy, Scalar zz) : fX(xx), fY(yy), fZ(zz) { }
61
62 /**
63 Construct from any Vector or coordinate system implementing
64 X(), Y() and Z()
65 */
66 template <class CoordSystem>
67 explicit Cartesian3D(const CoordSystem & v)
68 : fX(v.X()), fY(v.Y()), fZ(v.Z()) { }
69
70 // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
71 // re-implement them ( there is no no need to have them with g++4)
72 /**
73 copy constructor
74 */
76 fX(v.X()), fY(v.Y()), fZ(v.Z()) { }
77
78 /**
79 assignment operator
80 */
82 fX = v.x();
83 fY = v.y();
84 fZ = v.z();
85 return *this;
86 }
87
88 /**
89 Set internal data based on an array of 3 Scalar numbers
90 */
91 void SetCoordinates( const Scalar src[] ) { fX=src[0]; fY=src[1]; fZ=src[2]; }
92
93 /**
94 get internal data into an array of 3 Scalar numbers
95 */
96 void GetCoordinates( Scalar dest[] ) const
97 { dest[0] = fX; dest[1] = fY; dest[2] = fZ; }
98
99 /**
100 Set internal data based on 3 Scalar numbers
101 */
102 void SetCoordinates(Scalar xx, Scalar yy, Scalar zz) { fX=xx; fY=yy; fZ=zz; }
103
104 /**
105 get internal data into 3 Scalar numbers
106 */
107 void GetCoordinates(Scalar& xx, Scalar& yy, Scalar& zz) const {xx=fX; yy=fY; zz=fZ;}
108
109 Scalar X() const { return fX;}
110 Scalar Y() const { return fY;}
111 Scalar Z() const { return fZ;}
112 Scalar Mag2() const { return fX*fX + fY*fY + fZ*fZ;}
113 Scalar Perp2() const { return fX*fX + fY*fY ;}
114 Scalar Rho() const { using std::sqrt; return sqrt(Perp2()); }
115 Scalar R() const { using std::sqrt; return sqrt(Mag2()); }
116 Scalar Theta() const { using std::atan2; return atan2(Rho(), Z()); }
117 Scalar Phi() const { using std::atan2; return atan2(fY, fX); }
118
119 // pseudorapidity
120 Scalar Eta() const {
121 return Impl::Eta_FromRhoZ( Rho(), fZ );
122 }
123
124 /**
125 set the x coordinate value keeping y and z constant
126 */
127 void SetX(Scalar xx) { fX = xx; }
128
129 /**
130 set the y coordinate value keeping x and z constant
131 */
132 void SetY(Scalar yy) { fY = yy; }
133
134 /**
135 set the z coordinate value keeping x and y constant
136 */
137 void SetZ(Scalar zz) { fZ = zz; }
138
139 /**
140 set all values using cartesian coordinates
141 */
142 void SetXYZ(Scalar xx, Scalar yy, Scalar zz) {
143 fX=xx;
144 fY=yy;
145 fZ=zz;
146 }
147
148 /**
149 scale the vector by a scalar quantity a
150 */
152 {
153 fX *= a;
154 fY *= a;
155 fZ *= a;
156 }
157
158 /**
159 negate the vector
160 */
161 void Negate() { fX = -fX; fY = -fY; fZ = -fZ; }
162
163 /**
164 Assignment from any class implementing x(),y() and z()
165 (can assign from any coordinate system)
166 */
167 template <class CoordSystem>
168 Cartesian3D & operator = (const CoordSystem & v) {
169 fX = v.x();
170 fY = v.y();
171 fZ = v.z();
172 return *this;
173 }
174
175 /**
176 Exact equality
177 */
178 bool operator == (const Cartesian3D & rhs) const {
179 return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ;
180 }
181 bool operator != (const Cartesian3D & rhs) const {return !(operator==(rhs));}
182
183
184 // ============= Compatibility section ==================
185
186 // The following make this coordinate system look enough like a CLHEP
187 // vector that an assignment member template can work with either
188 T x() const { return X();}
189 T y() const { return Y();}
190 T z() const { return Z(); }
191
192 // ============= Overloads for improved speed ==================
193
194 template <class T2>
195 explicit Cartesian3D( const Polar3D<T2> & v ) : fZ (v.Z())
196 {
197 const T rho = v.Rho();
198 // re-using this instead of calling v.X() and v.Y()
199 // is the speed improvement
200 fX = rho * std::cos(v.Phi());
201 fY = rho * std::sin(v.Phi());
202 }
203 // Technical note: This works even though only Polar3Dfwd.h is
204 // included (and in fact, including Polar3D.h would cause circularity
205 // problems). It works because any program **using** this ctor must itself
206 // be including Polar3D.h.
207
208 template <class T2>
210 {
211 const T rho = v.Rho();
212 using std::cos;
213 fX = rho * cos(v.Phi());
214 using std::sin;
215 fY = rho * sin(v.Phi());
216 fZ = v.Z();
217 return *this;
218 }
219
220
221
222#if defined(__MAKECINT__) || defined(G__DICTIONARY)
223
224 // ====== Set member functions for coordinates in other systems =======
225
226 void SetR(Scalar r);
227
228 void SetTheta(Scalar theta);
229
230 void SetPhi(Scalar phi);
231
232 void SetRho(Scalar rho);
233
234 void SetEta(Scalar eta);
235
236#endif
237
238
239private:
240
241 T fX; // x coordinate
242 T fY; // y coordinate
243 T fZ; // z coordinate
244};
245
246
247 } // end namespace Math
248
249} // end namespace ROOT
250
251
252#if defined(__MAKECINT__) || defined(G__DICTIONARY)
253// need to put here setter methods to resolve nasty cyclical dependencies
254// I need to include other coordinate systems only when Cartesian is already defined
255// since they depend on it
259
260 // ====== Set member functions for coordinates in other systems =======
261
262namespace ROOT {
263
264 namespace Math {
265
266template <class T>
267void Cartesian3D<T>::SetR(Scalar r) {
268 GenVector_exception e("Cartesian3D::SetR() is not supposed to be called");
269 throw e;
270 Polar3D<Scalar> v(*this); v.SetR(r); *this = Cartesian3D<Scalar>(v);
271}
272
273template <class T>
274void Cartesian3D<T>::SetTheta(Scalar theta) {
275 GenVector_exception e("Cartesian3D::SetTheta() is not supposed to be called");
276 throw e;
277 Polar3D<Scalar> v(*this); v.SetTheta(theta); *this = Cartesian3D<Scalar>(v);
278}
279
280template <class T>
281void Cartesian3D<T>::SetPhi(Scalar phi) {
282 GenVector_exception e("Cartesian3D::SetPhi() is not supposed to be called");
283 throw e;
284 Polar3D<Scalar> v(*this); v.SetPhi(phi); *this = Cartesian3D<Scalar>(v);
285}
286
287template <class T>
288void Cartesian3D<T>::SetRho(Scalar rho) {
289 GenVector_exception e("Cartesian3D::SetRho() is not supposed to be called");
290 throw e;
291 CylindricalEta3D<Scalar> v(*this); v.SetRho(rho);
292 *this = Cartesian3D<Scalar>(v);
293}
294
295template <class T>
296void Cartesian3D<T>::SetEta(Scalar eta) {
297 GenVector_exception e("Cartesian3D::SetEta() is not supposed to be called");
298 throw e;
299 CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
300 *this = Cartesian3D<Scalar>(v);
301}
302
303
304
305 } // end namespace Math
306
307} // end namespace ROOT
308
309#endif
310
311
312
313
314#endif /* ROOT_Math_GenVector_Cartesian3D */
ROOT::R::TRInterface & r
Definition: Object.C:4
#define e(i)
Definition: RSha256.hxx:103
Class describing a 3D cartesian coordinate system (x, y, z coordinates)
Definition: Cartesian3D.h:46
void SetXYZ(Scalar xx, Scalar yy, Scalar zz)
set all values using cartesian coordinates
Definition: Cartesian3D.h:142
bool operator!=(const Cartesian3D &rhs) const
Definition: Cartesian3D.h:181
bool operator==(const Cartesian3D &rhs) const
Exact equality.
Definition: Cartesian3D.h:178
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
Definition: Cartesian3D.h:91
Cartesian3D(const Cartesian3D &v)
copy constructor
Definition: Cartesian3D.h:75
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
Definition: Cartesian3D.h:96
Cartesian3D & operator=(const Cartesian3D &v)
assignment operator
Definition: Cartesian3D.h:81
Cartesian3D(const Polar3D< T2 > &v)
Definition: Cartesian3D.h:195
Scalar Theta() const
Definition: Cartesian3D.h:116
void Scale(Scalar a)
scale the vector by a scalar quantity a
Definition: Cartesian3D.h:151
Cartesian3D()
Default constructor with x=y=z=0.
Definition: Cartesian3D.h:55
Scalar Eta() const
Definition: Cartesian3D.h:120
void SetCoordinates(Scalar xx, Scalar yy, Scalar zz)
Set internal data based on 3 Scalar numbers.
Definition: Cartesian3D.h:102
Scalar Perp2() const
Definition: Cartesian3D.h:113
Cartesian3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing X(), Y() and Z()
Definition: Cartesian3D.h:67
Cartesian3D(Scalar xx, Scalar yy, Scalar zz)
Constructor from x,y,z coordinates.
Definition: Cartesian3D.h:60
Scalar Rho() const
Definition: Cartesian3D.h:114
void SetZ(Scalar zz)
set the z coordinate value keeping x and y constant
Definition: Cartesian3D.h:137
void GetCoordinates(Scalar &xx, Scalar &yy, Scalar &zz) const
get internal data into 3 Scalar numbers
Definition: Cartesian3D.h:107
void SetX(Scalar xx)
set the x coordinate value keeping y and z constant
Definition: Cartesian3D.h:127
Scalar Phi() const
Definition: Cartesian3D.h:117
void SetY(Scalar yy)
set the y coordinate value keeping x and z constant
Definition: Cartesian3D.h:132
void Negate()
negate the vector
Definition: Cartesian3D.h:161
Scalar Mag2() const
Definition: Cartesian3D.h:112
Class describing a polar coordinate system based on r, theta and phi Phi is restricted to be in the r...
Definition: Polar3D.h:45
Namespace for new Math classes and functions.
double T(double x)
Definition: ChebyshevPol.h:34
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition: eta.h:48
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Rotation3D::Scalar Scalar
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
auto * a
Definition: textangle.C:12
#define dest(otri, vertexptr)
Definition: triangle.c:1041