g4tools  5.4.0
vec3d
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_vec3d
5 #define tools_vec3d
6 
7 #include "vec3"
8 #include "../S_STRING"
9 #include <cmath>
10 
11 namespace tools {
12 
13 class vec3d : public vec3<double> {
14  typedef vec3<double> parent;
15 public:
16  TOOLS_SCLASS(tools::vec3d) //for stype()
17 public:
18  vec3d():parent(){}
19  vec3d(const double a_vec[3]):parent(a_vec){}
20  vec3d(double a0,double a1,double a2):parent(a0,a1,a2){}
21  virtual ~vec3d() {}
22 public:
23  vec3d(const vec3d& a_from):parent(a_from){}
24  vec3d& operator=(const vec3d& a_from){
25  parent::operator=(a_from);
26  return *this;
27  }
28 
29  vec3d(const parent& a_from):parent(a_from){}
30 
31 public: //operators
32  vec3d operator*(double a_v) const {
33  return vec3d(m_data[0]*a_v,
34  m_data[1]*a_v,
35  m_data[2]*a_v);
36  }
37  vec3d operator+(const vec3d& a_v) const {
38  return vec3d(m_data[0]+a_v.m_data[0],
39  m_data[1]+a_v.m_data[1],
40  m_data[2]+a_v.m_data[2]);
41  }
42  vec3d operator-(const vec3d& a_v) const {
43  return vec3d(m_data[0]-a_v.m_data[0],
44  m_data[1]-a_v.m_data[1],
45  m_data[2]-a_v.m_data[2]);
46  }
47  vec3d& operator+=(const vec3d& a_v) {
48  m_data[0] += a_v.m_data[0];
49  m_data[1] += a_v.m_data[1];
50  m_data[2] += a_v.m_data[2];
51  return *this;
52  }
53  vec3d& operator-=(const vec3d& a_v) {
54  m_data[0] -= a_v.m_data[0];
55  m_data[1] -= a_v.m_data[1];
56  m_data[2] -= a_v.m_data[2];
57  return *this;
58  }
59  vec3d& operator*=(double a_v) {
60  m_data[0] *= a_v;
61  m_data[1] *= a_v;
62  m_data[2] *= a_v;
63  return *this;
64  }
65  vec3d operator-() const {
66  return vec3d(-m_data[0],-m_data[1],-m_data[2]);
67  }
68 public:
69  double length() const {return parent::length(::sqrt);}
70  double normalize() {return parent::normalize(::sqrt);}
71 public: //for g4dum/G4ThreeVector :
72  double mag2() const {return m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2];}
73  void set(double a_0,double a_1,double a_2) {
74  m_data[0] = a_0;
75  m_data[1] = a_1;
76  m_data[2] = a_2;
77  }
78  void rotateUz(const vec3d& a_new_uz_vector) { //from CLHEP/ThreeVector.cc.
79  // a_new_uz_vector must be normalized !
80  double& dx = m_data[0];
81  double& dy = m_data[1];
82  double& dz = m_data[2];
83  double u1 = a_new_uz_vector.x();
84  double u2 = a_new_uz_vector.y();
85  double u3 = a_new_uz_vector.z();
86  double up = u1*u1 + u2*u2;
87  if (up>0) {
88  up = std::sqrt(up);
89  double px = dx, py = dy, pz = dz;
90  dx = (u1*u3*px - u2*py)/up + u1*pz;
91  dy = (u2*u3*px + u1*py)/up + u2*pz;
92  dz = -up*px + u3*pz;
93  } else if (u3 < 0.) { // phi=0 teta=pi
94  dx = -dx; dz = -dz;
95  } else {
96  }
97  //return *this;
98  }
99 
100 
101 private:static void check_instantiation() {vec3d v(0,0,0);v.set_value(1,1,1);}
102 };
103 
104 inline vec3d operator*(double a_f,const vec3d& a_v) {
105  vec3d res(a_v);
106  res *= a_f;
107  return res;
108 }
109 
110 }
111 
112 
113 #include <vector>
114 
115 namespace tools {
116 
117 #ifndef SWIG
118 //for sf, mf :
119 inline bool set_from_vec(vec3d& a_v,const std::vector<double>& a_sv) {
120  if(a_sv.size()!=3) return false;
121  a_v[0] = a_sv[0];
122  a_v[1] = a_sv[1];
123  a_v[2] = a_sv[2];
124  return true;
125 }
126 #endif
127 
128 }
129 
130 #endif
vec3
tools::vec3< double >::normalize
double normalize(double(*a_sqrt)(double))
Definition: vec3:118
tools::vec3
Definition: vec3:16
tools::vec3d::operator-
vec3d operator-() const
Definition: vec3d:65
tools::vec3d::operator*=
vec3d & operator*=(double a_v)
Definition: vec3d:59
tools::vec3d::normalize
double normalize()
Definition: vec3d:70
tools::operator*
array< T > operator*(const T &a_fac, const array< T > &a_m)
Definition: array:617
tools::vec3d
Definition: vec3d:13
tools::vec3d::TOOLS_SCLASS
TOOLS_SCLASS(tools::vec3d) public
Definition: vec3d:16
tools::vec3d::rotateUz
void rotateUz(const vec3d &a_new_uz_vector)
Definition: vec3d:78
tools::vec3d::operator+
vec3d operator+(const vec3d &a_v) const
Definition: vec3d:37
tools::vec3d::~vec3d
virtual ~vec3d()
Definition: vec3d:21
tools::vec3d::set
void set(double a_0, double a_1, double a_2)
Definition: vec3d:73
tools::vec3< double >::length
double length(double(*a_sqrt)(double)) const
Definition: vec3:114
tools::vec3::y
const T & y() const
Definition: vec3:85
tools::vec3d::operator-
vec3d operator-(const vec3d &a_v) const
Definition: vec3d:42
tools::vec3d::mag2
double mag2() const
Definition: vec3d:72
tools::vec3::x
const T & x() const
Definition: vec3:84
tools::vec3d::vec3d
vec3d(const vec3d &a_from)
Definition: vec3d:23
tools::vec3d::length
double length() const
Definition: vec3d:69
tools::vec3d::operator*
vec3d operator*(double a_v) const
Definition: vec3d:32
tools::vec3d::operator+=
vec3d & operator+=(const vec3d &a_v)
Definition: vec3d:47
tools::vec3d::vec3d
vec3d(const parent &a_from)
Definition: vec3d:29
tools::vec3< double >::operator=
vec3 & operator=(const vec3 &a_from)
Definition: vec3:69
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::vec3d::vec3d
vec3d(const double a_vec[3])
Definition: vec3d:19
tools::vec3::z
const T & z() const
Definition: vec3:86
tools::vec3< double >::m_data
double m_data[3]
Definition: vec3:310
tools::set_from_vec
bool set_from_vec(vec2f &a_v, const std::vector< float > &a_sv)
Definition: vec2f:102
tools::vec3d::operator=
vec3d & operator=(const vec3d &a_from)
Definition: vec3d:24
tools::vec3d::operator-=
vec3d & operator-=(const vec3d &a_v)
Definition: vec3d:53
tools::vec3d::vec3d
vec3d(double a0, double a1, double a2)
Definition: vec3d:20