Belle II Software  release-05-01-25
MakeMotherKFit.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 <analysis/VertexFitting/KFit/MakeMotherKFit.h>
13 
14 
15 using namespace std;
16 using namespace Belle2;
17 using namespace Belle2::analysis;
18 using namespace CLHEP;
19 
20 MakeMotherKFit::MakeMotherKFit():
21  m_Vertex(Hep3Vector()),
22  m_VertexError(HepSymMatrix(3, 0))
23 {
25  m_FlagAtDecayPoint = true;
26  m_FlagVertexError = false;
27  m_FlagCorrelation = false;
28  m_FlagTrackVertexError = false;
31  m_TrackCount = 0;
32  m_Charge = 0;
33 }
34 
35 
37 
38 
41  m_Tracks.push_back(p);
42  m_Charge += p.getCharge();
43  m_TrackCount = m_Tracks.size();
44 
46 }
47 
48 
50 MakeMotherKFit::addTrack(const HepLorentzVector& p, const HepPoint3D& x, const HepSymMatrix& e, const double q, const int flag) {
51  if (e.num_row() != (int)KFitConst::kNumber7)
52  {
54  KFitError::displayError(__FILE__, __LINE__, __func__, m_ErrorCode);
55  return m_ErrorCode;
56  }
57 
58  return this->addTrack(KFitTrack(p, x, e, q, flag));
59 }
60 
61 
64  m_MagneticField = mf;
65 
67 }
68 
69 
72  m_Vertex = v;
73 
75 }
76 
77 
79 MakeMotherKFit::setVertexError(const HepSymMatrix& e) {
80  if (e.num_row() != 3)
81  {
83  KFitError::displayError(__FILE__, __LINE__, __func__, m_ErrorCode);
84  return m_ErrorCode;
85  }
86 
87  m_VertexError = e;
88  m_FlagVertexError = true;
89 
91 }
92 
93 
96  if (e.num_row() != 3 || e.num_col() != (int)KFitConst::kNumber7)
97  {
99  KFitError::displayError(__FILE__, __LINE__, __func__, m_ErrorCode);
100  return m_ErrorCode;
101  }
102 
103  m_TrackVertexError.push_back(e);
104  m_FlagTrackVertexError = true;
105 
107 }
108 
109 
110 enum KFitError::ECode
112  HepMatrix zero(3, KFitConst::kNumber7, 0);
113 
114  return this->setTrackVertexError(zero);
115 }
116 
117 
118 enum KFitError::ECode
119 MakeMotherKFit::setCorrelation(const HepMatrix& e) {
120  if (e.num_row() != (int)KFitConst::kNumber7 || e.num_col() != (int)KFitConst::kNumber7)
121  {
123  KFitError::displayError(__FILE__, __LINE__, __func__, m_ErrorCode);
124  return m_ErrorCode;
125  }
126 
127  m_Correlation.push_back(e);
128  m_FlagCorrelation = true;
129 
131 }
132 
133 
134 enum KFitError::ECode
136  HepMatrix zero(KFitConst::kNumber7, KFitConst::kNumber7, 0);
137 
138  return this->setCorrelation(zero);
139 }
140 
141 
142 enum KFitError::ECode
144  m_FlagAtDecayPoint = flag;
145 
147 }
148 
149 
150 enum KFitError::ECode
152  m_FlagBeforeAfter = flag;
153 
155 }
156 
157 
158 enum KFitError::ECode
160  return m_ErrorCode;
161 }
162 
163 const KFitTrack
165 {
166  return m_Mother;
167 }
168 
169 
170 const HepLorentzVector
172 {
174 }
175 
176 
177 const HepPoint3D
179 {
181 }
182 
183 
184 const HepSymMatrix
186 {
188 }
189 
190 
191 enum KFitError::ECode
193  // ...makes matrix.
194  HepMatrix dMdC(KFitConst::kNumber7, KFitConst::kNumber7 * m_TrackCount + 3, 0);
195  HepSymMatrix Ec(KFitConst::kNumber7 * m_TrackCount + 3, 0);
196 
197 
198  // ...sets error matrix
199  if (m_FlagCorrelation && m_Correlation.size() != static_cast<unsigned int>((m_TrackCount * m_TrackCount - m_TrackCount) / 2))
200  {
202  KFitError::displayError(__FILE__, __LINE__, __func__, m_ErrorCode);
203  return m_ErrorCode;
204  }
205  if (m_FlagTrackVertexError && m_TrackVertexError.size() != (unsigned int)m_TrackCount)
206  {
208  KFitError::displayError(__FILE__, __LINE__, __func__, m_ErrorCode);
209  return m_ErrorCode;
210  }
211  this->calculateError(&Ec);
212 
213 
214  // ...makes delMdelC to calculate error matrix of mother particle.
215  this->calculateDELMDELC(&dMdC);
216 
217 
218  // ...calculates error matrix of mother particle.
219  HepSymMatrix Em(Ec.similarity(dMdC));
220 
221 
222  // ...makes mother particle
223  double px = 0, py = 0, pz = 0, E = 0;
224  for (int i = 0; i < m_TrackCount; i++)
225  {
226  double a = 0, dx = 0, dy = 0;
227  if (m_FlagAtDecayPoint) {
228  const double c = KFitConst::kLightSpeed; // C++ bug?
229  // a = -KFitConst::kLightSpeed * m_MagneticField * m_Tracks[i].getCharge();
230  a = -c * m_MagneticField * m_Tracks[i].getCharge();
231  dx = m_Vertex.x() - m_Tracks[i].getPosition(m_FlagBeforeAfter).x();
232  dy = m_Vertex.y() - m_Tracks[i].getPosition(m_FlagBeforeAfter).y();
233  }
234  px += m_Tracks[i].getMomentum(m_FlagBeforeAfter).x() - a * dy;
235  py += m_Tracks[i].getMomentum(m_FlagBeforeAfter).y() + a * dx;
236  pz += m_Tracks[i].getMomentum(m_FlagBeforeAfter).z();
237  E += m_Tracks[i].getMomentum(m_FlagBeforeAfter).t();
238  }
239 
240 
241  // ...momentum
242  m_Mother.setMomentum(HepLorentzVector(px, py, pz, E));
243  // ...position
245  // ...error
246  m_Mother.setError(Em);
248 
249 
251 }
252 
253 
254 void
255 MakeMotherKFit::calculateError(HepSymMatrix* Ec) const
256 {
257  // ...error matrix of tracks
258  {
259  int i = 0;
260  for (const auto& track : m_Tracks) {
261  (*Ec).sub(i * KFitConst::kNumber7 + 1, track.getError(m_FlagBeforeAfter));
262  i++;
263  }
264  }
265 
266 
267  // ...error matrix between tracks
268  if (m_FlagCorrelation) {
269  int i = 0, j = 1;
270  for (const auto& hm : m_Correlation) {
271  for (int k = 0; k < KFitConst::kNumber7; k++) for (int l = 0; l < KFitConst::kNumber7; l++) {
272  (*Ec)[k + i * KFitConst::kNumber7][l + j * KFitConst::kNumber7] = hm[k][l];
273  }
274 
275  if (j != m_TrackCount - 1) {
276  j++;
277  } else if (i != m_TrackCount - 2) {
278  i++;
279  j = i + 1;
280  } else {
281  break;
282  }
283  }
284  }
285 
286 
287  // ...error of vertex
288  if (m_FlagVertexError) {
290  }
291 
292 
293  // ...error matrix between vertex and tracks
295  int i = 0;
296  for (const auto& hm : m_TrackVertexError) {
297  for (int j = 0; j < 3; j++) for (int k = 0; k < KFitConst::kNumber7; k++) {
298  (*Ec)[j + m_TrackCount * KFitConst::kNumber7][k + i * KFitConst::kNumber7] = hm[j][k];
299  }
300  i++;
301  }
302  }
303 }
304 
305 
306 void
307 MakeMotherKFit::calculateDELMDELC(HepMatrix* dMdC) const
308 {
309  // ...local parameters
310  double sum_a = 0;
311 
312  for (int i = 0; i < m_TrackCount; i++) {
313  const double c = KFitConst::kLightSpeed; // C++ bug?
314  // double a = -KFitConst::kLightSpeed * m_MagneticField * m_Tracks[i].getCharge();
315  double a = -c * m_MagneticField * m_Tracks[i].getCharge();
316  sum_a += a;
317 
318  // ...sets "a" in dMdC.
319  (*dMdC)[0][5 + i * KFitConst::kNumber7] = a;
320  (*dMdC)[1][4 + i * KFitConst::kNumber7] = -a;
321 
322  // ...sets "1" in dMdC.
323  (*dMdC)[0][0 + i * KFitConst::kNumber7] = 1.;
324  (*dMdC)[1][1 + i * KFitConst::kNumber7] = 1.;
325  (*dMdC)[2][2 + i * KFitConst::kNumber7] = 1.;
326  (*dMdC)[3][3 + i * KFitConst::kNumber7] = 1.;
327  }
328 
329  // ...sets "1" in dMdC.
330  (*dMdC)[4][0 + m_TrackCount * KFitConst::kNumber7] = 1.;
331  (*dMdC)[5][1 + m_TrackCount * KFitConst::kNumber7] = 1.;
332  (*dMdC)[6][2 + m_TrackCount * KFitConst::kNumber7] = 1.;
333 
334  // ...sets "sum_a" in dMdC.
335  (*dMdC)[0][1 + m_TrackCount * KFitConst::kNumber7] = - sum_a;
336  (*dMdC)[1][0 + m_TrackCount * KFitConst::kNumber7] = sum_a;
337 }
Belle2::analysis::MakeMotherKFit::m_FlagAtDecayPoint
bool m_FlagAtDecayPoint
Flag controlled by setFlagAtDecayPoint().
Definition: MakeMotherKFit.h:150
Belle2::analysis::MakeMotherKFit::getMother
const KFitTrack getMother(void) const
Get a track object of the mother particle.
Definition: MakeMotherKFit.cc:164
Belle2::analysis::KFitTrack::getError
const CLHEP::HepSymMatrix getError(const int flag=KFitConst::kAfterFit) const
Get an error matrix of the track.
Definition: KFitTrack.cc:173
Belle2::analysis::KFitTrack::getPosition
const HepPoint3D getPosition(const int flag=KFitConst::kAfterFit) const
Get a position of the track.
Definition: KFitTrack.cc:165
Belle2::analysis::MakeMotherKFit::setTrackZeroVertexError
enum KFitError::ECode setTrackZeroVertexError(void)
Indicate no vertex uncertainty in the child particle in the addTrack'ed order.
Definition: MakeMotherKFit.cc:111
Belle2::analysis::MakeMotherKFit::m_FlagTrackVertexError
bool m_FlagTrackVertexError
Flag to indicate if the vertex error matrix of the child particle is preset.
Definition: MakeMotherKFit.h:158
Belle2::analysis::MakeMotherKFit::m_Tracks
std::vector< KFitTrack > m_Tracks
Array of track objects of the child particles.
Definition: MakeMotherKFit.h:167
Belle2::analysis::KFitConst::kBeforeFit
static const int kBeforeFit
Input parameter to specify before-fit when setting/getting a track attribute.
Definition: KFitConst.h:43
Belle2::analysis::MakeMotherKFit::m_Vertex
CLHEP::Hep3Vector m_Vertex
Vertex position of the mother particle.
Definition: MakeMotherKFit.h:175
Belle2::analysis::MakeMotherKFit::m_FlagCorrelation
bool m_FlagCorrelation
Flag to indicate if the correlation matrix among the child particles is preset.
Definition: MakeMotherKFit.h:156
Belle2::analysis::MakeMotherKFit::setTrackVertexError
enum KFitError::ECode setTrackVertexError(const CLHEP::HepMatrix &e)
Set a vertex error matrix of the child particle in the addTrack'ed order.
Definition: MakeMotherKFit.cc:95
Belle2::analysis::MakeMotherKFit::setVertex
enum KFitError::ECode setVertex(const HepPoint3D &v)
Set a vertex position of the mother particle.
Definition: MakeMotherKFit.cc:71
Belle2::analysis::MakeMotherKFit::m_Mother
KFitTrack m_Mother
Track object of the mother particle.
Definition: MakeMotherKFit.h:183
Belle2::analysis::MakeMotherKFit::m_MagneticField
double m_MagneticField
Magnetic field.
Definition: MakeMotherKFit.h:161
Belle2::analysis::MakeMotherKFit::getErrorCode
enum KFitError::ECode getErrorCode(void) const
Get a code of the last error.
Definition: MakeMotherKFit.cc:159
Belle2::analysis::KFitError::displayError
static void displayError(const char *file, const int line, const char *func, const enum ECode code)
Display a description of error and its location.
Definition: KFitError.h:79
Belle2::analysis::MakeMotherKFit::getMotherError
const CLHEP::HepSymMatrix getMotherError(void) const
Get an error matrix of the mother particle.
Definition: MakeMotherKFit.cc:185
Belle2::analysis::KFitTrack::setPosition
void setPosition(const HepPoint3D &x, const int flag=KFitConst::kBeforeFit)
Set a position of the track.
Definition: KFitTrack.cc:110
Belle2::analysis::MakeMotherKFit::m_TrackVertexError
std::vector< CLHEP::HepMatrix > m_TrackVertexError
Array of vertex error matrices of the child particles.
Definition: MakeMotherKFit.h:169
Belle2::analysis::MakeMotherKFit::m_Correlation
std::vector< CLHEP::HepMatrix > m_Correlation
Array of correlation matrices among the child particles.
Definition: MakeMotherKFit.h:171
Belle2::analysis::KFitTrack::setMomentum
void setMomentum(const CLHEP::HepLorentzVector &p, const int flag=KFitConst::kBeforeFit)
Set a Lorentz vector of the track.
Definition: KFitTrack.cc:96
Belle2::analysis::MakeMotherKFit::getMotherMomentum
const CLHEP::HepLorentzVector getMotherMomentum(void) const
Get a Lorentz vector of the mother particle.
Definition: MakeMotherKFit.cc:171
Belle2::analysis::KFitError::kNoError
@ kNoError
No error.
Definition: KFitError.h:45
Belle2::analysis::MakeMotherKFit::setFlagAtDecayPoint
enum KFitError::ECode setFlagAtDecayPoint(const bool flag)
Set a flag to control computational point for the mother particle property at the decay point or not.
Definition: MakeMotherKFit.cc:143
Belle2::analysis::KFitConst::kAfterFit
static const int kAfterFit
Input parameter to specify after-fit when setting/getting a track attribute.
Definition: KFitConst.h:45
Belle2::analysis::MakeMotherKFit::m_VertexError
CLHEP::HepSymMatrix m_VertexError
Vertex error matrix of the mother particle.
Definition: MakeMotherKFit.h:177
Belle2::analysis::KFitTrack::setCharge
void setCharge(const double q)
Set a charge of the track.
Definition: KFitTrack.cc:135
Belle2::analysis::MakeMotherKFit::calculateDELMDELC
void calculateDELMDELC(CLHEP::HepMatrix *e) const
Make delMdelC to calculate error matrix of the mother particle.
Definition: MakeMotherKFit.cc:307
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::analysis::MakeMotherKFit::m_TrackCount
int m_TrackCount
Number of tracks.
Definition: MakeMotherKFit.h:163
Belle2::analysis::MakeMotherKFit::m_Charge
double m_Charge
Charge of the mother particle.
Definition: MakeMotherKFit.h:181
Belle2::analysis::MakeMotherKFit::setMagneticField
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
Definition: MakeMotherKFit.cc:63
Belle2::analysis::MakeMotherKFit::~MakeMotherKFit
~MakeMotherKFit(void)
Destruct the object.
Belle2::analysis::KFitTrack
KFitTrack is a container of the track information (Lorentz vector, position, and error matrix),...
Definition: KFitTrack.h:39
Belle2::analysis::MakeMotherKFit::m_FlagBeforeAfter
int m_FlagBeforeAfter
Flag controlled by setFlagBeforeAfter().
Definition: MakeMotherKFit.h:152
Belle2::analysis::KFitConst::kLightSpeed
static constexpr double kLightSpeed
Speed of light.
Definition: KFitConst.h:62
Belle2::analysis::MakeMotherKFit::setCorrelation
enum KFitError::ECode setCorrelation(const CLHEP::HepMatrix &e)
Set a correlation matrix.
Definition: MakeMotherKFit.cc:119
Belle2::analysis::MakeMotherKFit::setVertexError
enum KFitError::ECode setVertexError(const CLHEP::HepSymMatrix &e)
Set a vertex error matrix of the mother particle.
Definition: MakeMotherKFit.cc:79
Belle2::analysis::KFitConst::kDefaultMagneticField
static constexpr double kDefaultMagneticField
Default magnetic field.
Definition: KFitConst.h:59
Belle2::analysis::MakeMotherKFit::getMotherPosition
const HepPoint3D getMotherPosition(void) const
Get a position of the mother particle.
Definition: MakeMotherKFit.cc:178
Belle2::analysis::KFitTrack::getMomentum
const CLHEP::HepLorentzVector getMomentum(const int flag=KFitConst::kAfterFit) const
Get a Lorentz vector of the track.
Definition: KFitTrack.cc:157
Belle2::analysis::KFitTrack::setError
void setError(const CLHEP::HepSymMatrix &e, const int flag=KFitConst::kBeforeFit)
Set an error matrix of the track.
Definition: KFitTrack.cc:122
Belle2::analysis::MakeMotherKFit::addTrack
enum KFitError::ECode addTrack(const KFitTrack &kp)
Add a track to the make-mother object.
Definition: MakeMotherKFit.cc:40
Belle2::analysis::KFitError::ECode
ECode
ECode is a error code enumerate.
Definition: KFitError.h:43
Belle2::analysis::MakeMotherKFit::doMake
enum KFitError::ECode doMake(void)
Perform a reconstruction of mother particle.
Definition: MakeMotherKFit.cc:192
HepGeom::Point3D< double >
Belle2::analysis::MakeMotherKFit::setFlagBeforeAfter
enum KFitError::ECode setFlagBeforeAfter(const int flag)
Set a flag to control computational parameters for the mother particle property before or after the f...
Definition: MakeMotherKFit.cc:151
Belle2::analysis::KFitConst::kNumber7
static const int kNumber7
Constant 7 to check matrix size (internal use)
Definition: KFitConst.h:40
Belle2::analysis::MakeMotherKFit::m_FlagVertexError
bool m_FlagVertexError
Flag to indicate if the vertex error matrix of the mother particle is preset.
Definition: MakeMotherKFit.h:154
Belle2::analysis::KFitError::kBadTrackSize
@ kBadTrackSize
Track count too small to perform fit.
Definition: KFitError.h:54
Belle2::analysis::MakeMotherKFit::m_ErrorCode
enum KFitError::ECode m_ErrorCode
Error code.
Definition: MakeMotherKFit.h:147
Belle2::analysis::KFitError::kBadMatrixSize
@ kBadMatrixSize
Wrong correlation matrix size.
Definition: KFitError.h:56
Belle2::analysis::MakeMotherKFit::setZeroCorrelation
enum KFitError::ECode setZeroCorrelation(void)
Indicate no correlation between tracks.
Definition: MakeMotherKFit.cc:135
Belle2::analysis::MakeMotherKFit::calculateError
void calculateError(CLHEP::HepSymMatrix *Ec) const
Make a matrix to calculate error matrix of the mother particle.
Definition: MakeMotherKFit.cc:255