File indexing completed on 2025-01-18 09:58:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #define INCLXX_IN_GEANT4_MODE 1
0035
0036 #include "globals.hh"
0037
0038
0039
0040
0041
0042
0043
0044
0045 #ifndef G4INCLThreeVector_hh
0046 #define G4INCLThreeVector_hh 1
0047
0048 #include <string>
0049 #include <sstream>
0050 #include <cmath>
0051
0052 namespace G4INCL {
0053
0054 class ThreeVector {
0055 public:
0056 ThreeVector()
0057 :x(0.0), y(0.0), z(0.0)
0058 {}
0059
0060 ThreeVector(G4double ax, G4double ay, G4double az)
0061 :x(ax), y(ay), z(az)
0062 {}
0063
0064 inline G4double getX() const { return x; }
0065 inline G4double getY() const { return y; }
0066 inline G4double getZ() const { return z; }
0067
0068 inline G4double perp() const { return std::sqrt(x*x + y*y); }
0069 inline G4double perp2() const { return x*x + y*y; }
0070
0071
0072
0073 inline G4double mag() const { return std::sqrt(x*x + y*y + z*z); }
0074
0075
0076
0077
0078 inline G4double mag2() const { return (x*x + y*y + z*z); }
0079
0080
0081
0082
0083 inline G4double theta() const {
0084 return x == 0.0 && y == 0.0 && z == 0.0 ? 0.0 : std::atan2(perp(),z);
0085 }
0086
0087
0088
0089
0090 inline G4double phi() const {
0091 return x == 0.0 && y == 0.0 ? 0.0 : std::atan2(y,x);
0092 }
0093
0094
0095
0096
0097 inline G4double dot(const ThreeVector &v) const {
0098 return (x*v.x + y*v.y + z*v.z);
0099 }
0100
0101
0102
0103
0104 ThreeVector vector(const ThreeVector &v) const {
0105 return ThreeVector(
0106 y*v.z - z*v.y,
0107 z*v.x - x*v.z,
0108 x*v.y - y*v.x
0109 );
0110 }
0111
0112
0113 inline void setX(G4double ax) { x = ax; }
0114
0115
0116 inline void setY(G4double ay) { y = ay; }
0117
0118
0119 inline void setZ(G4double az) { z = az; }
0120
0121
0122 inline void set(const G4double ax, const G4double ay, const G4double az) { x=ax; y=ay; z=az; }
0123
0124 inline void operator+= (const ThreeVector &v) {
0125 x += v.x;
0126 y += v.y;
0127 z += v.z;
0128 }
0129
0130
0131 inline ThreeVector operator- () const {
0132 return ThreeVector(-x,-y,-z);
0133 }
0134
0135 inline void operator-= (const ThreeVector &v) {
0136 x -= v.x;
0137 y -= v.y;
0138 z -= v.z;
0139 }
0140
0141 template<typename T>
0142 inline void operator*= (const T &c) {
0143 x *= c;
0144 y *= c;
0145 z *= c;
0146 }
0147
0148 template<typename T>
0149 inline void operator/= (const T &c) {
0150 const G4double oneOverC = 1./c;
0151 this->operator*=(oneOverC);
0152 }
0153
0154 inline ThreeVector operator- (const ThreeVector &v) const {
0155 return ThreeVector(x-v.x, y-v.y, z-v.z);
0156 }
0157
0158 inline ThreeVector operator+ (const ThreeVector &v) const {
0159 return ThreeVector(x+v.x, y+v.y, z+v.z);
0160 }
0161
0162
0163
0164
0165 inline ThreeVector operator/ (const G4double C) const {
0166 const G4double oneOverC = 1./C;
0167 return ThreeVector(x*oneOverC, y*oneOverC, z*oneOverC);
0168 }
0169
0170 inline ThreeVector operator* (const G4double C) const {
0171 return ThreeVector(x*C, y*C, z*C);
0172 }
0173
0174
0175
0176
0177
0178
0179 inline void rotate(const G4double angle, const ThreeVector &axis) {
0180
0181 const G4double cos = std::cos(angle);
0182 const G4double sin = std::sin(angle);
0183 (*this) = (*this) * cos + axis.vector(*this) * sin + axis * (axis.dot(*this)*(1.-cos));
0184 }
0185
0186
0187
0188
0189
0190
0191 ThreeVector anyOrthogonal() const {
0192 if(x<=y && x<=z)
0193 return ThreeVector(0., -z, y);
0194 else if(y<=x && y<=z)
0195 return ThreeVector(-z, 0., x);
0196 else
0197 return ThreeVector(-y, x, 0.);
0198 }
0199
0200 std::string print() const {
0201 std::stringstream ss;
0202 ss <<"(x = " << x << " y = " << y << " z = " << z <<")";
0203 return ss.str();
0204 }
0205
0206 std::string dump() const {
0207 std::stringstream ss;
0208 ss <<"(vector3 " << x << " " << y << " " << z << ")";
0209 return ss.str();
0210 }
0211
0212 private:
0213 G4double x, y, z;
0214 };
0215
0216 }
0217
0218 #endif