Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CylindricalEta3D.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 CylindricalEta3D
13//
14// Created by: Lorenzo Moneta at Mon May 30 11:58:46 2005
15// Major revamp: M. Fischler at Fri Jun 10 2005
16//
17// Last update: $Id$
18
19//
20#ifndef ROOT_MathX_GenVectorX_CylindricalEta3D
21#define ROOT_MathX_GenVectorX_CylindricalEta3D 1
22
23#include "Math/Math.h"
24
26
28
30
31using namespace ROOT::ROOT_MATH_ARCH;
32
33#include <limits>
34#include <cmath>
35
36namespace ROOT {
37
38namespace ROOT_MATH_ARCH {
39
40//__________________________________________________________________________________________
41/**
42 Class describing a cylindrical coordinate system based on eta (pseudorapidity) instead of z.
43 The base coordinates are rho (transverse component) , eta and phi
44 Phi is restricted to be in the range [-PI,PI)
45
46 @ingroup GenVectorX
47
48 @see GenVectorX
49*/
50
51template <class T>
53
54public:
55 typedef T Scalar;
56
57 /**
58 Default constructor with rho=eta=phi=0
59 */
61
62 /**
63 Construct from rho eta and phi values
64 */
66 {
67 Restrict();
68 }
69
70 /**
71 Construct from any Vector or coordinate system implementing
72 Rho(), Eta() and Phi()
73 */
74 template <class CoordSystem>
75 explicit CylindricalEta3D(const CoordSystem &v) : fRho(v.Rho()), fEta(v.Eta()), fPhi(v.Phi())
76 {
77 static Scalar bigEta = Scalar(-0.3) * math_log(std::numeric_limits<Scalar>::epsilon());
78 if (math_fabs(fEta) > bigEta) {
79 // This gives a small absolute adjustment in rho,
80 // which, for large eta, results in a significant
81 // improvement in the faithfullness of reproducing z.
82 fRho *= v.Z() / Z();
83 }
84 }
85
86 /**
87 Set internal data based on an array of 3 Scalar numbers
88 */
90 {
91 fRho = src[0];
92 fEta = src[1];
93 fPhi = src[2];
94 Restrict();
95 }
96
97 /**
98 get internal data into an array of 3 Scalar numbers
99 */
101 {
102 dest[0] = fRho;
103 dest[1] = fEta;
104 dest[2] = fPhi;
105 }
106
107 /**
108 Set internal data based on 3 Scalar numbers
109 */
110 void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
111 {
112 fRho = rho;
113 fEta = eta;
114 fPhi = phi;
115 Restrict();
116 }
117
118 /**
119 get internal data into 3 Scalar numbers
120 */
121 void GetCoordinates(Scalar &rho, Scalar &eta, Scalar &phi) const
122 {
123 rho = fRho;
124 eta = fEta;
125 phi = fPhi;
126 }
127
128private:
129 inline static Scalar pi() { return M_PI; }
130 inline void Restrict()
131 {
132 if (fPhi <= -pi() || fPhi > pi())
133 fPhi = fPhi - math_floor(fPhi / (2 * pi()) + .5) * 2 * pi();
134 return;
135 }
136
137public:
138 // accessors
139
140 T Rho() const { return fRho; }
141 T Eta() const { return fEta; }
142 T Phi() const { return fPhi; }
143 T X() const { return fRho * math_cos(fPhi); }
144 T Y() const { return fRho * math_sin(fPhi); }
145 T Z() const
146 {
147 return fRho > 0 ? fRho * math_sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<T>() : fEta + etaMax<T>();
148 }
149 T R() const
150 {
151 return fRho > 0 ? fRho * math_cosh(fEta)
152 : fEta > etaMax<T>() ? fEta - etaMax<T>()
153 : fEta < -etaMax<T>() ? -fEta - etaMax<T>()
154 : 0;
155 }
156 T Mag2() const
157 {
158 const Scalar r = R();
159 return r * r;
160 }
161 T Perp2() const { return fRho * fRho; }
162 T Theta() const { return fRho > 0 ? 2 * math_atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); }
163
164 // setters (only for data members)
165
166 /**
167 set the rho coordinate value keeping eta and phi constant
168 */
169 void SetRho(T rho) { fRho = rho; }
170
171 /**
172 set the eta coordinate value keeping rho and phi constant
173 */
174 void SetEta(T eta) { fEta = eta; }
175
176 /**
177 set the phi coordinate value keeping rho and eta constant
178 */
179 void SetPhi(T phi)
180 {
181 fPhi = phi;
182 Restrict();
183 }
184
185 /**
186 set all values using cartesian coordinates
187 */
188 void SetXYZ(Scalar x, Scalar y, Scalar z);
189
190 /**
191 scale by a scalar quantity a --
192 for cylindrical eta coords, as long as a >= 0, only rho changes!
193 */
194 void Scale(T a)
195 {
196 if (a < 0) {
197 Negate();
198 a = -a;
199 }
200 // angles do not change when scaling by a positive quantity
201 if (fRho > 0) {
202 fRho *= a;
203 } else if (fEta > etaMax<T>()) {
204 fEta = (fEta - etaMax<T>()) * a + etaMax<T>();
205 } else if (fEta < -etaMax<T>()) {
206 fEta = (fEta + etaMax<T>()) * a - etaMax<T>();
207 } // when rho==0 and eta is not above etaMax, vector represents 0
208 // and remains unchanged
209 }
210
211 /**
212 negate the vector
213 */
214 void Negate()
215 {
216 fPhi = (fPhi > 0 ? fPhi - pi() : fPhi + pi());
217 fEta = -fEta;
218 }
219
220 // assignment operators
221 /**
222 generic assignment operator from any coordinate system
223 */
224 template <class CoordSystem>
225 CylindricalEta3D &operator=(const CoordSystem &c)
226 {
227 fRho = c.Rho();
228 fEta = c.Eta();
229 fPhi = c.Phi();
230 return *this;
231 }
232
233 /**
234 Exact component-by-component equality
235 Note: Peculiar representations of the zero vector such as (0,1,0) will
236 not test as equal to one another.
237 */
238 bool operator==(const CylindricalEta3D &rhs) const
239 {
240 return fRho == rhs.fRho && fEta == rhs.fEta && fPhi == rhs.fPhi;
241 }
242 bool operator!=(const CylindricalEta3D &rhs) const { return !(operator==(rhs)); }
243
244 // ============= Compatibility section ==================
245
246 // The following make this coordinate system look enough like a CLHEP
247 // vector that an assignment member template can work with either
248 T x() const { return X(); }
249 T y() const { return Y(); }
250 T z() const { return Z(); }
251
252 // ============= Specializations for improved speed ==================
253
254 // (none)
255
256#if defined(__MAKECINT__) || defined(G__DICTIONARY)
257
258 // ====== Set member functions for coordinates in other systems =======
259
260 void SetX(Scalar x);
261
262 void SetY(Scalar y);
263
264 void SetZ(Scalar z);
265
266 void SetR(Scalar r);
267
268 void SetTheta(Scalar theta);
269
270#endif
271
272private:
273 T fRho = 0;
274 T fEta = 0;
275 T fPhi = 0;
276};
277
278} // end namespace ROOT_MATH_ARCH
279
280} // end namespace ROOT
281
282// move implementations here to avoid circle dependencies
283
285
286#if defined(__MAKECINT__) || defined(G__DICTIONARY)
289#endif
290
291namespace ROOT {
292
293namespace ROOT_MATH_ARCH {
294
295template <class T>
300
301#if defined(__MAKECINT__) || defined(G__DICTIONARY)
302#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
303
304// ====== Set member functions for coordinates in other systems =======
305
306template <class T>
308{
309 GenVector_exception e("CylindricalEta3D::SetX() is not supposed to be called");
310 throw e;
311 Cartesian3D<Scalar> v(*this);
312 v.SetX(xx);
314}
315template <class T>
316void CylindricalEta3D<T>::SetY(Scalar yy)
317{
318 GenVector_exception e("CylindricalEta3D::SetY() is not supposed to be called");
319 throw e;
320 Cartesian3D<Scalar> v(*this);
321 v.SetY(yy);
323}
324template <class T>
326{
327 GenVector_exception e("CylindricalEta3D::SetZ() is not supposed to be called");
328 throw e;
329 Cartesian3D<Scalar> v(*this);
330 v.SetZ(zz);
332}
333template <class T>
335{
336 GenVector_exception e("CylindricalEta3D::SetR() is not supposed to be called");
337 throw e;
338 Polar3D<Scalar> v(*this);
339 v.SetR(r);
341}
342template <class T>
344{
345 GenVector_exception e("CylindricalEta3D::SetTheta() is not supposed to be called");
346 throw e;
347 Polar3D<Scalar> v(*this);
348 v.SetTheta(theta);
350}
351
352#endif
353#endif
354
355} // end namespace ROOT_MATH_ARCH
356
357} // end namespace ROOT
358
359#endif /* ROOT_MathX_GenVectorX_CylindricalEta3D */
#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 eta (pseudorapidity) instead of z.
CylindricalEta3D & operator=(const CoordSystem &c)
generic assignment operator from any coordinate system
void Scale(T a)
scale by a scalar quantity a – for cylindrical eta coords, as long as a >= 0, only rho changes!
void SetPhi(T phi)
set the phi coordinate value keeping rho and eta constant
void SetEta(T eta)
set the eta coordinate value keeping rho and phi constant
void SetRho(T rho)
set the rho coordinate value keeping eta and phi constant
void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
Set internal data based on 3 Scalar numbers.
void GetCoordinates(Scalar &rho, Scalar &eta, Scalar &phi) const
get internal data into 3 Scalar numbers
bool operator!=(const CylindricalEta3D &rhs) const
bool operator==(const CylindricalEta3D &rhs) const
Exact component-by-component equality Note: Peculiar representations of the zero vector such as (0,...
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
constexpr CylindricalEta3D() noexcept=default
Default constructor with rho=eta=phi=0.
CylindricalEta3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing Rho(), Eta() and Phi()
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
Scalar math_log(Scalar x)
Scalar math_floor(Scalar x)
Scalar math_cos(Scalar x)
Scalar math_atan(Scalar x)
Scalar math_sinh(Scalar x)
Scalar math_fabs(Scalar x)
Scalar math_cosh(Scalar x)
Scalar math_sin(Scalar x)