Geant4 Cross Reference |
1 // -*- C++ -*- 1 // -*- C++ -*- 2 // CLASSDOC OFF 2 // CLASSDOC OFF 3 // ------------------------------------------- 3 // --------------------------------------------------------------------------- 4 // CLASSDOC ON 4 // CLASSDOC ON 5 // 5 // 6 // This file is a part of the CLHEP - a Class 6 // This file is a part of the CLHEP - a Class Library for High Energy Physics. 7 // 7 // 8 // Hep2Vector is a general 2-vector class defi 8 // Hep2Vector is a general 2-vector class defining vectors in two 9 // dimension using double components. It com 9 // dimension using double components. It comes from the ZOOM 10 // PlaneVector class (the PhysicsVectors Plane 10 // PlaneVector class (the PhysicsVectors PlaneVector.h will typedef 11 // PlaneVector to Hep2Vector). 11 // PlaneVector to Hep2Vector). 12 // 12 // 13 // .SS See Also 13 // .SS See Also 14 // ThreeVector.h 14 // ThreeVector.h 15 // 15 // 16 // .SS Authors 16 // .SS Authors 17 // John Marraffino and Mark Fischler 17 // John Marraffino and Mark Fischler 18 // 18 // 19 19 20 #ifndef HEP_TWOVECTOR_H 20 #ifndef HEP_TWOVECTOR_H 21 #define HEP_TWOVECTOR_H 21 #define HEP_TWOVECTOR_H 22 22 >> 23 #ifdef GNUPRAGMA >> 24 #pragma interface >> 25 #endif >> 26 23 #include <iostream> 27 #include <iostream> 24 28 25 #include "CLHEP/Vector/ThreeVector.h" 29 #include "CLHEP/Vector/ThreeVector.h" 26 30 27 namespace CLHEP { 31 namespace CLHEP { 28 32 29 // Declarations of classes and global methods 33 // Declarations of classes and global methods 30 class Hep2Vector; 34 class Hep2Vector; 31 std::ostream & operator << (std::ostream &, co 35 std::ostream & operator << (std::ostream &, const Hep2Vector &); 32 std::istream & operator >> (std::istream &, He 36 std::istream & operator >> (std::istream &, Hep2Vector &); 33 inline double operator * (const Hep2Vector & a 37 inline double operator * (const Hep2Vector & a,const Hep2Vector & b); 34 inline Hep2Vector operator * (const Hep2Vector 38 inline Hep2Vector operator * (const Hep2Vector & p, double a); 35 inline Hep2Vector operator * (double a, const 39 inline Hep2Vector operator * (double a, const Hep2Vector & p); 36 Hep2Vector operator / (const Hep2Vector 40 Hep2Vector operator / (const Hep2Vector & p, double a); 37 inline Hep2Vector operator + (const Hep2Vector 41 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b); 38 inline Hep2Vector operator - (const Hep2Vector 42 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b); 39 43 40 /** 44 /** 41 * @author 45 * @author 42 * @ingroup vector 46 * @ingroup vector 43 */ 47 */ 44 class Hep2Vector { 48 class Hep2Vector { 45 49 46 public: 50 public: 47 51 48 enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM 52 enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM_COORDINATES }; 49 // Safe indexing of the coordinates when usi 53 // Safe indexing of the coordinates when using with matrices, arrays, etc. 50 54 51 inline Hep2Vector( double x = 0.0, double y 55 inline Hep2Vector( double x = 0.0, double y = 0.0 ); 52 // The constructor. 56 // The constructor. 53 57 54 inline Hep2Vector(const Hep2Vector & p); 58 inline Hep2Vector(const Hep2Vector & p); 55 inline Hep2Vector(Hep2Vector && p) = default 59 inline Hep2Vector(Hep2Vector && p) = default; 56 // The copy and move constructors. 60 // The copy and move constructors. 57 61 58 explicit Hep2Vector( const Hep3Vector & ); 62 explicit Hep2Vector( const Hep3Vector & ); 59 // "demotion" constructor" 63 // "demotion" constructor" 60 // WARNING -- THIS IGNORES THE Z COMPONENT O 64 // WARNING -- THIS IGNORES THE Z COMPONENT OF THE Hep3Vector. 61 // SO IN GENERAL, Hep2Vector(v)==v WILL N 65 // SO IN GENERAL, Hep2Vector(v)==v WILL NOT HOLD! 62 66 63 inline ~Hep2Vector(); 67 inline ~Hep2Vector(); 64 // The destructor. 68 // The destructor. 65 69 66 inline double x() const; 70 inline double x() const; 67 inline double y() const; 71 inline double y() const; 68 // The components in cartesian coordinate sy 72 // The components in cartesian coordinate system. 69 73 70 double operator () (int i) const; 74 double operator () (int i) const; 71 inline double operator [] (int i) const; 75 inline double operator [] (int i) const; 72 // Get components by index. 0-based. 76 // Get components by index. 0-based. 73 77 74 double & operator () (int i); 78 double & operator () (int i); 75 inline double & operator [] (int i); 79 inline double & operator [] (int i); 76 // Set components by index. 0-based. 80 // Set components by index. 0-based. 77 81 78 inline void setX(double x); 82 inline void setX(double x); 79 inline void setY(double y); 83 inline void setY(double y); 80 inline void set (double x, double y); 84 inline void set (double x, double y); 81 // Set the components in cartesian coordinat 85 // Set the components in cartesian coordinate system. 82 86 83 inline double phi() const; 87 inline double phi() const; 84 // The azimuth angle. 88 // The azimuth angle. 85 89 86 inline double mag2() const; 90 inline double mag2() const; 87 // The magnitude squared. 91 // The magnitude squared. 88 92 89 inline double mag() const; 93 inline double mag() const; 90 // The magnitude. 94 // The magnitude. 91 95 92 inline double r() const; 96 inline double r() const; 93 // r in polar coordinates (r, phi): equal t 97 // r in polar coordinates (r, phi): equal to mag(). 94 98 95 inline void setPhi(double phi); 99 inline void setPhi(double phi); 96 // Set phi keeping mag constant. 100 // Set phi keeping mag constant. 97 101 98 inline void setMag(double r); 102 inline void setMag(double r); 99 // Set magnitude keeping phi constant. 103 // Set magnitude keeping phi constant. 100 104 101 inline void setR(double r); 105 inline void setR(double r); 102 // Set R keeping phi constant. Same as setM 106 // Set R keeping phi constant. Same as setMag. 103 107 104 inline void setPolar(double r, double phi); 108 inline void setPolar(double r, double phi); 105 // Set by polar coordinates. 109 // Set by polar coordinates. 106 110 107 inline Hep2Vector & operator = (const Hep2Ve 111 inline Hep2Vector & operator = (const Hep2Vector & p); 108 inline Hep2Vector & operator = (Hep2Vector & 112 inline Hep2Vector & operator = (Hep2Vector && p) = default; 109 // The copy and move assignment operators. 113 // The copy and move assignment operators. 110 114 111 inline bool operator == (const Hep2Vector & 115 inline bool operator == (const Hep2Vector & v) const; 112 inline bool operator != (const Hep2Vector & 116 inline bool operator != (const Hep2Vector & v) const; 113 // Comparisons. 117 // Comparisons. 114 118 115 int compare (const Hep2Vector & v) const; 119 int compare (const Hep2Vector & v) const; 116 bool operator > (const Hep2Vector & v) const 120 bool operator > (const Hep2Vector & v) const; 117 bool operator < (const Hep2Vector & v) const 121 bool operator < (const Hep2Vector & v) const; 118 bool operator>= (const Hep2Vector & v) const 122 bool operator>= (const Hep2Vector & v) const; 119 bool operator<= (const Hep2Vector & v) const 123 bool operator<= (const Hep2Vector & v) const; 120 // dictionary ordering according to y, then 124 // dictionary ordering according to y, then x component 121 125 122 static inline double getTolerance(); 126 static inline double getTolerance(); 123 static double setTolerance(double tol); 127 static double setTolerance(double tol); 124 128 125 double howNear (const Hep2Vector &p) const; 129 double howNear (const Hep2Vector &p) const; 126 bool isNear (const Hep2Vector & p, double e 130 bool isNear (const Hep2Vector & p, double epsilon=tolerance) const; 127 131 128 double howParallel (const Hep2Vector &p) con 132 double howParallel (const Hep2Vector &p) const; 129 bool isParallel 133 bool isParallel 130 (const Hep2Vector & p, double epsilon=tole 134 (const Hep2Vector & p, double epsilon=tolerance) const; 131 135 132 double howOrthogonal (const Hep2Vector &p) c 136 double howOrthogonal (const Hep2Vector &p) const; 133 bool isOrthogonal 137 bool isOrthogonal 134 (const Hep2Vector & p, double epsilon=tole 138 (const Hep2Vector & p, double epsilon=tolerance) const; 135 139 136 inline Hep2Vector & operator += (const Hep2V 140 inline Hep2Vector & operator += (const Hep2Vector &p); 137 // Addition. 141 // Addition. 138 142 139 inline Hep2Vector & operator -= (const Hep2V 143 inline Hep2Vector & operator -= (const Hep2Vector &p); 140 // Subtraction. 144 // Subtraction. 141 145 142 inline Hep2Vector operator - () const; 146 inline Hep2Vector operator - () const; 143 // Unary minus. 147 // Unary minus. 144 148 145 inline Hep2Vector & operator *= (double a); 149 inline Hep2Vector & operator *= (double a); 146 // Scaling with real numbers. 150 // Scaling with real numbers. 147 151 148 inline Hep2Vector unit() const; 152 inline Hep2Vector unit() const; 149 // Unit vector parallel to this. 153 // Unit vector parallel to this. 150 154 151 inline Hep2Vector orthogonal() const; 155 inline Hep2Vector orthogonal() const; 152 // Vector orthogonal to this. 156 // Vector orthogonal to this. 153 157 154 inline double dot(const Hep2Vector &p) const 158 inline double dot(const Hep2Vector &p) const; 155 // Scalar product. 159 // Scalar product. 156 160 157 inline double angle(const Hep2Vector &) cons 161 inline double angle(const Hep2Vector &) const; 158 // The angle w.r.t. another 2-vector. 162 // The angle w.r.t. another 2-vector. 159 163 160 void rotate(double); 164 void rotate(double); 161 // Rotates the Hep2Vector. 165 // Rotates the Hep2Vector. 162 166 163 operator Hep3Vector () const; 167 operator Hep3Vector () const; 164 // Cast a Hep2Vector as a Hep3Vector. 168 // Cast a Hep2Vector as a Hep3Vector. 165 169 166 // The remaining methods are friends, thus d 170 // The remaining methods are friends, thus defined at global scope: 167 // - - - - - - - - - - - - - - - - - - - - - 171 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 168 172 169 friend std::ostream & operator<< (std::ostre 173 friend std::ostream & operator<< (std::ostream &, const Hep2Vector &); 170 // Output to a stream. 174 // Output to a stream. 171 175 172 inline friend double operator * (const Hep2V 176 inline friend double operator * (const Hep2Vector & a, 173 const Hep2Vector & b); 177 const Hep2Vector & b); 174 // Scalar product. 178 // Scalar product. 175 179 176 inline friend Hep2Vector operator * (const H 180 inline friend Hep2Vector operator * (const Hep2Vector & p, double a); 177 // v*c 181 // v*c 178 182 179 inline friend Hep2Vector operator * (double 183 inline friend Hep2Vector operator * (double a, const Hep2Vector & p); 180 // c*v 184 // c*v 181 185 182 friend Hep2Vector operator / (const H 186 friend Hep2Vector operator / (const Hep2Vector & p, double a); 183 // v/c 187 // v/c 184 188 185 inline friend Hep2Vector operator + (const H 189 inline friend Hep2Vector operator + (const Hep2Vector & a, 186 const Hep2Vector & b); 190 const Hep2Vector & b); 187 // v1+v2 191 // v1+v2 188 192 189 inline friend Hep2Vector operator - (const H 193 inline friend Hep2Vector operator - (const Hep2Vector & a, 190 const Hep2Vector & b); 194 const Hep2Vector & b); 191 // v1-v2 195 // v1-v2 192 196 193 static const int ZMpvToleranceTicks = 100; << 197 enum { ZMpvToleranceTicks = 100 }; 194 198 195 private: 199 private: 196 200 197 double dx; 201 double dx; 198 double dy; 202 double dy; 199 // The components. 203 // The components. 200 204 201 static double tolerance; 205 static double tolerance; 202 // default tolerance criterion for isNear() 206 // default tolerance criterion for isNear() to return true. 203 207 204 }; // Hep2Vector 208 }; // Hep2Vector 205 209 206 static const Hep2Vector X_HAT2(1.0, 0.0); 210 static const Hep2Vector X_HAT2(1.0, 0.0); 207 static const Hep2Vector Y_HAT2(0.0, 1.0); 211 static const Hep2Vector Y_HAT2(0.0, 1.0); 208 212 209 } // namespace CLHEP 213 } // namespace CLHEP 210 214 211 #include "CLHEP/Vector/TwoVector.icc" 215 #include "CLHEP/Vector/TwoVector.icc" 212 216 213 #endif /* HEP_TWOVECTOR_H */ 217 #endif /* HEP_TWOVECTOR_H */ 214 218