13 #ifndef DDREC_VECTOR3D_H
14 #define DDREC_VECTOR3D_H 1
21 namespace dd4hep{
namespace rec {
56 Vector3D(
double x_val,
double y_val,
double z_val ) :
84 _x = v[0] ;
_y = v[1] ;
_z = v[2] ;
91 _x = v[0] ;
_y = v[1] ;
_z = v[2] ;
96 inline const Vector3D&
fill(
double x_val,
double y_val,
double z_val) {
97 _x = x_val ;
_y = y_val ;
_z = z_val ;
103 inline double x()
const {
return _x ; }
106 inline double y()
const {
return _y ; }
109 inline double z()
const {
return _z ; }
112 inline double&
x() {
return _x ; }
115 inline double&
y() {
return _y ; }
118 inline double&
z() {
return _z ; }
124 case 0:
return _x ; break ;
125 case 1:
return _y ; break ;
126 case 2:
return _z ; break ;
133 case 0:
return _x ; break ;
134 case 1:
return _y ; break ;
135 case 2:
return _z ; break ;
137 static double dummy(0.0) ;
142 inline double phi()
const {
144 return _x == 0.0 &&
_y == 0.0 ? 0.0 : atan2(
_y,
_x);
148 inline double rho()
const {
166 inline double r()
const {
173 inline double r2()
const {
181 return _x == 0.0 &&
_y == 0.0 &&
_z == 0.0 ? 0.0 : atan2(
rho(),
_z) ;
186 return _x * v.
x() +
_y * v.
y() +
_z * v.
z() ;
195 _x * v.
y() -
_y * v.
x() ) ;
207 inline operator const double*()
const {
224 if( fabs(
x() - b.
x() ) < epsilon &&
225 fabs(
y() - b.
y() ) < epsilon &&
226 fabs(
z() - b.
z() ) < epsilon )
296 if( a.
x() == b.
x() && a.
y() == b.
y() && a.
z() == b.
z() )
305 return Vector3D( s * v.
x() , s * v.
y() , s * v.
z() ) ;
316 return v0.
dot( v1 ) ;
338 _x = rho_val * cos( phi_val ) ;
339 _y = rho_val * sin( phi_val ) ;
347 inline Vector3D::Vector3D(
double r_val,
double phi_val,
double theta_val, Vector3D::Spherical (&)() ) {
348 double rst = r_val * sin( theta_val ) ;
349 _x = rst * cos( phi_val ) ;
350 _y = rst * sin( phi_val ) ;
351 _z = r_val * cos( theta_val ) ;
363 <<
" ) - [ phi: " << v.
phi()
364 <<
" , rho: " << v.
rho() <<
" ] "
365 <<
" [ theta: " << v.
theta()
366 <<
" , r: " << v.
r() <<
" ] " ;
Vector3D operator+(const Vector3D &a, const Vector3D &b)
Addition of two vectors.
double r() const
Spherical r/magnitude.
double theta() const
Polar angle - spherical.
static Cartesian cartesian()
Vector3D(const double *v)
Constructor for double array.
double trans2() const
Transversal component squared.
double dot(const Vector3D &v) const
Scalar product.
double rho() const
Transversal component - cylindrical 'r'.
Vector3D(const Vector3D &v)
Copy constructor.
Vector3D operator*(double s, const Vector3D &v)
Multiplication with scalar.
Vector3D cross(const Vector3D &v) const
Vector product.
Vector3D operator-(const Vector3D &a, const Vector3D &b)
Subtraction of two vectors.
double & operator[](int i)
Accessing x,y,z with bracket operator for assignment.
double r2() const
Spherical r/magnitude, squared.
std::ostream & operator<<(std::ostream &io, const FixedPadSizeTPCData &d)
double * array()
direct access to data as double* - allows modification
static Spherical spherical()
double y() const
Cartesian y coordinate.
Simple three dimensional vector providing the components for cartesian, cylindrical and spherical coo...
Vector3D(const float *v)
Constructor for float array.
const Vector3D & fill(const T &v)
fill vector from arbitrary class that defines operator[]
Vector3D(double x_val, double y_val, double z_val)
Default corrdinate system for initialization is cartesian.
const Vector3D & fill(double x_val, double y_val, double z_val)
fill from double values
double phi() const
Azimuthal angle - cylindrical and spherical.
const double * const_array() const
direct access to data as const double*
T to() const
Implicit templated conversion to anything that has a c'tor T(x,y,z) and accessor functions x()...
static Cylindrical cylindrical()
double z() const
Cartesian cartesian z coordinate.
Vector3D unit() const
Parallel unit vector.
double trans() const
Transversal component.
bool operator==(const Vector3D &a, const Vector3D &b)
Exact comparison of two vectors.
double x() const
Cartesian x coordinate.
double & y()
Assign to cartesian y coordinate.
bool isEqual(const Vector3D &b, double epsilon=1e-6)
Component wise comparison of two vectors - true if all components differ less than epsilon...
const Vector3D & fill(const double *v)
fill vector from double array
double & x()
Assign to cartesian x coordinate.
double operator[](int i) const
Accessing x,y,z with bracket operator.
Vector3D()
Default c'tor - zero vector.
Vector3D & operator=(const Vector3D &v)
Copy c'tor for three vectors from other packages - requires T::x(),T::y(), T::z().
double & z()
Assign to cartesian z coordinate.