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