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