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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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