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
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 { using std::sin; return fR * sin(fTheta); }
114 Scalar X() const { using std::cos; return Rho() * cos(fPhi); }
115 Scalar Y() const { using std::sin; return Rho() * sin(fPhi); }
116 Scalar Z() const { using std::cos; 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 using std::floor;
161 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
162 }
163
164public:
165
166 /**
167 scale by a scalar quantity - for polar coordinates r changes
168 */
169 void Scale (T a) {
170 if (a < 0) {
171 Negate();
172 a = -a;
173 }
174 // angles do not change when scaling by a positive quantity
175 fR *= a;
176 }
177
178 /**
179 negate the vector
180 */
181 void Negate ( ) {
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 fR = c.R();
193 fTheta = c.Theta();
194 fPhi = c.Phi();
195 return *this;
196 }
197
198 /**
199 Exact equality
200 */
201 bool operator==(const Polar3D & rhs) const {
202 return fR == rhs.fR && fTheta == rhs.fTheta && fPhi == rhs.fPhi;
203 }
204 bool operator!= (const Polar3D & rhs) const {return !(operator==(rhs));}
205
206
207 // ============= Compatibility section ==================
208
209 // The following make this coordinate system look enough like a CLHEP
210 // vector that an assignment member template can work with either
211 T x() const { return X(); }
212 T y() const { return Y(); }
213 T z() const { return Z(); }
214
215 // ============= Specializations for improved speed ==================
216
217 // (none)
218
219#if defined(__MAKECINT__) || defined(G__DICTIONARY)
220
221 // ====== Set member functions for coordinates in other systems =======
222
223 void SetX(Scalar x);
224
225 void SetY(Scalar y);
226
227 void SetZ(Scalar z);
228
229 void SetRho(Scalar rho);
230
231 void SetEta(Scalar eta);
232
233#endif
234
235private:
236 T fR;
239};
240
241
242
243 } // end namespace Math
244
245} // end namespace ROOT
246
247// move implementations here to avoid circle dependencies
248
250
251#if defined(__MAKECINT__) || defined(G__DICTIONARY)
254#endif
255
256
257namespace ROOT {
258
259 namespace Math {
260
261template <class T>
263 *this = Cartesian3D<Scalar>(xx, yy, zz);
264}
265
266#if defined(__MAKECINT__) || defined(G__DICTIONARY)
267
268 // ====== Set member functions for coordinates in other systems =======
269
270
271template <class T>
272void Polar3D<T>::SetX(Scalar xx) {
273 GenVector_exception e("Polar3D::SetX() is not supposed to be called");
274 throw e;
275 Cartesian3D<Scalar> v(*this); v.SetX(xx); *this = Polar3D<Scalar>(v);
276}
277template <class T>
278void Polar3D<T>::SetY(Scalar yy) {
279 GenVector_exception e("Polar3D::SetY() is not supposed to be called");
280 throw e;
281 Cartesian3D<Scalar> v(*this); v.SetY(yy); *this = Polar3D<Scalar>(v);
282}
283template <class T>
284void Polar3D<T>::SetZ(Scalar zz) {
285 GenVector_exception e("Polar3D::SetZ() is not supposed to be called");
286 throw e;
287 Cartesian3D<Scalar> v(*this); v.SetZ(zz); *this = Polar3D<Scalar>(v);
288}
289template <class T>
290void Polar3D<T>::SetRho(Scalar rho) {
291 GenVector_exception e("Polar3D::SetRho() is not supposed to be called");
292 throw e;
293 CylindricalEta3D<Scalar> v(*this); v.SetRho(rho);
294 *this = Polar3D<Scalar>(v);
295}
296template <class T>
297void Polar3D<T>::SetEta(Scalar eta) {
298 GenVector_exception e("Polar3D::SetEta() is not supposed to be called");
299 throw e;
300 CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
301 *this = Polar3D<Scalar>(v);
302}
303
304#endif
305
306
307 } // end namespace Math
308
309} // end namespace ROOT
310
311
312
313#endif /* ROOT_Math_GenVector_Polar3D */
ROOT::R::TRInterface & r
Definition Object.C:4
#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
double cos(double)
double floor(double)
double sin(double)
Class describing a 3D cartesian coordinate system (x, y, z coordinates)
Definition Cartesian3D.h:44
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:181
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:204
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:169
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:201
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:262
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.
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...
#define dest(otri, vertexptr)
Definition triangle.c:1040