00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #define INCLXX_IN_GEANT4_MODE 1
00034
00035 #include "globals.hh"
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef G4INCLThreeVector_hh
00045 #define G4INCLThreeVector_hh 1
00046
00047 #include <string>
00048 #include <sstream>
00049 #include <cmath>
00050
00051 namespace G4INCL {
00052
00053 class ThreeVector {
00054 public:
00055 ThreeVector()
00056 :x(0.0), y(0.0), z(0.0)
00057 {}
00058
00059 ThreeVector(G4double ax, G4double ay, G4double az)
00060 :x(ax), y(ay), z(az)
00061 {}
00062
00063 inline G4double getX() const { return x; }
00064 inline G4double getY() const { return y; }
00065 inline G4double getZ() const { return z; }
00066
00067 inline G4double perp() const { return std::sqrt(x*x + y*y); }
00068 inline G4double perp2() const { return x*x + y*y; }
00072 inline G4double mag() const { return std::sqrt(x*x + y*y + z*z); }
00073
00077 inline G4double mag2() const { return (x*x + y*y + z*z); }
00078
00082 inline G4double theta() const {
00083 return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(perp(),z);
00084 }
00085
00089 inline G4double phi() const {
00090 return x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
00091 }
00092
00096 inline G4double dot(const ThreeVector &v) const {
00097 return (x*v.x + y*v.y + z*v.z);
00098 }
00099
00103 ThreeVector vector(const ThreeVector &v) const {
00104 return ThreeVector(
00105 y*v.z - z*v.y,
00106 z*v.x - x*v.z,
00107 x*v.y - y*v.x
00108 );
00109 }
00110
00112 inline void setX(G4double ax) { x = ax; }
00113
00115 inline void setY(G4double ay) { y = ay; }
00116
00118 inline void setZ(G4double az) { z = az; }
00119
00120 inline void operator+= (const ThreeVector &v) {
00121 x += v.x;
00122 y += v.y;
00123 z += v.z;
00124 }
00125
00127 inline ThreeVector operator- () const {
00128 return ThreeVector(-x,-y,-z);
00129 }
00130
00131 inline void operator-= (const ThreeVector &v) {
00132 x -= v.x;
00133 y -= v.y;
00134 z -= v.z;
00135 }
00136
00137 template<typename T>
00138 inline void operator*= (const T c) {
00139 x *= c;
00140 y *= c;
00141 z *= c;
00142 }
00143
00144 template<typename T>
00145 inline void operator/= (const T c) {
00146 x /= c;
00147 y /= c;
00148 z /= c;
00149 }
00150
00151 inline ThreeVector operator- (const ThreeVector &v) const {
00152 return ThreeVector(x-v.x, y-v.y, z-v.z);
00153 }
00154
00155 inline ThreeVector operator+ (const ThreeVector &v) const {
00156 return ThreeVector(x+v.x, y+v.y, z+v.z);
00157 }
00158
00162 inline ThreeVector operator/ (const G4double C) const {
00163 return ThreeVector(x/C, y/C, z/C);
00164 }
00165
00166 inline ThreeVector operator* (const G4double C) const {
00167 return ThreeVector(x*C, y*C, z*C);
00168 }
00169
00175 inline void rotate(const G4double angle, const ThreeVector &axis) {
00176
00177 const G4double cos = std::cos(angle);
00178 const G4double sin = std::sin(angle);
00179 (*this) = (*this) * cos + axis.vector(*this) * sin + axis * (axis.dot(*this)*(1.-cos));
00180 }
00181
00182 std::string print() const {
00183 std::stringstream ss;
00184 ss <<"(x = " << x << " y = " << y << " z = " << z <<")";
00185 return ss.str();
00186 }
00187
00188 std::string dump() const {
00189 std::stringstream ss;
00190 ss <<"(vector3 " << x << " " << y << " " << z << ")";
00191 return ss.str();
00192 }
00193
00194 private:
00195 G4double x, y, z;
00196 };
00197
00198 }
00199
00200 #endif