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