Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Polar3D.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT MathLib Team and *
7 * FNAL LCG ROOT MathLib Team *
8 * *
9 * *
10 **********************************************************************/
11
12// Header file for class Polar3D
13//
14// Created by: Lorenzo Moneta at Mon May 30 11:40:03 2005
15// Major revamp: M. Fischler at Wed Jun 8 2005
16//
17// Last update: $Id$
18//
19#ifndef ROOT_MathX_GenVectorX_Polar3D
20#define ROOT_MathX_GenVectorX_Polar3D 1
21
22#include "Math/Math.h"
23
25
27
29
30using namespace ROOT::ROOT_MATH_ARCH;
31
32#include <cmath>
33
34namespace ROOT {
35
36namespace ROOT_MATH_ARCH {
37
38//__________________________________________________________________________________________
39/**
40 Class describing a polar coordinate system based on r, theta and phi
41 Phi is restricted to be in the range [-PI,PI)
42
43 @ingroup GenVectorX
44
45 @see GenVectorX
46*/
47
48template <class T>
49class Polar3D {
50
51public:
52 typedef T Scalar;
53
54 /**
55 Default constructor with r=theta=phi=0
56 */
57 constexpr Polar3D() noexcept = default;
58
59 /**
60 Construct from the polar coordinates: r, theta and phi
61 */
62 constexpr Polar3D(T r, T theta, T phi) noexcept : fR(r), fTheta(theta), fPhi(phi) { Restrict(); }
63
64 /**
65 Construct from any Vector or coordinate system implementing
66 R(), Theta() and Phi()
67 */
68 template <class CoordSystem>
69 explicit Polar3D(const CoordSystem &v) : fR(v.R()), fTheta(v.Theta()), fPhi(v.Phi())
70 {
71 Restrict();
72 }
73
74 /**
75 Set internal data based on an array of 3 Scalar numbers
76 */
78 {
79 fR = src[0];
80 fTheta = src[1];
81 fPhi = src[2];
82 Restrict();
83 }
84
85 /**
86 get internal data into an array of 3 Scalar numbers
87 */
89 {
90 dest[0] = fR;
91 dest[1] = fTheta;
92 dest[2] = fPhi;
93 }
94
95 /**
96 Set internal data based on 3 Scalar numbers
97 */
99 {
100 fR = r;
101 fTheta = theta;
102 fPhi = phi;
103 Restrict();
104 }
105
106 /**
107 get internal data into 3 Scalar numbers
108 */
109 void GetCoordinates(Scalar &r, Scalar &theta, Scalar &phi) const
110 {
111 r = fR;
112 theta = fTheta;
113 phi = fPhi;
114 }
115
116 Scalar R() const { return fR; }
117 Scalar Phi() const { return fPhi; }
118 Scalar Theta() const { return fTheta; }
119 Scalar Rho() const { return fR * math_sin(fTheta); }
120 Scalar X() const { return Rho() * math_cos(fPhi); }
121 Scalar Y() const { return Rho() * math_sin(fPhi); }
122 Scalar Z() const { return fR * math_cos(fTheta); }
123 Scalar Mag2() const { return fR * fR; }
124 Scalar Perp2() const { return Rho() * Rho(); }
125
126 // pseudorapidity
127 Scalar Eta() const { return Impl::Eta_FromTheta(fTheta, fR); }
128
129 // setters (only for data members)
130
131 /**
132 set the r coordinate value keeping theta and phi constant
133 */
134 void SetR(const T &r) { fR = r; }
135
136 /**
137 set the theta coordinate value keeping r and phi constant
138 */
139 void SetTheta(const T &theta) { fTheta = theta; }
140
141 /**
142 set the phi coordinate value keeping r and theta constant
143 */
144 void SetPhi(const T &phi)
145 {
146 fPhi = phi;
147 Restrict();
148 }
149
150 /**
151 set all values using cartesian coordinates
152 */
153 void SetXYZ(Scalar x, Scalar y, Scalar z);
154
155private:
156 inline static Scalar pi() { return M_PI; }
157 inline void Restrict()
158 {
159 if (fPhi <= -pi() || fPhi > pi())
160 fPhi = fPhi - math_floor(fPhi / (2 * pi()) + .5) * 2 * pi();
161 }
162
163public:
164 /**
165 scale by a scalar quantity - for polar coordinates r changes
166 */
167 void Scale(T a)
168 {
169 if (a < 0) {
170 Negate();
171 a = -a;
172 }
173 // angles do not change when scaling by a positive quantity
174 fR *= a;
175 }
176
177 /**
178 negate the vector
179 */
180 void Negate()
181 {
182 fPhi = (fPhi > 0 ? fPhi - pi() : fPhi + pi());
183 fTheta = pi() - fTheta;
184 }
185
186 // assignment operators
187 /**
188 generic assignment operator from any coordinate system
189 */
190 template <class CoordSystem>
191 Polar3D &operator=(const CoordSystem &c)
192 {
193 fR = c.R();
194 fTheta = c.Theta();
195 fPhi = c.Phi();
196 return *this;
197 }
198
199 /**
200 Exact equality
201 */
202 bool operator==(const Polar3D &rhs) const { return fR == rhs.fR && fTheta == rhs.fTheta && fPhi == rhs.fPhi; }
203 bool operator!=(const Polar3D &rhs) const { return !(operator==(rhs)); }
204
205 // ============= Compatibility section ==================
206
207 // The following make this coordinate system look enough like a CLHEP
208 // vector that an assignment member template can work with either
209 T x() const { return X(); }
210 T y() const { return Y(); }
211 T z() const { return Z(); }
212
213 // ============= Specializations for improved speed ==================
214
215 // (none)
216
217#if defined(__MAKECINT__) || defined(G__DICTIONARY)
218
219 // ====== Set member functions for coordinates in other systems =======
220
221 void SetX(Scalar x);
222
223 void SetY(Scalar y);
224
225 void SetZ(Scalar z);
226
227 void SetRho(Scalar rho);
228
229 void SetEta(Scalar eta);
230
231#endif
232
233private:
234 T fR = 0;
235 T fTheta = 0;
236 T fPhi = 0;
237};
238
239} // end namespace ROOT_MATH_ARCH
240
241} // end namespace ROOT
242
243// move implementations here to avoid circle dependencies
244
246
247#if defined(__MAKECINT__) || defined(G__DICTIONARY)
250#endif
251
252namespace ROOT {
253
254namespace ROOT_MATH_ARCH {
255
256template <class T>
261
262#if defined(__MAKECINT__) || defined(G__DICTIONARY)
263#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
264// ====== Set member functions for coordinates in other systems =======
265
266template <class T>
268{
269 GenVector_exception e("Polar3D::SetX() is not supposed to be called");
270 throw e;
271 Cartesian3D<Scalar> v(*this);
272 v.SetX(xx);
273 *this = Polar3D<Scalar>(v);
274}
275template <class T>
276void Polar3D<T>::SetY(Scalar yy)
277{
278 GenVector_exception e("Polar3D::SetY() is not supposed to be called");
279 throw e;
280 Cartesian3D<Scalar> v(*this);
281 v.SetY(yy);
282 *this = Polar3D<Scalar>(v);
283}
284template <class T>
286{
287 GenVector_exception e("Polar3D::SetZ() is not supposed to be called");
288 throw e;
289 Cartesian3D<Scalar> v(*this);
290 v.SetZ(zz);
291 *this = Polar3D<Scalar>(v);
292}
293template <class T>
295{
296 GenVector_exception e("Polar3D::SetRho() is not supposed to be called");
297 throw e;
299 v.SetRho(rho);
300 *this = Polar3D<Scalar>(v);
301}
302template <class T>
304{
305 GenVector_exception e("Polar3D::SetEta() is not supposed to be called");
306 throw e;
308 v.SetEta(eta);
309 *this = Polar3D<Scalar>(v);
310}
311
312#endif
313#endif
314
315} // end namespace ROOT_MATH_ARCH
316
317} // end namespace ROOT
318
319#endif /* ROOT_MathX_GenVectorX_Polar3D */
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
#define M_PI
Definition Rotated.cxx:105
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 polar coordinate system based on r, theta and phi Phi is restricted to be in the r...
Definition Polar3D.h:49
void Scale(T a)
scale by a scalar quantity - for polar coordinates r changes
Definition Polar3D.h:167
void SetPhi(const T &phi)
set the phi coordinate value keeping r and theta constant
Definition Polar3D.h:144
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
Definition Polar3D.h:257
void SetCoordinates(Scalar r, Scalar theta, Scalar phi)
Set internal data based on 3 Scalar numbers.
Definition Polar3D.h:98
constexpr Polar3D() noexcept=default
Default constructor with r=theta=phi=0.
void GetCoordinates(Scalar &r, Scalar &theta, Scalar &phi) const
get internal data into 3 Scalar numbers
Definition Polar3D.h:109
void SetR(const T &r)
set the r coordinate value keeping theta and phi constant
Definition Polar3D.h:134
Polar3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing R(), Theta() and Phi()
Definition Polar3D.h:69
void SetTheta(const T &theta)
set the theta coordinate value keeping r and phi constant
Definition Polar3D.h:139
bool operator==(const Polar3D &rhs) const
Exact equality.
Definition Polar3D.h:202
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
Definition Polar3D.h:77
Polar3D & operator=(const CoordSystem &c)
generic assignment operator from any coordinate system
Definition Polar3D.h:191
void Negate()
negate the vector
Definition Polar3D.h:180
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
Definition Polar3D.h:88
bool operator!=(const Polar3D &rhs) const
Definition Polar3D.h:203
Scalar Eta_FromTheta(Scalar theta, Scalar r)
Implementation of eta from -log(tan(theta/2)).
Definition eta.h:81
Scalar math_floor(Scalar x)
Scalar math_cos(Scalar x)
Scalar math_sin(Scalar x)