Belle II Software development
KFitTrack.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * External Contributor: J. Tanaka *
5 * *
6 * See git log for contributors and copyright holders. *
7 * This file is licensed under LGPL-3.0, see LICENSE.md. *
8 **************************************************************************/
9
10#include <analysis/VertexFitting/KFit/KFitTrack.h>
11
12#include <cstdio>
13
14using namespace CLHEP;
15using namespace std;
16using namespace Belle2;
17using namespace Belle2::analysis;
18
19
21{
22 this->m_PXEBefore.m_P = HepLorentzVector();
23 this->m_PXEBefore.m_X = HepPoint3D();
24 this->m_PXEBefore.m_E = HepSymMatrix(KFitConst::kNumber7, 0);
25 this->m_PXEAfter. m_P = HepLorentzVector();
26 this->m_PXEAfter. m_X = HepPoint3D();
27 this->m_PXEAfter. m_E = HepSymMatrix(KFitConst::kNumber7, 0);
28 this->m_Charge = 0.;
29 this->m_Mass = 0.;
30 this->m_Vertex = HepPoint3D();
31 this->m_VertexError = HepSymMatrix(3, 0);
32}
33
34
35KFitTrack::KFitTrack(const KFitTrack& a) = default;
36
37
39(
40 const CLHEP::HepLorentzVector& p, const HepPoint3D& x, const CLHEP::HepSymMatrix& e, const double charge,
41 const int flag
42)
43{
44 checkFlag(flag);
46
47 switch (flag) {
49 m_PXEBefore.m_P = p;
50 m_PXEBefore.m_X = x;
51 m_PXEBefore.m_E = e;
52 m_PXEAfter.m_P = HepLorentzVector();
53 m_PXEAfter.m_X = HepPoint3D();
54 m_PXEAfter.m_E = HepSymMatrix(KFitConst::kNumber7, 0);
55 break;
56
58 m_PXEBefore.m_P = HepLorentzVector();
59 m_PXEBefore.m_X = HepPoint3D();
60 m_PXEBefore.m_E = HepSymMatrix(KFitConst::kNumber7, 0);
61 m_PXEAfter.m_P = p;
62 m_PXEAfter.m_X = x;
63 m_PXEAfter.m_E = e;
64 break;
65 }
66
67 m_Charge = charge;
68 m_Mass = p.mag();
69 m_Vertex = HepPoint3D();
70 m_VertexError = HepSymMatrix(3, 0);
71}
72
73
74KFitTrack::~KFitTrack() = default;
75
76
79{
80 if (this != &a) {
81 this->m_PXEBefore = a.m_PXEBefore;
82 this->m_PXEAfter = a.m_PXEAfter;
83 this->m_Charge = a.m_Charge;
84 this->m_Mass = a.m_Mass;
85 this->m_Vertex = a.m_Vertex;
86 this->m_VertexError = a.m_VertexError;
87 }
88
89 return *this;
90}
91
92
93void
94KFitTrack::setMomentum(const HepLorentzVector& p, const int flag)
95{
96 checkFlag(flag);
97
98 if (flag == KFitConst::kBeforeFit)
99 m_PXEBefore.m_P = p;
100 else
101 m_PXEAfter.m_P = p;
102
103 m_Mass = p.mag();
104}
105
106
107void
108KFitTrack::setPosition(const HepPoint3D& x, const int flag)
109{
110 checkFlag(flag);
111
112 if (flag == KFitConst::kBeforeFit)
113 m_PXEBefore.m_X = x;
114 else
115 m_PXEAfter.m_X = x;
116}
117
118
119void
120KFitTrack::setError(const HepSymMatrix& e, const int flag)
121{
122 checkFlag(flag);
124
125 if (flag == KFitConst::kBeforeFit)
126 m_PXEBefore.m_E = e;
127 else
128 m_PXEAfter.m_E = e;
129}
130
131
132void
133KFitTrack::setCharge(const double charge)
134{
135 m_Charge = charge;
136}
137
138
139void
140KFitTrack::setVertex(const HepPoint3D& v)
141{
142 m_Vertex = v;
143}
144
145
146void
147KFitTrack::setVertexError(const HepSymMatrix& ve)
148{
150 m_VertexError = ve;
151}
152
153
154const HepLorentzVector
155KFitTrack::getMomentum(const int flag) const
156{
157 checkFlag(flag);
158 return flag == KFitConst::kBeforeFit ? m_PXEBefore.m_P : m_PXEAfter.m_P;
159}
160
161
162const HepPoint3D
163KFitTrack::getPosition(const int flag) const
164{
165 checkFlag(flag);
166 return flag == KFitConst::kBeforeFit ? m_PXEBefore.m_X : m_PXEAfter.m_X;
167}
168
169
170const HepSymMatrix
171KFitTrack::getError(const int flag) const
172{
173 checkFlag(flag);
174 return flag == KFitConst::kBeforeFit ? m_PXEBefore.m_E : m_PXEAfter.m_E;
175}
176
177
178double
180{
181 return m_Charge;
182}
183
184
185double
187{
188 return m_Mass;
189}
190
191
192const HepPoint3D
194{
195 return m_Vertex;
196}
197
198
199const HepSymMatrix
201{
202 return m_VertexError;
203}
204
205
206double
207KFitTrack::getFitParameter(const int which, const int flag) const
208{
209 checkFlag(flag);
210
211 const struct KFitPXE& pxe = flag == KFitConst::kBeforeFit ? m_PXEBefore : m_PXEAfter;
212
213 switch (which) {
214 case 0: return pxe.m_P.x();
215 case 1: return pxe.m_P.y();
216 case 2: return pxe.m_P.z();
217 case 3: return pxe.m_X.x();
218 case 4: return pxe.m_X.y();
219 case 5: return pxe.m_X.z();
220 default: {
221 char buf[1024];
222 sprintf(buf, "%s:%s(): which=%d out of range", __FILE__, __func__, which);
223 B2FATAL(buf);
224 }
225 }
226
227 /* NEVER REACHED */
228 return -999.;
229}
230
231
232const HepMatrix
233KFitTrack::getFitParameter(const int flag) const
234{
235 HepMatrix a(KFitConst::kNumber6, 1, 0);
236
237 for (int i = 0; i <= 5; i++)
238 a[i][0] = getFitParameter(i, flag);
239
240 return a;
241}
242
243
244const HepSymMatrix
245KFitTrack::getFitError(const int flag) const
246{
247 checkFlag(flag);
248 HepSymMatrix err(KFitConst::kNumber6, 0);
249
250 const HepSymMatrix& e = flag == KFitConst::kBeforeFit ? m_PXEBefore.m_E : m_PXEAfter.m_E;
251
252
253 for (int i = 0; i < 3; i++) {
254 for (int j = i; j < 3; j++) {
255 err[i][j] = e[i][j];
256 err[3 + i][3 + j] = e[4 + i][4 + j];
257 }
258 }
259
260 for (int i = 0; i < 3; i++) {
261 for (int j = 0; j < 3; j++) {
262 err[i][3 + j] = e[i][4 + j];
263 }
264 }
265
266 return err;
267}
268
269
270const HepMatrix
271KFitTrack::getMomPos(const int flag) const
272{
273 HepMatrix a(KFitConst::kNumber7, 1, 0);
274
275 switch (flag) {
277 a[0][0] = m_PXEBefore.m_P.x();
278 a[1][0] = m_PXEBefore.m_P.y();
279 a[2][0] = m_PXEBefore.m_P.z();
280 a[3][0] = m_PXEBefore.m_P.t();
281 a[4][0] = m_PXEBefore.m_X.x();
282 a[5][0] = m_PXEBefore.m_X.y();
283 a[6][0] = m_PXEBefore.m_X.z();
284 break;
285
287 a[0][0] = m_PXEAfter.m_P.x();
288 a[1][0] = m_PXEAfter.m_P.y();
289 a[2][0] = m_PXEAfter.m_P.z();
290 a[3][0] = m_PXEAfter.m_P.t();
291 a[4][0] = m_PXEAfter.m_X.x();
292 a[5][0] = m_PXEAfter.m_X.y();
293 a[6][0] = m_PXEAfter.m_X.z();
294 }
295
296 return a;
297}
KFitTrack is a container of the track information (Lorentz vector, position, and error matrix),...
Definition KFitTrack.h:38
void checkMatrixDimension(const CLHEP::HepSymMatrix &m, const int dim) const
Check if the matrix size is intended one.
Definition KFitTrack.h:173
void checkFlag(const int flag) const
Check if the flag is one of KFitConst::kBeforeFit or KFitConst::kAfterFit.
Definition KFitTrack.h:164
double m_Charge
Charge of the track.
Definition KFitTrack.h:187
double m_Mass
Mass of the track.
Definition KFitTrack.h:189
KFitTrack & operator=(const KFitTrack &)
Operator: assignment operator.
Definition KFitTrack.cc:78
KFitTrack(void)
Construct an object with no argument.
Definition KFitTrack.cc:20
void setCharge(const double q)
Set a charge of the track.
Definition KFitTrack.cc:133
~KFitTrack(void)
Destruct the object.
const CLHEP::HepLorentzVector getMomentum(const int flag=KFitConst::kAfterFit) const
Get a Lorentz vector of the track.
Definition KFitTrack.cc:155
void setPosition(const HepPoint3D &x, const int flag=KFitConst::kBeforeFit)
Set a position of the track.
Definition KFitTrack.cc:108
const HepPoint3D getVertex(void) const
Get a vertex position associated to the track.
Definition KFitTrack.cc:193
const CLHEP::HepSymMatrix getVertexError(void) const
Get a vertex error matrix associated to the track.
Definition KFitTrack.cc:200
HepPoint3D m_Vertex
Vertex position associated to the track.
Definition KFitTrack.h:192
void setVertexError(const CLHEP::HepSymMatrix &ve)
Set a vertex error matrix associated to the track.
Definition KFitTrack.cc:147
CLHEP::HepSymMatrix m_VertexError
Vertex error matrix associated to the track.
Definition KFitTrack.h:194
const CLHEP::HepSymMatrix getError(const int flag=KFitConst::kAfterFit) const
Get an error matrix of the track.
Definition KFitTrack.cc:171
const CLHEP::HepSymMatrix getFitError(const int flag) const
Get an error matrix of the track.
Definition KFitTrack.cc:245
void setVertex(const HepPoint3D &v)
Set a vertex position associated to the track.
Definition KFitTrack.cc:140
double getCharge(void) const
Get a charge of the track.
Definition KFitTrack.cc:179
void setMomentum(const CLHEP::HepLorentzVector &p, const int flag=KFitConst::kBeforeFit)
Set a Lorentz vector of the track.
Definition KFitTrack.cc:94
struct KFitPXE m_PXEBefore
Lorentz vector, position, and error matrix of the track before the fit.
Definition KFitTrack.h:181
double getFitParameter(const int which, const int flag) const
Get a parameter of the track.
Definition KFitTrack.cc:207
void setError(const CLHEP::HepSymMatrix &e, const int flag=KFitConst::kBeforeFit)
Set an error matrix of the track.
Definition KFitTrack.cc:120
const HepPoint3D getPosition(const int flag=KFitConst::kAfterFit) const
Get a position of the track.
Definition KFitTrack.cc:163
const CLHEP::HepMatrix getMomPos(const int flag) const
Get a combination of Lorentz vector and position of the track.
Definition KFitTrack.cc:271
struct KFitPXE m_PXEAfter
Lorentz vector, position, and error matrix of the track after the fit.
Definition KFitTrack.h:184
double getMass(void) const
Get a mass of the track.
Definition KFitTrack.cc:186
Abstract base class for different kinds of events.
STL namespace.
static const int kNumber6
Constant 6 to check matrix size (internal use)
Definition KFitConst.h:28
static const int kAfterFit
Input parameter to specify after-fit when setting/getting a track attribute.
Definition KFitConst.h:35
static const int kBeforeFit
Input parameter to specify before-fit when setting/getting a track attribute.
Definition KFitConst.h:33
static const int kNumber7
Constant 7 to check matrix size (internal use)
Definition KFitConst.h:30
KFitPXE is a container of the track information (Lorentz vector, position, and error matrix).
Definition KFitTrack.h:43
HepPoint3D m_X
Position of the track.
Definition KFitTrack.h:47
CLHEP::HepLorentzVector m_P
Lorentz vector of the track.
Definition KFitTrack.h:45