Logo ROOT   6.14/05
Reference Guide
Cylindrical3D.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  * *
8  * *
9  **********************************************************************/
10 
11 // Header file for class Cylindrica3D
12 //
13 // Created by: Lorenzo Moneta at Tue Dec 06 2005
14 //
15 //
16 #ifndef ROOT_Math_GenVector_Cylindrical3D
17 #define ROOT_Math_GenVector_Cylindrical3D 1
18 
19 #include "Math/Math.h"
20 
21 #include "Math/GenVector/eta.h"
22 
23 #include <limits>
24 #include <cmath>
25 
26 namespace ROOT {
27 
28 namespace Math {
29 
30 //__________________________________________________________________________________________
31  /**
32  Class describing a cylindrical coordinate system based on rho, z and phi.
33  The base coordinates are rho (transverse component) , z and phi
34  Phi is restricted to be in the range [-PI,PI)
35 
36  @ingroup GenVector
37  */
38 
39 template <class T>
41 
42 public :
43 
44  typedef T Scalar;
45 
46  /**
47  Default constructor with rho=z=phi=0
48  */
49  Cylindrical3D() : fRho(0), fZ(0), fPhi(0) { }
50 
51  /**
52  Construct from rho eta and phi values
53  */
54  Cylindrical3D(Scalar rho, Scalar zz, Scalar phi) :
55  fRho(rho), fZ(zz), fPhi(phi) { Restrict(); }
56 
57  /**
58  Construct from any Vector or coordinate system implementing
59  Rho(), Z() and Phi()
60  */
61  template <class CoordSystem >
62  explicit Cylindrical3D( const CoordSystem & v ) :
63  fRho( v.Rho() ), fZ( v.Z() ), fPhi( v.Phi() ) { Restrict(); }
64 
65  // for g++ 3.2 and 3.4 on 32 bits found that the compiler generated copy ctor and assignment are much slower
66  // re-implement them ( there is no no need to have them with g++4)
67 
68  /**
69  copy constructor
70  */
72  fRho(v.Rho() ), fZ(v.Z() ), fPhi(v.Phi() ) { }
73 
74  /**
75  assignment operator
76  */
78  fRho = v.Rho();
79  fZ = v.Z();
80  fPhi = v.Phi();
81  return *this;
82  }
83 
84  /**
85  Set internal data based on an array of 3 Scalar numbers ( rho, z , phi)
86  */
87  void SetCoordinates( const Scalar src[] )
88  { fRho=src[0]; fZ=src[1]; fPhi=src[2]; Restrict(); }
89 
90  /**
91  get internal data into an array of 3 Scalar numbers ( rho, z , phi)
92  */
93  void GetCoordinates( Scalar dest[] ) const
94  { dest[0] = fRho; dest[1] = fZ; dest[2] = fPhi; }
95 
96  /**
97  Set internal data based on 3 Scalar numbers ( rho, z , phi)
98  */
99  void SetCoordinates(Scalar rho, Scalar zz, Scalar phi)
100  { fRho=rho; fZ=zz; fPhi=phi; Restrict(); }
101 
102  /**
103  get internal data into 3 Scalar numbers ( rho, z , phi)
104  */
105  void GetCoordinates(Scalar& rho, Scalar& zz, Scalar& phi) const
106  {rho=fRho; zz=fZ; phi=fPhi;}
107 
108 private:
109  inline static Scalar pi() { return Scalar(M_PI); }
110  inline void Restrict()
111  {
112  if (fPhi <= -pi() || fPhi > pi()) fPhi = fPhi - floor(fPhi / (2 * pi()) + .5) * 2 * pi();
113  }
114 public:
115 
116  // accessors
117 
118  Scalar Rho() const { return fRho; }
119  Scalar Z() const { return fZ; }
120  Scalar Phi() const { return fPhi; }
121 
122  Scalar X() const { return fRho * cos(fPhi); }
123  Scalar Y() const { return fRho * sin(fPhi); }
124 
125  Scalar Mag2() const { return fRho*fRho + fZ*fZ; }
126  Scalar R() const { return sqrt(Mag2()); }
127  Scalar Perp2() const { return fRho*fRho; }
128  Scalar Theta() const { return (fRho == Scalar(0) && fZ == Scalar(0)) ? Scalar(0) : atan2(fRho, fZ); }
129 
130  // pseudorapidity - use same implementation as in Cartesian3D
131  Scalar Eta() const {
132  return Impl::Eta_FromRhoZ( fRho, fZ);
133  }
134 
135  // setters (only for data members)
136 
137 
138  /**
139  set the rho coordinate value keeping z and phi constant
140  */
141  void SetRho(T rho) {
142  fRho = rho;
143  }
144 
145  /**
146  set the z coordinate value keeping rho and phi constant
147  */
148  void SetZ(T zz) {
149  fZ = zz;
150  }
151 
152  /**
153  set the phi coordinate value keeping rho and z constant
154  */
155  void SetPhi(T phi) {
156  fPhi = phi;
157  Restrict();
158  }
159 
160  /**
161  set all values using cartesian coordinates
162  */
163  void SetXYZ(Scalar x, Scalar y, Scalar z);
164 
165  /**
166  scale by a scalar quantity a --
167  for cylindrical coords only rho and z change
168  */
169  void Scale (T a) {
170  if (a < 0) {
171  Negate();
172  a = -a;
173  }
174  fRho *= a;
175  fZ *= a;
176  }
177 
178  /**
179  negate the vector
180  */
181  void Negate ( ) {
182  fPhi = ( fPhi > 0 ? fPhi - pi() : fPhi + pi() );
183  fZ = -fZ;
184  }
185 
186  // assignment operators
187  /**
188  generic assignment operator from any coordinate system implementing Rho(), Z() and Phi()
189  */
190  template <class CoordSystem >
191  Cylindrical3D & operator= ( const CoordSystem & c ) {
192  fRho = c.Rho();
193  fZ = c.Z();
194  fPhi = c.Phi();
195  return *this;
196  }
197 
198  /**
199  Exact component-by-component equality
200  */
201  bool operator==(const Cylindrical3D & rhs) const {
202  return fRho == rhs.fRho && fZ == rhs.fZ && fPhi == rhs.fPhi;
203  }
204  bool operator!= (const Cylindrical3D & rhs) const
205  {return !(operator==(rhs));}
206 
207 
208  // ============= Compatibility section ==================
209 
210  // The following make this coordinate system look enough like a CLHEP
211  // vector that an assignment member template can work with either
212  T x() const { return X();}
213  T y() const { return Y();}
214  T z() const { return Z(); }
215 
216  // ============= Specializations for improved speed ==================
217 
218  // (none)
219 
220 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
221 
222  // ====== Set member functions for coordinates in other systems =======
223 
224  void SetX(Scalar x);
225 
226  void SetY(Scalar y);
227 
228  void SetEta(Scalar eta);
229 
230  void SetR(Scalar r);
231 
232  void SetTheta(Scalar theta);
233 
234 #endif
235 
236 
237 private:
238 
240  T fZ;
242 
243 };
244 
245  } // end namespace Math
246 
247 } // end namespace ROOT
248 
249 // move implementations here to avoid circle dependencies
250 
252 
253 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
256 #include "Math/GenVector/Polar3D.h"
257 #endif
258 
259 namespace ROOT {
260 
261  namespace Math {
262 
263 template <class T>
265  *this = Cartesian3D<Scalar>(xx, yy, zz);
266 }
267 
268 #if defined(__MAKECINT__) || defined(G__DICTIONARY)
269 
270 
271  // ====== Set member functions for coordinates in other systems =======
272 
273 
274 
275 template <class T>
277  GenVector_exception e("Cylindrical3D::SetX() is not supposed to be called");
278  throw e;
279  Cartesian3D<Scalar> v(*this); v.SetX(xx); *this = Cylindrical3D<Scalar>(v);
280 }
281 template <class T>
283  GenVector_exception e("Cylindrical3D::SetY() is not supposed to be called");
284  throw e;
285  Cartesian3D<Scalar> v(*this); v.SetY(yy); *this = Cylindrical3D<Scalar>(v);
286 }
287 template <class T>
289  GenVector_exception e("Cylindrical3D::SetR() is not supposed to be called");
290  throw e;
291  Polar3D<Scalar> v(*this); v.SetR(r);
292  *this = Cylindrical3D<Scalar>(v);
293 }
294 template <class T>
296  GenVector_exception e("Cylindrical3D::SetTheta() is not supposed to be called");
297  throw e;
298  Polar3D<Scalar> v(*this); v.SetTheta(theta);
299  *this = Cylindrical3D<Scalar>(v);
300 }
301 template <class T>
303  GenVector_exception e("Cylindrical3D::SetEta() is not supposed to be called");
304  throw e;
305  CylindricalEta3D<Scalar> v(*this); v.SetEta(eta);
306  *this = Cylindrical3D<Scalar>(v);
307 }
308 
309 #endif
310 
311  } // end namespace Math
312 
313 } // end namespace ROOT
314 
315 
316 #endif /* ROOT_Math_GenVector_Cylindrical3D */
void GetCoordinates(Scalar &rho, Scalar &zz, Scalar &phi) const
get internal data into 3 Scalar numbers ( rho, z , phi)
void SetX(Scalar xx)
set the x coordinate value keeping y and z constant
Definition: Cartesian3D.h:125
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
Cylindrical3D(Scalar rho, Scalar zz, Scalar phi)
Construct from rho eta and phi values.
Definition: Cylindrical3D.h:54
Cylindrical3D(const Cylindrical3D &v)
copy constructor
Definition: Cylindrical3D.h:71
double T(double x)
Definition: ChebyshevPol.h:34
Class describing a cylindrical coordinate system based on eta (pseudorapidity) instead of z...
void SetPhi(T phi)
set the phi coordinate value keeping rho and z constant
Cylindrical3D(const CoordSystem &v)
Construct from any Vector or coordinate system implementing Rho(), Z() and Phi()
Definition: Cylindrical3D.h:62
Cylindrical3D & operator=(const Cylindrical3D &v)
assignment operator
Definition: Cylindrical3D.h:77
double cos(double)
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
void SetR(const T &r)
set the r coordinate value keeping theta and phi constant
Definition: Polar3D.h:132
Class describing a cylindrical coordinate system based on rho, z and phi.
Definition: Cylindrical3D.h:40
bool operator!=(const Cylindrical3D &rhs) const
void SetY(Scalar yy)
set the y coordinate value keeping x and z constant
Definition: Cartesian3D.h:130
void Negate()
negate the vector
double sin(double)
void SetCoordinates(Scalar rho, Scalar zz, Scalar phi)
Set internal data based on 3 Scalar numbers ( rho, z , phi)
Definition: Cylindrical3D.h:99
Cylindrical3D()
Default constructor with rho=z=phi=0.
Definition: Cylindrical3D.h:49
void SetTheta(const T &theta)
set the theta coordinate value keeping r and phi constant
Definition: Polar3D.h:139
ROOT::R::TRInterface & r
Definition: Object.C:4
#define M_PI
Definition: Rotated.cxx:105
void SetXYZ(Scalar x, Scalar y, Scalar z)
set all values using cartesian coordinates
SVector< double, 2 > v
Definition: Dict.h:5
auto * a
Definition: textangle.C:12
double floor(double)
void SetRho(T rho)
set the rho coordinate value keeping z and phi constant
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition: eta.h:48
void Scale(T a)
scale by a scalar quantity a – for cylindrical coords only rho and z change
void SetEta(T eta)
set the eta coordinate value keeping rho and phi constant
void SetCoordinates(const Scalar src[])
Set internal data based on an array of 3 Scalar numbers ( rho, z , phi)
Definition: Cylindrical3D.h:87
void SetZ(T zz)
set the z coordinate value keeping rho and phi constant
double atan2(double, double)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
bool operator==(const Cylindrical3D &rhs) const
Exact component-by-component equality.
Namespace for new Math classes and functions.
#define dest(otri, vertexptr)
Definition: triangle.c:1040
#define c(i)
Definition: RSha256.hxx:101
void GetCoordinates(Scalar dest[]) const
get internal data into an array of 3 Scalar numbers ( rho, z , phi)
Definition: Cylindrical3D.h:93
Class describing a polar coordinate system based on r, theta and phi Phi is restricted to be in the r...
Definition: Polar3D.h:43