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_MathX_GenVectorX_Cartesian3D
20#define ROOT_MathX_GenVectorX_Cartesian3D 1
21
23
24#include "Math/Math.h"
25
27
29
31
32using namespace ROOT::ROOT_MATH_ARCH;
33
34#include <limits>
35#include <cmath>
36
37namespace ROOT {
38
39namespace ROOT_MATH_ARCH {
40
41//__________________________________________________________________________________________
42/**
43 Class describing a 3D cartesian coordinate system
44 (x, y, z coordinates)
45
46 @ingroup GenVectorX
47
48 @see GenVectorX
49*/
50
51template <class T = double>
53
54public:
55 typedef T Scalar;
56
57 /**
58 Default constructor with x=y=z=0
59 */
61
62 /**
63 Constructor from x,y,z coordinates
64 */
66
67 /**
68 Construct from any Vector or coordinate system implementing
69 X(), Y() and Z()
70 */
71 template <class CoordSystem>
72 explicit constexpr Cartesian3D(const CoordSystem &v) : fX(v.X()), fY(v.Y()), fZ(v.Z())
73 {
74 }
75
76 /**
77 Set internal data based on an array of 3 Scalar numbers
78 */
80 {
81 fX = src[0];
82 fY = src[1];
83 fZ = src[2];
84 }
85
86 /**
87 get internal data into an array of 3 Scalar numbers
88 */
90 {
91 dest[0] = fX;
92 dest[1] = fY;
93 dest[2] = fZ;
94 }
95
96 /**
97 Set internal data based on 3 Scalar numbers
98 */
100 {
101 fX = xx;
102 fY = yy;
103 fZ = zz;
104 }
105
106 /**
107 get internal data into 3 Scalar numbers
108 */
110 {
111 xx = fX;
112 yy = fY;
113 zz = fZ;
114 }
115
116 Scalar X() const { return fX; }
117 Scalar Y() const { return fY; }
118 Scalar Z() const { return fZ; }
119 Scalar Mag2() const { return fX * fX + fY * fY + fZ * fZ; }
120 Scalar Perp2() const { return fX * fX + fY * fY; }
121 Scalar Rho() const { return math_sqrt(Perp2()); }
122 Scalar R() const { return math_sqrt(Mag2()); }
123 Scalar Theta() const { return math_atan2(Rho(), Z()); }
124 Scalar Phi() const { return math_atan2(fY, fX); }
125
126 // pseudorapidity
127 Scalar Eta() const { return Impl::Eta_FromRhoZ(Rho(), fZ); }
128
129 /**
130 set the x coordinate value keeping y and z constant
131 */
132 void SetX(Scalar xx) { fX = xx; }
133
134 /**
135 set the y coordinate value keeping x and z constant
136 */
137 void SetY(Scalar yy) { fY = yy; }
138
139 /**
140 set the z coordinate value keeping x and y constant
141 */
142 void SetZ(Scalar zz) { fZ = zz; }
143
144 /**
145 set all values using cartesian coordinates
146 */
148 {
149 fX = xx;
150 fY = yy;
151 fZ = zz;
152 }
153
154 /**
155 scale the vector by a scalar quantity a
156 */
158 {
159 fX *= a;
160 fY *= a;
161 fZ *= a;
162 }
163
164 /**
165 negate the vector
166 */
167 void Negate()
168 {
169 fX = -fX;
170 fY = -fY;
171 fZ = -fZ;
172 }
173
174 /**
175 Assignment from any class implementing x(),y() and z()
176 (can assign from any coordinate system)
177 */
178 template <class CoordSystem>
179 Cartesian3D &operator=(const CoordSystem &v)
180 {
181 fX = v.x();
182 fY = v.y();
183 fZ = v.z();
184 return *this;
185 }
186
187 /**
188 Exact equality
189 */
190 bool operator==(const Cartesian3D &rhs) const { return fX == rhs.fX && fY == rhs.fY && fZ == rhs.fZ; }
191 bool operator!=(const Cartesian3D &rhs) const { return !(operator==(rhs)); }
192
193 // ============= Compatibility section ==================
194
195 // The following make this coordinate system look enough like a CLHEP
196 // vector that an assignment member template can work with either
197 T x() const { return X(); }
198 T y() const { return Y(); }
199 T z() const { return Z(); }
200
201 // ============= Overloads for improved speed ==================
202
203 template <class T2>
204 explicit Cartesian3D(const Polar3D<T2> &v) : fZ(v.Z())
205 {
206 const T rho = v.Rho();
207 // re-using this instead of calling v.X() and v.Y()
208 // is the speed improvement
209 fX = rho * math_cos(v.Phi());
210 fY = rho * math_sin(v.Phi());
211 }
212 // Technical note: This works even though only Polar3Dfwd.h is
213 // included (and in fact, including Polar3D.h would cause circularity
214 // problems). It works because any program **using** this ctor must itself
215 // be including Polar3D.h.
216
217 template <class T2>
219 {
220 const T rho = v.Rho();
221 fX = rho * math_cos(v.Phi());
222 fY = rho * math_sin(v.Phi());
223 fZ = v.Z();
224 return *this;
225 }
226
227#if defined(__MAKECINT__) || defined(G__DICTIONARY)
228
229 // ====== Set member functions for coordinates in other systems =======
230
231 void SetR(Scalar r);
232
233 void SetTheta(Scalar theta);
234
235 void SetPhi(Scalar phi);
236
237 void SetRho(Scalar rho);
238
239 void SetEta(Scalar eta);
240
241#endif
242
243private:
244 T fX = 0; // x coordinate
245 T fY = 0; // y coordinate
246 T fZ = 0; // z coordinate
247};
248
249} // end namespace ROOT_MATH_ARCH
250
251} // end namespace ROOT
252
253#if defined(__MAKECINT__) || defined(G__DICTIONARY)
254#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
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
266namespace ROOT_MATH_ARCH {
267
268template <class T>
270{
271 GenVector_exception e("Cartesian3D::SetR() is not supposed to be called");
272 throw e;
273 Polar3D<Scalar> v(*this);
274 v.SetR(r);
275 *this = Cartesian3D<Scalar>(v);
276}
277
278template <class T>
280{
281 GenVector_exception e("Cartesian3D::SetTheta() is not supposed to be called");
282 throw e;
283 Polar3D<Scalar> v(*this);
284 v.SetTheta(theta);
285 *this = Cartesian3D<Scalar>(v);
286}
287
288template <class T>
290{
291 GenVector_exception e("Cartesian3D::SetPhi() is not supposed to be called");
292 throw e;
293 Polar3D<Scalar> v(*this);
294 v.SetPhi(phi);
295 *this = Cartesian3D<Scalar>(v);
296}
297
298template <class T>
300{
301 GenVector_exception e("Cartesian3D::SetRho() is not supposed to be called");
302 throw e;
304 v.SetRho(rho);
305 *this = Cartesian3D<Scalar>(v);
306}
307
308template <class T>
310{
311 GenVector_exception e("Cartesian3D::SetEta() is not supposed to be called");
312 throw e;
314 v.SetEta(eta);
315 *this = Cartesian3D<Scalar>(v);
316}
317
318} // end namespace ROOT_MATH_ARCH
319
320} // end namespace ROOT
321
322#endif
323#endif
324
325#endif /* ROOT_MathX_GenVectorX_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:52
void Negate()
negate the vector
void GetCoordinates(Scalar &xx, Scalar &yy, Scalar &zz) const
get internal data into 3 Scalar numbers
constexpr Cartesian3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing X(), Y() and Z()
Definition Cartesian3D.h:72
void SetY(Scalar yy)
set the y coordinate value keeping x and z constant
bool operator==(const Cartesian3D &rhs) const
Exact equality.
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
Definition Cartesian3D.h:89
Cartesian3D & operator=(const Polar3D< T2 > &v)
void SetXYZ(Scalar xx, Scalar yy, Scalar zz)
set all values using cartesian coordinates
void SetX(Scalar xx)
set the x coordinate value keeping y and z constant
bool operator!=(const Cartesian3D &rhs) const
Cartesian3D & operator=(const CoordSystem &v)
Assignment from any class implementing x(),y() and z() (can assign from any coordinate system)
Cartesian3D(const Polar3D< T2 > &v)
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
Definition Cartesian3D.h:79
constexpr Cartesian3D() noexcept=default
Default constructor with x=y=z=0.
void SetZ(Scalar zz)
set the z coordinate value keeping x and y constant
void Scale(Scalar a)
scale the vector by a scalar quantity a
void SetCoordinates(Scalar xx, Scalar yy, Scalar zz)
Set internal data based on 3 Scalar numbers.
Definition Cartesian3D.h:99
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition eta.h:50
Scalar math_cos(Scalar x)
Scalar math_sqrt(Scalar x)
Scalar math_atan2(Scalar x, Scalar y)
Scalar math_sin(Scalar x)