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 @see GenVector
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 */
58
59 /**
60 Constructor from x,y,z coordinates
61 */
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 /**
73 Set internal data based on an array of 3 Scalar numbers
74 */
75 void SetCoordinates( const Scalar src[] ) { fX=src[0]; fY=src[1]; fZ=src[2]; }
76
77 /**
78 get internal data into an array of 3 Scalar numbers
79 */
80 void GetCoordinates( Scalar dest[] ) const
81 { dest[0] = fX; dest[1] = fY; dest[2] = fZ; }
82
83 /**
84 Set internal data based on 3 Scalar numbers
85 */
87
88 /**
89 get internal data into 3 Scalar numbers
90 */
92
93 Scalar X() const { return fX;}
94 Scalar Y() const { return fY;}
95 Scalar Z() const { return fZ;}
96 Scalar Mag2() const { return fX*fX + fY*fY + fZ*fZ;}
97 Scalar Perp2() const { return fX*fX + fY*fY ;}
98 Scalar Rho() const { using std::sqrt; return sqrt(Perp2()); }
99 Scalar R() const { using std::sqrt; return sqrt(Mag2()); }
100 Scalar Theta() const { using std::atan2; return atan2(Rho(), Z()); }
101 Scalar Phi() const { using std::atan2; return atan2(fY, fX); }
102
103 // pseudorapidity
104 Scalar Eta() const {
105 return Impl::Eta_FromRhoZ( Rho(), fZ );
106 }
107
108 /**
109 set the x coordinate value keeping y and z constant
110 */
111 void SetX(Scalar xx) { fX = xx; }
112
113 /**
114 set the y coordinate value keeping x and z constant
115 */
116 void SetY(Scalar yy) { fY = yy; }
117
118 /**
119 set the z coordinate value keeping x and y constant
120 */
121 void SetZ(Scalar zz) { fZ = zz; }
122
123 /**
124 set all values using cartesian coordinates
125 */
127 fX=xx;
128 fY=yy;
129 fZ=zz;
130 }
131
132 /**
133 scale the vector by a scalar quantity a
134 */
136 {
137 fX *= a;
138 fY *= a;
139 fZ *= a;
140 }
141
142 /**
143 negate the vector
144 */
145 void Negate() { fX = -fX; fY = -fY; fZ = -fZ; }
146
147 /**
148 Assignment from any class implementing x(),y() and z()
149 (can assign from any coordinate system)
150 */
151 template <class CoordSystem>
152 Cartesian3D & operator = (const CoordSystem & v) {
153 fX = v.x();
154 fY = v.y();
155 fZ = v.z();
156 return *this;
157 }
158
159 /**
160 Exact equality
161 */
162 bool operator == (const Cartesian3D & rhs) const {
163 return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ;
164 }
165 bool operator != (const Cartesian3D & rhs) const {return !(operator==(rhs));}
166
167
168 // ============= Compatibility section ==================
169
170 // The following make this coordinate system look enough like a CLHEP
171 // vector that an assignment member template can work with either
172 T x() const { return X();}
173 T y() const { return Y();}
174 T z() const { return Z(); }
175
176 // ============= Overloads for improved speed ==================
177
178 template <class T2>
179 explicit constexpr Cartesian3D( const Polar3D<T2> & v ) : fZ (v.Z())
180 {
181 const T rho = v.Rho();
182 // re-using this instead of calling v.X() and v.Y()
183 // is the speed improvement
184 fX = rho * std::cos(v.Phi());
185 fY = rho * std::sin(v.Phi());
186 }
187 // Technical note: This works even though only Polar3Dfwd.h is
188 // included (and in fact, including Polar3D.h would cause circularity
189 // problems). It works because any program **using** this ctor must itself
190 // be including Polar3D.h.
191
192 template <class T2>
194 {
195 const T rho = v.Rho();
196 using std::cos;
197 fX = rho * cos(v.Phi());
198 using std::sin;
199 fY = rho * sin(v.Phi());
200 fZ = v.Z();
201 return *this;
202 }
203
204
205
206#if defined(__MAKECINT__) || defined(G__DICTIONARY)
207
208 // ====== Set member functions for coordinates in other systems =======
209
210 void SetR(Scalar r);
211
212 void SetTheta(Scalar theta);
213
214 void SetPhi(Scalar phi);
215
216 void SetRho(Scalar rho);
217
218 void SetEta(Scalar eta);
219
220#endif
221
222
223private:
224 T fX = 0; // x coordinate
225 T fY = 0; // y coordinate
226 T fZ = 0; // z coordinate
227};
228
229
230 } // end namespace Math
231
232} // end namespace ROOT
233
234
235#if defined(__MAKECINT__) || defined(G__DICTIONARY)
236// need to put here setter methods to resolve nasty cyclical dependencies
237// I need to include other coordinate systems only when Cartesian is already defined
238// since they depend on it
242
243 // ====== Set member functions for coordinates in other systems =======
244
245namespace ROOT {
246
247 namespace Math {
248
249template <class T>
250void Cartesian3D<T>::SetR(Scalar r) {
251 GenVector_exception e("Cartesian3D::SetR() is not supposed to be called");
252 throw e;
253 Polar3D<Scalar> v(*this); v.SetR(r); *this = Cartesian3D<Scalar>(v);
254}
255
256template <class T>
257void Cartesian3D<T>::SetTheta(Scalar theta) {
258 GenVector_exception e("Cartesian3D::SetTheta() is not supposed to be called");
259 throw e;
260 Polar3D<Scalar> v(*this); v.SetTheta(theta); *this = Cartesian3D<Scalar>(v);
261}
262
263template <class T>
264void Cartesian3D<T>::SetPhi(Scalar phi) {
265 GenVector_exception e("Cartesian3D::SetPhi() is not supposed to be called");
266 throw e;
267 Polar3D<Scalar> v(*this); v.SetPhi(phi); *this = Cartesian3D<Scalar>(v);
268}
269
270template <class T>
271void Cartesian3D<T>::SetRho(Scalar rho) {
272 GenVector_exception e("Cartesian3D::SetRho() is not supposed to be called");
273 throw e;
274 CylindricalEta3D<Scalar> v(*this); v.SetRho(rho);
275 *this = Cartesian3D<Scalar>(v);
276}
277
278template <class T>
279void Cartesian3D<T>::SetEta(Scalar eta) {
280 GenVector_exception e("Cartesian3D::SetEta() is not supposed to be called");
281 throw e;
282 CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
283 *this = Cartesian3D<Scalar>(v);
284}
285
286
287
288 } // end namespace Math
289
290} // end namespace ROOT
291
292#endif
293
294
295
296
297#endif /* ROOT_Math_GenVector_Cartesian3D */
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
#define X(type, name)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
Cartesian3D & operator=(const CoordSystem &v)
Assignment from any class implementing x(),y() and z() (can assign from any coordinate system)
constexpr Cartesian3D() noexcept=default
Default constructor with x=y=z=0.
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:75
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
Definition Cartesian3D.h:80
void Scale(Scalar a)
scale the vector by a scalar quantity a
constexpr Cartesian3D(const Polar3D< T2 > &v)
void SetCoordinates(Scalar xx, Scalar yy, Scalar zz)
Set internal data based on 3 Scalar numbers.
Definition Cartesian3D.h:86
Scalar Perp2() const
Definition Cartesian3D.h:97
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
Definition Cartesian3D.h:91
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
Scalar Mag2() const
Definition Cartesian3D.h:96
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...