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