CbmRoot
Loading...
Searching...
No Matches
KfTrackKalmanFilter.h
Go to the documentation of this file.
1/* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov [committer], Maksym Zyzak */
4
5
10
11#pragma once // include this header only once per compilation unit
12
13#include "KfFieldRegion.h"
14#include "KfMeasurementTime.h"
15#include "KfMeasurementU.h"
16#include "KfMeasurementXy.h"
17#include "KfSimd.h"
18#include "KfTrackParam.h"
19#include "KfUtils.h"
20
21#include <type_traits>
22
23namespace cbm::algo::kf
24{
25 class Hit;
26
27 enum class FitDirection
28 {
31 };
32
37
40 template<typename DataT>
42
43 public:
46
47 TrackKalmanFilter() = default;
48
50
51 TrackKalmanFilter(const DataTmask& m, bool fitV) : fMask(m), fDoFitVelocity(fitV) {}
52
53 template<typename T>
55 {
56 SetTrack(t);
57 }
58
59 void SetMask(const DataTmask& m) { fMask = m; }
60
61 template<typename T>
63 {
64 fTr.Set(t);
65 fQp0 = fTr.GetQp();
66 }
67
68 void SetQp0(DataT qp0) { fQp0 = qp0; }
69
71
72 DataT& Qp0() { return fQp0; }
73
75
76 void SetOneEntry(const int i0, const TrackKalmanFilter& T1, const int i1);
77
78 std::string ToString(int i = -1);
79
82
84 void SetParticleMass(DataT mass)
85 {
86 fMass = mass;
87 fMass2 = mass * mass;
88 }
89
91 DataT GetParticleMass() const { return fMass; }
92
94 DataT GetParticleMass2() const { return fMass2; }
95
97 void SetMaxExtrapolationStep(double step) { fMaxExtraplationStep = DataT(step); }
98
101
103 void Filter1d(const kf::MeasurementU<DataT>& m);
104
106 void FilterXY(const kf::MeasurementXy<DataT>& m, bool skipUnmeasuredCoordinates = false);
107
109 void FilterTime(DataT t, DataT dt2, const DataTmask& m);
110
112 void FilterTime(kf::MeasurementTime<DataT> mt) { FilterTime(mt.T(), mt.Dt2(), DataTmask(mt.NdfT() > DataT(0.))); }
113
115 void FilterVi(DataT vi);
116
119
124 void Extrapolate(DataT z, const kf::FieldRegion<DataT>& F);
125
128 void ExtrapolateStep(DataT z_out, const kf::FieldRegion<DataT>& F);
129
131 void ExtrapolateLine(DataT z_out, const kf::FieldRegion<DataT>& F);
132
134 void ExtrapolateLineNoField(DataT z_out);
135
139 void EnergyLossCorrection(DataT radThick, FitDirection direction);
140
149 void EnergyLossCorrection(int atomicZ, DataTscal atomicA, DataTscal rho, DataTscal radLen, DataT radThick,
150 FitDirection direction);
151
152
154 void MultipleScattering(DataT radThick, DataT tx0, DataT ty0, DataT qp0);
155
157 void MultipleScattering(DataT radThick) { MultipleScattering(radThick, fTr.GetTx(), fTr.GetTy(), fQp0); }
158
160 void MultipleScatteringInThickMaterial(DataT radThick, DataT thickness, bool fDownstream);
161
164
166 void GetExtrapolatedXYline(DataT z, const kf::FieldRegion<DataT>& F, DataT& extrX, DataT& extrY,
167 std::array<DataT, kf::TrackParam<DataT>::kNtrackParam>& Jx,
168 std::array<DataT, kf::TrackParam<DataT>::kNtrackParam>& Jy) const;
169
176 void FilterExtrapolatedXY(const kf::MeasurementXy<DataT>& m, DataT extrX, DataT extrY,
177 const std::array<DataT, kf::TrackParam<DataT>::kNtrackParam>& Jx,
178 const std::array<DataT, kf::TrackParam<DataT>::kNtrackParam>& Jy);
179
183 std::pair<DataT, DataT> ExtrapolateLineXdX2(DataT z_out) const;
184
188 std::pair<DataT, DataT> ExtrapolateLineYdY2(DataT z_out) const;
189
193 DataT ExtrapolateLineDxy(DataT z_out) const;
194
196 void FilterWithTargetAtLine(DataT targZ, const kf::MeasurementXy<DataT>& targXYInfo,
197 const kf::FieldRegion<DataT>& F);
198
202 static DataT ApproximateBetheBloch(DataT bg2);
203
212 static DataT ApproximateBetheBloch(DataT bg2, DataT kp0, DataT kp1, DataT kp2, DataT kp3, DataT kp4);
213
223 static std::tuple<DataT, DataT> GetChi2XChi2U(kf::MeasurementXy<DataT> m, DataT x, DataT y, DataT C00, DataT C10,
224 DataT C11);
225
236 void GuessTrack(const DataT& trackZ, const DataT hitX[], const DataT hitY[], const DataT hitZ[], const DataT hitT[],
237 const DataT By[], const DataTmask hitW[], const DataTmask hitWtime[], int NHits);
238
239 private:
240 typedef const DataT cnst;
241
244
246
248 DataT fQp0{0.};
249
250 DataT fMass{0.10565800};
251 DataT fMass2{fMass * fMass};
252
254
255 bool fDoFitVelocity{0}; // should the track velocity be fitted as an independent parameter
256
258
259 // =============================================================================================
260
261 template<typename DataT>
262 inline std::string TrackKalmanFilter<DataT>::ToString(int i)
263 {
264 return fTr.ToString(i);
265 }
266
267
268 template<typename DataT>
269 inline void TrackKalmanFilter<DataT>::SetOneEntry(const int i0, const TrackKalmanFilter& T1, const int i1)
270 {
271 fTr.SetOneEntry(i0, T1.fTr, i1);
273 }
274
275 template<typename DataT>
276 inline std::pair<DataT, DataT> TrackKalmanFilter<DataT>::ExtrapolateLineXdX2(DataT z_out) const
277 {
278 DataT dz = (z_out - fTr.GetZ());
279 return std::pair(fTr.GetX() + fTr.GetTx() * dz, fTr.C00() + dz * (2 * fTr.C20() + dz * fTr.C22()));
280 }
281
282 template<typename DataT>
283 inline std::pair<DataT, DataT> TrackKalmanFilter<DataT>::ExtrapolateLineYdY2(DataT z_out) const
284 {
285 DataT dz = (z_out - fTr.GetZ());
286 return std::pair(fTr.GetY() + fTr.GetTy() * dz, fTr.C11() + dz * (DataT(2.) * fTr.C31() + dz * fTr.C33()));
287 }
288
289 template<typename DataT>
290 inline DataT TrackKalmanFilter<DataT>::ExtrapolateLineDxy(DataT z_out) const
291 {
292 DataT dz = (z_out - fTr.GetZ());
293 return fTr.C10() + dz * (fTr.C21() + fTr.C30() + dz * fTr.C32());
294 }
295
296} // namespace cbm::algo::kf
Magnetic flux density interpolation along the track vs. z-coordinate (header)
Definition of the KfMeasurementXy class.
fscal v[fmask::Size]
Definition KfSimdPseudo.h:4
Implementation selection for the SIMD utilities (VS or pseudo)
Magnetic field region, corresponding to a hit triplet.
The class describes a time measurement.
std::string ToString(int indentLevel=0) const
The class describes a 1D - measurement U in XY coordinate system.
The class describes a 2D - measurement (x, y) in XY coordinate system.
kf::TrackParam< DataT > fTr
track parameters
void Filter1d(const kf::MeasurementU< DataT > &m)
filter the track with the 1d measurement
void Extrapolate(DataT z, const kf::FieldRegion< DataT > &F)
DataT fMass
particle mass (muon mass by default)
void FilterWithTargetAtLine(DataT targZ, const kf::MeasurementXy< DataT > &targXYInfo, const kf::FieldRegion< DataT > &F)
add target measuremet to the track using linearisation at a straight line
std::pair< DataT, DataT > ExtrapolateLineYdY2(DataT z_out) const
void MeasureVelocityWithQp()
measure the track velocity with the track Qp and the mass
DataTmask fMask
mask of active elements in simd vectors
void FilterExtrapolatedXY(const kf::MeasurementXy< DataT > &m, DataT extrX, DataT extrY, const std::array< DataT, kf::TrackParam< DataT >::kNtrackParam > &Jx, const std::array< DataT, kf::TrackParam< DataT >::kNtrackParam > &Jy)
void FilterTime(kf::MeasurementTime< DataT > mt)
filter the track with the time measurement
static std::tuple< DataT, DataT > GetChi2XChi2U(kf::MeasurementXy< DataT > m, DataT x, DataT y, DataT C00, DataT C10, DataT C11)
git two chi^2 components of the track fit to measurement
void MultipleScattering(DataT radThick)
apply multiple scattering correction to the track
TrackKalmanFilter(const DataTmask &m, bool fitV)
void ExtrapolateStep(DataT z_out, const kf::FieldRegion< DataT > &F)
void FilterXY(const kf::MeasurementXy< DataT > &m, bool skipUnmeasuredCoordinates=false)
filter the track with the XY measurement
DataT fMaxExtraplationStep
max extrapolation step [cm]
void ExtrapolateLineNoField(DataT z_out)
extrapolate the track to the given Z assuming no magnetic field
TrackKalmanFilter(const kf::TrackParam< DataT > &t)
void MultipleScatteringInThickMaterial(DataT radThick, DataT thickness, bool fDownstream)
apply multiple scattering correction in thick material to the track
void FilterVi(DataT vi)
filter the inverse speed
kf::TrackParam< DataT > & Tr()
static DataT ApproximateBetheBloch(DataT bg2)
Approximate mean energy loss with Bethe-Bloch formula.
void MultipleScattering(DataT radThick, DataT tx0, DataT ty0, DataT qp0)
apply multiple scattering correction to the track with the given Qp0
void GetExtrapolatedXYline(DataT z, const kf::FieldRegion< DataT > &F, DataT &extrX, DataT &extrY, std::array< DataT, kf::TrackParam< DataT >::kNtrackParam > &Jx, std::array< DataT, kf::TrackParam< DataT >::kNtrackParam > &Jy) const
extrapolate track as a line, return the extrapolated X, Y and the Jacobians
void GuessTrack(const DataT &trackZ, const DataT hitX[], const DataT hitY[], const DataT hitZ[], const DataT hitT[], const DataT By[], const DataTmask hitW[], const DataTmask hitWtime[], int NHits)
fast guess of track parameterts based on its hits
kf::utils::scaltype< DataT > DataTscal
DataT GetParticleMass() const
get the particle mass
TrackKalmanFilter(const kf::TrackParam< T > &t)
void SetOneEntry(const int i0, const TrackKalmanFilter &T1, const int i1)
void EnergyLossCorrection(DataT radThick, FitDirection direction)
DataT ExtrapolateLineDxy(DataT z_out) const
DataT GetParticleMass2() const
get the particle mass squared
std::pair< DataT, DataT > ExtrapolateLineXdX2(DataT z_out) const
void FilterTime(DataT t, DataT dt2, const DataTmask &m)
filter the track with the time measurement
void SetParticleMass(DataT mass)
set particle mass for the fit
void SetTrack(const kf::TrackParam< T > &t)
kf::utils::masktype< DataT > DataTmask
DataT GetMaxExtrapolationStep() const
get the particle mass
void SetMaxExtrapolationStep(double step)
set max extrapolation step [cm]
void ExtrapolateLine(DataT z_out, const kf::FieldRegion< DataT > &F)
extrapolate the track to the given Z using linearization at the straight line
T GetTy() const
Gets slope along y-axis.
T GetTx() const
Gets slope along x-axis.
T GetQp() const
Gets charge over momentum [ec/GeV].
void Set(const TrackParamBase< T1 > &Tb)
TrackParam classes of different types.
static void CopyEntries(TdataA &a, int ia, const TdataB &b, int ib)
Definition KfUtils.h:181
typename std::conditional< std::is_same< T, fvec >::value, fmask, bool >::type masktype
Definition KfUtils.h:27
typename std::conditional< std::is_same< T, fvec >::value, fscal, T >::type scaltype
Definition KfUtils.h:24
FitDirection operator!(FitDirection d)
class cbm::algo::kf::MeasurementTime _fvecalignment