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 |
|
---|
45 | /**
|
---|
46 | * @author
|
---|
47 | * @ingroup vector
|
---|
48 | */
|
---|
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 & s);
|
---|
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 */
|
---|