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