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#include "TMath.h"
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 @see GenVector
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 */
59
60 /**
61 Construct from rho eta and phi values
62 */
64 {
65 Restrict();
66 }
67
68 /**
69 Construct from any Vector or coordinate system implementing
70 Rho(), Eta() and Phi()
71 */
72 template <class CoordSystem >
73 explicit CylindricalEta3D( const CoordSystem & v ) :
74 fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() )
75 {
76 using std::log;
77 static Scalar bigEta = Scalar(-0.3) * log(std::numeric_limits<Scalar>::epsilon());
78 if (std::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 */
89 void SetCoordinates( const Scalar src[] )
90 { fRho=src[0]; fEta=src[1]; fPhi=src[2]; Restrict(); }
91
92 /**
93 get internal data into an array of 3 Scalar numbers
94 */
95 void GetCoordinates( Scalar dest[] ) const
96 { dest[0] = fRho; dest[1] = fEta; dest[2] = fPhi; }
97
98 /**
99 Set internal data based on 3 Scalar numbers
100 */
101 void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
102 { fRho=rho; fEta=eta; fPhi=phi; Restrict(); }
103
104 /**
105 get internal data into 3 Scalar numbers
106 */
107 void GetCoordinates(Scalar& rho, Scalar& eta, Scalar& phi) const
108 {rho=fRho; eta=fEta; phi=fPhi;}
109
110private:
111 inline static Scalar pi() { return TMath::Pi(); }
112 inline void Restrict() {
113 using std::floor;
114 if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
115 return;
116 }
117public:
118
119 // accessors
120
121 T Rho() const { return fRho; }
122 T Eta() const { return fEta; }
123 T Phi() const { return fPhi; }
124 T X() const { using std::cos; return fRho * cos(fPhi); }
125 T Y() const { using std::sin; return fRho * sin(fPhi); }
126 T Z() const
127 {
128 using std::sinh;
129 return fRho > 0 ? fRho * sinh(fEta) : fEta == 0 ? 0 : fEta > 0 ? fEta - etaMax<T>() : fEta + etaMax<T>();
130 }
131 T R() const
132 {
133 using std::cosh;
134 return fRho > 0 ? fRho * cosh(fEta)
135 : fEta > etaMax<T>() ? fEta - etaMax<T>() : fEta < -etaMax<T>() ? -fEta - etaMax<T>() : 0;
136 }
137 T Mag2() const
138 {
139 const Scalar r = R();
140 return r * r;
141 }
142 T Perp2() const { return fRho*fRho; }
143 T Theta() const { using std::atan; return fRho > 0 ? 2 * atan(exp(-fEta)) : (fEta >= 0 ? 0 : pi()); }
144
145 // setters (only for data members)
146
147
148 /**
149 set the rho coordinate value keeping eta and phi constant
150 */
151 void SetRho(T rho) {
152 fRho = rho;
153 }
154
155 /**
156 set the eta coordinate value keeping rho and phi constant
157 */
158 void SetEta(T eta) {
159 fEta = eta;
160 }
161
162 /**
163 set the phi coordinate value keeping rho and eta constant
164 */
165 void SetPhi(T phi) {
166 fPhi = phi;
167 Restrict();
168 }
169
170 /**
171 set all values using cartesian coordinates
172 */
173 void SetXYZ(Scalar x, Scalar y, Scalar z);
174
175
176 /**
177 scale by a scalar quantity a --
178 for cylindrical eta coords, as long as a >= 0, only rho changes!
179 */
180 void Scale (T a) {
181 if (a < 0) {
182 Negate();
183 a = -a;
184 }
185 // angles do not change when scaling by a positive quantity
186 if (fRho > 0) {
187 fRho *= a;
188 } else if ( fEta > etaMax<T>() ) {
189 fEta = ( fEta-etaMax<T>())*a + etaMax<T>();
190 } else if ( fEta < -etaMax<T>() ) {
191 fEta = ( fEta+etaMax<T>())*a - etaMax<T>();
192 } // when rho==0 and eta is not above etaMax, vector represents 0
193 // and remains unchanged
194 }
195
196 /**
197 negate the vector
198 */
199 void Negate ( ) {
200 fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
201 fEta = -fEta;
202 }
203
204 // assignment operators
205 /**
206 generic assignment operator from any coordinate system
207 */
208 template <class CoordSystem >
209 CylindricalEta3D & operator= ( const CoordSystem & c ) {
210 fRho = c.Rho();
211 fEta = c.Eta();
212 fPhi = c.Phi();
213 return *this;
214 }
215
216 /**
217 Exact component-by-component equality
218 Note: Peculiar representations of the zero vector such as (0,1,0) will
219 not test as equal to one another.
220 */
221 bool operator==(const CylindricalEta3D & rhs) const {
222 return fRho == rhs.fRho && fEta == rhs.fEta && fPhi == rhs.fPhi;
223 }
224 bool operator!= (const CylindricalEta3D & rhs) const
225 {return !(operator==(rhs));}
226
227
228 // ============= Compatibility section ==================
229
230 // The following make this coordinate system look enough like a CLHEP
231 // vector that an assignment member template can work with either
232 T x() const { return X();}
233 T y() const { return Y();}
234 T z() const { return Z(); }
235
236 // ============= Specializations for improved speed ==================
237
238 // (none)
239
240#if defined(__MAKECINT__) || defined(G__DICTIONARY)
241
242 // ====== Set member functions for coordinates in other systems =======
243
244 void SetX(Scalar x);
245
246 void SetY(Scalar y);
247
248 void SetZ(Scalar z);
249
250 void SetR(Scalar r);
251
252 void SetTheta(Scalar theta);
253
254
255#endif
256
257 private:
258 T fRho = 0;
259 T fEta = 0;
260 T fPhi = 0;
261};
262
263 } // end namespace Math
264
265} // end namespace ROOT
266
267
268// move implementations here to avoid circle dependencies
269
271
272#if defined(__MAKECINT__) || defined(G__DICTIONARY)
275#endif
276
277namespace ROOT {
278
279 namespace Math {
280
281template <class T>
285
286#if defined(__MAKECINT__) || defined(G__DICTIONARY)
287
288
289 // ====== Set member functions for coordinates in other systems =======
290
291
292template <class T>
294 GenVector_exception e("CylindricalEta3D::SetX() is not supposed to be called");
295 throw e;
296 Cartesian3D<Scalar> v(*this); v.SetX(xx);
298}
299template <class T>
300void CylindricalEta3D<T>::SetY(Scalar yy) {
301 GenVector_exception e("CylindricalEta3D::SetY() is not supposed to be called");
302 throw e;
303 Cartesian3D<Scalar> v(*this); v.SetY(yy);
305}
306template <class T>
307void CylindricalEta3D<T>::SetZ(Scalar zz) {
308 GenVector_exception e("CylindricalEta3D::SetZ() is not supposed to be called");
309 throw e;
310 Cartesian3D<Scalar> v(*this); v.SetZ(zz);
312}
313template <class T>
314void CylindricalEta3D<T>::SetR(Scalar r) {
315 GenVector_exception e("CylindricalEta3D::SetR() is not supposed to be called");
316 throw e;
317 Polar3D<Scalar> v(*this); v.SetR(r);
319}
320template <class T>
321void CylindricalEta3D<T>::SetTheta(Scalar theta) {
322 GenVector_exception e("CylindricalEta3D::SetTheta() is not supposed to be called");
323 throw e;
324 Polar3D<Scalar> v(*this); v.SetTheta(theta);
326}
327
328#endif
329
330
331 } // end namespace Math
332
333} // end namespace ROOT
334
335
336
337#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
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.
void SetEta(T eta)
set the eta coordinate value keeping rho and phi constant
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
CylindricalEta3D & operator=(const CoordSystem &c)
generic assignment operator from any coordinate system
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
constexpr CylindricalEta3D() noexcept=default
Default constructor with rho=eta=phi=0.
void SetRho(T rho)
set the rho coordinate value keeping eta and phi constant
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
Namespace for new ROOT classes and functions.
constexpr Double_t Pi()
Definition TMath.h:38