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