CbmRoot
Loading...
Searching...
No Matches
CbmLitKalmanSmoother.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2017 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
11
12#include "data/CbmLitTrack.h"
13#include "utils/CbmLitMath.h"
15
16#include <iostream>
17
19
21
23{
24 int n = track->GetNofHits();
25
26 FitNodeVector nodes = track->GetFitNodes();
27 nodes[n - 1].SetSmoothedParam(nodes[n - 1].GetUpdatedParam());
28
29 // start with the before the last detector plane
30 for (int i = n - 1; i > 0; i--) {
31 Smooth(&nodes[i - 1], &nodes[i]);
32 }
33
34 // Calculate the chi2 of the track
35 track->SetChi2(0.);
36 for (int i = 0; i < n; i++) {
37 litfloat chi2Hit = lit::ChiSq(nodes[i].GetSmoothedParam(), track->GetHit(i));
38 nodes[i].SetChiSqSmoothed(chi2Hit);
39 track->SetChi2(track->GetChi2() + chi2Hit);
40 }
41
42 track->SetParamFirst(nodes[0].GetSmoothedParam());
43 track->SetFitNodes(nodes);
44 track->SetNDF(lit::NDF(track));
45
46 return kLITSUCCESS;
47}
48
49// We are going in the upstream direction
50// this Node (k) , prevNode (k+1)
52{
53 // TMatrixDSym invPrevPredC(5);
54 // prevNode->GetPredictedParam()->GetCovMatrix(invPrevPredC);
55 // invPrevPredC.Invert();
56 std::vector<litfloat> invPrevPredC(prevNode->GetPredictedParam()->GetCovMatrix());
57 InvSym15(invPrevPredC);
58
59 // TMatrixD Ft(5, 5);
60 // prevNode->GetF(Ft);
61 // Ft.T();
62 std::vector<litfloat> Ft(prevNode->GetF());
63 Transpose25(Ft);
64
65 // TMatrixDSym thisUpdC(5);
66 // thisNode->GetUpdatedParam()->GetCovMatrix(thisUpdC);
67 const std::vector<litfloat>& thisUpdC = thisNode->GetUpdatedParam()->GetCovMatrix();
68
69 // TMatrixD A(5, 5);
70 // A = thisUpdC * Ft * invPrevPredC;
71 std::vector<litfloat> A(25);
72 std::vector<litfloat> temp1(25);
73 Mult15On25(thisUpdC, Ft, temp1);
74 Mult25On15(temp1, invPrevPredC, A);
75
76 // TVectorD thisUpdX(5), prevSmoothedX(5), prevPredX(5);
77 // thisNode->GetUpdatedParam()->GetStateVector(thisUpdX);
78 // prevNode->GetSmoothedParam()->GetStateVector(prevSmoothedX);
79 // prevNode->GetPredictedParam()->GetStateVector(prevPredX);
80 // TVectorD thisSmoothedX(thisUpdX + A * (prevSmoothedX - prevPredX));
81
82 const std::vector<litfloat>& thisUpdX = thisNode->GetUpdatedParam()->GetStateVector();
83 const std::vector<litfloat>& prevSmoothedX = prevNode->GetSmoothedParam()->GetStateVector();
84 const std::vector<litfloat>& prevPredX = prevNode->GetPredictedParam()->GetStateVector();
85
86 std::vector<litfloat> temp2(7), temp3(7);
87 Subtract(prevSmoothedX, prevPredX, temp2);
88 Mult25On5(A, temp2, temp3);
89 std::vector<litfloat> thisSmoothedX(7);
90 Add(thisUpdX, temp3, thisSmoothedX);
91
92
93 // TMatrixDSym prevSmoothedC(5), prevPredC(5), Cdiff(5);
94 // prevNode->GetSmoothedParam()->GetCovMatrix(prevSmoothedC);
95 // prevNode->GetPredictedParam()->GetCovMatrix(prevPredC);
96 // Cdiff = prevSmoothedC - prevPredC;
97
98 const std::vector<litfloat>& prevSmoothedC = prevNode->GetSmoothedParam()->GetCovMatrix();
99 const std::vector<litfloat>& prevPredC = prevNode->GetPredictedParam()->GetCovMatrix();
100 std::vector<litfloat> temp4(15);
101 Subtract(prevSmoothedC, prevPredC, temp4);
102
103
104 // TMatrixDSym thisSmoothedC(5);
105 // thisSmoothedC = thisUpdC + Cdiff.Similarity(A);
106 std::vector<litfloat> temp5(15);
107 Similarity(A, temp4, temp5);
108 std::vector<litfloat> thisSmoothedC(15);
109 Add(thisUpdC, temp5, thisSmoothedC);
110
112
113 par.SetStateVector(thisSmoothedX);
114 par.SetCovMatrix(thisSmoothedC);
115 par.SetZ(thisNode->GetUpdatedParam()->GetZ());
116
117 thisNode->SetSmoothedParam(&par);
118}
LitStatus
Definition CbmLitEnums.h:29
@ kLITSUCCESS
Definition CbmLitEnums.h:30
double litfloat
Definition CbmLitFloat.h:19
Implementation of Kalman smoother algorithm.
bool Similarity(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Add(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Transpose25(std::vector< litfloat > &a)
bool Subtract(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Mult25On15(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Mult25On5(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool Mult15On25(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
bool InvSym15(std::vector< litfloat > &a)
Base data class for track.
vector< CbmLitFitNode > FitNodeVector
Definition CbmLitTypes.h:39
Data class for storage of fitted track parameters, transport matrix and chi-square on each detector s...
const CbmLitTrackParam * GetPredictedParam() const
const CbmLitTrackParam * GetSmoothedParam() const
const CbmLitTrackParam * GetUpdatedParam() const
void SetSmoothedParam(const CbmLitTrackParam *par)
const vector< litfloat > & GetF() const
virtual LitStatus Fit(CbmLitTrack *track, bool downstream=false)
Inherited from CbmLitTrackFitter.
virtual ~CbmLitKalmanSmoother()
Destructor.
void Smooth(CbmLitFitNode *thisNode, const CbmLitFitNode *prevNode)
Smooth one fit node.
Data class for track parameters.
litfloat GetZ() const
void SetStateVector(const vector< litfloat > &x)
Set parameters from vector.
vector< litfloat > GetStateVector() const
Return state vector as vector.
void SetZ(litfloat z)
const vector< litfloat > & GetCovMatrix() const
void SetCovMatrix(const vector< litfloat > &C)
Base data class for track.
Definition CbmLitTrack.h:34
const vector< CbmLitFitNode > & GetFitNodes() const
Definition CbmLitTrack.h:74
void SetParamFirst(const CbmLitTrackParam *par)
Definition CbmLitTrack.h:85
void SetNDF(Int_t ndf)
Definition CbmLitTrack.h:82
const CbmLitHit * GetHit(Int_t index) const
Definition CbmLitTrack.h:71
void SetChi2(litfloat chi2)
Definition CbmLitTrack.h:81
Int_t GetNofHits() const
Definition CbmLitTrack.h:62
void SetFitNodes(const vector< CbmLitFitNode > &nodes)
Definition CbmLitTrack.h:90
litfloat GetChi2() const
Definition CbmLitTrack.h:64
Int_t NDF(const CbmLitTrack *track)
litfloat ChiSq(const CbmLitTrackParam *par, const CbmLitHit *hit)