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