Logo ROOT   6.08/07
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 #ifndef ROOT_Math_Math
24 #include "Math/Math.h"
25 #endif
26 
27 #ifndef ROOT_Math_GenVector_etaMax
28 #include "Math/GenVector/etaMax.h"
29 #endif
30 
31 
32 #include <limits>
33 
34 #include "Math/Math.h"
35 
36 
37 namespace ROOT {
38 
39 namespace Math {
40 
41 //__________________________________________________________________________________________
42  /**
43  Class describing a cylindrical coordinate system based on eta (pseudorapidity) instead of z.
44  The base coordinates are rho (transverse component) , eta and phi
45  Phi is restricted to be in the range [-PI,PI)
46 
47  @ingroup GenVector
48  */
49 
50 template <class T>
52 
53 public :
54 
55  typedef T Scalar;
56 
57  /**
58  Default constructor with rho=eta=phi=0
59  */
60  CylindricalEta3D() : fRho(0), fEta(0), fPhi(0) { }
61 
62  /**
63  Construct from rho eta and phi values
64  */
65  CylindricalEta3D(Scalar rho, Scalar eta, Scalar phi) :
66  fRho(rho), fEta(eta), fPhi(phi) { Restrict(); }
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  static Scalar bigEta =
78  if ( std::fabs(fEta) > bigEta ) {
79  fRho *= v.Z()/Z(); // 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  }
83  }
84 
85  // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
86  // re-implement them ( there is no no need to have them with g++4)
87 
88  /**
89  copy constructor
90  */
92  fRho(v.Rho() ), fEta(v.Eta() ), fPhi(v.Phi() ) { }
93 
94  /**
95  assignment operator
96  */
98  fRho = v.Rho();
99  fEta = v.Eta();
100  fPhi = v.Phi();
101  return *this;
102  }
103 
104  /**
105  Set internal data based on an array of 3 Scalar numbers
106  */
107  void SetCoordinates( const Scalar src[] )
108  { fRho=src[0]; fEta=src[1]; fPhi=src[2]; Restrict(); }
109 
110  /**
111  get internal data into an array of 3 Scalar numbers
112  */
113  void GetCoordinates( Scalar dest[] ) const
114  { dest[0] = fRho; dest[1] = fEta; dest[2] = fPhi; }
115 
116  /**
117  Set internal data based on 3 Scalar numbers
118  */
119  void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
120  { fRho=rho; fEta=eta; fPhi=phi; Restrict(); }
121 
122  /**
123  get internal data into 3 Scalar numbers
124  */
125  void GetCoordinates(Scalar& rho, Scalar& eta, Scalar& phi) const
126  {rho=fRho; eta=fEta; phi=fPhi;}
127 
128 private:
129  inline static Scalar pi() { return M_PI; }
130  inline void Restrict() {
131  if ( fPhi <= -pi() || fPhi > pi() )
132  fPhi = fPhi - std::floor( fPhi/(2*pi()) +.5 ) * 2*pi();
133  return;
134  }
135 public:
136 
137  // accessors
138 
139  T Rho() const { return fRho; }
140  T Eta() const { return fEta; }
141  T Phi() const { return fPhi; }
142  T X() const { return fRho*std::cos(fPhi); }
143  T Y() const { return fRho*std::sin(fPhi); }
144  T Z() const { return fRho > 0 ? fRho*std::sinh(fEta) :
145  fEta == 0 ? 0 :
146  fEta > 0 ? fEta - etaMax<T>() :
147  fEta + etaMax<T>() ; }
148  T R() const { return fRho > 0 ? fRho*std::cosh(fEta) :
149  fEta > etaMax<T>() ? fEta - etaMax<T>() :
150  fEta < -etaMax<T>() ? -fEta - etaMax<T>() :
151  0 ; }
152  T Mag2() const { return R()*R(); }
153  T Perp2() const { return fRho*fRho; }
154  T Theta() const { return fRho > 0 ? 2* std::atan( std::exp( - fEta ) ) :
155  (fEta >= 0 ? 0 : pi() ); }
156 
157  // setters (only for data members)
158 
159 
160  /**
161  set the rho coordinate value keeping eta and phi constant
162  */
163  void SetRho(T rho) {
164  fRho = rho;
165  }
166 
167  /**
168  set the eta coordinate value keeping rho and phi constant
169  */
170  void SetEta(T eta) {
171  fEta = eta;
172  }
173 
174  /**
175  set the phi coordinate value keeping rho and eta constant
176  */
177  void SetPhi(T phi) {
178  fPhi = phi;
179  Restrict();
180  }
181 
182  /**
183  set all values using cartesian coordinates
184  */
185  void SetXYZ(Scalar x, Scalar y, Scalar z);
186 
187 
188  /**
189  scale by a scalar quantity a --
190  for cylindrical eta coords, as long as a >= 0, only rho changes!
191  */
192  void Scale (T a) {
193  if (a < 0) {
194  Negate();
195  a = -a;
196  }
197  // angles do not change when scaling by a positive quantity
198  if (fRho > 0) {
199  fRho *= a;
200  } else if ( fEta > etaMax<T>() ) {
201  fEta = ( fEta-etaMax<T>())*a + etaMax<T>();
202  } else if ( fEta < -etaMax<T>() ) {
203  fEta = ( fEta+etaMax<T>())*a - etaMax<T>();
204  } // when rho==0 and eta is not above etaMax, vector represents 0
205  // and remains unchanged
206  }
207 
208  /**
209  negate the vector
210  */
211  void Negate ( ) {
212  fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
213  fEta = -fEta;
214  }
215 
216  // assignment operators
217  /**
218  generic assignment operator from any coordinate system
219  */
220  template <class CoordSystem >
221  CylindricalEta3D & operator= ( const CoordSystem & c ) {
222  fRho = c.Rho();
223  fEta = c.Eta();
224  fPhi = c.Phi();
225  return *this;
226  }
227 
228  /**
229  Exact component-by-component equality
230  Note: Peculiar representaions of the zero vector such as (0,1,0) will
231  not test as equal to one another.
232  */
233  bool operator==(const CylindricalEta3D & rhs) const {
234  return fRho == rhs.fRho && fEta == rhs.fEta && fPhi == rhs.fPhi;
235  }
236  bool operator!= (const CylindricalEta3D & rhs) const
237  {return !(operator==(rhs));}
238 
239 
240  // ============= Compatibility section ==================
241 
242  // The following make this coordinate system look enough like a CLHEP
243  // vector that an assignment member template can work with either
244  T x() const { return X();}
245  T y() const { return Y();}
246  T z() const { return Z(); }
247 
248  // ============= Specializations for improved speed ==================
249 
250  // (none)
251 
252 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
253 
254  // ====== Set member functions for coordinates in other systems =======
255 
256  void SetX(Scalar x);
257 
258  void SetY(Scalar y);
259 
260  void SetZ(Scalar z);
261 
262  void SetR(Scalar r);
263 
264  void SetTheta(Scalar theta);
265 
266 
267 #endif
268 
269 
270 private:
274 
275 };
276 
277  } // end namespace Math
278 
279 } // end namespace ROOT
280 
281 
282 // move implementations here to avoid circle dependencies
283 
284 #ifndef ROOT_Math_GenVector_Cartesian3D
286 #endif
287 
288 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
289 #ifndef ROOT_Math_GenVector_GenVector_exception
291 #endif
292 #ifndef ROOT_Math_GenVector_Polar3D
293 #include "Math/GenVector/Polar3D.h"
294 #endif
295 #endif
296 
297 namespace ROOT {
298 
299  namespace Math {
300 
301 template <class T>
303  *this = Cartesian3D<Scalar>(xx, yy, zz);
304 }
305 
306 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
307 
308 
309  // ====== Set member functions for coordinates in other systems =======
310 
311 
312 template <class T>
314  GenVector_exception e("CylindricalEta3D::SetX() is not supposed to be called");
315  throw e;
316  Cartesian3D<Scalar> v(*this); v.SetX(xx);
317  *this = CylindricalEta3D<Scalar>(v);
318 }
319 template <class T>
321  GenVector_exception e("CylindricalEta3D::SetY() is not supposed to be called");
322  throw e;
323  Cartesian3D<Scalar> v(*this); v.SetY(yy);
324  *this = CylindricalEta3D<Scalar>(v);
325 }
326 template <class T>
328  GenVector_exception e("CylindricalEta3D::SetZ() is not supposed to be called");
329  throw e;
330  Cartesian3D<Scalar> v(*this); v.SetZ(zz);
331  *this = CylindricalEta3D<Scalar>(v);
332 }
333 template <class T>
335  GenVector_exception e("CylindricalEta3D::SetR() is not supposed to be called");
336  throw e;
337  Polar3D<Scalar> v(*this); v.SetR(r);
338  *this = CylindricalEta3D<Scalar>(v);
339 }
340 template <class T>
342  GenVector_exception e("CylindricalEta3D::SetTheta() is not supposed to be called");
343  throw e;
344  Polar3D<Scalar> v(*this); v.SetTheta(theta);
345  *this = CylindricalEta3D<Scalar>(v);
346 }
347 
348 #endif
349 
350 
351  } // end namespace Math
352 
353 } // end namespace ROOT
354 
355 
356 
357 #endif /* ROOT_Math_GenVector_CylindricalEta3D */
CylindricalEta3D(const CylindricalEta3D &v)
copy constructor
bool operator!=(const CylindricalEta3D &rhs) const
void SetX(Scalar xx)
set the x coordinate value keeping y and z constant
Definition: Cartesian3D.h:134
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers.
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
return c
double T(double x)
Definition: ChebyshevPol.h:34
CylindricalEta3D(Scalar rho, Scalar eta, Scalar phi)
Construct from rho eta and phi values.
Class describing a cylindrical coordinate system based on eta (pseudorapidity) instead of z...
TArc * a
Definition: textangle.C:12
CylindricalEta3D & operator=(const CylindricalEta3D &v)
assignment operator
void GetCoordinates(Scalar &rho, Scalar &eta, Scalar &phi) const
get internal data into 3 Scalar numbers
double cos(double)
void SetR(const T &r)
set the r coordinate value keeping theta and phi constant
Definition: Polar3D.h:135
bool operator==(const CylindricalEta3D &rhs) const
Exact component-by-component equality Note: Peculiar representaions of the zero vector such as (0...
void SetY(Scalar yy)
set the y coordinate value keeping x and z constant
Definition: Cartesian3D.h:139
CylindricalEta3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing Rho(), Eta() and Phi() ...
double sinh(double)
double sin(double)
void SetPhi(T phi)
set the phi coordinate value keeping rho and eta constant
void SetTheta(const T &theta)
set the theta coordinate value keeping r and phi constant
Definition: Polar3D.h:142
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
void SetZ(Scalar zz)
set the z coordinate value keeping x and y constant
Definition: Cartesian3D.h:144
TRandom2 r(17)
#define M_PI
Definition: Rotated.cxx:105
SVector< double, 2 > v
Definition: Dict.h:5
double cosh(double)
void SetRho(T rho)
set the rho coordinate value keeping eta and phi constant
void Scale(T a)
scale by a scalar quantity a – for cylindrical eta coords, as long as a >= 0, only rho changes! ...
double floor(double)
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
REAL epsilon
Definition: triangle.c:617
void SetEta(T eta)
set the eta coordinate value keeping rho and phi constant
double atan(double)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
void SetCoordinates(Scalar rho, Scalar eta, Scalar phi)
Set internal data based on 3 Scalar numbers.
Namespace for new Math classes and functions.
#define dest(otri, vertexptr)
Definition: triangle.c:1040
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers
void Negate()
negate the vector
CylindricalEta3D()
Default constructor with rho=eta=phi=0.
double exp(double)
double log(double)
Class describing a polar coordinate system based on r, theta and phi Phi is restricted to be in the r...
Definition: Polar3D.h:46