ROOT   Reference Guide
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_Math_GenVector_CylindricalEta3D
21#define ROOT_Math_GenVector_CylindricalEta3D 1
22
23#include "Math/Math.h"
24
26
27
28#include <limits>
29#include <cmath>
30
31
32namespace ROOT {
33
34namespace Math {
35
36//__________________________________________________________________________________________
37 /**
38 Class describing a cylindrical coordinate system based on eta (pseudorapidity) instead of z.
39 The base coordinates are rho (transverse component) , eta and phi
40 Phi is restricted to be in the range [-PI,PI)
41
42 @ingroup GenVector
43
44 @sa Overview of the @ref GenVector "physics vector library"
45 */
46
47template <class T>
49
50public :
51
52 typedef T Scalar;
53 static constexpr unsigned int Dimension = 3U;
54
55 /**
56 Default constructor with rho=eta=phi=0
57 */
58 CylindricalEta3D() : fRho(0), fEta(0), fPhi(0) { }
59
60 /**
61 Construct from rho eta and phi values
62 */
64 fRho(rho), fEta(eta), fPhi(phi) { Restrict(); }
65
66 /**
67 Construct from any Vector or coordinate system implementing
68 Rho(), Eta() and Phi()
69 */
70 template <class CoordSystem >
71 explicit CylindricalEta3D( const CoordSystem & v ) :
72 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() )
73 {
74 using std::log;
75 static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits<Scalar>::epsilon());
76 if (std::fabs(fEta) > bigEta) {
77 // This gives a small absolute adjustment in rho,
78 // which, for large eta, results in a significant
79 // improvement in the faithfullness of reproducing z.
80 fRho *= v.Z() / Z();
81 }
82 }
83
84 // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
85 // re-implement them ( there is no no need to have them with g++4)
86
87 /**
88 copy constructor
89 */
91 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { }
92
93 /**
94 assignment operator
95 */
97 fRho = v.Rho();
98 fEta = v.Eta();
99 fPhi = v.Phi();
100 return *this;
101 }
102
103 /**
104 Set internal data based on an array of 3 Scalar numbers
105 */
106 void SetCoordinates( const Scalar src[] )
107 { fRho=src[0]; fEta=src[1]; fPhi=src[2]; Restrict(); }
108
109 /**
110 get internal data into an array of 3 Scalar numbers
111 */
112 void GetCoordinates( Scalar dest[] ) const
113 { dest[0] = fRho; dest[1] = fEta; dest[2] = fPhi; }
114
115 /**
116 Set internal data based on 3 Scalar numbers
117 */
118 void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
119 { fRho=rho; fEta=eta; fPhi=phi; Restrict(); }
120
121 /**
122 get internal data into 3 Scalar numbers
123 */
124 void GetCoordinates(Scalar& rho, Scalar& eta, Scalar& phi) const
125 {rho=fRho; eta=fEta; phi=fPhi;}
126
127private:
128 inline static Scalar pi() { return M_PI; }
129 inline void Restrict() {
130 using std::floor;
131 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
132 return;
133 }
134public:
135
136 // accessors
137
138 T Rho() const { return fRho; }
139 T Eta() const { return fEta; }
140 T Phi() const { return fPhi; }
141 T X() const { using std::cos; return fRho * cos(fPhi); }
142 T Y() const { using std::sin; return fRho * sin(fPhi); }
143 T Z() const
144 {
145 using std::sinh;
146 return fRho > 0 ? fRho * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<T>() : fEta + etaMax<T>();
147 }
148 T R() const
149 {
150 using std::cosh;
151 return fRho > 0 ? fRho * cosh(fEta)
152 : fEta > etaMax<T>() ? fEta - etaMax<T>() : fEta < -etaMax<T>() ? -fEta - etaMax<T>() : 0;
153 }
154 T Mag2() const
155 {
156 const Scalar r = R();
157 return r * r;
158 }
159 T Perp2() const { return fRho*fRho; }
160 T Theta() const { using std::atan; return fRho > 0 ? 2 * atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); }
161
162 // setters (only for data members)
163
164
165 /**
166 set the rho coordinate value keeping eta and phi constant
167 */
168 void SetRho(T rho) {
169 fRho = rho;
170 }
171
172 /**
173 set the eta coordinate value keeping rho and phi constant
174 */
175 void SetEta(T eta) {
176 fEta = eta;
177 }
178
179 /**
180 set the phi coordinate value keeping rho and eta constant
181 */
182 void SetPhi(T phi) {
183 fPhi = phi;
184 Restrict();
185 }
186
187 /**
188 set all values using cartesian coordinates
189 */
190 void SetXYZ(Scalar x, Scalar y, Scalar z);
191
192
193 /**
194 scale by a scalar quantity a --
195 for cylindrical eta coords, as long as a >= 0, only rho changes!
196 */
197 void Scale (T a) {
198 if (a < 0) {
199 Negate();
200 a = -a;
201 }
202 // angles do not change when scaling by a positive quantity
203 if (fRho > 0) {
204 fRho *= a;
205 } else if ( fEta > etaMax<T>() ) {
206 fEta = ( fEta-etaMax<T>())*a + etaMax<T>();
207 } else if ( fEta < -etaMax<T>() ) {
208 fEta = ( fEta+etaMax<T>())*a - etaMax<T>();
209 } // when rho==0 and eta is not above etaMax, vector represents 0
210 // and remains unchanged
211 }
212
213 /**
214 negate the vector
215 */
216 void Negate ( ) {
217 fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
218 fEta = -fEta;
219 }
220
221 // assignment operators
222 /**
223 generic assignment operator from any coordinate system
224 */
225 template <class CoordSystem >
226 CylindricalEta3D & operator= ( const CoordSystem & c ) {
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 return fRho == rhs.fRho && fEta == rhs.fEta && fPhi == rhs.fPhi;
240 }
241 bool operator!= (const CylindricalEta3D & rhs) const
242 {return !(operator==(rhs));}
243
244
245 // ============= Compatibility section ==================
246
247 // The following make this coordinate system look enough like a CLHEP
248 // vector that an assignment member template can work with either
249 T x() const { return X();}
250 T y() const { return Y();}
251 T z() const { return Z(); }
252
253 // ============= Specializations for improved speed ==================
254
255 // (none)
256
257#if defined(__MAKECINT__) || defined(G__DICTIONARY)
258
259 // ====== Set member functions for coordinates in other systems =======
260
261 void SetX(Scalar x);
262
263 void SetY(Scalar y);
264
265 void SetZ(Scalar z);
266
267 void SetR(Scalar r);
268
269 void SetTheta(Scalar theta);
270
271
272#endif
273
274
275private:
279
280};
281
282 } // end namespace Math
283
284} // end namespace ROOT
285
286
287// move implementations here to avoid circle dependencies
288
290
291#if defined(__MAKECINT__) || defined(G__DICTIONARY)
294#endif
295
296namespace ROOT {
297
298 namespace Math {
299
300template <class T>
302 *this = Cartesian3D<Scalar>(xx, yy, zz);
303}
304
305#if defined(__MAKECINT__) || defined(G__DICTIONARY)
306
307
308 // ====== Set member functions for coordinates in other systems =======
309
310
311template <class T>
313 GenVector_exception e("CylindricalEta3D::SetX() is not supposed to be called");
314 throw e;
315 Cartesian3D<Scalar> v(*this); v.SetX(xx);
317}
318template <class T>
319void CylindricalEta3D<T>::SetY(Scalar yy) {
320 GenVector_exception e("CylindricalEta3D::SetY() is not supposed to be called");
321 throw e;
322 Cartesian3D<Scalar> v(*this); v.SetY(yy);
323 *this = CylindricalEta3D<Scalar>(v);
324}
325template <class T>
326void CylindricalEta3D<T>::SetZ(Scalar zz) {
327 GenVector_exception e("CylindricalEta3D::SetZ() is not supposed to be called");
328 throw e;
329 Cartesian3D<Scalar> v(*this); v.SetZ(zz);
330 *this = CylindricalEta3D<Scalar>(v);
331}
332template <class T>
333void CylindricalEta3D<T>::SetR(Scalar r) {
334 GenVector_exception e("CylindricalEta3D::SetR() is not supposed to be called");
335 throw e;
336 Polar3D<Scalar> v(*this); v.SetR(r);
337 *this = CylindricalEta3D<Scalar>(v);
338}
339template <class T>
340void CylindricalEta3D<T>::SetTheta(Scalar theta) {
341 GenVector_exception e("CylindricalEta3D::SetTheta() is not supposed to be called");
342 throw e;
343 Polar3D<Scalar> v(*this); v.SetTheta(theta);
344 *this = CylindricalEta3D<Scalar>(v);
345}
346
347#endif
348
349
350 } // end namespace Math
351
352} // end namespace ROOT
353
354
355
356#endif /* ROOT_Math_GenVector_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
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 eta (pseudorapidity) instead of z.
void SetEta(T eta)
set the eta coordinate value keeping rho and phi constant
CylindricalEta3D()
Default constructor with rho=eta=phi=0.
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
Set internal data based on 3 Scalar numbers.
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
void Negate()
negate the vector
CylindricalEta3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing Rho(), Eta() and Phi()
void Scale(T a)
scale by a scalar quantity a – for cylindrical eta coords, as long as a >= 0, only rho changes!
void GetCoordinates(Scalar &rho, Scalar &eta, Scalar &phi) const
get internal data into 3 Scalar numbers
void SetPhi(T phi)
set the phi coordinate value keeping rho and eta constant
CylindricalEta3D & operator=(const CylindricalEta3D &v)
assignment operator
CylindricalEta3D(const CylindricalEta3D &v)
copy constructor
void SetRho(T rho)
set the rho coordinate value keeping eta and phi constant
CylindricalEta3D(Scalar rho, Scalar eta, Scalar phi)
Construct from rho eta and phi values.
static constexpr unsigned int Dimension
bool operator==(const CylindricalEta3D &rhs) const
Exact component-by-component equality Note: Peculiar representations of the zero vector such as (0,...
bool operator!=(const CylindricalEta3D &rhs) const
Namespace for new Math classes and functions.
Rotation3D::Scalar Scalar
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...