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