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