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(IN_DICTBUILD) || 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 #if defined(USE_EXTVECT)
52  // constructor from Vec2 or vec4
53  template<typename U>
54  Basic2DVector(Vec2<U> const& iv) :
55  theX(iv[0]), theY(iv[1]) {}
56  template<typename U>
57  Basic2DVector(Vec4<U> const& iv) :
58  theX(iv.arr[0]), theY(iv.arr[1]) {}
59 #elif defined(USE_SSEVECT)
60  // constructor from Vec2 or vec4
61  template<typename U>
62  Basic2DVector(mathSSE::Vec2<U> const& iv) :
63  theX(iv.arr[0]), theY(iv.arr[1]) {}
64  template<typename U>
65  Basic2DVector(mathSSE::Vec4<U> const& iv) :
66  theX(iv.arr[0]), theY(iv.arr[1]) {}
67 #endif
68 
69  T operator[](int i) const { return i==0 ? theX : theY ;}
70  T & operator[](int i) { return i==0 ? theX : theY ;}
71 
73  T x() const { return theX;}
74 
76  T y() const { return theY;}
77 
79  T mag2() const { return theX*theX + theY*theY;}
80 
82  T mag() const { return std::sqrt( mag2());}
83 
85  T r() const { return mag();}
86 
91  T barePhi() const {return std::atan2(theY,theX);}
92  Geom::Phi<T> phi() const {return Geom::Phi<T>(atan2(theY,theX));}
93 
97  Basic2DVector unit() const {
98  T my_mag = mag();
99  return my_mag == 0 ? *this : *this / my_mag;
100  }
101 
104  template <class U>
106  theX += p.x();
107  theY += p.y();
108  return *this;
109  }
110 
113  template <class U>
115  theX -= p.x();
116  theY -= p.y();
117  return *this;
118  }
119 
121  Basic2DVector operator-() const { return Basic2DVector(-x(),-y());}
122 
125  theX *= t;
126  theY *= t;
127  return *this;
128  }
129 
132  theX /= t;
133  theY /= t;
134  return *this;
135  }
136 
138  T dot( const Basic2DVector& v) const { return x()*v.x() + y()*v.y();}
139 
145  template <class U>
147  return x()*v.x() + y()*v.y();
148  }
149 
150 
151 
153  T cross( const Basic2DVector& v) const { return x()*v.y() - y()*v.x();}
154 
160  template <class U>
162  return x()*v.y() - y()*v.x();
163  }
164 
165 
166 private:
169 };
170 
171 
172 namespace geometryDetails {
173  std::ostream & print2D(std::ostream& s, double x, double y);
174 
175 }
176 
178 template <class T>
179 inline std::ostream & operator<<( std::ostream& s, const Basic2DVector<T>& v) {
180  return geometryDetails::print2D(s, v.x(),v.y());
181 }
182 
183 
185 template <class T, class U>
189  return RT(a.x()+b.x(), a.y()+b.y());
190 }
191 
192 template <class T, class U>
196  return RT(a.x()-b.x(), a.y()-b.y());
197 }
198 
199 
200 
201 
202 // scalar product of vectors of same precision
203 template <class T>
204 inline T operator*( const Basic2DVector<T>& v1, const Basic2DVector<T>& v2) {
205  return v1.dot(v2);
206 }
207 
209 template <class T, class U>
211  const Basic2DVector<U>& v2) {
212  return v1.x()*v2.x() + v1.y()*v2.y();
213 }
214 
218 template <class T, class Scalar>
220  T t = static_cast<T>(s);
221  return Basic2DVector<T>(v.x()*t, v.y()*t);
222 }
223 
225 template <class T, class Scalar>
227  T t = static_cast<T>(s);
228  return Basic2DVector<T>(v.x()*t, v.y()*t);
229 }
230 
234 template <class T, class Scalar>
236  T t = static_cast<T>(s);
237  return Basic2DVector<T>(v.x()/t, v.y()/t);
238 }
239 
240 
243 
244 #endif // GeometryVector_Basic2DVector_h
int i
Definition: DBlmapReader.cc:9
Basic2DVector(const T &x, const T &y)
construct from cartesian coordinates
double Scalar
Definition: Definitions.h:27
ExtVec< T, 4 > Vec4
Definition: ExtVec.h:74
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< double > Basic2DVectorD
Basic2DVector unit() const
T x() const
Cartesian x coordinate.
Basic2DVector< float > Basic2DVectorF
Geom::Polar2Cartesian< T > Polar
T sqrt(T t)
Definition: SSEVec.h:48
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.
T & operator[](int i)
PreciseFloatType< T, U >::Type dot(const Basic2DVector< U > &v) const
Basic2DVector & operator-=(const Basic2DVector< U > &p)
ExtVec< T, 2 > Vec2
Definition: ExtVec.h:75
double b
Definition: hdecay.h:120
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
T operator[](int i) const
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.
Geom::Phi< T > phi() const
long double T
Definition: Phi.h:20
T x() const
Cartesian x coordinate.