Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/lina/vec3d is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_vec3d
0005 #define tools_vec3d
0006 
0007 #include "vec3"
0008 #include "../S_STRING"
0009 #include <cmath>
0010 
0011 namespace tools {
0012 
0013 class vec3d : public vec3<double> {
0014   typedef vec3<double> parent;
0015 public:
0016   TOOLS_SCLASS(tools::vec3d) //for stype()
0017 public:
0018   vec3d():parent(){}
0019   vec3d(const double a_vec[3]):parent(a_vec){}
0020   vec3d(double a0,double a1,double a2):parent(a0,a1,a2){}
0021   virtual ~vec3d() {}
0022 public:
0023   vec3d(const vec3d& a_from):parent(a_from){}
0024   vec3d& operator=(const vec3d& a_from){
0025     parent::operator=(a_from);
0026     return *this;
0027   }
0028 
0029   vec3d(const parent& a_from):parent(a_from){}
0030 
0031 public: //operators
0032   vec3d operator*(double a_v) const {
0033     return vec3d(m_data[0]*a_v,
0034                  m_data[1]*a_v,
0035                  m_data[2]*a_v);
0036   }
0037   vec3d operator+(const vec3d& a_v) const {
0038     return vec3d(m_data[0]+a_v.m_data[0],
0039                  m_data[1]+a_v.m_data[1],
0040                  m_data[2]+a_v.m_data[2]);
0041   }
0042   vec3d operator-(const vec3d& a_v) const {
0043     return vec3d(m_data[0]-a_v.m_data[0],
0044                  m_data[1]-a_v.m_data[1],
0045                  m_data[2]-a_v.m_data[2]);
0046   }
0047   vec3d& operator+=(const vec3d& a_v) {
0048     m_data[0] += a_v.m_data[0];
0049     m_data[1] += a_v.m_data[1];
0050     m_data[2] += a_v.m_data[2];
0051     return *this;
0052   }
0053   vec3d& operator-=(const vec3d& a_v) {
0054     m_data[0] -= a_v.m_data[0];
0055     m_data[1] -= a_v.m_data[1];
0056     m_data[2] -= a_v.m_data[2];
0057     return *this;
0058   }
0059   vec3d& operator*=(double a_v) {
0060     m_data[0] *= a_v;
0061     m_data[1] *= a_v;
0062     m_data[2] *= a_v;
0063     return *this;
0064   }
0065   vec3d operator-() const {
0066     return vec3d(-m_data[0],-m_data[1],-m_data[2]);
0067   }
0068 public:
0069   double length() const {return parent::length(::sqrt);}
0070   double normalize() {return parent::normalize(::sqrt);}
0071 public: //for g4dum/G4ThreeVector :
0072   double mag2() const {return m_data[0]*m_data[0]+m_data[1]*m_data[1]+m_data[2]*m_data[2];}
0073   void set(double a_0,double a_1,double a_2) {
0074     m_data[0] = a_0;
0075     m_data[1] = a_1;
0076     m_data[2] = a_2;
0077   }
0078   void rotateUz(const vec3d& a_new_uz_vector) { //from CLHEP/ThreeVector.cc.
0079     // a_new_uz_vector must be normalized !
0080     double& dx = m_data[0];
0081     double& dy = m_data[1];
0082     double& dz = m_data[2];
0083     double u1 = a_new_uz_vector.x();
0084     double u2 = a_new_uz_vector.y();
0085     double u3 = a_new_uz_vector.z();
0086     double up = u1*u1 + u2*u2;
0087     if (up>0) {
0088       up = std::sqrt(up);
0089       double px = dx,  py = dy,  pz = dz;
0090       dx = (u1*u3*px - u2*py)/up + u1*pz;
0091       dy = (u2*u3*px + u1*py)/up + u2*pz;
0092       dz =    -up*px +             u3*pz;
0093     } else if (u3 < 0.) { // phi=0  teta=pi
0094       dx = -dx; dz = -dz;
0095     } else {
0096     }
0097     //return *this;
0098   }
0099 
0100 
0101 private:static void check_instantiation() {vec3d v(0,0,0);v.set_value(1,1,1);}
0102 };
0103 
0104 inline vec3d operator*(double a_f,const vec3d& a_v) {
0105   vec3d res(a_v);
0106   res *= a_f;
0107   return res;
0108 }
0109 
0110 }
0111 
0112 
0113 #include <vector>
0114 
0115 namespace tools {
0116 
0117 #ifndef SWIG
0118 //for sf, mf :
0119 inline bool set_from_vec(vec3d& a_v,const std::vector<double>& a_sv) {
0120   if(a_sv.size()!=3) return false;
0121   a_v[0] = a_sv[0];
0122   a_v[1] = a_sv[1];
0123   a_v[2] = a_sv[2];
0124   return true;
0125 }
0126 #endif
0127 
0128 }
0129 
0130 #endif