-
Notifications
You must be signed in to change notification settings - Fork 3
/
SoLKalTrackState.cxx
273 lines (225 loc) · 8.97 KB
/
SoLKalTrackState.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//c++
#include <cassert>
//ROOT
#include "TMath.h"
//SoLIDTracking
#include "SoLKalTrackState.h"
#include "SoLKalFieldStepper.h"
ClassImp(SoLKalTrackState)
//_________________________________________________________________
SoLKalTrackState::SoLKalTrackState(Int_t type, Int_t p)
: SoLKalMatrix(p,1), fType(type), fSitePtr(nullptr),
fF(p,p), fFt(p,p), fQ(p,p), fC(p,p), fAttemptState(nullptr)
{
fF.UnitMatrix();
fFt.UnitMatrix();
fZ0 = 0.;
//fFieldStepper = SoLKalFieldStepper::GetInstance();
}
//_________________________________________________________________
SoLKalTrackState::SoLKalTrackState(const SoLKalMatrix &sv,
Int_t type, Int_t p)
: SoLKalMatrix(sv), fType(type), fSitePtr(nullptr),
fF(p,p), fFt(p,p), fQ(p,p), fC(p,p), fAttemptState(nullptr)
{
fF.UnitMatrix();
fFt.UnitMatrix();
fZ0 = 0.;
//fFieldStepper = SoLKalFieldStepper::GetInstance();
}
//_________________________________________________________________
SoLKalTrackState::SoLKalTrackState(const SoLKalMatrix &sv, const SoLKalMatrix &c,
Int_t type, Int_t p)
: SoLKalMatrix(sv), fType(type), fSitePtr(nullptr), fF(p,p), fFt(p,p),
fQ(p,p), fC(c), fAttemptState(nullptr)
{
fF.UnitMatrix();
fFt.UnitMatrix();
fZ0 = 0.;
//fFieldStepper = SoLKalFieldStepper::GetInstance();
}
//__________________________________________________________________
SoLKalTrackState::SoLKalTrackState(const SoLKalMatrix &sv, const SoLKalTrackSite &site,
Int_t type, Int_t p)
: SoLKalMatrix(sv), fType(type), fSitePtr((SoLKalTrackSite *)&site),
fF(p,p), fFt(p,p), fQ(p,p), fC(p,p), fAttemptState(nullptr)
{
fF.UnitMatrix();
fFt.UnitMatrix();
fZ0 = ((SoLKalTrackSite *)&site)->GetZ();
//fFieldStepper = SoLKalFieldStepper::GetInstance();
}
//__________________________________________________________________
SoLKalTrackState::SoLKalTrackState(const SoLKalMatrix &sv, const SoLKalMatrix &c,
const SoLKalTrackSite &site, Int_t type, Int_t p)
: SoLKalMatrix(sv), fType(type), fSitePtr((SoLKalTrackSite *)&site),
fF(p,p), fFt(p,p), fQ(p,p), fC(c), fAttemptState(nullptr)
{
fF.UnitMatrix();
fFt.UnitMatrix();
fZ0 = ((SoLKalTrackSite *)&site)->GetZ();
//fFieldStepper = SoLKalFieldStepper::GetInstance();
}
//___________________________________________________________________
SoLKalTrackState::~SoLKalTrackState()
{
if (fAttemptState != nullptr && (&fAttemptState->GetSite()) == nullptr){
delete fAttemptState;
}
}
//___________________________________________________________________
void SoLKalTrackState::Propagate(SoLKalTrackSite &to)
{
// Calculate
// prea: predicted state vector : a^k-1_k = f_k-1(a_k-1)
// fF: propagator derivative : F_k-1 = (@f_k-1/@a_k-1)
// fQ: process noise from k-1 to k : Q_k-1)
SoLKalTrackState &prea = MoveTo(to,fF,fQ);
SoLKalTrackState *preaPtr = &prea;
fFt = SoLKalMatrix(SoLKalMatrix::kTransposed, fF);
// Calculate covariance matrix
SoLKalMatrix preC = fF * fC * fFt + fQ;
if (preC.Determinant() == 0) {
cout<<"SoLKalTrackState::Propagate"<<endl;
fF.Print();
fC.Print();
fQ.Print();
}
// Set predicted state vector and covariance matrix to next site
prea.SetCovMat(preC);
to.Add(preaPtr);
to.SetOwner();
}
//____________________________________________________________________
SoLKalTrackState * SoLKalTrackState::MoveTo(SoLKalTrackSite &to,
SoLKalMatrix &F,
SoLKalMatrix *QPtr) const
{
if (QPtr) {
const SoLKalTrackSite &from = static_cast<const SoLKalTrackSite &>(GetSite());
SoLKalTrackSite &siteto = static_cast<SoLKalTrackSite &>(to);
SoLKalMatrix sv(kSdim,1);
SoLKalFieldStepper::GetInstance()->Transport(from, to, sv, F, *QPtr);
return new SoLKalTrackState(sv, siteto, SoLKalTrackSite::kPredicted, kSdim);
} else {
return nullptr;
}
}
//_____________________________________________________________________
SoLKalTrackState & SoLKalTrackState::MoveTo(SoLKalTrackSite &to,
SoLKalMatrix &F,
SoLKalMatrix &Q) const
{
return *MoveTo(to, F, &Q);
}
//______________________________________________________________________
SoLKalTrackState* SoLKalTrackState::PredictSVatZ(Double_t &z)
{
//simply pass the current filtered state vector to the next detector
//it is up to the track finder to decide whether we have a hit in the
//next measurement layer
SoLKalTrackState &prea = MoveToZ(z,fF,fQ);
SoLKalTrackState *preaPtr = &prea;
fFt = SoLKalMatrix(SoLKalMatrix::kTransposed, fF);
// Calculate covariance matrix
SoLKalMatrix preC = fF * fC * fFt + fQ;
prea.SetCovMat(preC);
//only a filtered state can be used to predict hit position on the next layer
if (fType == SoLKalTrackSite::kFiltered) fAttemptState = preaPtr;
return preaPtr;
}
//______________________________________________________________________
void SoLKalTrackState::InitPredictSV()
{
assert(fType != SoLKalTrackSite::kPredicted);
if (fAttemptState == nullptr){
SoLKalMatrix sv(kSdim,1);
for (Int_t i=0; i<kSdim; i++) { sv(i, 0) = (*this)(i, 0); }
fAttemptState = new SoLKalTrackState(sv, SoLKalTrackSite::kPredicted, kSdim);
fAttemptState->SetZ0(this->GetZ0());
}else{
return;
}
}
//______________________________________________________________________
SoLKalTrackState* SoLKalTrackState::PredictSVatNextZ(Double_t &z)
{
//this function can be called only if the PredictSVatZ has been called
//which is the first attempt to find hits on the next measurement site
assert(fAttemptState != nullptr && fType != SoLKalTrackSite::kPredicted);
SoLKalMatrix thisSV (kSdim, 1);
SoLKalMatrix thisF (kSdim, kSdim);
SoLKalMatrix thisQ (kSdim, kSdim);
SoLKalFieldStepper::GetInstance()->Transport(*fAttemptState, z, thisSV, thisF, thisQ);
for (Int_t i=0; i<kSdim; i++) { (*fAttemptState)(i, 0) = thisSV(i, 0); }
fF = thisF*fF;
fFt = SoLKalMatrix(SoLKalMatrix::kTransposed, fF);
fQ = fQ + thisQ;
SoLKalMatrix preC = fF * fC * fFt + fQ;
fAttemptState->SetCovMat(preC);
fAttemptState->SetZ0(SoLKalFieldStepper::GetInstance()->GetTrackPosAtZ());
return fAttemptState;
}
//______________________________________________________________________
SoLKalTrackState * SoLKalTrackState::MoveToZ(Double_t z,
SoLKalMatrix &F,
SoLKalMatrix *QPtr) const
{
if (QPtr) {
const SoLKalTrackSite &from = static_cast<const SoLKalTrackSite &>(GetSite());
SoLKalMatrix sv(kSdim,1);
SoLKalFieldStepper::GetInstance()->Transport(from, z, sv, F, *QPtr);
SoLKalTrackState* thisState = new SoLKalTrackState(sv, SoLKalTrackSite::kPredicted, kSdim);
thisState->SetZ0(SoLKalFieldStepper::GetInstance()->GetTrackPosAtZ());
return thisState;
} else {
return nullptr;
}
}
//_____________________________________________________________________
SoLKalTrackState & SoLKalTrackState::MoveToZ(Double_t z,
SoLKalMatrix &F,
SoLKalMatrix &Q) const
{
return *MoveToZ(z, F, &Q);
}
//______________________________________________________________________
void SoLKalTrackState::CalcDir(TVector3 &dir) const {
// Calculates a direction unit vector from this state.
// dir: track direction (return value).
CalcDir(dir, (*this));
}
//______________________________________________________________________
void SoLKalTrackState::CalcDir(TVector3 &dir, const SoLKalMatrix &sv) {
// Calculates a direction unit vector from a state vector given by function
// parameter sv.
// dir: track direction (return value)
// sv: state vector to calculate direction from.
Double_t tanx = sv(2,0);
Double_t tany = sv(3,0);
Double_t qp = sv(4,0);
dir.SetZ( 1./(TMath::Abs(qp) * TMath::Sqrt(tanx*tanx + tany*tany + 1. )) );
dir.SetX(tanx * dir.Z());
dir.SetY(tany * dir.Z());
dir = dir.Unit();
}
//________________________________________________________________________
void SoLKalTrackState::CalcMomVec(TVector3 &dir) const {
// Calculates the momentum vector from this state.
// dir: track momentum (return value).
CalcMomVec(dir, (*this));
}
//_______________________________________________________________________
void SoLKalTrackState::CalcMomVec(TVector3 &dir, const SoLKalMatrix &sv) {
// Calculates momentum vector from a state vector given by function
// parameter sv.
// dir: track momentum (return value)
// sv: state vector to calculate direction from.
Double_t tanx = sv(2,0);
Double_t tany = sv(3,0);
Double_t qp = sv(4,0);
dir.SetZ( 1./(TMath::Abs(qp) * TMath::Sqrt(tanx*tanx + tany*tany + 1)) );
dir.SetX(tanx * dir.Z());
dir.SetY(tany * dir.Z());
}
//________________________________________________________________________