Logo ROOT   6.16/01
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
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 { return sqrt(Perp2()); }
113 Scalar R() const { return sqrt(Mag2()); }
114 Scalar Theta() const { return atan2(Rho(), Z()); }
115 Scalar Phi() const { 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 fX = rho * cos(v.Phi());
211 fY = rho * sin(v.Phi());
212 fZ = v.Z();
213 return *this;
214 }
215
216
217
218#if defined(__MAKECINT__) || defined(G__DICTIONARY)
219
220 // ====== Set member functions for coordinates in other systems =======
221
222 void SetR(Scalar r);
223
224 void SetTheta(Scalar theta);
225
226 void SetPhi(Scalar phi);
227
228 void SetRho(Scalar rho);
229
230 void SetEta(Scalar eta);
231
232#endif
233
234
235private:
236
237 T fX; // x coordinate
238 T fY; // y coordinate
239 T fZ; // z coordinate
240};
241
242
243 } // end namespace Math
244
245} // end namespace ROOT
246
247
248#if defined(__MAKECINT__) || defined(G__DICTIONARY)
249// need to put here setter methods to resolve nasty cyclical dependencies
250// I need to include other coordinate systems only when Cartesian is already defined
251// since they depend on it
255
256 // ====== Set member functions for coordinates in other systems =======
257
258namespace ROOT {
259
260 namespace Math {
261
262template <class T>
263void Cartesian3D<T>::SetR(Scalar r) {
264 GenVector_exception e("Cartesian3D::SetR() is not supposed to be called");
265 throw e;
266 Polar3D<Scalar> v(*this); v.SetR(r); *this = Cartesian3D<Scalar>(v);
267}
268
269template <class T>
270void Cartesian3D<T>::SetTheta(Scalar theta) {
271 GenVector_exception e("Cartesian3D::SetTheta() is not supposed to be called");
272 throw e;
273 Polar3D<Scalar> v(*this); v.SetTheta(theta); *this = Cartesian3D<Scalar>(v);
274}
275
276template <class T>
277void Cartesian3D<T>::SetPhi(Scalar phi) {
278 GenVector_exception e("Cartesian3D::SetPhi() is not supposed to be called");
279 throw e;
280 Polar3D<Scalar> v(*this); v.SetPhi(phi); *this = Cartesian3D<Scalar>(v);
281}
282
283template <class T>
284void Cartesian3D<T>::SetRho(Scalar rho) {
285 GenVector_exception e("Cartesian3D::SetRho() is not supposed to be called");
286 throw e;
287 CylindricalEta3D<Scalar> v(*this); v.SetRho(rho);
288 *this = Cartesian3D<Scalar>(v);
289}
290
291template <class T>
292void Cartesian3D<T>::SetEta(Scalar eta) {
293 GenVector_exception e("Cartesian3D::SetEta() is not supposed to be called");
294 throw e;
295 CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
296 *this = Cartesian3D<Scalar>(v);
297}
298
299
300
301 } // end namespace Math
302
303} // end namespace ROOT
304
305#endif
306
307
308
309
310#endif /* ROOT_Math_GenVector_Cartesian3D */
SVector< double, 2 > v
Definition: Dict.h:5
ROOT::R::TRInterface & r
Definition: Object.C:4
#define e(i)
Definition: RSha256.hxx:103
double atan2(double, double)
double cos(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
Definition: Cartesian3D.h:140
bool operator!=(const Cartesian3D &rhs) const
Definition: Cartesian3D.h:179
bool operator==(const Cartesian3D &rhs) const
Exact equality.
Definition: Cartesian3D.h:176
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)
Definition: Cartesian3D.h:193
Scalar Theta() const
Definition: Cartesian3D.h:114
void Scale(Scalar a)
scale the vector by a scalar quantity a
Definition: Cartesian3D.h:149
Cartesian3D()
Default constructor with x=y=z=0.
Definition: Cartesian3D.h:53
Scalar Eta() const
Definition: Cartesian3D.h:118
void SetCoordinates(Scalar xx, Scalar yy, Scalar zz)
Set internal data based on 3 Scalar numbers.
Definition: Cartesian3D.h:100
Scalar Perp2() const
Definition: Cartesian3D.h:111
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
Scalar Rho() const
Definition: Cartesian3D.h:112
void SetZ(Scalar zz)
set the z coordinate value keeping x and y constant
Definition: Cartesian3D.h:135
void GetCoordinates(Scalar &xx, Scalar &yy, Scalar &zz) const
get internal data into 3 Scalar numbers
Definition: Cartesian3D.h:105
void SetX(Scalar xx)
set the x coordinate value keeping y and z constant
Definition: Cartesian3D.h:125
Scalar Phi() const
Definition: Cartesian3D.h:115
void SetY(Scalar yy)
set the y coordinate value keeping x and z constant
Definition: Cartesian3D.h:130
void Negate()
negate the vector
Definition: Cartesian3D.h:159
Scalar Mag2() const
Definition: Cartesian3D.h:110
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.
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
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12
#define dest(otri, vertexptr)
Definition: triangle.c:1040