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_MathX_GenVectorX_Cylindrical3D
17#define ROOT_MathX_GenVectorX_Cylindrical3D 1
18
19#include "Math/Math.h"
20
22
24
26
27using namespace ROOT::ROOT_MATH_ARCH;
28
29#include <limits>
30#include <cmath>
31
32namespace ROOT {
33
34namespace ROOT_MATH_ARCH {
35
36//__________________________________________________________________________________________
37/**
38 Class describing a cylindrical coordinate system based on rho, z and phi.
39 The base coordinates are rho (transverse component) , z and phi
40 Phi is restricted to be in the range [-PI,PI)
41
42 @ingroup GenVectorX
43
44 @see GenVectorX
45*/
46
47template <class T>
49
50public:
51 typedef T Scalar;
52
53 /**
54 Default constructor with rho=z=phi=0
55 */
57
58 /**
59 Construct from rho eta and phi values
60 */
62
63 /**
64 Construct from any Vector or coordinate system implementing
65 Rho(), Z() and Phi()
66 */
67 template <class CoordSystem>
68 explicit constexpr Cylindrical3D(const CoordSystem &v) : fRho(v.Rho()), fZ(v.Z()), fPhi(v.Phi())
69 {
70 Restrict();
71 }
72
73 /**
74 Set internal data based on an array of 3 Scalar numbers ( rho, z , phi)
75 */
77 {
78 fRho = src[0];
79 fZ = src[1];
80 fPhi = src[2];
81 Restrict();
82 }
83
84 /**
85 get internal data into an array of 3 Scalar numbers ( rho, z , phi)
86 */
88 {
89 dest[0] = fRho;
90 dest[1] = fZ;
91 dest[2] = fPhi;
92 }
93
94 /**
95 Set internal data based on 3 Scalar numbers ( rho, z , phi)
96 */
98 {
99 fRho = rho;
100 fZ = zz;
101 fPhi = phi;
102 Restrict();
103 }
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 {
110 rho = fRho;
111 zz = fZ;
112 phi = fPhi;
113 }
114
115private:
116 inline static Scalar pi() { return Scalar(M_PI); }
117 inline void Restrict()
118 {
119 if (fPhi <= -pi() || fPhi > pi())
120 fPhi = fPhi - math_floor(fPhi / (2 * pi()) + .5) * 2 * pi();
121 }
122
123public:
124 // accessors
125
126 Scalar Rho() const { return fRho; }
127 Scalar Z() const { return fZ; }
128 Scalar Phi() const { return fPhi; }
129 Scalar X() const { return fRho * math_cos(fPhi); }
130 Scalar Y() const { return fRho * math_sin(fPhi); }
131
132 Scalar Mag2() const { return fRho * fRho + fZ * fZ; }
133 Scalar R() const { return math_sqrt(Mag2()); }
134 Scalar Perp2() const { return fRho * fRho; }
135 Scalar Theta() const { return (fRho == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : math_atan2(fRho, fZ); }
136
137 // pseudorapidity - use same implementation as in Cartesian3D
138 Scalar Eta() const { return Impl::Eta_FromRhoZ(fRho, fZ); }
139
140 // setters (only for data members)
141
142 /**
143 set the rho coordinate value keeping z and phi constant
144 */
145 void SetRho(T rho) { fRho = rho; }
146
147 /**
148 set the z coordinate value keeping rho and phi constant
149 */
150 void SetZ(T zz) { fZ = zz; }
151
152 /**
153 set the phi coordinate value keeping rho and z constant
154 */
155 void SetPhi(T phi)
156 {
157 fPhi = phi;
158 Restrict();
159 }
160
161 /**
162 set all values using cartesian coordinates
163 */
164 void SetXYZ(Scalar x, Scalar y, Scalar z);
165
166 /**
167 scale by a scalar quantity a --
168 for cylindrical coords only rho and z change
169 */
170 void Scale(T a)
171 {
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 {
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 {
196 fRho = c.Rho();
197 fZ = c.Z();
198 fPhi = c.Phi();
199 return *this;
200 }
201
202 /**
203 Exact component-by-component equality
204 */
205 bool operator==(const Cylindrical3D &rhs) const { return fRho == rhs.fRho && fZ == rhs.fZ && fPhi == rhs.fPhi; }
206 bool operator!=(const Cylindrical3D &rhs) const { return !(operator==(rhs)); }
207
208 // ============= Compatibility section ==================
209
210 // The following make this coordinate system look enough like a CLHEP
211 // vector that an assignment member template can work with either
212 T x() const { return X(); }
213 T y() const { return Y(); }
214 T z() const { return Z(); }
215
216 // ============= Specializations for improved speed ==================
217
218 // (none)
219
220#if defined(__MAKECINT__) || defined(G__DICTIONARY)
221
222 // ====== Set member functions for coordinates in other systems =======
223
224 void SetX(Scalar x);
225
226 void SetY(Scalar y);
227
228 void SetEta(Scalar eta);
229
230 void SetR(Scalar r);
231
232 void SetTheta(Scalar theta);
233
234#endif
235
236private:
237 T fRho = 0;
238 T fZ = 0;
239 T fPhi = 0;
240};
241
242} // end namespace ROOT_MATH_ARCH
243
244} // end namespace ROOT
245
246// move implementations here to avoid circle dependencies
247
249
250#if defined(__MAKECINT__) || defined(G__DICTIONARY)
254#endif
255
256namespace ROOT {
257
258namespace ROOT_MATH_ARCH {
259
260template <class T>
265
266#if defined(__MAKECINT__) || defined(G__DICTIONARY)
267#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
268
269// ====== Set member functions for coordinates in other systems =======
270
271template <class T>
273{
274 GenVector_exception e("Cylindrical3D::SetX() is not supposed to be called");
275 throw e;
276 Cartesian3D<Scalar> v(*this);
277 v.SetX(xx);
278 *this = Cylindrical3D<Scalar>(v);
279}
280template <class T>
281void Cylindrical3D<T>::SetY(Scalar yy)
282{
283 GenVector_exception e("Cylindrical3D::SetY() is not supposed to be called");
284 throw e;
285 Cartesian3D<Scalar> v(*this);
286 v.SetY(yy);
287 *this = Cylindrical3D<Scalar>(v);
288}
289template <class T>
291{
292 GenVector_exception e("Cylindrical3D::SetR() is not supposed to be called");
293 throw e;
294 Polar3D<Scalar> v(*this);
295 v.SetR(r);
296 *this = Cylindrical3D<Scalar>(v);
297}
298template <class T>
300{
301 GenVector_exception e("Cylindrical3D::SetTheta() is not supposed to be called");
302 throw e;
303 Polar3D<Scalar> v(*this);
304 v.SetTheta(theta);
305 *this = Cylindrical3D<Scalar>(v);
306}
307template <class T>
309{
310 GenVector_exception e("Cylindrical3D::SetEta() is not supposed to be called");
311 throw e;
313 v.SetEta(eta);
314 *this = Cylindrical3D<Scalar>(v);
315}
316
317#endif
318#endif
319
320} // end namespace ROOT_MATH_ARCH
321
322} // end namespace ROOT
323
324#endif /* ROOT_MathX_GenVectorX_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
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.
constexpr Cylindrical3D() noexcept=default
Default constructor with rho=z=phi=0.
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers ( rho, z , phi)
void SetPhi(T phi)
set the phi coordinate value keeping rho and z constant
void GetCoordinates(Scalar &rho, Scalar &zz, Scalar &phi) const
get internal data into 3 Scalar numbers ( rho, z , phi)
void SetRho(T rho)
set the rho coordinate value keeping z and phi constant
bool operator!=(const Cylindrical3D &rhs) const
Cylindrical3D & operator=(const CoordSystem &c)
generic assignment operator from any coordinate system implementing Rho(), Z() and Phi()
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers ( rho, z , phi)
void Scale(T a)
scale by a scalar quantity a – for cylindrical coords only rho and z change
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
void SetCoordinates(Scalar rho, Scalar zz, Scalar phi)
Set internal data based on 3 Scalar numbers ( rho, z , phi)
constexpr Cylindrical3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing Rho(), Z() and Phi()
void SetZ(T zz)
set the z coordinate value keeping rho and phi constant
bool operator==(const Cylindrical3D &rhs) const
Exact component-by-component equality.
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition eta.h:50
Scalar math_floor(Scalar x)
Scalar math_cos(Scalar x)
Scalar math_sqrt(Scalar x)
Scalar math_atan2(Scalar x, Scalar y)
Scalar math_sin(Scalar x)