CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
oldBasic2DVector.h
Go to the documentation of this file.
1 #ifndef GeometryVector_oldBasic2DVector_h
2 #define GeometryVector_oldBasic2DVector_h
3 #if defined(__CINT__) && !defined(__REFLEX__)
4 #define __REFLEX__
5 #endif
6 
10 #ifndef __REFLEX__
12 #endif
13 
14 
15 #include <cmath>
16 #include <iosfwd>
17 
18 
19 template < class T>
20 class Basic2DVector {
21 public:
23 
24  typedef T ScalarType;
26 
31  Basic2DVector() : theX(0), theY(0) {}
32 
35  theX(p.x()), theY(p.y()) {}
36 
44  template <class Other>
45  explicit Basic2DVector( const Other& p) : theX(p.x()), theY(p.y()) {}
46 
48  Basic2DVector( const T& x, const T& y) : theX(x), theY(y) {}
49 
50 
51 #ifndef __REFLEX__
52  // constructor from Vec2 or vec4
53  template<typename U>
55  theX(iv.arr[0]), theY(iv.arr[1]) {}
56  template<typename U>
58  theX(iv.arr[0]), theY(iv.arr[1]) {}
59 #endif
60 
61 
63  T x() const { return theX;}
64 
66  T y() const { return theY;}
67 
69  T mag2() const { return theX*theX + theY*theY;}
70 
72  T mag() const { return std::sqrt( mag2());}
73 
75  T r() const { return mag();}
76 
81  T barePhi() const {return std::atan2(theY,theX);}
82  Geom::Phi<T> phi() const {return Geom::Phi<T>(atan2(theY,theX));}
83 
87  Basic2DVector unit() const {
88  T my_mag = mag();
89  return my_mag == 0 ? *this : *this / my_mag;
90  }
91 
94  template <class U>
96  theX += p.x();
97  theY += p.y();
98  return *this;
99  }
100 
103  template <class U>
105  theX -= p.x();
106  theY -= p.y();
107  return *this;
108  }
109 
111  Basic2DVector operator-() const { return Basic2DVector(-x(),-y());}
112 
115  theX *= t;
116  theY *= t;
117  return *this;
118  }
119 
122  theX /= t;
123  theY /= t;
124  return *this;
125  }
126 
128  T dot( const Basic2DVector& v) const { return x()*v.x() + y()*v.y();}
129 
135  template <class U>
137  return x()*v.x() + y()*v.y();
138  }
139 
140 
141 
143  T cross( const Basic2DVector& v) const { return x()*v.y() - y()*v.x();}
144 
150  template <class U>
152  return x()*v.y() - y()*v.x();
153  }
154 
155 
156 private:
159 };
160 
161 
162 namespace geometryDetails {
163  std::ostream & print2D(std::ostream& s, double x, double y);
164 
165 }
166 
168 template <class T>
169 inline std::ostream & operator<<( std::ostream& s, const Basic2DVector<T>& v) {
170  return geometryDetails::print2D(s, v.x(),v.y());
171 }
172 
173 
175 template <class T, class U>
179  return RT(a.x()+b.x(), a.y()+b.y());
180 }
181 
182 template <class T, class U>
186  return RT(a.x()-b.x(), a.y()-b.y());
187 }
188 
189 
190 
191 
192 // scalar product of vectors of same precision
193 template <class T>
194 inline T operator*( const Basic2DVector<T>& v1, const Basic2DVector<T>& v2) {
195  return v1.dot(v2);
196 }
197 
199 template <class T, class U>
201  const Basic2DVector<U>& v2) {
202  return v1.x()*v2.x() + v1.y()*v2.y();
203 }
204 
208 template <class T, class Scalar>
210  T t = static_cast<T>(s);
211  return Basic2DVector<T>(v.x()*t, v.y()*t);
212 }
213 
215 template <class T, class Scalar>
217  T t = static_cast<T>(s);
218  return Basic2DVector<T>(v.x()*t, v.y()*t);
219 }
220 
224 template <class T, class Scalar>
226  T t = static_cast<T>(s);
227  return Basic2DVector<T>(v.x()/t, v.y()/t);
228 }
229 
230 
233 
234 #endif // GeometryVector_Basic2DVector_h
Basic2DVector(const T &x, const T &y)
construct from cartesian coordinates
Basic2DVector(mathSSE::Vec2< U > const &iv)
double Scalar
Definition: Definitions.h:27
MatrixMeschach operator+(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
Basic2DVector(const Basic2DVector &p)
Copy constructor from same type. Should not be needed but for gcc bug 12685.
T dot(const Basic2DVector &lh) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
MatrixMeschach operator-(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Basic2DVector operator-() const
Unary minus, returns a vector with components (-x(),-y(),-z())
T r() const
Radius, same as mag()
T barePhi() const
Basic2DVector(const Other &p)
Basic3DVector< long double > operator/(const Basic3DVector< long double > &v, S s)
Basic2DVector unit() const
Geom::Polar2Cartesian< T > Polar
Basic2DVector< float > Basic2DVectorF
T sqrt(T t)
Definition: SSEVec.h:46
Basic2DVector & operator*=(T t)
Scaling by a scalar value (multiplication)
Basic2DVector & operator/=(T t)
Scaling by a scalar value (division)
T dot(const Basic2DVector &v) const
Scalar product, or &quot;dot&quot; product, with a vector of same type.
std::ostream & print2D(std::ostream &s, double x, double y)
Definition: print.cc:8
Basic2DVector & operator+=(const Basic2DVector< U > &p)
T y() const
Cartesian y coordinate.
PreciseFloatType< T, U >::Type dot(const Basic2DVector< U > &v) const
Basic2DVector & operator-=(const Basic2DVector< U > &p)
double b
Definition: hdecay.h:120
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Basic2DVector(mathSSE::Vec4< U > const &iv)
double a
Definition: hdecay.h:121
Basic2DVector< T > MathVector
PreciseFloatType< T, U >::Type cross(const Basic2DVector< U > &v) const
MatrixMeschach operator*(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
T cross(const Basic2DVector &v) const
Vector product, or &quot;cross&quot; product, with a vector of same type.
Basic2DVector< double > Basic2DVectorD
x
Definition: VDTMath.h:216
Geom::Phi< T > phi() const
long double T
Definition: Phi.h:20
mathSSE::Vec4< T > v
mathSSE::Vec2< T > v
T x() const
Cartesian x coordinate.