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_Math_GenVector_Polar3D
20#define ROOT_Math_GenVector_Polar3D 1
21
22#include "Math/Math.h"
23
24#include "Math/GenVector/eta.h"
25
26#include <cmath>
27
28namespace ROOT {
29
30namespace Math {
31
32
33//__________________________________________________________________________________________
34 /**
35 Class describing a polar coordinate system based on r, theta and phi
36 Phi is restricted to be in the range [-PI,PI)
37
38 @ingroup GenVector
39
40 @sa Overview of the @ref GenVector "physics vector library"
41 */
42
43
44template <class T>
45class Polar3D {
46
47public :
48
49 typedef T Scalar;
50 static constexpr unsigned int Dimension = 3U;
51
52 /**
53 Default constructor with r=theta=phi=0
54 */
55 Polar3D() : fR(0), fTheta(0), fPhi(0) { }
56
57 /**
58 Construct from the polar coordinates: r, theta and phi
59 */
60 Polar3D(T r,T theta,T phi) : fR(r), fTheta(theta), fPhi(phi) { Restrict(); }
61
62 /**
63 Construct from any Vector or coordinate system implementing
64 R(), Theta() and Phi()
65 */
66 template <class CoordSystem >
67 explicit constexpr Polar3D( const CoordSystem & v ) :
68 fR(v.R() ), fTheta(v.Theta() ), fPhi(v.Phi() ) { Restrict(); }
69
70 // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
71 // re-implement them ( there is no no need to have them with g++4)
72
73 /**
74 copy constructor
75 */
76 Polar3D(const Polar3D & v) :
77 fR(v.R() ), fTheta(v.Theta() ), fPhi(v.Phi() ) { }
78
79 /**
80 assignment operator
81 */
83 fR = v.R();
84 fTheta = v.Theta();
85 fPhi = v.Phi();
86 return *this;
87 }
88
89 /**
90 Set internal data based on an array of 3 Scalar numbers
91 */
92 void SetCoordinates( const Scalar src[] )
93 { fR=src[0]; fTheta=src[1]; fPhi=src[2]; Restrict(); }
94
95 /**
96 get internal data into an array of 3 Scalar numbers
97 */
98 void GetCoordinates( Scalar dest[] ) const
99 { dest[0] = fR; dest[1] = fTheta; dest[2] = fPhi; }
100
101 /**
102 Set internal data based on 3 Scalar numbers
103 */
105 { fR=r; fTheta=theta; fPhi=phi; Restrict(); }
106
107 /**
108 get internal data into 3 Scalar numbers
109 */
110 void GetCoordinates(Scalar& r, Scalar& theta, Scalar& phi) const {r=fR; theta=fTheta; phi=fPhi;}
111
112
113 Scalar R() const { return fR;}
114 Scalar Phi() const { return fPhi; }
115 Scalar Theta() const { return fTheta; }
116 Scalar Rho() const { using std::sin; return fR * sin(fTheta); }
117 Scalar X() const { using std::cos; return Rho() * cos(fPhi); }
118 Scalar Y() const { using std::sin; return Rho() * sin(fPhi); }
119 Scalar Z() const { using std::cos; return fR * cos(fTheta); }
120 Scalar Mag2() const { return fR*fR;}
121 Scalar Perp2() const { return Rho() * Rho(); }
122
123 // pseudorapidity
124 Scalar Eta() const
125 {
127 }
128
129 // setters (only for data members)
130
131
132 /**
133 set the r coordinate value keeping theta and phi constant
134 */
135 void SetR(const T & r) {
136 fR = r;
137 }
138
139 /**
140 set the theta coordinate value keeping r and phi constant
141 */
142 void SetTheta(const T & theta) {
143 fTheta = theta;
144 }
145
146 /**
147 set the phi coordinate value keeping r and theta constant
148 */
149 void SetPhi(const T & phi) {
150 fPhi = phi;
151 Restrict();
152 }
153
154 /**
155 set all values using cartesian coordinates
156 */
157 void SetXYZ(Scalar x, Scalar y, Scalar z);
158
159
160private:
161 inline static Scalar pi() { return M_PI; }
162 inline void Restrict() {
163 using std::floor;
164 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
165 }
166
167public:
168
169 /**
170 scale by a scalar quantity - for polar coordinates r changes
171 */
172 void Scale (T a) {
173 if (a < 0) {
174 Negate();
175 a = -a;
176 }
177 // angles do not change when scaling by a positive quantity
178 fR *= a;
179 }
180
181 /**
182 negate the vector
183 */
184 void Negate ( ) {
185 fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
186 fTheta = pi() - fTheta;
187 }
188
189 // assignment operators
190 /**
191 generic assignment operator from any coordinate system
192 */
193 template <class CoordSystem >
194 Polar3D & operator= ( const CoordSystem & c ) {
195 fR = c.R();
196 fTheta = c.Theta();
197 fPhi = c.Phi();
198 return *this;
199 }
200
201 /**
202 Exact equality
203 */
204 bool operator==(const Polar3D & rhs) const {
205 return fR == rhs.fR && fTheta == rhs.fTheta && fPhi == rhs.fPhi;
206 }
207 bool operator!= (const Polar3D & rhs) const {return !(operator==(rhs));}
208
209
210 // ============= Compatibility section ==================
211
212 // The following make this coordinate system look enough like a CLHEP
213 // vector that an assignment member template can work with either
214 T x() const { return X(); }
215 T y() const { return Y(); }
216 T z() const { return Z(); }
217
218 // ============= Specializations for improved speed ==================
219
220 // (none)
221
222#if defined(__MAKECINT__) || defined(G__DICTIONARY)
223
224 // ====== Set member functions for coordinates in other systems =======
225
226 void SetX(Scalar x);
227
228 void SetY(Scalar y);
229
230 void SetZ(Scalar z);
231
232 void SetRho(Scalar rho);
233
234 void SetEta(Scalar eta);
235
236#endif
237
238private:
239 T fR;
242};
243
244
245
246 } // end namespace Math
247
248} // end namespace ROOT
249
250// move implementations here to avoid circle dependencies
251
253
254#if defined(__MAKECINT__) || defined(G__DICTIONARY)
257#endif
258
259
260namespace ROOT {
261
262 namespace Math {
263
264template <class T>
266 *this = Cartesian3D<Scalar>(xx, yy, zz);
267}
268
269#if defined(__MAKECINT__) || defined(G__DICTIONARY)
270
271 // ====== Set member functions for coordinates in other systems =======
272
273
274template <class T>
275void Polar3D<T>::SetX(Scalar xx) {
276 GenVector_exception e("Polar3D::SetX() is not supposed to be called");
277 throw e;
278 Cartesian3D<Scalar> v(*this); v.SetX(xx); *this = Polar3D<Scalar>(v);
279}
280template <class T>
281void Polar3D<T>::SetY(Scalar yy) {
282 GenVector_exception e("Polar3D::SetY() is not supposed to be called");
283 throw e;
284 Cartesian3D<Scalar> v(*this); v.SetY(yy); *this = Polar3D<Scalar>(v);
285}
286template <class T>
287void Polar3D<T>::SetZ(Scalar zz) {
288 GenVector_exception e("Polar3D::SetZ() is not supposed to be called");
289 throw e;
290 Cartesian3D<Scalar> v(*this); v.SetZ(zz); *this = Polar3D<Scalar>(v);
291}
292template <class T>
293void Polar3D<T>::SetRho(Scalar rho) {
294 GenVector_exception e("Polar3D::SetRho() is not supposed to be called");
295 throw e;
296 CylindricalEta3D<Scalar> v(*this); v.SetRho(rho);
297 *this = Polar3D<Scalar>(v);
298}
299template <class T>
300void Polar3D<T>::SetEta(Scalar eta) {
301 GenVector_exception e("Polar3D::SetEta() is not supposed to be called");
302 throw e;
303 CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
304 *this = Polar3D<Scalar>(v);
305}
306
307#endif
308
309
310 } // end namespace Math
311
312} // end namespace ROOT
313
314
315
316#endif /* ROOT_Math_GenVector_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
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
Class describing a polar coordinate system based on r, theta and phi Phi is restricted to be in the r...
Definition Polar3D.h:45
void Negate()
negate the vector
Definition Polar3D.h:184
void SetTheta(const T &theta)
set the theta coordinate value keeping r and phi constant
Definition Polar3D.h:142
Scalar X() const
Definition Polar3D.h:117
void SetCoordinates(Scalar r, Scalar theta, Scalar phi)
Set internal data based on 3 Scalar numbers.
Definition Polar3D.h:104
bool operator!=(const Polar3D &rhs) const
Definition Polar3D.h:207
Scalar Eta() const
Definition Polar3D.h:124
Polar3D()
Default constructor with r=theta=phi=0.
Definition Polar3D.h:55
void SetR(const T &r)
set the r coordinate value keeping theta and phi constant
Definition Polar3D.h:135
void SetPhi(const T &phi)
set the phi coordinate value keeping r and theta constant
Definition Polar3D.h:149
Polar3D(const Polar3D &v)
copy constructor
Definition Polar3D.h:76
void Scale(T a)
scale by a scalar quantity - for polar coordinates r changes
Definition Polar3D.h:172
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
Definition Polar3D.h:92
void GetCoordinates(Scalar &r, Scalar &theta, Scalar &phi) const
get internal data into 3 Scalar numbers
Definition Polar3D.h:110
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
Definition Polar3D.h:98
Scalar Mag2() const
Definition Polar3D.h:120
Scalar Y() const
Definition Polar3D.h:118
Polar3D & operator=(const Polar3D &v)
assignment operator
Definition Polar3D.h:82
static Scalar pi()
Definition Polar3D.h:161
constexpr Polar3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing R(), Theta() and Phi()
Definition Polar3D.h:67
static constexpr unsigned int Dimension
Definition Polar3D.h:50
bool operator==(const Polar3D &rhs) const
Exact equality.
Definition Polar3D.h:204
Scalar Z() const
Definition Polar3D.h:119
Scalar Theta() const
Definition Polar3D.h:115
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
Definition Polar3D.h:265
Scalar Perp2() const
Definition Polar3D.h:121
Scalar Rho() const
Definition Polar3D.h:116
Scalar Phi() const
Definition Polar3D.h:114
Polar3D(T r, T theta, T phi)
Construct from the polar coordinates: r, theta and phi.
Definition Polar3D.h:60
Scalar R() const
Definition Polar3D.h:113
Namespace for new Math classes and functions.
Scalar Eta_FromTheta(Scalar theta, Scalar r)
Implementation of eta from -log(tan(theta/2)).
Definition eta.h:85
Rotation3D::Scalar Scalar
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...