Belle II Software light-2406-ragdoll
MakeMotherKFit.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 <analysis/VertexFitting/KFit/MakeMotherKFit.h>
12#include <framework/gearbox/Const.h>
13
14using namespace std;
15using namespace Belle2;
16using namespace Belle2::analysis;
17using namespace CLHEP;
18
20 m_Vertex(Hep3Vector()),
21 m_VertexError(HepSymMatrix(3, 0))
22{
24 m_FlagAtDecayPoint = true;
25 m_FlagVertexError = false;
26 m_FlagCorrelation = false;
30 m_TrackCount = 0;
31 m_Charge = 0;
32}
33
34
36
37
40 m_Tracks.push_back(p);
41 m_Charge += p.getCharge();
42 m_TrackCount = m_Tracks.size();
43
45}
46
47
49MakeMotherKFit::addTrack(const CLHEP::HepLorentzVector& p, const HepPoint3D& x, const CLHEP::HepSymMatrix& e, const double q,
50 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
71MakeMotherKFit::setVertex(const HepPoint3D& v) {
72 m_Vertex = v;
73
75}
76
77
79MakeMotherKFit::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);
105
107}
108
109
112 HepMatrix zero(3, KFitConst::kNumber7, 0);
113
114 return this->setTrackVertexError(zero);
115}
116
117
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
136 HepMatrix zero(KFitConst::kNumber7, KFitConst::kNumber7, 0);
137
138 return this->setCorrelation(zero);
139}
140
141
144 m_FlagAtDecayPoint = flag;
145
147}
148
149
152 m_FlagBeforeAfter = flag;
153
155}
156
157
160 return m_ErrorCode;
161}
162
163const KFitTrack
165{
166 return m_Mother;
167}
168
169
170const HepLorentzVector
172{
174}
175
176
177const HepPoint3D
179{
181}
182
183
184const HepSymMatrix
186{
188}
189
190
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 = Belle2::Const::speedOfLight * 1e-4;
229 a = -c * m_MagneticField * m_Tracks[i].getCharge();
230 dx = m_Vertex.x() - m_Tracks[i].getPosition(m_FlagBeforeAfter).x();
231 dy = m_Vertex.y() - m_Tracks[i].getPosition(m_FlagBeforeAfter).y();
232 }
233 px += m_Tracks[i].getMomentum(m_FlagBeforeAfter).x() - a * dy;
234 py += m_Tracks[i].getMomentum(m_FlagBeforeAfter).y() + a * dx;
235 pz += m_Tracks[i].getMomentum(m_FlagBeforeAfter).z();
236 E += m_Tracks[i].getMomentum(m_FlagBeforeAfter).t();
237 }
238
239
240 // ...momentum
241 m_Mother.setMomentum(HepLorentzVector(px, py, pz, E));
242 // ...position
244 // ...error
245 m_Mother.setError(Em);
247
248
250}
251
252
253void
254MakeMotherKFit::calculateError(HepSymMatrix* Ec) const
255{
256 // ...error matrix of tracks
257 {
258 int i = 0;
259 for (const auto& track : m_Tracks) {
260 (*Ec).sub(i * KFitConst::kNumber7 + 1, track.getError(m_FlagBeforeAfter));
261 i++;
262 }
263 }
264
265
266 // ...error matrix between tracks
267 if (m_FlagCorrelation) {
268 int i = 0, j = 1;
269 for (const auto& hm : m_Correlation) {
270 for (int k = 0; k < KFitConst::kNumber7; k++) for (int l = 0; l < KFitConst::kNumber7; l++) {
271 (*Ec)[k + i * KFitConst::kNumber7][l + j * KFitConst::kNumber7] = hm[k][l];
272 }
273
274 if (j != m_TrackCount - 1) {
275 j++;
276 } else if (i != m_TrackCount - 2) {
277 i++;
278 j = i + 1;
279 } else {
280 break;
281 }
282 }
283 }
284
285
286 // ...error of vertex
287 if (m_FlagVertexError) {
289 }
290
291
292 // ...error matrix between vertex and tracks
294 int i = 0;
295 for (const auto& hm : m_TrackVertexError) {
296 for (int j = 0; j < 3; j++) for (int k = 0; k < KFitConst::kNumber7; k++) {
297 (*Ec)[j + m_TrackCount * KFitConst::kNumber7][k + i * KFitConst::kNumber7] = hm[j][k];
298 }
299 i++;
300 }
301 }
302}
303
304
305void
307{
308 // ...local parameters
309 double sum_a = 0;
310
311 for (int i = 0; i < m_TrackCount; i++) {
312 const double c = Belle2::Const::speedOfLight * 1e-4;
313 double a = -c * m_MagneticField * m_Tracks[i].getCharge();
314 sum_a += a;
315
316 // ...sets "a" in dMdC.
317 (*dMdC)[0][5 + i * KFitConst::kNumber7] = a;
318 (*dMdC)[1][4 + i * KFitConst::kNumber7] = -a;
319
320 // ...sets "1" in dMdC.
321 (*dMdC)[0][0 + i * KFitConst::kNumber7] = 1.;
322 (*dMdC)[1][1 + i * KFitConst::kNumber7] = 1.;
323 (*dMdC)[2][2 + i * KFitConst::kNumber7] = 1.;
324 (*dMdC)[3][3 + i * KFitConst::kNumber7] = 1.;
325 }
326
327 // ...sets "1" in dMdC.
328 (*dMdC)[4][0 + m_TrackCount * KFitConst::kNumber7] = 1.;
329 (*dMdC)[5][1 + m_TrackCount * KFitConst::kNumber7] = 1.;
330 (*dMdC)[6][2 + m_TrackCount * KFitConst::kNumber7] = 1.;
331
332 // ...sets "sum_a" in dMdC.
333 (*dMdC)[0][1 + m_TrackCount * KFitConst::kNumber7] = - sum_a;
334 (*dMdC)[1][0 + m_TrackCount * KFitConst::kNumber7] = sum_a;
335}
static const double speedOfLight
[cm/ns]
Definition: Const.h:695
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:72
ECode
ECode is a error code enumerate.
Definition: KFitError.h:34
@ kBadTrackSize
Track count too small to perform fit.
Definition: KFitError.h:47
@ kBadMatrixSize
Wrong correlation matrix size.
Definition: KFitError.h:49
KFitTrack is a container of the track information (Lorentz vector, position, and error matrix),...
Definition: KFitTrack.h:38
void setCharge(const double q)
Set a charge of the track.
Definition: KFitTrack.cc:134
const CLHEP::HepLorentzVector getMomentum(const int flag=KFitConst::kAfterFit) const
Get a Lorentz vector of the track.
Definition: KFitTrack.cc:156
void setPosition(const HepPoint3D &x, const int flag=KFitConst::kBeforeFit)
Set a position of the track.
Definition: KFitTrack.cc:109
const CLHEP::HepSymMatrix getError(const int flag=KFitConst::kAfterFit) const
Get an error matrix of the track.
Definition: KFitTrack.cc:172
void setMomentum(const CLHEP::HepLorentzVector &p, const int flag=KFitConst::kBeforeFit)
Set a Lorentz vector of the track.
Definition: KFitTrack.cc:95
void setError(const CLHEP::HepSymMatrix &e, const int flag=KFitConst::kBeforeFit)
Set an error matrix of the track.
Definition: KFitTrack.cc:121
const HepPoint3D getPosition(const int flag=KFitConst::kAfterFit) const
Get a position of the track.
Definition: KFitTrack.cc:164
enum KFitError::ECode setFlagBeforeAfter(const int flag)
Set a flag to control computational parameters for the mother particle property before or after the f...
enum KFitError::ECode setVertex(const HepPoint3D &v)
Set a vertex position of the mother particle.
bool m_FlagTrackVertexError
Flag to indicate if the vertex error matrix of the child particle is preset.
double m_Charge
Charge of the mother particle.
bool m_FlagAtDecayPoint
Flag controlled by setFlagAtDecayPoint().
enum KFitError::ECode addTrack(const KFitTrack &kp)
Add a track to the make-mother object.
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.
double m_MagneticField
Magnetic field.
enum KFitError::ECode setTrackZeroVertexError(void)
Indicate no vertex uncertainty in the child particle in the addTrack'ed order.
enum KFitError::ECode doMake(void)
Perform a reconstruction of mother particle.
const CLHEP::HepSymMatrix getMotherError(void) const
Get an error matrix of the mother particle.
enum KFitError::ECode setCorrelation(const CLHEP::HepMatrix &e)
Set a correlation matrix.
const HepPoint3D getMotherPosition(void) const
Get a position of the mother particle.
CLHEP::Hep3Vector m_Vertex
Vertex position of the mother particle.
const KFitTrack getMother(void) const
Get a track object of the mother particle.
enum KFitError::ECode m_ErrorCode
Error code.
CLHEP::HepSymMatrix m_VertexError
Vertex error matrix of the mother particle.
enum KFitError::ECode setZeroCorrelation(void)
Indicate no correlation between tracks.
KFitTrack m_Mother
Track object of the mother particle.
enum KFitError::ECode setVertexError(const CLHEP::HepSymMatrix &e)
Set a vertex error matrix of the mother particle.
enum KFitError::ECode setTrackVertexError(const CLHEP::HepMatrix &e)
Set a vertex error matrix of the child particle in the addTrack'ed order.
const CLHEP::HepLorentzVector getMotherMomentum(void) const
Get a Lorentz vector of the mother particle.
enum KFitError::ECode setMagneticField(const double mf)
Change a magnetic field from the default value KFitConst::kDefaultMagneticField.
bool m_FlagVertexError
Flag to indicate if the vertex error matrix of the mother particle is preset.
std::vector< CLHEP::HepMatrix > m_TrackVertexError
Array of vertex error matrices of the child particles.
bool m_FlagCorrelation
Flag to indicate if the correlation matrix among the child particles is preset.
~MakeMotherKFit(void)
Destruct the object.
void calculateError(CLHEP::HepSymMatrix *Ec) const
Make a matrix to calculate error matrix of the mother particle.
void calculateDELMDELC(CLHEP::HepMatrix *e) const
Make delMdelC to calculate error matrix of the mother particle.
std::vector< KFitTrack > m_Tracks
Array of track objects of the child particles.
MakeMotherKFit(void)
Construct an object with no argument.
int m_TrackCount
Number of tracks.
int m_FlagBeforeAfter
Flag controlled by setFlagBeforeAfter().
std::vector< CLHEP::HepMatrix > m_Correlation
Array of correlation matrices among the child particles.
enum KFitError::ECode getErrorCode(void) const
Get a code of the last error.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.
static constexpr double kDefaultMagneticField
Default magnetic field when not set externally.
Definition: KFitConst.h:51
static const int kAfterFit
Input parameter to specify after-fit when setting/getting a track attribute.
Definition: KFitConst.h:37
static const int kBeforeFit
Input parameter to specify before-fit when setting/getting a track attribute.
Definition: KFitConst.h:35
static const int kNumber7
Constant 7 to check matrix size (internal use)
Definition: KFitConst.h:32