Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
31 namespace CLHEP {
32 
33 // Declarations of classes and global methods
34 class Hep2Vector;
35 std::ostream & operator << (std::ostream &, const Hep2Vector &);
36 std::istream & operator >> (std::istream &, Hep2Vector &);
37 inline double operator * (const Hep2Vector & a,const Hep2Vector & b);
38 inline Hep2Vector operator * (const Hep2Vector & p, double a);
39 inline Hep2Vector operator * (double a, const Hep2Vector & p);
40  Hep2Vector operator / (const Hep2Vector & p, double a);
41 inline Hep2Vector operator + (const Hep2Vector & a, const Hep2Vector & b);
42 inline Hep2Vector operator - (const Hep2Vector & a, const Hep2Vector & b);
43 
48 class Hep2Vector {
49 
50 public:
51 
52  enum { X=0, Y=1, NUM_COORDINATES=2, SIZE=NUM_COORDINATES };
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 
138  inline Hep2Vector & operator += (const Hep2Vector &p);
139  // Addition.
140 
141  inline Hep2Vector & operator -= (const Hep2Vector &p);
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 
197 private:
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 
208 static const Hep2Vector X_HAT2(1.0, 0.0);
209 static 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 operator[](int i) const
double y() const
void setR(double r)
bool operator==(const Hep2Vector &v) const
double x() const
double howNear(const Hep2Vector &p) const
Definition: TwoVector.cc:121
HepLorentzRotation operator*(const HepRotation &r, const HepLorentzRotation &lt)
bool operator>=(const Hep2Vector &v) const
Definition: TwoVector.cc:109
bool isOrthogonal(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:177
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
const char * p
Definition: xmltok.h:285
Hep2Vector & operator*=(double a)
Hep2Vector operator-() const
friend std::ostream & operator<<(std::ostream &, const Hep2Vector &)
void setPhi(double phi)
bool operator<=(const Hep2Vector &v) const
Definition: TwoVector.cc:112
static const Hep2Vector Y_HAT2(0.0, 1.0)
friend Hep2Vector operator/(const Hep2Vector &p, double a)
static double getTolerance()
Hep3Vector operator+(const Hep3Vector &, const Hep3Vector &)
bool isNear(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:116
friend double operator*(const Hep2Vector &a, const Hep2Vector &b)
bool operator>(const Hep2Vector &v) const
Definition: TwoVector.cc:103
double operator()(int i) const
Definition: TwoVector.cc:27
Hep2Vector(double x=0.0, double y=0.0)
tuple b
Definition: test.py:12
bool operator<(const Hep2Vector &v) const
Definition: TwoVector.cc:106
double mag2() const
std::ostream & operator<<(std::ostream &os, const HepRandom &dist)
Definition: Random.cc:216
void set(double x, double y)
friend Hep2Vector operator+(const Hep2Vector &a, const Hep2Vector &b)
void setPolar(double r, double phi)
Hep2Vector unit() const
double howParallel(const Hep2Vector &p) const
Definition: TwoVector.cc:133
tuple v
Definition: test.py:18
HepLorentzVector operator/(const HepLorentzVector &, double a)
Hep2Vector & operator+=(const Hep2Vector &p)
Hep3Vector operator-(const Hep3Vector &, const Hep3Vector &)
void setMag(double r)
double phi() const
Hep2Vector orthogonal() const
static const Hep2Vector X_HAT2(1.0, 0.0)
Hep2Vector & operator-=(const Hep2Vector &p)
bool operator!=(const Hep2Vector &v) const
Hep2Vector & operator=(const Hep2Vector &p)
static double setTolerance(double tol)
Definition: TwoVector.cc:20
double howOrthogonal(const Hep2Vector &p) const
Definition: TwoVector.cc:162
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:220
double mag() const
bool isParallel(const Hep2Vector &p, double epsilon=tolerance) const
Definition: TwoVector.cc:149
void setY(double y)
double r() const
double dot(const Hep2Vector &p) const
int compare(const Hep2Vector &v) const
Definition: TwoVector.cc:88
void rotate(double)
Definition: TwoVector.cc:53
double epsilon(double density, double temperature)
double angle(const Hep2Vector &) const
void setX(double x)