Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:41

0001 // -*- C++ -*-
0002 // CLASSDOC OFF
0003 // ---------------------------------------------------------------------------
0004 // CLASSDOC ON
0005 //
0006 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
0007 //
0008 // Hep2Vector is a general 2-vector class defining vectors in two 
0009 // dimension using double components.   It comes from the ZOOM
0010 // PlaneVector class (the PhysicsVectors PlaneVector.h will typedef
0011 // PlaneVector to Hep2Vector).
0012 //
0013 // .SS See Also
0014 // ThreeVector.h
0015 //
0016 // .SS Authors
0017 // John Marraffino and Mark Fischler
0018 //
0019 
0020 #ifndef HEP_TWOVECTOR_H
0021 #define HEP_TWOVECTOR_H
0022 
0023 #include <iostream>
0024 
0025 #include "CLHEP/Vector/defs.h" 
0026 #include "CLHEP/Vector/ThreeVector.h" 
0027 
0028 namespace CLHEP {
0029 
0030 // Declarations of classes and global methods
0031 class Hep2Vector;
0032 std::ostream & operator << (std::ostream &, const Hep2Vector &);
0033 std::istream & operator >> (std::istream &, Hep2Vector &);
0034 inline double operator * (const Hep2Vector & a,const Hep2Vector & b);
0035 inline Hep2Vector operator * (const Hep2Vector & p, double a);
0036 inline Hep2Vector operator * (double a, const Hep2Vector & p);
0037        Hep2Vector operator / (const Hep2Vector & p, double a);
0038 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b);
0039 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b);
0040 
0041 /**
0042  * @author
0043  * @ingroup vector
0044  */
0045 class Hep2Vector {
0046 
0047 public:
0048 
0049   enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM_COORDINATES };
0050   // Safe indexing of the coordinates when using with matrices, arrays, etc.
0051 
0052   inline Hep2Vector( double x = 0.0, double y = 0.0 );
0053   // The constructor.
0054 
0055   inline Hep2Vector(const Hep2Vector & p);
0056   inline Hep2Vector(Hep2Vector && p) = default;
0057   // The copy and move constructors.
0058 
0059   explicit Hep2Vector( const Hep3Vector & );
0060   // "demotion" constructor"
0061   // WARNING -- THIS IGNORES THE Z COMPONENT OF THE Hep3Vector.
0062   //        SO IN GENERAL, Hep2Vector(v)==v WILL NOT HOLD!
0063 
0064   inline ~Hep2Vector();
0065   // The destructor.
0066 
0067   inline double x() const;
0068   inline double y() const;
0069   // The components in cartesian coordinate system.
0070 
0071          double operator () (int i) const;
0072   inline double operator [] (int i) const;
0073   // Get components by index.  0-based.
0074 
0075          double & operator () (int i);
0076   inline double & operator [] (int i);
0077   // Set components by index.  0-based.
0078 
0079   inline void setX(double x);
0080   inline void setY(double y);
0081   inline void set (double x, double y);
0082   // Set the components in cartesian coordinate system.
0083 
0084   inline double phi() const;
0085   // The azimuth angle.
0086 
0087   inline double mag2() const;
0088   // The magnitude squared.
0089 
0090   inline double mag() const;
0091   // The magnitude.
0092 
0093   inline double r() const;
0094   // r in polar coordinates (r, phi):  equal to mag().
0095 
0096   inline void setPhi(double phi);
0097   // Set phi keeping mag constant.
0098 
0099   inline void setMag(double r);
0100   // Set magnitude keeping phi constant.
0101 
0102   inline void setR(double r);
0103   // Set R keeping phi constant.  Same as setMag.
0104 
0105   inline void setPolar(double r, double phi);
0106   // Set by polar coordinates.
0107 
0108   inline Hep2Vector & operator = (const Hep2Vector & p);
0109   inline Hep2Vector & operator = (Hep2Vector && p) = default;
0110   // The copy and move assignment operators.
0111 
0112   inline bool operator == (const Hep2Vector & v) const;
0113   inline bool operator != (const Hep2Vector & v) const;
0114   // Comparisons.
0115 
0116   int compare (const Hep2Vector & v) const;
0117   bool operator > (const Hep2Vector & v) const;
0118   bool operator < (const Hep2Vector & v) const;
0119   bool operator>= (const Hep2Vector & v) const;
0120   bool operator<= (const Hep2Vector & v) const;
0121   // dictionary ordering according to y, then x component
0122 
0123   static inline double getTolerance();
0124   static double setTolerance(double tol);
0125 
0126   double howNear (const Hep2Vector &p) const;
0127   bool isNear  (const Hep2Vector & p, double epsilon=tolerance) const;
0128 
0129   double howParallel (const Hep2Vector &p) const;
0130   bool isParallel 
0131         (const Hep2Vector & p, double epsilon=tolerance) const;
0132 
0133   double howOrthogonal (const Hep2Vector &p) const;
0134   bool isOrthogonal
0135         (const Hep2Vector & p, double epsilon=tolerance) const;
0136 
0137   inline Hep2Vector & operator += (const Hep2Vector &p);
0138   // Addition.
0139 
0140   inline Hep2Vector & operator -= (const Hep2Vector &p);
0141   // Subtraction.
0142 
0143   inline Hep2Vector operator - () const;
0144   // Unary minus.
0145 
0146   inline Hep2Vector & operator *= (double a);
0147   // Scaling with real numbers.
0148 
0149   inline Hep2Vector unit() const;
0150   // Unit vector parallel to this.
0151 
0152   inline Hep2Vector orthogonal() const;
0153   // Vector orthogonal to this.
0154 
0155   inline double dot(const Hep2Vector &p) const;
0156   // Scalar product.
0157 
0158   inline double angle(const Hep2Vector &) const;
0159   // The angle w.r.t. another 2-vector.
0160 
0161   void rotate(double);
0162   // Rotates the Hep2Vector.
0163 
0164   operator Hep3Vector () const;
0165   // Cast a Hep2Vector as a Hep3Vector.
0166 
0167   // The remaining methods are friends, thus defined at global scope:
0168   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
0169 
0170   friend std::ostream & operator<< (std::ostream &, const Hep2Vector &);
0171   // Output to a stream.
0172 
0173   inline friend double operator * (const Hep2Vector & a,
0174                    const Hep2Vector & b);
0175   // Scalar product.
0176 
0177   inline friend Hep2Vector operator * (const Hep2Vector & p, double a);
0178   // v*c
0179 
0180   inline friend Hep2Vector operator * (double a, const Hep2Vector & p);
0181   // c*v
0182 
0183          friend Hep2Vector operator / (const Hep2Vector & p, double a);
0184   // v/c
0185 
0186   inline friend Hep2Vector operator + (const Hep2Vector & a,
0187                        const Hep2Vector & b);
0188   // v1+v2
0189 
0190   inline friend Hep2Vector operator - (const Hep2Vector & a,
0191                         const Hep2Vector & b);
0192   // v1-v2
0193 
0194   static const int ZMpvToleranceTicks = 100;
0195 
0196 private:
0197 
0198   double dx;
0199   double dy;
0200   // The components.
0201 
0202   static double tolerance;
0203   // default tolerance criterion for isNear() to return true.
0204 
0205 };  // Hep2Vector
0206 
0207 static const Hep2Vector X_HAT2(1.0, 0.0);
0208 static const Hep2Vector Y_HAT2(0.0, 1.0);
0209 
0210 }  // namespace CLHEP
0211 
0212 #include "CLHEP/Vector/TwoVector.icc"
0213 
0214 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0215 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0216 using namespace CLHEP;
0217 #endif
0218 
0219 
0220 #endif /* HEP_TWOVECTOR_H */