CbmRoot
Loading...
Searching...
No Matches
CbmKfUtil.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov [committer] */
4
5#include "CbmKfUtil.h"
6
7#include "FairTrackParam.h"
8#include "KFParticle.h"
9#include "KfDefs.h"
10#include "KfFieldRegion.h"
11#include "KfTrackKalmanFilter.h"
12
13
14namespace cbm::kf
15{
16 using namespace cbm::algo;
17
19 {
21 t.X() = par.GetX();
22 t.Y() = par.GetY();
23 t.Tx() = par.GetTx();
24 t.Ty() = par.GetTy();
25 t.Qp() = par.GetQp();
26 t.Z() = par.GetZ();
27 t.Time() = 0.;
29
30 t.CovMatrix().fill(0.);
31
32 t.ChiSq() = 0.;
33 t.Ndf() = 0.;
34 t.ChiSqTime() = 0.;
35 t.NdfTime() = 0.;
36
37 for (int i = 0; i < 5; i++) {
38 for (int j = 0; j <= i; j++) {
39 t.C(i, j) = par.GetCovariance(i, j);
40 }
41 }
42
43 t.C55() = 1.;
44 t.C66() = 1.;
45
46 return t;
47 }
48
50 {
51 FairTrackParam par;
52 par.SetX(t.GetX());
53 par.SetY(t.GetY());
54 par.SetZ(t.GetZ());
55 par.SetTx(t.GetTx());
56 par.SetTy(t.GetTy());
57 par.SetQp(t.GetQp());
58 for (int i = 0; i < 5; i++) {
59 for (int j = 0; j <= i; j++) {
60 par.SetCovariance(i, j, t.C(i, j));
61 }
62 }
63 return par;
64 }
65
66 std::optional<KFParticle> CreateKfParticle(const cbm::algo::kf::TrackParamD& trackParam, double mass, int absCharge)
67 {
68
69 if (!trackParam.IsConsistent(false, 1)) {
70 return std::nullopt;
71 }
72
73 double par[6] = {0.};
74
75 double tx = trackParam.GetTx();
76 double ty = trackParam.GetTy();
77 double qp = trackParam.GetQp();
78
79 int q = 0;
80 if (qp > 0.) {
81 q = absCharge;
82 }
83 if (qp < 0.) {
84 q = -absCharge;
85 }
86
87 double t2i = 1. / (1. + tx * tx + ty * ty);
88 double t1i = sqrt(t2i);
89 double t3i = t1i * t2i;
90
91 double p = 1.e4; // limit the momentum to 10,000 GeV/c
92 double DpDqp = 0.;
93
94 if ((q != 0) && fabs(qp / q) >= 1e-4) { // define the momentum from the fitted value of q/p
95 p = fabs(q / qp);
96 DpDqp = -p / qp;
97 }
98
99 double pz = p * t1i;
100 double px = tx * pz;
101 double py = ty * pz;
102
103 par[0] = trackParam.GetX();
104 par[1] = trackParam.GetY();
105 par[2] = trackParam.GetZ();
106 par[3] = px;
107 par[4] = py;
108 par[5] = pz;
109
110 //calculate covariance matrix
111
112 double DpzDtx = -px * t2i;
113 double DpzDty = -py * t2i;
114 double DpzDqp = DpDqp * t1i;
115
116 double DpxDtx = (1. + ty * ty) * t3i * p;
117 double DpxDty = -tx * ty * t3i * p;
118 double DpxDqp = tx * DpzDqp;
119
120 double DpyDtx = DpxDty;
121 double DpyDty = (1. + tx * tx) * t3i * p;
122 double DpyDqp = ty * DpzDqp;
123
124 double J[6][5] = {{1., 0., 0., 0., 0.},
125 {0., 1., 0., 0., 0.},
126 {0., 0., 0., 0., 0.},
127 {0., 0., DpxDtx, DpxDty, DpxDqp},
128 {0., 0., DpyDtx, DpyDty, DpyDqp},
129 {0., 0., DpzDtx, DpzDty, DpzDqp}};
130
131 double CJt[5][6];
132 for (int i = 0; i < 5; i++) {
133 for (int j = 0; j < 6; j++) {
134 CJt[i][j] = 0;
135 for (int k = 0; k < 5; k++) {
136 CJt[i][j] += trackParam.GetCovariance(i, k) * J[j][k];
137 }
138 }
139 }
140
141 double cov[21];
142 for (int i = 0, l = 0; i < 6; i++) {
143 for (int j = 0; j <= i; j++, l++) {
144 cov[l] = 0;
145 for (int k = 0; k < 5; k++) {
146 cov[l] += J[i][k] * CJt[k][j];
147 }
148 }
149 }
150
151 KFParticle kfParticle;
152 kfParticle.Create(par, cov, q, mass);
153
154 // Set field to the particle
155
158
160 fit.SetTrack(trackParam);
161 fit.SetParticleMass(mass);
162 auto& tr = fit.Tr();
163
164 double z0 = trackParam.GetZ();
165 double z1 = z0 - 10.;
166 double z2 = z0 - 20.;
167
168 algo::kf::FieldValue<double> B0 = fieldOrig.Get(tr.GetX(), tr.GetY(), tr.GetZ());
169
170 fit.Extrapolate(z1, fieldOrig);
171
172 algo::kf::FieldValue<double> B1 = fieldOrig.Get(tr.GetX(), tr.GetY(), tr.GetZ());
173
174 fit.Extrapolate(z2, fieldOrig);
175
176 algo::kf::FieldValue<double> B2 = fieldOrig.Get(tr.GetX(), tr.GetY(), tr.GetZ());
177
179
180 fieldInterpolated.Set(B0, B1, B2);
181
182 for (int i = 0, j = 0; j < 3; j++) {
183 for (int k = 0; k < 3; k++, i++) {
184 kfParticle.SetFieldCoeff(fieldInterpolated.GetCoefficients()[j][k], i);
185 }
186 }
187
188 kfParticle.SetFieldCoeff(fieldInterpolated.GetZfirst(), 9);
189
190 return kfParticle;
191 }
192
193} // namespace cbm::kf
Common constant definitions for the Kalman Filter library.
Magnetic flux density interpolation along the track vs. z-coordinate (header)
friend fvec sqrt(const fvec &a)
Track fit utilities for the CA tracking based on the Kalman filter.
Magnetic field region, corresponding to a hit triplet.
FieldValue< T > Get(T x, T y, T z) const
Gets the field value in a spatial point on the track.
Magnetic flux density vector.
static EFieldType fgOriginalFieldType
Global field type.
static FieldFn_t fgOriginalField
Global variable to store the field function (x,y,z)->(Bx,By,Bz)
void Extrapolate(DataT z, const kf::FieldRegion< DataT > &F)
void SetParticleMass(DataT mass)
set particle mass for the fit
kf::TrackParam< DataT > & Tr()
void SetTrack(const kf::TrackParam< T > &t)
T Ndf() const
Gets NDF of track fit model.
T Vi() const
Gets inverse velocity [ns/cm].
T NdfTime() const
Gets NDF of time measurements.
T GetTy() const
Gets slope along y-axis.
T GetZ() const
Gets z position [cm].
T ChiSq() const
Gets Chi-square of track fit model.
bool IsConsistent(bool printWhenWrong, int nFilled) const
Checks whether first nFilled SIMD entries are consistent.
T Tx() const
Gets slope along x-axis.
T X() const
Gets x position [cm].
T ChiSqTime() const
Gets Chi-square of time measurements.
T GetTx() const
Gets slope along x-axis.
T GetQp() const
Gets charge over momentum [ec/GeV].
T Y() const
Gets y position [cm].
T Qp() const
Gets charge over momentum [ec/GeV].
T Z() const
Gets z position [cm].
T Time() const
Gets time [ns].
T GetY() const
Gets y position [cm].
T C(int i, int j) const
Get covariance matrix element.
CovMatrix_t & CovMatrix()
Reference to covariance matrix.
T GetCovariance(int i, int j) const
Get covariance matrix element.
T Ty() const
Gets slope along y-axis.
T GetX() const
Gets x position [cm].
Concrete representation of the FieldRegion class (primary template)
constexpr auto SpeedOfLightInv
Inverse speed of light [ns/cm].
Definition KfDefs.h:210
TrackParam< double > TrackParamD
std::optional< KFParticle > CreateKfParticle(const cbm::algo::kf::TrackParamD &trackParam, double mass, int absCharge)
Definition CbmKfUtil.cxx:66
cbm::algo::kf::TrackParamD ConvertTrackParam(const FairTrackParam &par)
copy fair track param to Ca track param
Definition CbmKfUtil.cxx:18