Logo 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 @sa Overview of the @ref GenVector "physics vector library"
45 */
46
47template <class T>
49
50public :
51
52 typedef T Scalar;
53
54 /**
55 Default constructor with rho=eta=phi=0
56 */
57 CylindricalEta3D() : fRho(0), fEta(0), fPhi(0) { }
58
59 /**
60 Construct from rho eta and phi values
61 */
63 fRho(rho), fEta(eta), fPhi(phi) { Restrict(); }
64
65 /**
66 Construct from any Vector or coordinate system implementing
67 Rho(), Eta() and Phi()
68 */
69 template <class CoordSystem >
70 explicit CylindricalEta3D( const CoordSystem & v ) :
71 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() )
72 {
73 using std::log;
74 static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits<Scalar>::epsilon());
75 if (std::fabs(fEta) > bigEta) {
76 // This gives a small absolute adjustment in rho,
77 // which, for large eta, results in a significant
78 // improvement in the faithfullness of reproducing z.
79 fRho *= v.Z() / Z();
80 }
81 }
82
83 // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
84 // re-implement them ( there is no no need to have them with g++4)
85
86 /**
87 copy constructor
88 */
90 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { }
91
92 /**
93 assignment operator
94 */
96 fRho = v.Rho();
97 fEta = v.Eta();
98 fPhi = v.Phi();
99 return *this;
100 }
101
102 /**
103 Set internal data based on an array of 3 Scalar numbers
104 */
105 void SetCoordinates( const Scalar src[] )
106 { fRho=src[0]; fEta=src[1]; fPhi=src[2]; Restrict(); }
107
108 /**
109 get internal data into an array of 3 Scalar numbers
110 */
111 void GetCoordinates( Scalar dest[] ) const
112 { dest[0] = fRho; dest[1] = fEta; dest[2] = fPhi; }
113
114 /**
115 Set internal data based on 3 Scalar numbers
116 */
117 void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
118 { fRho=rho; fEta=eta; fPhi=phi; Restrict(); }
119
120 /**
121 get internal data into 3 Scalar numbers
122 */
123 void GetCoordinates(Scalar& rho, Scalar& eta, Scalar& phi) const
124 {rho=fRho; eta=fEta; phi=fPhi;}
125
126private:
127 inline static Scalar pi() { return M_PI; }
128 inline void Restrict() {
129 using std::floor;
130 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
131 return;
132 }
133public:
134
135 // accessors
136
137 T Rho() const { return fRho; }
138 T Eta() const { return fEta; }
139 T Phi() const { return fPhi; }
140 T X() const { using std::cos; return fRho * cos(fPhi); }
141 T Y() const { using std::sin; return fRho * sin(fPhi); }
142 T Z() const
143 {
144 using std::sinh;
145 return fRho > 0 ? fRho * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<T>() : fEta + etaMax<T>();
146 }
147 T R() const
148 {
149 using std::cosh;
150 return fRho > 0 ? fRho * cosh(fEta)
151 : fEta > etaMax<T>() ? fEta - etaMax<T>() : fEta < -etaMax<T>() ? -fEta - etaMax<T>() : 0;
152 }
153 T Mag2() const
154 {
155 const Scalar r = R();
156 return r * r;
157 }
158 T Perp2() const { return fRho*fRho; }
159 T Theta() const { using std::atan; return fRho > 0 ? 2 * atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); }
160
161 // setters (only for data members)
162
163
164 /**
165 set the rho coordinate value keeping eta and phi constant
166 */
167 void SetRho(T rho) {
168 fRho = rho;
169 }
170
171 /**
172 set the eta coordinate value keeping rho and phi constant
173 */
174 void SetEta(T eta) {
175 fEta = eta;
176 }
177
178 /**
179 set the phi coordinate value keeping rho and eta constant
180 */
181 void SetPhi(T phi) {
182 fPhi = phi;
183 Restrict();
184 }
185
186 /**
187 set all values using cartesian coordinates
188 */
189 void SetXYZ(Scalar x, Scalar y, Scalar z);
190
191
192 /**
193 scale by a scalar quantity a --
194 for cylindrical eta coords, as long as a >= 0, only rho changes!
195 */
196 void Scale (T a) {
197 if (a < 0) {
198 Negate();
199 a = -a;
200 }
201 // angles do not change when scaling by a positive quantity
202 if (fRho > 0) {
203 fRho *= a;
204 } else if ( fEta > etaMax<T>() ) {
205 fEta = ( fEta-etaMax<T>())*a + etaMax<T>();
206 } else if ( fEta < -etaMax<T>() ) {
207 fEta = ( fEta+etaMax<T>())*a - etaMax<T>();
208 } // when rho==0 and eta is not above etaMax, vector represents 0
209 // and remains unchanged
210 }
211
212 /**
213 negate the vector
214 */
215 void Negate ( ) {
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 fRho = c.Rho();
227 fEta = c.Eta();
228 fPhi = c.Phi();
229 return *this;
230 }
231
232 /**
233 Exact component-by-component equality
234 Note: Peculiar representaions of the zero vector such as (0,1,0) will
235 not test as equal to one another.
236 */
237 bool operator==(const CylindricalEta3D & rhs) const {
238 return fRho == rhs.fRho && fEta == rhs.fEta && fPhi == rhs.fPhi;
239 }
240 bool operator!= (const CylindricalEta3D & rhs) const
241 {return !(operator==(rhs));}
242
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
271#endif
272
273
274private:
278
279};
280
281 } // end namespace Math
282
283} // end namespace ROOT
284
285
286// move implementations here to avoid circle dependencies
287
289
290#if defined(__MAKECINT__) || defined(G__DICTIONARY)
293#endif
294
295namespace ROOT {
296
297 namespace Math {
298
299template <class T>
301 *this = Cartesian3D<Scalar>(xx, yy, zz);
302}
303
304#if defined(__MAKECINT__) || defined(G__DICTIONARY)
305
306
307 // ====== Set member functions for coordinates in other systems =======
308
309
310template <class T>
312 GenVector_exception e("CylindricalEta3D::SetX() is not supposed to be called");
313 throw e;
314 Cartesian3D<Scalar> v(*this); v.SetX(xx);
316}
317template <class T>
318void CylindricalEta3D<T>::SetY(Scalar yy) {
319 GenVector_exception e("CylindricalEta3D::SetY() is not supposed to be called");
320 throw e;
321 Cartesian3D<Scalar> v(*this); v.SetY(yy);
322 *this = CylindricalEta3D<Scalar>(v);
323}
324template <class T>
325void CylindricalEta3D<T>::SetZ(Scalar zz) {
326 GenVector_exception e("CylindricalEta3D::SetZ() is not supposed to be called");
327 throw e;
328 Cartesian3D<Scalar> v(*this); v.SetZ(zz);
329 *this = CylindricalEta3D<Scalar>(v);
330}
331template <class T>
332void CylindricalEta3D<T>::SetR(Scalar r) {
333 GenVector_exception e("CylindricalEta3D::SetR() is not supposed to be called");
334 throw e;
335 Polar3D<Scalar> v(*this); v.SetR(r);
336 *this = CylindricalEta3D<Scalar>(v);
337}
338template <class T>
339void CylindricalEta3D<T>::SetTheta(Scalar theta) {
340 GenVector_exception e("CylindricalEta3D::SetTheta() is not supposed to be called");
341 throw e;
342 Polar3D<Scalar> v(*this); v.SetTheta(theta);
343 *this = CylindricalEta3D<Scalar>(v);
344}
345
346#endif
347
348
349 } // end namespace Math
350
351} // end namespace ROOT
352
353
354
355#endif /* ROOT_Math_GenVector_CylindricalEta3D */
#define c(i)
Definition: RSha256.hxx:101
#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 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
RVec< PromoteType< T > > cosh(const RVec< T > &v)
Definition: RVec.hxx:1806
RVec< PromoteType< T > > cos(const RVec< T > &v)
Definition: RVec.hxx:1798
RVec< PromoteType< T > > floor(const RVec< T > &v)
Definition: RVec.hxx:1812
RVec< PromoteType< T > > log(const RVec< T > &v)
Definition: RVec.hxx:1787
RVec< PromoteType< T > > sinh(const RVec< T > &v)
Definition: RVec.hxx:1805
RVec< PromoteType< T > > exp(const RVec< T > &v)
Definition: RVec.hxx:1783
RVec< PromoteType< T > > atan(const RVec< T > &v)
Definition: RVec.hxx:1802
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition: RVec.hxx:1797
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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
TArc a
Definition: textangle.C:12
double epsilon
Definition: triangle.c:618