CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

Vector/CLHEP/Vector/TwoVector.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // CLASSDOC OFF
3 // ---------------------------------------------------------------------------
4 // CLASSDOC ON
5 //
6 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
7 //
8 // Hep2Vector is a general 2-vector class defining vectors in two
9 // dimension using double components. It comes from the ZOOM
10 // PlaneVector class (the PhysicsVectors PlaneVector.h will typedef
11 // PlaneVector to Hep2Vector).
12 //
13 // .SS See Also
14 // ThreeVector.h
15 //
16 // .SS Authors
17 // John Marraffino and Mark Fischler
18 //
19 
20 #ifndef HEP_TWOVECTOR_H
21 #define HEP_TWOVECTOR_H
22 
23 #ifdef GNUPRAGMA
24 #pragma interface
25 #endif
26 
27 #include <iostream>
28 
29 #include "CLHEP/Vector/defs.h"
30 #include "CLHEP/Vector/ThreeVector.h"
31 
32 namespace CLHEP {
33 
34 // Declarations of classes and global methods
35 class Hep2Vector;
36 std::ostream & operator << (std::ostream &, const Hep2Vector &);
37 std::istream & operator >> (std::istream &, Hep2Vector &);
38 inline double operator * (const Hep2Vector & a,const Hep2Vector & b);
39 inline Hep2Vector operator * (const Hep2Vector & p, double a);
40 inline Hep2Vector operator * (double a, const Hep2Vector & p);
41  Hep2Vector operator / (const Hep2Vector & p, double a);
42 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b);
43 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b);
44 
49 class Hep2Vector {
50 
51 public:
52 
53  enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM_COORDINATES };
54  // Safe indexing of the coordinates when using with matrices, arrays, etc.
55 
56  inline Hep2Vector( double x = 0.0, double y = 0.0 );
57  // The constructor.
58 
59  inline Hep2Vector(const Hep2Vector & p);
60  // The copy constructor.
61 
62  explicit Hep2Vector( const Hep3Vector & );
63  // "demotion" constructor"
64  // WARNING -- THIS IGNORES THE Z COMPONENT OF THE Hep3Vector.
65  // SO IN GENERAL, Hep2Vector(v)==v WILL NOT HOLD!
66 
67  inline ~Hep2Vector();
68  // The destructor.
69 
70  inline double x() const;
71  inline double y() const;
72  // The components in cartesian coordinate system.
73 
74  double operator () (int i) const;
75  inline double operator [] (int i) const;
76  // Get components by index. 0-based.
77 
78  double & operator () (int i);
79  inline double & operator [] (int i);
80  // Set components by index. 0-based.
81 
82  inline void setX(double x);
83  inline void setY(double y);
84  inline void set (double x, double y);
85  // Set the components in cartesian coordinate system.
86 
87  inline double phi() const;
88  // The azimuth angle.
89 
90  inline double mag2() const;
91  // The magnitude squared.
92 
93  inline double mag() const;
94  // The magnitude.
95 
96  inline double r() const;
97  // r in polar coordinates (r, phi): equal to mag().
98 
99  inline void setPhi(double phi);
100  // Set phi keeping mag constant.
101 
102  inline void setMag(double r);
103  // Set magnitude keeping phi constant.
104 
105  inline void setR(double r);
106  // Set R keeping phi constant. Same as setMag.
107 
108  inline void setPolar(double r, double phi);
109  // Set by polar coordinates.
110 
111  inline Hep2Vector & operator = (const Hep2Vector & p);
112  // Assignment.
113 
114  inline bool operator == (const Hep2Vector & v) const;
115  inline bool operator != (const Hep2Vector & v) const;
116  // Comparisons.
117 
118  int compare (const Hep2Vector & v) const;
119  bool operator > (const Hep2Vector & v) const;
120  bool operator < (const Hep2Vector & v) const;
121  bool operator>= (const Hep2Vector & v) const;
122  bool operator<= (const Hep2Vector & v) const;
123  // dictionary ordering according to y, then x component
124 
125  static inline double getTolerance();
126  static double setTolerance(double tol);
127 
128  double howNear (const Hep2Vector &p) const;
129  bool isNear (const Hep2Vector & p, double epsilon=tolerance) const;
130 
131  double howParallel (const Hep2Vector &p) const;
132  bool isParallel
133  (const Hep2Vector & p, double epsilon=tolerance) const;
134 
135  double howOrthogonal (const Hep2Vector &p) const;
136  bool isOrthogonal
137  (const Hep2Vector & p, double epsilon=tolerance) const;
138 
139  inline Hep2Vector & operator += (const Hep2Vector &p);
140  // Addition.
141 
142  inline Hep2Vector & operator -= (const Hep2Vector &p);
143  // Subtraction.
144 
145  inline Hep2Vector operator - () const;
146  // Unary minus.
147 
148  inline Hep2Vector & operator *= (double a);
149  // Scaling with real numbers.
150 
151  inline Hep2Vector unit() const;
152  // Unit vector parallel to this.
153 
154  inline Hep2Vector orthogonal() const;
155  // Vector orthogonal to this.
156 
157  inline double dot(const Hep2Vector &p) const;
158  // Scalar product.
159 
160  inline double angle(const Hep2Vector &) const;
161  // The angle w.r.t. another 2-vector.
162 
163  void rotate(double);
164  // Rotates the Hep2Vector.
165 
166  operator Hep3Vector () const;
167  // Cast a Hep2Vector as a Hep3Vector.
168 
169  // The remaining methods are friends, thus defined at global scope:
170  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171 
172  friend std::ostream & operator<< (std::ostream &, const Hep2Vector &);
173  // Output to a stream.
174 
175  inline friend double operator * (const Hep2Vector & a,
176  const Hep2Vector & b);
177  // Scalar product.
178 
179  inline friend Hep2Vector operator * (const Hep2Vector & p, double a);
180  // v*c
181 
182  inline friend Hep2Vector operator * (double a, const Hep2Vector & p);
183  // c*v
184 
185  friend Hep2Vector operator / (const Hep2Vector & p, double a);
186  // v/c
187 
188  inline friend Hep2Vector operator + (const Hep2Vector & a,
189  const Hep2Vector & b);
190  // v1+v2
191 
192  inline friend Hep2Vector operator - (const Hep2Vector & a,
193  const Hep2Vector & b);
194  // v1-v2
195 
196  enum { ZMpvToleranceTicks = 100 };
197 
198 private:
199 
200  double dx;
201  double dy;
202  // The components.
203 
204  static double tolerance;
205  // default tolerance criterion for isNear() to return true.
206 
207 }; // Hep2Vector
208 
209 static const Hep2Vector X_HAT2(1.0, 0.0);
210 static const Hep2Vector Y_HAT2(0.0, 1.0);
211 
212 } // namespace CLHEP
213 
214 #include "CLHEP/Vector/TwoVector.icc"
215 
216 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
217 // backwards compatibility will be enabled ONLY in CLHEP 1.9
218 using namespace CLHEP;
219 #endif
220 
221 
222 #endif /* HEP_TWOVECTOR_H */
CLHEP::Hep2Vector::operator-
Hep2Vector operator-() const
CLHEP::Hep2Vector::y
double y() const
X
Definition: testSharedPtrBasic.cc:28
CLHEP::Hep2Vector::orthogonal
Hep2Vector orthogonal() const
CLHEP::Hep2Vector::operator*=
Hep2Vector & operator*=(double a)
a
@ a
Definition: testCategories.cc:125
CLHEP::Hep2Vector::howNear
double howNear(const Hep2Vector &p) const
Definition: TwoVector.cc:122
b
@ b
Definition: testCategories.cc:125
CLHEP::Hep2Vector::operator()
double operator()(int i) const
Definition: TwoVector.cc:29
CLHEP::Hep2Vector::unit
Hep2Vector unit() const
CLHEP::Hep2Vector::setY
void setY(double y)
CLHEP::Hep2Vector::operator==
bool operator==(const Hep2Vector &v) const
CLHEP::Hep2Vector::operator<=
bool operator<=(const Hep2Vector &v) const
Definition: TwoVector.cc:113
CLHEP::Hep2Vector::setPolar
void setPolar(double r, double phi)
CLHEP::Hep2Vector::setX
void setX(double x)
CLHEP::Hep2Vector::operator+=
Hep2Vector & operator+=(const Hep2Vector &p)
CLHEP::Hep2Vector::operator+
friend Hep2Vector operator+(const Hep2Vector &a, const Hep2Vector &b)
CLHEP::Hep2Vector::compare
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:89
CLHEP::Hep2Vector::setTolerance
static double setTolerance(double tol)
Definition: TwoVector.cc:22
CLHEP::Hep2Vector::Hep2Vector
Hep2Vector(double x=0.0, double y=0.0)
CLHEP::operator/
HepLorentzVector operator/(const HepLorentzVector &, double a)
Definition: LorentzVector.cc:162
CLHEP::Hep2Vector::getTolerance
static double getTolerance()
CLHEP::Hep2Vector::ZMpvToleranceTicks
@ ZMpvToleranceTicks
Definition: Geometry/CLHEP/Vector/TwoVector.h:196
CLHEP::Hep2Vector::isNear
bool isNear(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:117
CLHEP::Hep2Vector::SIZE
@ SIZE
Definition: Geometry/CLHEP/Vector/TwoVector.h:53
CLHEP::Hep2Vector::operator>
bool operator>(const Hep2Vector &v) const
Definition: TwoVector.cc:104
CLHEP
Definition: ClhepVersion.h:13
CLHEP::Hep2Vector::setPhi
void setPhi(double phi)
CLHEP::operator-
Hep3Vector operator-(const Hep3Vector &, const Hep3Vector &)
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
CLHEP::Hep2Vector::mag
double mag() const
Hep3Vector
Issues Concerning the PhysicsVectors CLHEP Vector Merge The merge of ZOOM PhysicsVdectors and the CLHEP Vector package is completed The purpose of this document is to list the major issues that affected the merge of these and where relevant describe the resolutions More detailed documents describe more minor issues General Approach As agreed at the June CLHEP the approach is to combine the features of each ZOOM class with the corresponding CLHEP class expanding the interface to create a single lingua franca of what a Hep3Vector(for example) means. We are not forming SpaceVector as an class derived from Hep3Vector and enhancing it in that way. Another rule imposed by the agreement is to avoid using the Exceptions package(even though that will later go into CLHEP for other uses). A desirable goal is to avoid cluttering the interface and enlarging the code linked in when ordinary CLHEP Vector functionallity is used. To this end
CLHEP::Hep2Vector::operator!=
bool operator!=(const Hep2Vector &v) const
CLHEP::Hep2Vector::setR
void setR(double r)
CLHEP::Hep2Vector::x
double x() const
CLHEP::Hep2Vector::~Hep2Vector
~Hep2Vector()
CLHEP::Hep2Vector::operator-=
Hep2Vector & operator-=(const Hep2Vector &p)
CLHEP::Hep2Vector::operator*
friend double operator*(const Hep2Vector &a, const Hep2Vector &b)
CLHEP::Hep2Vector::operator/
friend Hep2Vector operator/(const Hep2Vector &p, double a)
Definition: TwoVector.cc:63
CLHEP::operator>>
std::istream & operator>>(std::istream &is, HepAxisAngle &aa)
Definition: AxisAngle.cc:96
Y
Definition: testSharedPtrBasic.cc:34
CLHEP::Hep2Vector::howOrthogonal
double howOrthogonal(const Hep2Vector &p) const
Definition: TwoVector.cc:163
CLHEP::Hep2Vector::set
void set(double x, double y)
CLHEP::Hep2Vector::mag2
double mag2() const
CLHEP::Hep2Vector::angle
double angle(const Hep2Vector &) const
CLHEP::Hep2Vector::isOrthogonal
bool isOrthogonal(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:178
CLHEP::Hep2Vector::operator<
bool operator<(const Hep2Vector &v) const
Definition: TwoVector.cc:107
CLHEP::Hep2Vector::operator[]
double operator[](int i) const
i
long i
Definition: JamesRandomSeeding.txt:27
CLHEP::Hep2Vector::howParallel
double howParallel(const Hep2Vector &p) const
Definition: TwoVector.cc:134
CLHEP::operator+
Hep3Vector operator+(const Hep3Vector &, const Hep3Vector &)
CLHEP::Hep2Vector::operator=
Hep2Vector & operator=(const Hep2Vector &p)
CLHEP::Hep2Vector::r
double r() const
CLHEP::operator<<
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)
Definition: AxisAngle.cc:86
CLHEP::Hep2Vector::operator>=
bool operator>=(const Hep2Vector &v) const
Definition: TwoVector.cc:110
CLHEP::Hep2Vector::operator<<
friend std::ostream & operator<<(std::ostream &, const Hep2Vector &)
Definition: TwoVector.cc:70
CLHEP::operator*
HepLorentzRotation operator*(const HepRotation &r, const HepLorentzRotation &lt)
Definition: LorentzRotation.cc:262
CLHEP::Hep2Vector::phi
double phi() const
CLHEP::Hep2Vector::setMag
void setMag(double r)
CLHEP::Hep2Vector::rotate
void rotate(double)
Definition: TwoVector.cc:55
CLHEP::Hep2Vector::isParallel
bool isParallel(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:150
CLHEP::Hep2Vector::NUM_COORDINATES
@ NUM_COORDINATES
Definition: Geometry/CLHEP/Vector/TwoVector.h:53
CLHEP::Hep2Vector::dot
double dot(const Hep2Vector &p) const