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