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