Belle II Software light-2406-ragdoll
FourVector.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 __FOURVECTOR_H
18#define __FOURVECTOR_H
19
20#include "analysis/OrcaKinFit/ThreeVector.h"
21
22#include <iostream>
23#include <cmath>
24#include <cassert>
25
26namespace Belle2 {
32 namespace OrcaKinFit {
33
34// Class FourVector:
36
43 class FourVector {
44 public:
46 inline FourVector();
48 inline FourVector(double E_, double px_, double py_, double pz_);
50 inline FourVector(double E_, const ThreeVector& p_);
52 inline FourVector(const ThreeVector& p_, double m_);
53 // automatically generated copy constructor and assignment is fine
54
56 inline double getE() const;
58 inline double getPx() const;
60 inline double getPy() const;
62 inline double getPz() const;
64 inline double getM2() const;
66 inline double getM() const;
68 inline double getMass() const;
69
71 inline double getP2() const;
73 inline double getP() const;
75 inline double getPt2() const;
77 inline double getPt() const;
78
80 inline double getPhi() const;
82 inline double getTheta() const;
84 inline double getEta() const;
85
87 inline double getComponent(int i) const;
88
89 inline ThreeVector getBeta() const { assert(E > 0); return (1. / E) * p;};
90 inline double getGamma() const { assert(getM() > 0); return getE() / getM();};
91 inline ThreeVector getBetaGamma() const { assert(getM() > 0); return (1. / getM() > 0) * p;};
92
94 inline const ThreeVector& getThreeVector() const { return p;}
95
96 FourVector& boost(const FourVector& P);
97 void decayto(FourVector& d1, FourVector& d2) const;
98
99 inline void setValues(double E_, double px_, double py_, double pz_);
100
101 inline FourVector& operator+= (const FourVector& rhs);
102 inline FourVector& operator-= (const FourVector& rhs);
103
104 inline FourVector& operator*= (double rhs);
105
106 private:
107 double E;
109 };
110
112 : E(0), p()
113 {}
114
115 FourVector::FourVector(double E_, double px_, double py_, double pz_)
116 : E(E_), p(px_, py_, pz_)
117 {}
118
120 : E(E_), p(p_)
121 {}
122
124 : E(std::sqrt(p_.getP2() + m * m)), p(p_)
125 {}
126
127 double FourVector::getE() const { return E; }
128 double FourVector::getPx() const { return p.getPx(); }
129 double FourVector::getPy() const { return p.getPy(); }
130 double FourVector::getPz() const { return p.getPz(); }
131
132 double FourVector::getPt2() const { return p.getPt2(); }
133 double FourVector::getPt() const { return p.getPt(); }
134
135 double FourVector::getP2() const { return p.getP2(); }
136 double FourVector::getP() const { return p.getP(); }
137
138 double FourVector::getM2() const { return std::abs(getE() * getE() - getP2()); }
139 double FourVector::getM() const { return std::sqrt(getM2()); }
140 double FourVector::getMass() const { return std::sqrt(getM2()); }
141
142 double FourVector::getPhi() const { return p.getPhi(); }
143 double FourVector::getTheta() const { return p.getTheta(); }
144
145 double FourVector::getEta() const { return p.getEta(); }
146
147 double FourVector::getComponent(int i) const
148 {
149 switch (i) {
150 case 1: return getPx();
151 case 2: return getPy();
152 case 3: return getPz();
153 }
154 return getE();
155 }
156
157 void FourVector::setValues(double E_, double px_, double py_, double pz_)
158 {
159 E = E_;
160 p.setValues(px_, py_, pz_);
161 }
162
163 FourVector& FourVector::operator+= (const FourVector& rhs)
164 {
165 p += rhs.p;
166 E += rhs.E;
167 return *this;
168 }
169
170 FourVector& FourVector::operator-= (const FourVector& rhs)
171 {
172 p -= rhs.p;
173 E -= rhs.E;
174 return *this;
175 }
176
177 FourVector& FourVector::operator*= (double rhs)
178 {
179 p *= rhs;
180 E *= rhs;
181 return *this;
182 }
183
188 inline FourVector operator+ (const FourVector& lhs, const FourVector& rhs)
189 {
190 return FourVector(lhs.getE() + rhs.getE(), lhs.getPx() + rhs.getPx(), lhs.getPy() + rhs.getPy(), lhs.getPz() + rhs.getPz());
191 }
192
197 inline FourVector operator- (const FourVector& lhs, const FourVector& rhs)
198 {
199 return FourVector(lhs.getE() - rhs.getE(), lhs.getPx() - rhs.getPx(), lhs.getPy() - rhs.getPy(), lhs.getPz() - rhs.getPz());
200 }
201
206 inline FourVector operator- (const FourVector& rhs)
207 {
208 return FourVector(-rhs.getE(), -rhs.getPx(), -rhs.getPy(), -rhs.getPz());
209 }
210
215 inline FourVector operator* (double lhs, const FourVector& rhs)
216 {
217 return FourVector(lhs * rhs.getE(), lhs * rhs.getPx(), lhs * rhs.getPy(), lhs * rhs.getPz());
218 }
219
224 inline double operator* (const FourVector& lhs, const FourVector& rhs)
225 {
226 return lhs.getE() * rhs.getE() - lhs.getPx() * rhs.getPx() - lhs.getPy() * rhs.getPy() - lhs.getPz() * rhs.getPz();
227 }
228
229
234 inline std::ostream& operator<< (std::ostream& os,
235 const FourVector& rhs
236 )
237 {
238 os << "(" << rhs.getE() << ", " << rhs.getPx() << ", " << rhs.getPy() << ", " << rhs.getPz() << ")";
239 return os;
240 }
241
242 }// end OrcaKinFit namespace
244} // end Belle2 namespace
245
246#endif // __FOURVECTOR_H
Yet another four vector class, with metric +—.
Definition: FourVector.h:43
double getPx() const
Returns the x momentum / 1 component.
Definition: FourVector.h:128
FourVector()
Default constructor.
Definition: FourVector.h:111
double E
The energy / 0 component.
Definition: FourVector.h:107
const ThreeVector & getThreeVector() const
Returns the momentum three vector.
Definition: FourVector.h:94
double getM2() const
Returns the mass squared / magnitude squared.
Definition: FourVector.h:138
double getPz() const
Returns the z momentum / 3 component.
Definition: FourVector.h:130
double getPhi() const
Returns the azimuthal angle of the momentum / three vector squared.
Definition: FourVector.h:142
double getEta() const
Returns the pseudo rapidity of the momentum / three vector squared.
Definition: FourVector.h:145
double getM() const
Returns the mass / magnitude.
Definition: FourVector.h:139
double getPt2() const
Returns the transverse momentum squared / magnitude of the 1 and 2 component vector squared.
Definition: FourVector.h:132
ThreeVector p
The momentum three vector.
Definition: FourVector.h:108
double getPy() const
Returns the y momentum / 2 component.
Definition: FourVector.h:129
double getComponent(int i) const
Returns the i'th component (starting from 0=energy)
Definition: FourVector.h:147
double getP2() const
Returns the momentum squared / magnitude of the three vector squared.
Definition: FourVector.h:135
double getPt() const
Returns the transverse momentum / magnitude of the 1 and 2 component vector.
Definition: FourVector.h:133
double getP() const
Returns the momentum / magnitude of the three vector.
Definition: FourVector.h:136
double getE() const
Returns the energy / 0 component.
Definition: FourVector.h:127
double getTheta() const
Returns the polar angle of the momentum / three vector squared.
Definition: FourVector.h:143
double getMass() const
Returns the mass / magnitude.
Definition: FourVector.h:140
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.