CLHEP/Vector/TwoVector.h

00001 // -*- C++ -*-
00002 // CLASSDOC OFF
00003 // ---------------------------------------------------------------------------
00004 // CLASSDOC ON
00005 //
00006 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00007 //
00008 // Hep2Vector is a general 2-vector class defining vectors in two 
00009 // dimension using double components.   It comes from the ZOOM
00010 // PlaneVector class (the PhysicsVectors PlaneVector.h will typedef
00011 // PlaneVector to Hep2Vector).
00012 //
00013 // .SS See Also
00014 // ThreeVector.h
00015 //
00016 // .SS Authors
00017 // John Marraffino and Mark Fischler
00018 //
00019 
00020 #ifndef HEP_TWOVECTOR_H
00021 #define HEP_TWOVECTOR_H
00022 
00023 #ifdef GNUPRAGMA
00024 #pragma interface
00025 #endif
00026 
00027 #include "CLHEP/config/CLHEP.h"
00028 #include "CLHEP/config/iostream.h"
00029 
00030 #ifdef HEP_NO_INLINE_IN_DECLARATION
00031 #define inline
00032 #endif
00033 
00034 #include "CLHEP/Vector/ThreeVector.h" 
00035 
00036 // Declarations of classes and global methods
00037 class Hep2Vector;
00038 HepStd::ostream & operator << (HepStd::ostream &, const Hep2Vector &);
00039 HepStd::istream & operator >> (HepStd::istream &, Hep2Vector &);
00040 inline double operator * (const Hep2Vector & a,const Hep2Vector & b);
00041 inline Hep2Vector operator * (const Hep2Vector & p, double a);
00042 inline Hep2Vector operator * (double a, const Hep2Vector & p);
00043        Hep2Vector operator / (const Hep2Vector & p, double a);
00044 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b);
00045 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b);
00046 
00051 class Hep2Vector {
00052 
00053 public:
00054 
00055   enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM_COORDINATES };
00056   // Safe indexing of the coordinates when using with matrices, arrays, etc.
00057 
00058   inline Hep2Vector( double x = 0.0, double y = 0.0 );
00059   // The constructor.
00060 
00061   inline Hep2Vector(const Hep2Vector & p);
00062   // The copy constructor.
00063 
00064   explicit Hep2Vector( const Hep3Vector & s);
00065   // "demotion" constructor"
00066   // WARNING -- THIS IGNORES THE Z COMPONENT OF THE Hep3Vector.
00067   //            SO IN GENERAL, Hep2Vector(v)==v WILL NOT HOLD!
00068 
00069   inline ~Hep2Vector();
00070   // The destructor.
00071 
00072   inline double x() const;
00073   inline double y() const;
00074   // The components in cartesian coordinate system.
00075 
00076          double operator () (int i) const;
00077   inline double operator [] (int i) const;
00078   // Get components by index.  0-based.
00079 
00080          double & operator () (int i);
00081   inline double & operator [] (int i);
00082   // Set components by index.  0-based.
00083 
00084   inline void setX(double x);
00085   inline void setY(double y);
00086   inline void set (double x, double y);
00087   // Set the components in cartesian coordinate system.
00088 
00089   inline double phi() const;
00090   // The azimuth angle.
00091 
00092   inline double mag2() const;
00093   // The magnitude squared.
00094 
00095   inline double mag() const;
00096   // The magnitude.
00097 
00098   inline double r() const;
00099   // r in polar coordinates (r, phi):  equal to mag().
00100 
00101   inline void setPhi(double phi);
00102   // Set phi keeping mag constant.
00103 
00104   inline void setMag(double r);
00105   // Set magnitude keeping phi constant.
00106 
00107   inline void setR(double r);
00108   // Set R keeping phi constant.  Same as setMag.
00109 
00110   inline void setPolar(double r, double phi);
00111   // Set by polar coordinates.
00112 
00113   inline Hep2Vector & operator = (const Hep2Vector & p);
00114   // Assignment.
00115 
00116   inline bool operator == (const Hep2Vector & v) const;
00117   inline bool operator != (const Hep2Vector & v) const;
00118   // Comparisons.
00119 
00120   int compare (const Hep2Vector & v) const;
00121   bool operator > (const Hep2Vector & v) const;
00122   bool operator < (const Hep2Vector & v) const;
00123   bool operator>= (const Hep2Vector & v) const;
00124   bool operator<= (const Hep2Vector & v) const;
00125   // dictionary ordering according to y, then x component
00126 
00127   static inline double getTolerance();
00128   static double setTolerance(double tol);
00129 
00130   double howNear (const Hep2Vector &p) const;
00131   bool isNear  (const Hep2Vector & p, double epsilon=tolerance) const;
00132 
00133   double howParallel (const Hep2Vector &p) const;
00134   bool isParallel 
00135                 (const Hep2Vector & p, double epsilon=tolerance) const;
00136 
00137   double howOrthogonal (const Hep2Vector &p) const;
00138   bool isOrthogonal
00139                 (const Hep2Vector & p, double epsilon=tolerance) const;
00140 
00141   inline Hep2Vector & operator += (const Hep2Vector &p);
00142   // Addition.
00143 
00144   inline Hep2Vector & operator -= (const Hep2Vector &p);
00145   // Subtraction.
00146 
00147   inline Hep2Vector operator - () const;
00148   // Unary minus.
00149 
00150   inline Hep2Vector & operator *= (double a);
00151   // Scaling with real numbers.
00152 
00153   inline Hep2Vector unit() const;
00154   // Unit vector parallel to this.
00155 
00156   inline Hep2Vector orthogonal() const;
00157   // Vector orthogonal to this.
00158 
00159   inline double dot(const Hep2Vector &p) const;
00160   // Scalar product.
00161 
00162   inline double angle(const Hep2Vector &) const;
00163   // The angle w.r.t. another 2-vector.
00164 
00165   void rotate(double);
00166   // Rotates the Hep2Vector.
00167 
00168   operator Hep3Vector () const;
00169   // Cast a Hep2Vector as a Hep3Vector.
00170 
00171   // The remaining methods are friends, thus defined at global scope:
00172   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
00173 
00174   friend HepStd::ostream & operator<< (HepStd::ostream &, const Hep2Vector &);
00175   // Output to a stream.
00176 
00177   inline friend double operator * (const Hep2Vector & a,
00178                                    const Hep2Vector & b);
00179   // Scalar product.
00180 
00181   inline friend Hep2Vector operator * (const Hep2Vector & p, double a);
00182   // v*c
00183 
00184   inline friend Hep2Vector operator * (double a, const Hep2Vector & p);
00185   // c*v
00186 
00187          friend Hep2Vector operator / (const Hep2Vector & p, double a);
00188   // v/c
00189 
00190   inline friend Hep2Vector operator + (const Hep2Vector & a,
00191                                        const Hep2Vector & b);
00192   // v1+v2
00193 
00194   inline friend Hep2Vector operator - (const Hep2Vector & a,
00195                                         const Hep2Vector & b);
00196   // v1-v2
00197 
00198   enum { ZMpvToleranceTicks = 100 };
00199 
00200 private:
00201 
00202   double dx;
00203   double dy;
00204   // The components.
00205 
00206   static double tolerance;
00207   // default tolerance criterion for isNear() to return true.
00208 
00209 };  // Hep2Vector
00210 
00211 static const Hep2Vector X_HAT2(1.0, 0.0);
00212 static const Hep2Vector Y_HAT2(0.0, 1.0);
00213 
00214 #include "CLHEP/Vector/TwoVector.icc"
00215 
00216 
00217 #endif /* HEP_TWOVECTOR_H */

Class Library for High Energy Physics (version 1.8)