CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

TwoVector.h

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

Generated on Thu Jul 1 22:02:31 2010 for CLHEP by  doxygen 1.4.7