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