CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
HepGeom::BasicVector3D< T > Class Template Reference

#include <BasicVector3D.h>

+ Inheritance diagram for HepGeom::BasicVector3D< T >:

Public Types

enum  {
  X = 0 , Y = 1 , Z = 2 , NUM_COORDINATES = 3 ,
  SIZE = NUM_COORDINATES
}
 

Public Member Functions

 BasicVector3D (T x1, T y1, T z1)
 
 BasicVector3D (const BasicVector3D< T > &)=default
 
template<typename U = T, typename = typename std::enable_if<!std::is_same<U,float>::value >::type>
 BasicVector3D (const BasicVector3D< float > &v)
 
 BasicVector3D (BasicVector3D< T > &&)=default
 
virtual ~BasicVector3D ()=default
 
 operator T* ()
 
 operator const T * () const
 
 operator CLHEP::Hep3Vector () const
 
BasicVector3D< T > & operator= (const BasicVector3D< T > &)=default
 
BasicVector3D< T > & operator= (BasicVector3D< T > &&)=default
 
BasicVector3D< T > & operator+= (const BasicVector3D< T > &v)
 
BasicVector3D< T > & operator-= (const BasicVector3D< T > &v)
 
BasicVector3D< T > & operator*= (double a)
 
BasicVector3D< T > & operator/= (double a)
 
operator() (int i) const
 
operator[] (int i) const
 
T & operator() (int i)
 
T & operator[] (int i)
 
x () const
 
y () const
 
z () const
 
void setX (T a)
 
void setY (T a)
 
void setZ (T a)
 
void set (T x1, T y1, T z1)
 
perp2 () const
 
perp () const
 
rho () const
 
void setPerp (T rh)
 
mag2 () const
 
mag () const
 
r () const
 
phi () const
 
theta () const
 
cosTheta () const
 
getR () const
 
getPhi () const
 
getTheta () const
 
void setMag (T ma)
 
void setR (T ma)
 
void setPhi (T ph)
 
void setTheta (T th)
 
pseudoRapidity () const
 
eta () const
 
getEta () const
 
void setEta (T a)
 
dot (const BasicVector3D< T > &v) const
 
BasicVector3D< T > cross (const BasicVector3D< T > &v) const
 
perp2 (const BasicVector3D< T > &v) const
 
perp (const BasicVector3D< T > &v) const
 
angle (const BasicVector3D< T > &v) const
 
BasicVector3D< T > unit () const
 
BasicVector3D< T > orthogonal () const
 
BasicVector3D< T > & rotateX (T a)
 
BasicVector3D< T > & rotateY (T a)
 
BasicVector3D< T > & rotateZ (T a)
 
BasicVector3D< T > & rotate (T a, const BasicVector3D< T > &v)
 
float pseudoRapidity () const
 
void setEta (float a)
 
float angle (const BasicVector3D< float > &v) const
 
BasicVector3D< float > & rotateX (float a)
 
BasicVector3D< float > & rotateY (float a)
 
BasicVector3D< float > & rotateZ (float a)
 
BasicVector3D< float > & rotate (float a, const BasicVector3D< float > &v)
 
double pseudoRapidity () const
 
void setEta (double a)
 
double angle (const BasicVector3D< double > &v) const
 
BasicVector3D< double > & rotateX (double a)
 
BasicVector3D< double > & rotateY (double a)
 
BasicVector3D< double > & rotateZ (double a)
 
BasicVector3D< double > & rotate (double a, const BasicVector3D< double > &v)
 

Protected Member Functions

 BasicVector3D ()
 

Protected Attributes

v_ [3]
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &, const BasicVector3D< float > &)
 
std::istream & operator>> (std::istream &, BasicVector3D< float > &)
 
BasicVector3D< float > operator+ (const BasicVector3D< float > &v)
 
BasicVector3D< float > operator+ (const BasicVector3D< float > &a, const BasicVector3D< float > &b)
 
BasicVector3D< float > operator- (const BasicVector3D< float > &v)
 
BasicVector3D< float > operator- (const BasicVector3D< float > &a, const BasicVector3D< float > &b)
 
BasicVector3D< float > operator* (const BasicVector3D< float > &v, double a)
 
float operator* (const BasicVector3D< float > &a, const BasicVector3D< float > &b)
 
BasicVector3D< float > operator* (double a, const BasicVector3D< float > &v)
 
BasicVector3D< float > operator/ (const BasicVector3D< float > &v, double a)
 
bool operator== (const BasicVector3D< float > &a, const BasicVector3D< float > &b)
 
bool operator!= (const BasicVector3D< float > &a, const BasicVector3D< float > &b)
 
std::ostream & operator<< (std::ostream &, const BasicVector3D< double > &)
 
std::istream & operator>> (std::istream &, BasicVector3D< double > &)
 
BasicVector3D< doubleoperator+ (const BasicVector3D< double > &v)
 
BasicVector3D< doubleoperator+ (const BasicVector3D< double > &a, const BasicVector3D< double > &b)
 
BasicVector3D< doubleoperator- (const BasicVector3D< double > &v)
 
BasicVector3D< doubleoperator- (const BasicVector3D< double > &a, const BasicVector3D< double > &b)
 
BasicVector3D< doubleoperator* (const BasicVector3D< double > &v, double a)
 
double operator* (const BasicVector3D< double > &a, const BasicVector3D< double > &b)
 
BasicVector3D< doubleoperator* (double a, const BasicVector3D< double > &v)
 
BasicVector3D< doubleoperator/ (const BasicVector3D< double > &v, double a)
 
bool operator== (const BasicVector3D< double > &a, const BasicVector3D< double > &b)
 
bool operator!= (const BasicVector3D< double > &a, const BasicVector3D< double > &b)
 

Detailed Description

template<class T>
class HepGeom::BasicVector3D< T >

Base class for Point3D<T>, Vector3D<T> and Normal3D<T>. It defines only common functionality for those classes and should not be used as separate class.

Author
Evgeni Chernyaev Evgue.nosp@m.ni.T.nosp@m.chern.nosp@m.iaev.nosp@m.@cern.nosp@m..ch

Definition at line 29 of file BasicVector3D.h.

Member Enumeration Documentation

◆ anonymous enum

template<class T >
anonymous enum

Safe indexing of the coordinates when using with matrices, arrays, etc.

Enumerator

index for x-component

index for y-component

index for z-component

NUM_COORDINATES 

number of components

SIZE 

number of components

Definition at line 43 of file BasicVector3D.h.

43 {
44 X = 0, /**< index for x-component */
45 Y = 1, /**< index for y-component */
46 Z = 2, /**< index for z-component */
47 NUM_COORDINATES = 3, /**< number of components */
48 SIZE = NUM_COORDINATES /**< number of components */
49 };

Constructor & Destructor Documentation

◆ BasicVector3D() [1/5]

template<class T >
HepGeom::BasicVector3D< T >::BasicVector3D ( )
inlineprotected

Default constructor. It is protected - this class should not be instantiated directly.

Definition at line 37 of file BasicVector3D.h.

37{ v_[0] = 0; v_[1] = 0; v_[2] = 0; }

◆ BasicVector3D() [2/5]

template<class T >
HepGeom::BasicVector3D< T >::BasicVector3D ( x1,
y1,
z1 
)
inline

Constructor from three numbers.

Definition at line 53 of file BasicVector3D.h.

53{ v_[0] = x1; v_[1] = y1; v_[2] = z1; }

◆ BasicVector3D() [3/5]

template<class T >
HepGeom::BasicVector3D< T >::BasicVector3D ( const BasicVector3D< T > &  )
default

Copy constructor.

◆ BasicVector3D() [4/5]

template<class T >
template<typename U = T, typename = typename std::enable_if<!std::is_same<U,float>::value >::type>
HepGeom::BasicVector3D< T >::BasicVector3D ( const BasicVector3D< float > &  v)
inline

Constructor for BasicVector3D<double> from BasicVector3D<float>.

Definition at line 63 of file BasicVector3D.h.

63 {
64 v_[0] = v.x(); v_[1] = v.y(); v_[2] = v.z();
65 }

◆ BasicVector3D() [5/5]

template<class T >
HepGeom::BasicVector3D< T >::BasicVector3D ( BasicVector3D< T > &&  )
default

Move constructor.

◆ ~BasicVector3D()

template<class T >
virtual HepGeom::BasicVector3D< T >::~BasicVector3D ( )
virtualdefault

Destructor.

Member Function Documentation

◆ angle() [1/3]

double HepGeom::BasicVector3D< double >::angle ( const BasicVector3D< double > &  v) const

Definition at line 193 of file BasicVector3D.cc.

193 {
194 double cosa = 0;
195 double ptot = mag()*v.mag();
196 if(ptot > 0) {
197 cosa = dot(v)/ptot;
198 if(cosa > 1) cosa = 1;
199 if(cosa < -1) cosa = -1;
200 }
201 return std::acos(cosa);
202 }
T dot(const BasicVector3D< T > &v) const

◆ angle() [2/3]

float HepGeom::BasicVector3D< float >::angle ( const BasicVector3D< float > &  v) const

Definition at line 37 of file BasicVector3D.cc.

37 {
38 double cosa = 0;
39 double ptot = mag()*v.mag();
40 if(ptot > 0) {
41 cosa = dot(v)/ptot;
42 if(cosa > 1) cosa = 1;
43 if(cosa < -1) cosa = -1;
44 }
45 return std::acos(cosa);
46 }

◆ angle() [3/3]

template<class T >
T HepGeom::BasicVector3D< T >::angle ( const BasicVector3D< T > &  v) const

Returns angle w.r.t. another vector.

◆ cosTheta()

template<class T >
T HepGeom::BasicVector3D< T >::cosTheta ( ) const
inline

Gets cosine of polar angle.

Definition at line 219 of file BasicVector3D.h.

219{ T ma = mag(); return ma == 0 ? 1 : z()/ma; }

◆ cross()

template<class T >
BasicVector3D< T > HepGeom::BasicVector3D< T >::cross ( const BasicVector3D< T > &  v) const
inline

Vector product.

Definition at line 283 of file BasicVector3D.h.

283 {
284 return BasicVector3D<T>(y()*v.z()-v.y()*z(),
285 z()*v.x()-v.z()*x(),
286 x()*v.y()-v.x()*y());
287 }

Referenced by HepGeom::Transform3D::Transform3D().

◆ dot()

template<class T >
T HepGeom::BasicVector3D< T >::dot ( const BasicVector3D< T > &  v) const
inline

Scalar product.

Definition at line 277 of file BasicVector3D.h.

277 {
278 return x()*v.x()+y()*v.y()+z()*v.z();
279 }

Referenced by HepGeom::BasicVector3D< T >::operator*(), and HepGeom::BasicVector3D< T >::perp2().

◆ eta()

template<class T >
T HepGeom::BasicVector3D< T >::eta ( ) const
inline

Gets pseudo-rapidity.

Definition at line 262 of file BasicVector3D.h.

262{ return pseudoRapidity(); }

◆ getEta()

template<class T >
T HepGeom::BasicVector3D< T >::getEta ( ) const
inline

Gets pseudo-rapidity.

Definition at line 265 of file BasicVector3D.h.

265{ return pseudoRapidity(); }

◆ getPhi()

template<class T >
T HepGeom::BasicVector3D< T >::getPhi ( ) const
inline

Gets phi-component in spherical coordinate system

Definition at line 226 of file BasicVector3D.h.

226{ return phi(); }

◆ getR()

template<class T >
T HepGeom::BasicVector3D< T >::getR ( ) const
inline

Gets r-component in spherical coordinate system

Definition at line 223 of file BasicVector3D.h.

223{ return r(); }

◆ getTheta()

template<class T >
T HepGeom::BasicVector3D< T >::getTheta ( ) const
inline

Gets theta-component in spherical coordinate system

Definition at line 229 of file BasicVector3D.h.

229{ return theta(); }

◆ mag()

◆ mag2()

template<class T >
T HepGeom::BasicVector3D< T >::mag2 ( ) const
inline

Gets magnitude squared of the vector.

Definition at line 200 of file BasicVector3D.h.

200{ return x()*x()+y()*y()+z()*z(); }

Referenced by HepGeom::Point3D< float >::distance2(), HepGeom::Point3D< double >::distance2(), HepGeom::BasicVector3D< T >::mag(), and HepGeom::BasicVector3D< T >::perp2().

◆ operator CLHEP::Hep3Vector()

template<class T >
HepGeom::BasicVector3D< T >::operator CLHEP::Hep3Vector ( ) const
inline

Conversion (cast) to CLHEP::Hep3Vector. This operator is needed only for backward compatibility and in principle should not exit.

Definition at line 92 of file BasicVector3D.h.

92{ return CLHEP::Hep3Vector(x(),y(),z()); }

◆ operator const T *()

template<class T >
HepGeom::BasicVector3D< T >::operator const T * ( ) const
inline

Conversion (cast) to ordinary const array.

Definition at line 85 of file BasicVector3D.h.

85{ return v_; }

◆ operator T*()

template<class T >
HepGeom::BasicVector3D< T >::operator T* ( )
inline

Conversion (cast) to ordinary array.

Definition at line 81 of file BasicVector3D.h.

81{ return v_; }

◆ operator()() [1/2]

template<class T >
T & HepGeom::BasicVector3D< T >::operator() ( int  i)
inline

Sets components by index.

Definition at line 138 of file BasicVector3D.h.

138{ return v_[i]; }

◆ operator()() [2/2]

template<class T >
T HepGeom::BasicVector3D< T >::operator() ( int  i) const
inline

Gets components by index.

Definition at line 131 of file BasicVector3D.h.

131{ return v_[i]; }

◆ operator*=()

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::operator*= ( double  a)
inline

Multiplication by scalar.

Definition at line 116 of file BasicVector3D.h.

116 {
117 v_[0] *= a; v_[1] *= a; v_[2] *= a; return *this;
118 }

◆ operator+=()

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::operator+= ( const BasicVector3D< T > &  v)
inline

Addition.

Definition at line 106 of file BasicVector3D.h.

106 {
107 v_[0] += v.v_[0]; v_[1] += v.v_[1]; v_[2] += v.v_[2]; return *this;
108 }

◆ operator-=()

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::operator-= ( const BasicVector3D< T > &  v)
inline

Subtraction.

Definition at line 111 of file BasicVector3D.h.

111 {
112 v_[0] -= v.v_[0]; v_[1] -= v.v_[1]; v_[2] -= v.v_[2]; return *this;
113 }

◆ operator/=()

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::operator/= ( double  a)
inline

Division by scalar.

Definition at line 121 of file BasicVector3D.h.

121 {
122 v_[0] /= a; v_[1] /= a; v_[2] /= a; return *this;
123 }

◆ operator=() [1/2]

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::operator= ( BasicVector3D< T > &&  )
default

Move assignment.

◆ operator=() [2/2]

◆ operator[]() [1/2]

template<class T >
T & HepGeom::BasicVector3D< T >::operator[] ( int  i)
inline

Sets components by index.

Definition at line 141 of file BasicVector3D.h.

141{ return v_[i]; }

◆ operator[]() [2/2]

template<class T >
T HepGeom::BasicVector3D< T >::operator[] ( int  i) const
inline

Gets components by index.

Definition at line 134 of file BasicVector3D.h.

134{ return v_[i]; }

◆ orthogonal()

template<class T >
BasicVector3D< T > HepGeom::BasicVector3D< T >::orthogonal ( ) const
inline

Returns orthogonal vector.

Definition at line 320 of file BasicVector3D.h.

320 {
321 T dx = x() < 0 ? -x() : x();
322 T dy = y() < 0 ? -y() : y();
323 T dz = z() < 0 ? -z() : z();
324 if (dx < dy) {
325 return dx < dz ?
326 BasicVector3D<T>(0,z(),-y()) : BasicVector3D<T>(y(),-x(),0);
327 }else{
328 return dy < dz ?
329 BasicVector3D<T>(-z(),0,x()) : BasicVector3D<T>(y(),-x(),0);
330 }
331 }

◆ perp() [1/2]

template<class T >
T HepGeom::BasicVector3D< T >::perp ( ) const
inline

◆ perp() [2/2]

template<class T >
T HepGeom::BasicVector3D< T >::perp ( const BasicVector3D< T > &  v) const
inline

Returns transverse component w.r.t. given axis.

Definition at line 298 of file BasicVector3D.h.

298 {
299 return std::sqrt(perp2(v));
300 }

◆ perp2() [1/2]

template<class T >
T HepGeom::BasicVector3D< T >::perp2 ( ) const
inline

Gets transverse component squared.

Definition at line 177 of file BasicVector3D.h.

177{ return x()*x()+y()*y(); }

Referenced by HepGeom::BasicVector3D< T >::perp().

◆ perp2() [2/2]

template<class T >
T HepGeom::BasicVector3D< T >::perp2 ( const BasicVector3D< T > &  v) const
inline

Returns transverse component w.r.t. given axis squared.

Definition at line 291 of file BasicVector3D.h.

291 {
292 T tot = v.mag2(), s = dot(v);
293 return tot > 0 ? mag2()-s*s/tot : mag2();
294 }

◆ phi()

template<class T >
T HepGeom::BasicVector3D< T >::phi ( ) const
inline

Gets azimuth angle.

Definition at line 209 of file BasicVector3D.h.

209 {
210 return x() == 0 && y() == 0 ? 0 : std::atan2(y(),x());
211 }

Referenced by HepGeom::BasicVector3D< T >::getPhi(), main(), and HepGeom::BasicVector3D< T >::setTheta().

◆ pseudoRapidity() [1/3]

template<class T >
T HepGeom::BasicVector3D< T >::pseudoRapidity ( ) const

Gets pseudo-rapidity: -ln(tan(theta/2))

Referenced by HepGeom::BasicVector3D< T >::eta(), and HepGeom::BasicVector3D< T >::getEta().

◆ pseudoRapidity() [2/3]

float HepGeom::BasicVector3D< float >::pseudoRapidity ( ) const

Definition at line 14 of file BasicVector3D.cc.

14 {
15 float ma = mag(), dz = z();
16 if (ma == 0) return 0;
17 if (ma == dz) return FLT_MAX;
18 if (ma == -dz) return -FLT_MAX;
19 return 0.5*std::log((ma+dz)/(ma-dz));
20 }

◆ pseudoRapidity() [3/3]

double HepGeom::BasicVector3D< double >::pseudoRapidity ( ) const

Definition at line 170 of file BasicVector3D.cc.

170 {
171 double ma = mag(), dz = z();
172 if (ma == 0) return 0;
173 if (ma == dz) return DBL_MAX;
174 if (ma == -dz) return -DBL_MAX;
175 return 0.5*std::log((ma+dz)/(ma-dz));
176 }

◆ r()

template<class T >
T HepGeom::BasicVector3D< T >::r ( ) const
inline

Gets r-component in spherical coordinate system

Definition at line 206 of file BasicVector3D.h.

206{ return mag(); }

Referenced by HepGeom::BasicVector3D< T >::getR().

◆ rho()

template<class T >
T HepGeom::BasicVector3D< T >::rho ( ) const
inline

Gets rho-component in cylindrical coordinate system

Definition at line 183 of file BasicVector3D.h.

183{ return perp(); }

◆ rotate() [1/3]

BasicVector3D< double > & HepGeom::BasicVector3D< double >::rotate ( double  a,
const BasicVector3D< double > &  v 
)

Definition at line 234 of file BasicVector3D.cc.

234 {
235 if (a == 0) return *this;
236 double cx = v.x(), cy = v.y(), cz = v.z();
237 double ll = std::sqrt(cx*cx + cy*cy + cz*cz);
238 if (ll == 0) {
239 std::cerr << "BasicVector<double>::rotate() : zero axis" << std::endl;
240 return *this;
241 }
242 double cosa = std::cos(a), sina = std::sin(a);
243 cx /= ll; cy /= ll; cz /= ll;
244
245 double xx = cosa + (1-cosa)*cx*cx;
246 double xy = (1-cosa)*cx*cy - sina*cz;
247 double xz = (1-cosa)*cx*cz + sina*cy;
248
249 double yx = (1-cosa)*cy*cx + sina*cz;
250 double yy = cosa + (1-cosa)*cy*cy;
251 double yz = (1-cosa)*cy*cz - sina*cx;
252
253 double zx = (1-cosa)*cz*cx - sina*cy;
254 double zy = (1-cosa)*cz*cy + sina*cx;
255 double zz = cosa + (1-cosa)*cz*cz;
256
257 cx = x(); cy = y(); cz = z();
258 set(xx*cx+xy*cy+xz*cz, yx*cx+yy*cy+yz*cz, zx*cx+zy*cy+zz*cz);
259 return *this;
260 }
void set(T x1, T y1, T z1)

◆ rotate() [2/3]

BasicVector3D< float > & HepGeom::BasicVector3D< float >::rotate ( float  a,
const BasicVector3D< float > &  v 
)

Definition at line 78 of file BasicVector3D.cc.

78 {
79 if (a == 0) return *this;
80 double cx = v.x(), cy = v.y(), cz = v.z();
81 double ll = std::sqrt(cx*cx + cy*cy + cz*cz);
82 if (ll == 0) {
83 std::cerr << "BasicVector<float>::rotate() : zero axis" << std::endl;
84 return *this;
85 }
86 double cosa = std::cos(a), sina = std::sin(a);
87 cx /= ll; cy /= ll; cz /= ll;
88
89 double xx = cosa + (1-cosa)*cx*cx;
90 double xy = (1-cosa)*cx*cy - sina*cz;
91 double xz = (1-cosa)*cx*cz + sina*cy;
92
93 double yx = (1-cosa)*cy*cx + sina*cz;
94 double yy = cosa + (1-cosa)*cy*cy;
95 double yz = (1-cosa)*cy*cz - sina*cx;
96
97 double zx = (1-cosa)*cz*cx - sina*cy;
98 double zy = (1-cosa)*cz*cy + sina*cx;
99 double zz = cosa + (1-cosa)*cz*cz;
100
101 cx = x(); cy = y(); cz = z();
102 set(xx*cx+xy*cy+xz*cz, yx*cx+yy*cy+yz*cz, zx*cx+zy*cy+zz*cz);
103 return *this;
104 }

◆ rotate() [3/3]

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::rotate ( a,
const BasicVector3D< T > &  v 
)

Rotates around the axis specified by another vector.

◆ rotateX() [1/3]

Definition at line 206 of file BasicVector3D.cc.

206 {
207 double sina = std::sin(a), cosa = std::cos(a), dy = y(), dz = z();
208 setY(dy*cosa-dz*sina);
209 setZ(dz*cosa+dy*sina);
210 return *this;
211 }

◆ rotateX() [2/3]

BasicVector3D< float > & HepGeom::BasicVector3D< float >::rotateX ( float  a)

Definition at line 50 of file BasicVector3D.cc.

50 {
51 double sina = std::sin(a), cosa = std::cos(a), dy = y(), dz = z();
52 setY(dy*cosa-dz*sina);
53 setZ(dz*cosa+dy*sina);
54 return *this;
55 }

◆ rotateX() [3/3]

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::rotateX ( a)

Rotates around x-axis.

◆ rotateY() [1/3]

Definition at line 215 of file BasicVector3D.cc.

215 {
216 double sina = std::sin(a), cosa = std::cos(a), dz = z(), dx = x();
217 setZ(dz*cosa-dx*sina);
218 setX(dx*cosa+dz*sina);
219 return *this;
220 }

◆ rotateY() [2/3]

BasicVector3D< float > & HepGeom::BasicVector3D< float >::rotateY ( float  a)

Definition at line 59 of file BasicVector3D.cc.

59 {
60 double sina = std::sin(a), cosa = std::cos(a), dz = z(), dx = x();
61 setZ(dz*cosa-dx*sina);
62 setX(dx*cosa+dz*sina);
63 return *this;
64 }

◆ rotateY() [3/3]

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::rotateY ( a)

Rotates around y-axis.

◆ rotateZ() [1/3]

Definition at line 224 of file BasicVector3D.cc.

224 {
225 double sina = std::sin(a), cosa = std::cos(a), dx = x(), dy = y();
226 setX(dx*cosa-dy*sina);
227 setY(dy*cosa+dx*sina);
228 return *this;
229 }

◆ rotateZ() [2/3]

BasicVector3D< float > & HepGeom::BasicVector3D< float >::rotateZ ( float  a)

Definition at line 68 of file BasicVector3D.cc.

68 {
69 double sina = std::sin(a), cosa = std::cos(a), dx = x(), dy = y();
70 setX(dx*cosa-dy*sina);
71 setY(dy*cosa+dx*sina);
72 return *this;
73 }

◆ rotateZ() [3/3]

template<class T >
BasicVector3D< T > & HepGeom::BasicVector3D< T >::rotateZ ( a)

Rotates around z-axis.

◆ set()

template<class T >
void HepGeom::BasicVector3D< T >::set ( x1,
y1,
z1 
)
inline

Sets components in cartesian coordinate system.

Definition at line 169 of file BasicVector3D.h.

169{ v_[0] = x1; v_[1] = y1; v_[2] = z1; }

Referenced by HepGeom::BasicVector3D< T >::setTheta().

◆ setEta() [1/3]

void HepGeom::BasicVector3D< double >::setEta ( double  a)

Definition at line 180 of file BasicVector3D.cc.

180 {
181 double ma = mag();
182 if (ma == 0) return;
183 double tanHalfTheta = std::exp(-a);
184 double tanHalfTheta2 = tanHalfTheta * tanHalfTheta;
185 double cosTheta1 = (1 - tanHalfTheta2) / (1 + tanHalfTheta2);
186 double rh = ma * std::sqrt(1 - cosTheta1*cosTheta1);
187 double ph = phi();
188 set(rh*std::cos(ph), rh*std::sin(ph), ma*cosTheta1);
189 }

◆ setEta() [2/3]

void HepGeom::BasicVector3D< float >::setEta ( float  a)

Definition at line 24 of file BasicVector3D.cc.

24 {
25 double ma = mag();
26 if (ma == 0) return;
27 double tanHalfTheta = std::exp(-a);
28 double tanHalfTheta2 = tanHalfTheta * tanHalfTheta;
29 double cosTheta1 = (1 - tanHalfTheta2) / (1 + tanHalfTheta2);
30 double rh = ma * std::sqrt(1 - cosTheta1*cosTheta1);
31 double ph = phi();
32 set(rh*std::cos(ph), rh*std::sin(ph), ma*cosTheta1);
33 }

◆ setEta() [3/3]

template<class T >
void HepGeom::BasicVector3D< T >::setEta ( a)

Sets pseudo-rapidity, keeping magnitude and phi fixed.

◆ setMag()

template<class T >
void HepGeom::BasicVector3D< T >::setMag ( ma)
inline

Sets magnitude.

Definition at line 233 of file BasicVector3D.h.

233 {
234 T factor = mag();
235 if (factor > 0) {
236 factor = ma/factor; v_[0] *= factor; v_[1] *= factor; v_[2] *= factor;
237 }
238 }

Referenced by HepGeom::BasicVector3D< T >::setR().

◆ setPerp()

template<class T >
void HepGeom::BasicVector3D< T >::setPerp ( rh)
inline

Sets transverse component keeping phi and z constant.

Definition at line 187 of file BasicVector3D.h.

187 {
188 T factor = perp();
189 if (factor > 0) {
190 factor = rh/factor; v_[0] *= factor; v_[1] *= factor;
191 }
192 }

◆ setPhi()

template<class T >
void HepGeom::BasicVector3D< T >::setPhi ( ph)
inline

Sets phi-component in spherical coordinate system.

Definition at line 244 of file BasicVector3D.h.

244{ T xy = perp(); setX(xy*std::cos(ph)); setY(xy*std::sin(ph)); }

◆ setR()

template<class T >
void HepGeom::BasicVector3D< T >::setR ( ma)
inline

Sets r-component in spherical coordinate system.

Definition at line 241 of file BasicVector3D.h.

241{ setMag(ma); }

◆ setTheta()

template<class T >
void HepGeom::BasicVector3D< T >::setTheta ( th)
inline

Sets theta-component in spherical coordinate system.

Definition at line 247 of file BasicVector3D.h.

247 {
248 T ma = mag();
249 T ph = phi();
250 set(ma*std::sin(th)*std::cos(ph), ma*std::sin(th)*std::sin(ph), ma*std::cos(th));
251 }

◆ setX()

template<class T >
void HepGeom::BasicVector3D< T >::setX ( a)
inline

Sets x-component in cartesian coordinate system.

Definition at line 159 of file BasicVector3D.h.

159{ v_[0] = a; }

Referenced by HepGeom::BasicVector3D< T >::operator>>(), and HepGeom::BasicVector3D< T >::setPhi().

◆ setY()

template<class T >
void HepGeom::BasicVector3D< T >::setY ( a)
inline

Sets y-component in cartesian coordinate system.

Definition at line 162 of file BasicVector3D.h.

162{ v_[1] = a; }

Referenced by HepGeom::BasicVector3D< T >::operator>>(), and HepGeom::BasicVector3D< T >::setPhi().

◆ setZ()

template<class T >
void HepGeom::BasicVector3D< T >::setZ ( a)
inline

Sets z-component in cartesian coordinate system.

Definition at line 165 of file BasicVector3D.h.

165{ v_[2] = a; }

Referenced by HepGeom::BasicVector3D< T >::operator>>().

◆ theta()

template<class T >
T HepGeom::BasicVector3D< T >::theta ( ) const
inline

Gets polar angle.

Definition at line 214 of file BasicVector3D.h.

214 {
215 return x() == 0 && y() == 0 && z() == 0 ? 0 : std::atan2(perp(),z());
216 }

Referenced by HepGeom::BasicVector3D< T >::getTheta(), and main().

◆ unit()

template<class T >
BasicVector3D< T > HepGeom::BasicVector3D< T >::unit ( ) const
inline

Returns unit vector parallel to this.

Definition at line 312 of file BasicVector3D.h.

312 {
313 T len = mag();
314 return (len > 0) ?
315 BasicVector3D<T>(x()/len, y()/len, z()/len) : BasicVector3D<T>();
316 }

Referenced by main().

◆ x()

◆ y()

◆ z()

Friends And Related Function Documentation

◆ operator!=() [1/2]

template<class T >
bool operator!= ( const BasicVector3D< double > &  a,
const BasicVector3D< double > &  b 
)
related

Comparison of two vectors for inequality.

Definition at line 564 of file BasicVector3D.h.

565 {
566 return (a.x()!=b.x() || a.y()!=b.y() || a.z()!=b.z());
567 }

◆ operator!=() [2/2]

template<class T >
bool operator!= ( const BasicVector3D< float > &  a,
const BasicVector3D< float > &  b 
)
related

Comparison of two vectors for inequality.

Definition at line 455 of file BasicVector3D.h.

455 {
456 return (a.x()!=b.x() || a.y()!=b.y() || a.z()!=b.z());
457 }

◆ operator*() [1/6]

template<class T >
double operator* ( const BasicVector3D< double > &  a,
const BasicVector3D< double > &  b 
)
related

Scalar product of two vectors.

Definition at line 527 of file BasicVector3D.h.

527 {
528 return a.dot(b);
529 }

◆ operator*() [2/6]

template<class T >
BasicVector3D< double > operator* ( const BasicVector3D< double > &  v,
double  a 
)
related

Multiplication vector by scalar.

Definition at line 518 of file BasicVector3D.h.

518 {
519 return BasicVector3D<double>(v.x()*a, v.y()*a, v.z()*a);
520 }

◆ operator*() [3/6]

template<class T >
float operator* ( const BasicVector3D< float > &  a,
const BasicVector3D< float > &  b 
)
related

Scalar product of two vectors.

Definition at line 419 of file BasicVector3D.h.

419 {
420 return a.dot(b);
421 }

◆ operator*() [4/6]

template<class T >
BasicVector3D< float > operator* ( const BasicVector3D< float > &  v,
double  a 
)
related

Multiplication vector by scalar.

Definition at line 410 of file BasicVector3D.h.

410 {
411 return BasicVector3D<float>(v.x()*static_cast<float>(a), v.y()*static_cast<float>(a), v.z()*static_cast<float>(a));
412 }

◆ operator*() [5/6]

template<class T >
BasicVector3D< double > operator* ( double  a,
const BasicVector3D< double > &  v 
)
related

Multiplication scalar by vector.

Definition at line 536 of file BasicVector3D.h.

536 {
537 return BasicVector3D<double>(a*v.x(), a*v.y(), a*v.z());
538 }

◆ operator*() [6/6]

template<class T >
BasicVector3D< float > operator* ( double  a,
const BasicVector3D< float > &  v 
)
related

Multiplication scalar by vector.

Definition at line 428 of file BasicVector3D.h.

428 {
429 return BasicVector3D<float>(static_cast<float>(a)*v.x(), static_cast<float>(a)*v.y(), static_cast<float>(a)*v.z());
430 }

◆ operator+() [1/4]

template<class T >
BasicVector3D< double > operator+ ( const BasicVector3D< double > &  a,
const BasicVector3D< double > &  b 
)
related

Addition of two vectors.

Definition at line 491 of file BasicVector3D.h.

491 {
492 return BasicVector3D<double>(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
493 }

◆ operator+() [2/4]

template<class T >
BasicVector3D< double > operator+ ( const BasicVector3D< double > &  v)
related

Unary plus.

Definition at line 484 of file BasicVector3D.h.

484{ return v; }

◆ operator+() [3/4]

template<class T >
BasicVector3D< float > operator+ ( const BasicVector3D< float > &  a,
const BasicVector3D< float > &  b 
)
related

Addition of two vectors.

Definition at line 383 of file BasicVector3D.h.

383 {
384 return BasicVector3D<float>(a.x()+b.x(), a.y()+b.y(), a.z()+b.z());
385 }

◆ operator+() [4/4]

template<class T >
BasicVector3D< float > operator+ ( const BasicVector3D< float > &  v)
related

Unary plus.

Definition at line 376 of file BasicVector3D.h.

376{ return v; }

◆ operator-() [1/4]

template<class T >
BasicVector3D< double > operator- ( const BasicVector3D< double > &  a,
const BasicVector3D< double > &  b 
)
related

Subtraction of two vectors.

Definition at line 509 of file BasicVector3D.h.

509 {
510 return BasicVector3D<double>(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
511 }

◆ operator-() [2/4]

template<class T >
BasicVector3D< double > operator- ( const BasicVector3D< double > &  v)
related

Unary minus.

Definition at line 500 of file BasicVector3D.h.

500 {
501 return BasicVector3D<double>(-v.x(), -v.y(), -v.z());
502 }

◆ operator-() [3/4]

template<class T >
BasicVector3D< float > operator- ( const BasicVector3D< float > &  a,
const BasicVector3D< float > &  b 
)
related

Subtraction of two vectors.

Definition at line 401 of file BasicVector3D.h.

401 {
402 return BasicVector3D<float>(a.x()-b.x(), a.y()-b.y(), a.z()-b.z());
403 }

◆ operator-() [4/4]

template<class T >
BasicVector3D< float > operator- ( const BasicVector3D< float > &  v)
related

Unary minus.

Definition at line 392 of file BasicVector3D.h.

392 {
393 return BasicVector3D<float>(-v.x(), -v.y(), -v.z());
394 }

◆ operator/() [1/2]

template<class T >
BasicVector3D< double > operator/ ( const BasicVector3D< double > &  v,
double  a 
)
related

Division vector by scalar.

Definition at line 545 of file BasicVector3D.h.

545 {
546 return BasicVector3D<double>(v.x()/a, v.y()/a, v.z()/a);
547 }

◆ operator/() [2/2]

template<class T >
BasicVector3D< float > operator/ ( const BasicVector3D< float > &  v,
double  a 
)
related

Division vector by scalar.

Definition at line 437 of file BasicVector3D.h.

437 {
438 return BasicVector3D<float>(v.x()/static_cast<float>(a), v.y()/static_cast<float>(a), v.z()/static_cast<float>(a));
439 }

◆ operator<<() [1/2]

template<class T >
std::ostream & operator<< ( std::ostream &  ,
const BasicVector3D< double > &   
)
related

Output to stream.

Definition at line 263 of file BasicVector3D.cc.

265 {
266 return os << "(" << a.x() << "," << a.y() << "," << a.z() << ")";
267 }

◆ operator<<() [2/2]

template<class T >
std::ostream & operator<< ( std::ostream &  ,
const BasicVector3D< float > &   
)
related

Output to stream.

Definition at line 107 of file BasicVector3D.cc.

109 {
110 return os << "(" << a.x() << "," << a.y() << "," << a.z() << ")";
111 }

◆ operator==() [1/2]

template<class T >
bool operator== ( const BasicVector3D< double > &  a,
const BasicVector3D< double > &  b 
)
related

Comparison of two vectors for equality.

Definition at line 554 of file BasicVector3D.h.

555 {
556 return (a.x()==b.x() && a.y()==b.y() && a.z()==b.z());
557 }

◆ operator==() [2/2]

template<class T >
bool operator== ( const BasicVector3D< float > &  a,
const BasicVector3D< float > &  b 
)
related

Comparison of two vectors for equality.

Definition at line 446 of file BasicVector3D.h.

446 {
447 return (a.x()==b.x() && a.y()==b.y() && a.z()==b.z());
448 }

◆ operator>>() [1/2]

template<class T >
std::istream & operator>> ( std::istream &  ,
BasicVector3D< double > &   
)
related

Input from stream.

Definition at line 271 of file BasicVector3D.cc.

272 {
273 // Required format is ( a, b, c ) that is, three numbers, preceded by
274 // (, followed by ), and separated by commas. The three numbers are
275 // taken as x, y, z.
276
277 double x, y, z;
278 char c;
279
280 is >> std::ws >> c;
281 // ws is defined to invoke eatwhite(istream & )
282 // see (Stroustrup gray book) page 333 and 345.
283 if (is.fail() || c != '(' ) {
284 std::cerr
285 << "Could not find required opening parenthesis "
286 << "in input of a BasicVector3D<double>"
287 << std::endl;
288 return is;
289 }
290
291 is >> x >> std::ws >> c;
292 if (is.fail() || c != ',' ) {
293 std::cerr
294 << "Could not find x value and required trailing comma "
295 << "in input of a BasicVector3D<double>"
296 << std::endl;
297 return is;
298 }
299
300 is >> y >> std::ws >> c;
301 if (is.fail() || c != ',' ) {
302 std::cerr
303 << "Could not find y value and required trailing comma "
304 << "in input of a BasicVector3D<double>"
305 << std::endl;
306 return is;
307 }
308
309 is >> z >> std::ws >> c;
310 if (is.fail() || c != ')' ) {
311 std::cerr
312 << "Could not find z value and required close parenthesis "
313 << "in input of a BasicVector3D<double>"
314 << std::endl;
315 return is;
316 }
317
318 a.setX(x);
319 a.setY(y);
320 a.setZ(z);
321 return is;
322 }

◆ operator>>() [2/2]

template<class T >
std::istream & operator>> ( std::istream &  ,
BasicVector3D< float > &   
)
related

Input from stream.

Definition at line 115 of file BasicVector3D.cc.

116 {
117 // Required format is ( a, b, c ) that is, three numbers, preceded by
118 // (, followed by ), and separated by commas. The three numbers are
119 // taken as x, y, z.
120
121 float x, y, z;
122 char c;
123
124 is >> std::ws >> c;
125 // ws is defined to invoke eatwhite(istream & )
126 // see (Stroustrup gray book) page 333 and 345.
127 if (is.fail() || c != '(' ) {
128 std::cerr
129 << "Could not find required opening parenthesis "
130 << "in input of a BasicVector3D<float>"
131 << std::endl;
132 return is;
133 }
134
135 is >> x >> std::ws >> c;
136 if (is.fail() || c != ',' ) {
137 std::cerr
138 << "Could not find x value and required trailing comma "
139 << "in input of a BasicVector3D<float>"
140 << std::endl;
141 return is;
142 }
143
144 is >> y >> std::ws >> c;
145 if (is.fail() || c != ',' ) {
146 std::cerr
147 << "Could not find y value and required trailing comma "
148 << "in input of a BasicVector3D<float>"
149 << std::endl;
150 return is;
151 }
152
153 is >> z >> std::ws >> c;
154 if (is.fail() || c != ')' ) {
155 std::cerr
156 << "Could not find z value and required close parenthesis "
157 << "in input of a BasicVector3D<float>"
158 << std::endl;
159 return is;
160 }
161
162 a.setX(x);
163 a.setY(y);
164 a.setZ(z);
165 return is;
166 }

Member Data Documentation

◆ v_


The documentation for this class was generated from the following file: