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