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