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