Belle II Software  release-08-01-10
TwoVector.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * Forked from https://github.com/iLCSoft/MarlinKinfit *
6  * *
7  * Further information about the fit engine and the user interface *
8  * provided in MarlinKinfit can be found at *
9  * https://www.desy.de/~blist/kinfit/doc/html/ *
10  * and in the LCNotes LC-TOOL-2009-001 and LC-TOOL-2009-004 available *
11  * from http://www-flc.desy.de/lcnotes/ *
12  * *
13  * See git log for contributors and copyright holders. *
14  * This file is licensed under LGPL-3.0, see LICENSE.md. *
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 
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
Definition: B2Vector3.h:537
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
B2Vector3< DataType > operator-(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for substracting a TVector3 from a B2Vector3
Definition: B2Vector3.h:551
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
Definition: B2Vector3.h:544
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.