CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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#include <iostream>
24
25#include "CLHEP/Vector/defs.h"
26#include "CLHEP/Vector/ThreeVector.h"
27
28namespace CLHEP {
29
30// Declarations of classes and global methods
31class Hep2Vector;
32std::ostream & operator << (std::ostream &, const Hep2Vector &);
33std::istream & operator >> (std::istream &, Hep2Vector &);
34inline double operator * (const Hep2Vector & a,const Hep2Vector & b);
35inline Hep2Vector operator * (const Hep2Vector & p, double a);
36inline Hep2Vector operator * (double a, const Hep2Vector & p);
37 Hep2Vector operator / (const Hep2Vector & p, double a);
38inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b);
39inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b);
40
41/**
42 * @author
43 * @ingroup vector
44 */
46
47public:
48
50 // Safe indexing of the coordinates when using with matrices, arrays, etc.
51
52 inline Hep2Vector( double x = 0.0, double y = 0.0 );
53 // The constructor.
54
55 inline Hep2Vector(const Hep2Vector & p);
56 inline Hep2Vector(Hep2Vector && p) = default;
57 // The copy and move constructors.
58
59 explicit Hep2Vector( const Hep3Vector & );
60 // "demotion" constructor"
61 // WARNING -- THIS IGNORES THE Z COMPONENT OF THE Hep3Vector.
62 // SO IN GENERAL, Hep2Vector(v)==v WILL NOT HOLD!
63
64 inline ~Hep2Vector();
65 // The destructor.
66
67 inline double x() const;
68 inline double y() const;
69 // The components in cartesian coordinate system.
70
71 double operator () (int i) const;
72 inline double operator [] (int i) const;
73 // Get components by index. 0-based.
74
75 double & operator () (int i);
76 inline double & operator [] (int i);
77 // Set components by index. 0-based.
78
79 inline void setX(double x);
80 inline void setY(double y);
81 inline void set (double x, double y);
82 // Set the components in cartesian coordinate system.
83
84 inline double phi() const;
85 // The azimuth angle.
86
87 inline double mag2() const;
88 // The magnitude squared.
89
90 inline double mag() const;
91 // The magnitude.
92
93 inline double r() const;
94 // r in polar coordinates (r, phi): equal to mag().
95
96 inline void setPhi(double phi);
97 // Set phi keeping mag constant.
98
99 inline void setMag(double r);
100 // Set magnitude keeping phi constant.
101
102 inline void setR(double r);
103 // Set R keeping phi constant. Same as setMag.
104
105 inline void setPolar(double r, double phi);
106 // Set by polar coordinates.
107
108 inline Hep2Vector & operator = (const Hep2Vector & p);
109 inline Hep2Vector & operator = (Hep2Vector && p) = default;
110 // The copy and move assignment operators.
111
112 inline bool operator == (const Hep2Vector & v) const;
113 inline bool operator != (const Hep2Vector & v) const;
114 // Comparisons.
115
116 int compare (const Hep2Vector & v) const;
117 bool operator > (const Hep2Vector & v) const;
118 bool operator < (const Hep2Vector & v) const;
119 bool operator>= (const Hep2Vector & v) const;
120 bool operator<= (const Hep2Vector & v) const;
121 // dictionary ordering according to y, then x component
122
123 static inline double getTolerance();
124 static double setTolerance(double tol);
125
126 double howNear (const Hep2Vector &p) const;
127 bool isNear (const Hep2Vector & p, double epsilon=tolerance) const;
128
129 double howParallel (const Hep2Vector &p) const;
130 bool isParallel
131 (const Hep2Vector & p, double epsilon=tolerance) const;
132
133 double howOrthogonal (const Hep2Vector &p) const;
134 bool isOrthogonal
135 (const Hep2Vector & p, double epsilon=tolerance) const;
136
138 // Addition.
139
141 // Subtraction.
142
143 inline Hep2Vector operator - () const;
144 // Unary minus.
145
146 inline Hep2Vector & operator *= (double a);
147 // Scaling with real numbers.
148
149 inline Hep2Vector unit() const;
150 // Unit vector parallel to this.
151
152 inline Hep2Vector orthogonal() const;
153 // Vector orthogonal to this.
154
155 inline double dot(const Hep2Vector &p) const;
156 // Scalar product.
157
158 inline double angle(const Hep2Vector &) const;
159 // The angle w.r.t. another 2-vector.
160
161 void rotate(double);
162 // Rotates the Hep2Vector.
163
164 operator Hep3Vector () const;
165 // Cast a Hep2Vector as a Hep3Vector.
166
167 // The remaining methods are friends, thus defined at global scope:
168 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169
170 friend std::ostream & operator<< (std::ostream &, const Hep2Vector &);
171 // Output to a stream.
172
173 inline friend double operator * (const Hep2Vector & a,
174 const Hep2Vector & b);
175 // Scalar product.
176
177 inline friend Hep2Vector operator * (const Hep2Vector & p, double a);
178 // v*c
179
180 inline friend Hep2Vector operator * (double a, const Hep2Vector & p);
181 // c*v
182
183 friend Hep2Vector operator / (const Hep2Vector & p, double a);
184 // v/c
185
186 inline friend Hep2Vector operator + (const Hep2Vector & a,
187 const Hep2Vector & b);
188 // v1+v2
189
190 inline friend Hep2Vector operator - (const Hep2Vector & a,
191 const Hep2Vector & b);
192 // v1-v2
193
194 static const int ZMpvToleranceTicks = 100;
195
196private:
197
198 double dx;
199 double dy;
200 // The components.
201
202 static double tolerance;
203 // default tolerance criterion for isNear() to return true.
204
205}; // Hep2Vector
206
207static const Hep2Vector X_HAT2(1.0, 0.0);
208static const Hep2Vector Y_HAT2(0.0, 1.0);
209
210} // namespace CLHEP
211
212#include "CLHEP/Vector/TwoVector.icc"
213
214#ifdef ENABLE_BACKWARDS_COMPATIBILITY
215// backwards compatibility will be enabled ONLY in CLHEP 1.9
216using namespace CLHEP;
217#endif
218
219
220#endif /* HEP_TWOVECTOR_H */
double mag2() const
Hep2Vector & operator+=(const Hep2Vector &p)
bool operator==(const Hep2Vector &v) const
bool isOrthogonal(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:178
void setMag(double r)
bool operator<=(const Hep2Vector &v) const
Definition: TwoVector.cc:113
Hep2Vector operator-() const
double r() const
void setY(double y)
static double getTolerance()
friend std::ostream & operator<<(std::ostream &, const Hep2Vector &)
Definition: TwoVector.cc:70
double dot(const Hep2Vector &p) const
void setX(double x)
double howOrthogonal(const Hep2Vector &p) const
Definition: TwoVector.cc:163
double operator[](int i) const
double x() const
void setR(double r)
double angle(const Hep2Vector &) const
bool isNear(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:117
Hep2Vector orthogonal() const
double howNear(const Hep2Vector &p) const
Definition: TwoVector.cc:122
double mag() const
double howParallel(const Hep2Vector &p) const
Definition: TwoVector.cc:134
void setPhi(double phi)
friend double operator*(const Hep2Vector &a, const Hep2Vector &b)
friend Hep2Vector operator+(const Hep2Vector &a, const Hep2Vector &b)
bool operator!=(const Hep2Vector &v) const
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:89
void setPolar(double r, double phi)
double phi() const
double y() const
bool isParallel(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:150
Hep2Vector(const Hep3Vector &)
bool operator>(const Hep2Vector &v) const
Definition: TwoVector.cc:104
static const int ZMpvToleranceTicks
Definition: TwoVector.h:194
void set(double x, double y)
double operator()(int i) const
Definition: TwoVector.cc:29
Hep2Vector & operator*=(double a)
bool operator>=(const Hep2Vector &v) const
Definition: TwoVector.cc:110
Hep2Vector & operator=(const Hep2Vector &p)
Hep2Vector(const Hep2Vector &p)
void rotate(double)
Definition: TwoVector.cc:55
Hep2Vector & operator-=(const Hep2Vector &p)
static double setTolerance(double tol)
Definition: TwoVector.cc:22
Hep2Vector unit() const
bool operator<(const Hep2Vector &v) const
Definition: TwoVector.cc:107
Hep2Vector(Hep2Vector &&p)=default
Hep2Vector(double x=0.0, double y=0.0)
friend Hep2Vector operator/(const Hep2Vector &p, double a)
Definition: TwoVector.cc:63
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:225
std::ostream & operator<<(std::ostream &s, const HepDiagMatrix &q)
Definition: DiagMatrix.cc:560
HepMatrix operator+(const HepMatrix &hm1, const HepDiagMatrix &d2)
Definition: DiagMatrix.cc:193
HepMatrix operator-(const HepMatrix &hm1, const HepDiagMatrix &d2)
Definition: DiagMatrix.cc:264
HepDiagMatrix operator/(const HepDiagMatrix &hm1, double t)
Definition: DiagMatrix.cc:335
HepMatrix operator*(const HepMatrix &hm1, const HepDiagMatrix &hm2)
Definition: DiagMatrix.cc:372