Belle II Software  release-05-02-19
TwoVector.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * See https://github.com/tferber/OrcaKinfit, forked from *
4  * https://github.com/iLCSoft/MarlinKinfit *
5  * *
6  * Further information about the fit engine and the user interface *
7  * provided in MarlinKinfit can be found at *
8  * https://www.desy.de/~blist/kinfit/doc/html/ *
9  * and in the LCNotes LC-TOOL-2009-001 and LC-TOOL-2009-004 available *
10  * from http://www-flc.desy.de/lcnotes/ *
11  * *
12  * Adopted by: Torben Ferber (torben.ferber@desy.de) (TF) *
13  * *
14  * This software is provided "as is" without any warranty. *
15  **************************************************************************/
16 
17 #ifndef __TWOVECTOR_H
18 #define __TWOVECTOR_H
19 
20 #include <iostream>
21 #include <cmath>
22 
23 namespace Belle2 {
29  namespace OrcaKinFit {
30 
31  class TwoVector {
32  public:
33  inline TwoVector();
34  inline TwoVector(double x_, double y_);
35  // automatically generated copy constructor and assignment is fine
36 
37  inline double getX() const;
38  inline double getY() const;
39 
40  inline double getMag2() const;
41  inline double getMag() const;
42 
43  inline double getPhi() const;
44 
45  inline double getComponent(int i) const;
46 
47  inline TwoVector& setValues(double x_, double y_);
48 
49  inline TwoVector& operator+= (const TwoVector& rhs);
50  inline TwoVector& operator-= (const TwoVector& rhs);
51  inline TwoVector& operator*= (double rhs);
52 
53  private:
54  double x, y;
55  };
56 
57  TwoVector::TwoVector()
58  : x(0), y(0)
59  {}
60 
61  TwoVector::TwoVector(double x_, double y_)
62  : x(x_), y(y_)
63  {}
64 
65  double TwoVector::getX() const { return x; }
66  double TwoVector::getY() const { return y; }
67 
68  double TwoVector::getMag2() const { return x * x + y * y; }
69  double TwoVector::getMag()const { return std::sqrt(getMag2()); }
70 
71  double TwoVector::getPhi() const { return std::atan2(y, x); }
72 
73  double TwoVector::getComponent(int i) const
74  {
75  switch (i) {
76  case 0: return getX();
77  case 1: return getY();
78  }
79  return NAN; // not-a-number, defined in cmath
80  }
81 
82  TwoVector& TwoVector::setValues(double x_, double y_)
83  {
84  x = x_;
85  y = y_;
86  return *this;
87  }
88 
89 
90  TwoVector& TwoVector::operator+= (const TwoVector& rhs)
91  {
92  x += rhs.x;
93  y += rhs.y;
94  return *this;
95  }
96 
97  TwoVector& TwoVector::operator-= (const TwoVector& rhs)
98  {
99  x -= rhs.x;
100  y -= rhs.y;
101  return *this;
102  }
103 
104  TwoVector& TwoVector::operator*= (double rhs)
105  {
106  x *= rhs;
107  y *= rhs;
108  return *this;
109  }
110 
111  inline TwoVector operator+ (const TwoVector& lhs, const TwoVector& rhs)
112  {
113  return TwoVector(lhs.getX() + rhs.getX(), lhs.getY() + rhs.getY());
114  }
115 
116  inline TwoVector operator- (const TwoVector& lhs, const TwoVector& rhs)
117  {
118  return TwoVector(lhs.getX() - rhs.getX(), lhs.getY() - rhs.getY());
119  }
120 
121  inline TwoVector operator- (const TwoVector& rhs)
122  {
123  return TwoVector(-rhs.getX(), -rhs.getY());
124  }
125 
126  inline double operator* (const TwoVector& lhs, const TwoVector& rhs)
127  {
128  return lhs.getX() * rhs.getX() + lhs.getY() * rhs.getY();
129  }
130 
131  inline TwoVector operator* (double lhs, const TwoVector& rhs)
132  {
133  return TwoVector(lhs * rhs.getX(), lhs * rhs.getY());
134  }
135 
136  inline std::ostream& operator<< (std::ostream& out, const TwoVector& v)
137  {
138  out << "(" << v.getX() << ", " << v.getY() << ")";
139  return out;
140  }
141 
142  }// end OrcaKinFit namespace
144 } // end Belle2 namespace
145 
146 #endif /* #ifndef __TWOVECTOR_H */
147 
148 
Belle2::operator<<
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
Definition: IntervalOfValidity.cc:196
Belle2::operator*
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
Definition: B2Vector3.h:528
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::operator-
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for substracting a TVector3 from a B2Vector3
Definition: B2Vector3.h:542
Belle2::operator+
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Definition: B2Vector3.h:535
Belle2::OrcaKinFit::TwoVector
Definition: TwoVector.h:45