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