29 KFbase::KFbase(
const Settings *settings,
const uint nHelixPar,
const string &fitterName,
const uint nMeas)
30 : TrackFitGeneric(settings, fitterName) {
31 nHelixPar_ = nHelixPar;
46 auto orderByLayer = [](
const Stub *
a,
const Stub *
b) {
return bool(
a->layerId() <
b->layerId()); };
50 const TP *tpa(
nullptr);
58 PrintL1trk() <<
"===============================================================================";
59 std::stringstream
text;
61 text <<
"Input track cand: [phiSec,etaReg]=[" << l1track3D.
iPhiSec() <<
"," << l1track3D.
iEtaReg() <<
"]";
63 <<
") q/pt=" << l1track3D.
qOverPt() <<
" tanL=" << l1track3D.
tanLambda() <<
" z0=" << l1track3D.
z0()
64 <<
" phi0=" << l1track3D.
phi0() <<
" nStubs=" << l1track3D.
numStubs() <<
" d0=" << l1track3D.
d0();
78 if (
cand !=
nullptr) {
103 double chi2rphi_bcon = 0.;
109 bool accepted =
true;
110 if (chi2scaled > kfLayerVsChiSqCut[
cand->nStubLayers()])
113 fitTrk.setBeamConstr(trackPars_bcon[
QOVERPT], trackPars_bcon[
PHI0], chi2rphi_bcon, accepted);
122 fitTrk.digitizeTrack(
"KF4ParamsComb");
124 if (!fitTrk.consistentSector()) {
126 PrintL1trk() <<
"Track rejected by sector consistency test";
137 bool goodTrack = (tpa && tpa->useForAlgEff());
139 int tpin = tpa->index();
140 PrintL1trk() <<
"TRACK LOST: eta=" << l1track3D.
iEtaReg() <<
" pt=" << l1track3D.
pt() <<
" tp=" << tpin;
142 for (
auto stub :
stubs) {
144 this->
kalmanLayer(l1track3D.
iEtaReg(), stub->layerIdReduced(), stub->barrel(), stub->r(), stub->z());
145 std::stringstream
text;
147 text <<
" Stub: lay_red=" << stub->layerIdReduced() <<
" KFlay=" << kalmanLay <<
" r=" << stub->r()
148 <<
" z=" << stub->z() <<
" assoc TPs =";
149 for (
const TP *tp_i : stub->assocTPs())
150 text <<
" " << tp_i->index();
152 if (stub->assocTPs().empty())
161 if (tpa && tpa->useForAlgEff()) {
162 PrintL1trk() <<
"TP for eff. missed addr. index : " << tpa <<
" " << tpa->index();
177 map<unsigned int, const KalmanState *, std::greater<unsigned int>>
178 best_state_by_nstubs;
181 TVectorD x0 =
seedX(l1track3D);
182 TMatrixD pxx0 =
seedC(l1track3D);
186 const KalmanState *state0 =
mkState(l1track3D, 0, -1,
nullptr, x0, pxx0, K, dcov,
nullptr, 0, 0);
189 vector<const KalmanState *> new_states;
190 vector<const KalmanState *> prev_states;
191 prev_states.push_back(state0);
198 int etaReg = l1track3D.
iEtaReg();
199 map<int, vector<Stub *>> layerStubs;
201 for (
auto stub :
stubs) {
203 int kalmanLay = this->
kalmanLayer(etaReg, stub->layerIdReduced(), stub->barrel(), stub->r(), stub->z());
207 layerStubs[kalmanLay].push_back(stub);
210 layerStubs[kalmanLay].back() = stub;
216 constexpr unsigned int nTypicalLayers = 6;
221 unsigned int kalmanMaxSkipLayers =
225 vector<const KalmanState *>::const_iterator i_state = prev_states.begin();
226 for (; i_state != prev_states.end(); i_state++) {
229 unsigned int layer = the_state->
nextLayer();
236 unsigned nSkippedDeadLayers = 0;
237 unsigned nSkippedAmbiguousLayers = 0;
238 while (kfDeadLayers.find(layer) != kfDeadLayers.end() && layerStubs[layer].empty()) {
240 ++nSkippedDeadLayers;
244 ++nSkippedAmbiguousLayers;
248 vector<const KalmanState *> next_states;
249 vector<const KalmanState *> next_states_skipped;
253 vector<Stub *> thislay_stubs = layerStubs[layer];
257 vector<Stub *> nextlay_stubs;
261 unsigned nSkippedDeadLayers_nextStubs = 0;
262 unsigned nSkippedAmbiguousLayers_nextStubs = 0;
263 if (nSkipped < kalmanMaxSkipLayers) {
264 if (kfDeadLayers.find(layer + 1) != kfDeadLayers.end() && layerStubs[layer + 1].empty()) {
265 nextlay_stubs = layerStubs[layer + 2];
266 nSkippedDeadLayers_nextStubs++;
268 nextlay_stubs = layerStubs[layer + 2];
269 nSkippedAmbiguousLayers_nextStubs++;
271 nextlay_stubs = layerStubs[layer + 1];
278 nextlay_stubs.empty())
280 <<
" : #thislay_stubs=" << thislay_stubs.size() <<
" #nextlay_stubs=" << nextlay_stubs.size()
281 <<
" layer=" << layer <<
" eta=" << l1track3D.
iEtaReg();
284 nSkipped += nSkippedDeadLayers;
285 nSkipped += nSkippedAmbiguousLayers;
291 vector<Stub *> temp_thislaystubs;
292 vector<Stub *> temp_nextlaystubs;
293 for (
auto stub : thislay_stubs) {
294 if (stub->psModule())
295 temp_thislaystubs.push_back(stub);
297 for (
auto stub : nextlay_stubs) {
298 if (stub->psModule())
299 temp_nextlaystubs.push_back(stub);
301 thislay_stubs = temp_thislaystubs;
302 nextlay_stubs = temp_nextlaystubs;
306 for (
unsigned i = 0;
i < thislay_stubs.size();
i++) {
307 Stub *stub = thislay_stubs[
i];
314 next_states.push_back(new_state);
318 for (
unsigned i = 0;
i < nextlay_stubs.size();
i++) {
319 Stub *stub = nextlay_stubs[
i];
322 kalmanUpdate(nSkipped + 1 + nSkippedDeadLayers_nextStubs + nSkippedAmbiguousLayers_nextStubs,
323 layer + 1 + nSkippedDeadLayers_nextStubs + nSkippedAmbiguousLayers_nextStubs,
329 next_states_skipped.push_back(new_state);
334 return bool(
a->chi2scaled() <
b->chi2scaled());
336 sort(next_states.begin(), next_states.end(), orderByChi2);
337 sort(next_states_skipped.begin(), next_states_skipped.end(), orderByChi2);
339 new_states.insert(new_states.end(), next_states.begin(), next_states.end());
340 new_states.insert(new_states.end(), next_states_skipped.begin(), next_states_skipped.end());
347 return bool((
a->chi2scaled()) * (
a->nSkippedLayers() + 1) < (
b->chi2scaled()) * (
b->nSkippedLayers() + 1));
349 sort(new_states.begin(), new_states.end(), orderByMinSkipChi2);
354 best_state_by_nstubs[nStubs] = new_states[0];
363 prev_states = new_states;
368 if (not best_state_by_nstubs.empty()) {
370 finished_state = best_state_by_nstubs.begin()->second;
372 std::stringstream
text;
374 text <<
"Track found! final state selection: nLay=" << finished_state->
nStubLayers()
376 <<
" phiSec=" << l1track3D.
iPhiSec() <<
" etaReg=" << l1track3D.
iEtaReg() <<
" HT(m,c)=(" 379 text <<
" q/pt=" << y[
QOVERPT] <<
" tanL=" << y[
T] <<
" z0=" << y[
Z0] <<
" phi0=" << y[
PHI0];
382 text <<
" chosen from states:";
383 for (
const auto &
p : best_state_by_nstubs)
384 text <<
" " <<
p.second->chi2() <<
"/" <<
p.second->nStubLayers();
393 return finished_state;
410 TVectorD vecX =
state->vectorX();
411 TMatrixD matC =
state->matrixC();
414 PrintL1trk() <<
"STATE BARREL TO ENDCAP BEFORE ";
415 PrintL1trk() <<
"state : " << vecX[0] <<
" " << vecX[1] <<
" " << vecX[2] <<
" " << vecX[3];
420 PrintL1trk() <<
"STATE BARREL TO ENDCAP AFTER ";
421 PrintL1trk() <<
"state : " << vecX[0] <<
" " << vecX[1] <<
" " << vecX[2] <<
" " << vecX[3];
428 TMatrixD matFtrans(TMatrixD::kTransposed, matF);
435 TVectorD vecXref = matF * vecX;
464 TMatrixD matCref = matF * matC * matFtrans + matScat;
476 TMatrixD matRinv =
matrixRinv(matH, matCref, matV);
495 double new_chi2rphi = 0, new_chi2rz = 0;
500 PrintL1trk() <<
"adjusted x = " << new_vecX[0] <<
", " << new_vecX[1] <<
", " << new_vecX[2] <<
", " 503 PrintL1trk() <<
"adjusted x = " << new_vecX[0] <<
", " << new_vecX[1] <<
", " << new_vecX[2] <<
", " 504 << new_vecX[3] <<
", " << new_vecX[4];
507 PrintL1trk() <<
"adjust chi2rphi=" << new_chi2rphi <<
" chi2rz=" << new_chi2rz;
511 state->candidate(), nSkipped, layer,
state, new_vecX, new_matC, matK, matV, stub, new_chi2rphi, new_chi2rz);
522 const TVectorD &vecX,
523 const TMatrixD &matC,
524 const TMatrixD &matK,
525 const TMatrixD &matV,
529 auto new_state = std::make_unique<const KalmanState>(
530 settings_, candidate, nSkipped, layer, last_state, vecX, matC, matK, matV, stub, chi2rphi, chi2rz);
540 TMatrixD matHtrans(TMatrixD::kTransposed, matH);
541 return matH * matC * matHtrans;
546 TMatrixD
KFbase::matrixRinv(
const TMatrixD &matH,
const TMatrixD &matCref,
const TMatrixD &matV)
const {
548 TMatrixD matR = matV + matHCHt;
549 TMatrixD matRinv(2, 2);
550 if (matR.Determinant() > 0) {
551 matRinv = TMatrixD(TMatrixD::kInverted, matR);
554 const TMatrixD unitMatrix(TMatrixD::kUnit, TMatrixD(2, 2));
555 const double big = 9.9e9;
556 matRinv =
big * unitMatrix;
570 TMatrixD matHtrans(TMatrixD::kTransposed, matH);
571 TMatrixD matCrefht = matCref * matHtrans;
572 TMatrixD matK = matCrefht * matRinv;
581 TVectorD hx =
h * vecX;
592 float tanL = vecX[
T];
598 double corr = stub->
r() * inv2R;
603 deltaS = (1. / 6.) * (stub->
r()) *
pow(
corr, 2);
614 float rShift = (stub->
z() - z0) / tanL - stub->
r();
642 const TMatrixD &matCref,
643 const TVectorD &vecXref,
644 const TMatrixD &matH,
645 const TVectorD &
delta,
647 TMatrixD &new_matC)
const {
648 new_vecX = vecXref + matK *
delta;
650 TMatrixD
tmp = unitMatrix - matK * matH;
651 new_matC =
tmp * matCref;
657 const TMatrixD &matRinv,
658 const TVectorD &
delta,
660 double &chi2rz)
const {
666 PrintL1trk() <<
"delta(chi2rphi)=" << delChi2rphi <<
" delta(chi2rz)= " << delChi2rz;
668 chi2rphi =
state->chi2rphi() + delChi2rphi;
669 chi2rz =
state->chi2rz() + delChi2rz;
680 unsigned int iEtaReg,
unsigned int layerIDreduced,
bool barrel,
float r,
float z)
const {
683 <<
"ERROR KFbase::getKalmanLayer hardwired value of nEta_ differs from NumEtaRegions cfg param";
685 unsigned int kfEtaReg;
692 unsigned int kalmanLay =
699 if (layerIDreduced > 2) {
751 {
false,
false,
false,
false,
false,
false,
false},
752 {
false,
false,
false,
false,
false,
false,
false},
753 {
false,
false,
false,
false,
false,
false,
false},
754 {
false,
false,
false,
false,
false,
false,
false},
755 {
false,
false,
false,
false,
false,
false,
false},
756 {
false,
false,
true,
false,
false,
false,
false},
757 {
true,
true,
false,
false,
false,
false,
false},
758 {
true,
false,
false,
false,
false,
false,
false},
761 unsigned int kfEtaReg;
768 bool ambiguous =
false;
770 ambiguous = ambiguityMap[kfEtaReg][kfLayer];
785 set<pair<unsigned, bool>> deadGPlayers;
791 deadGPlayers.insert(pair<unsigned, bool>(4,
true));
794 if (iEtaReg_ <= 7 && iPhiSec_ >= 1 &&
iPhiSec_ <= 5) {
795 deadGPlayers.insert(pair<unsigned, bool>(1,
true));
799 if (iEtaReg_ <= 7 && iPhiSec_ >= 1 &&
iPhiSec_ <= 5) {
800 deadGPlayers.insert(pair<unsigned, bool>(1,
true));
803 deadGPlayers.insert(pair<unsigned, bool>(2,
true));
807 if (iEtaReg_ <= 7 && iPhiSec_ >= 1 &&
iPhiSec_ <= 5) {
808 deadGPlayers.insert(pair<unsigned, bool>(1,
true));
810 if (iEtaReg_ <= 3 && iPhiSec_ >= 1 &&
iPhiSec_ <= 5) {
811 deadGPlayers.insert(pair<unsigned, bool>(3,
false));
817 set<unsigned> kfDeadLayers;
818 for (
const auto &
p : deadGPlayers) {
819 unsigned int layer =
p.first;
824 kfDeadLayers.insert(kalmanLay);
839 TVectorD tpParams(5);
840 bool useForAlgEff(
false);
842 useForAlgEff =
tp->useForAlgEff();
844 tpParams[
PHI0] =
tp->phi0();
845 tpParams[
Z0] =
tp->z0();
846 tpParams[
T] =
tp->tanLambda();
847 tpParams[
D0] =
tp->d0();
849 std::stringstream
text;
852 text <<
" TP index = " <<
tp->index() <<
" useForAlgEff = " << useForAlgEff <<
" ";
853 const string helixNames[5] = {
"qOverPt",
"phi0",
"z0",
"tanL",
"d0"};
854 for (
int i = 0;
i < tpParams.GetNrows();
i++) {
855 text << helixNames[
i] <<
":" << tpParams[
i] <<
", ";
867 std::stringstream
text;
870 text <<
"stub layers = []\n";
872 text <<
"stub layers = [ ";
873 for (
unsigned i = 0;
i <
stubs.size();
i++) {
875 if (
i !=
stubs.size() - 1)
879 text <<
"KF stub layers = [ ";
880 for (
unsigned j = 0;
j <
stubs.size();
j++) {
881 unsigned int kalmanLay =
884 if (
j !=
stubs.size() - 1)
895 std::stringstream
text;
898 text <<
"index=" << stub->
index() <<
" ";
900 text <<
"r=" << stub->
r() <<
" ";
901 text <<
"phi=" << stub->
phi() <<
" ";
902 text <<
"z=" << stub->
z() <<
" ";
906 std::set<const TP *> tps = stub->
assocTPs();
908 text <<
tp->index() <<
",";
915 for (
auto &stub :
stubs) {
unsigned int kalmanMaxStubsPerLayer() const
unsigned int iEtaReg() const override
constexpr double deltaPhi(double phi1, double phi2)
bool kalmanHOhelixExp() const
static constexpr std::pair< unsigned, unsigned > layerMap_[nEta_/2][nGPlayer_+1]
unsigned int layerId() const
float phi0() const override
unsigned nextLayer() const
bool enableDigitize() const
unsigned nSkippedLayers() const
unsigned int kalmanHOalpha() const
const Settings * settings() const
float qOverPt() const override
double bApprox_intercept() const
void printStubLayers(const std::vector< Stub *> &stubs, unsigned int iEtaReg) const
void adjustState(const TMatrixD &K, const TMatrixD &pxcov, const TVectorD &x, const TMatrixD &h, const TVectorD &delta, TVectorD &new_x, TMatrixD &new_xcov) const
void printTP(const TP *tp) const
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
const TP * matchedTP() const override
void printStubs(const std::vector< Stub *> &stubs) const
unsigned int killScenario() const
L1fittedTrack fit(const L1track3D &l1track3D) override
bool kalmanRemove2PScut() const
std::set< unsigned > kalmanDeadLayers(bool &remove2PSCut) const
float approxB(float z, float r) const
static const unsigned int nEta_
const std::vector< Stub * > & stubs() const override
unsigned int kalmanMaxStubsEasy() const
std::pair< unsigned int, unsigned int > cellLocationHT() const override
unsigned int numEtaRegions() const
virtual TVectorD trackParams(const KalmanState *state) const =0
unsigned int index() const
unsigned nStubLayers() const
unsigned kalmanDebugLevel() const
unsigned int iPhiSec() const override
const KalmanState * mkState(const L1track3D &candidate, unsigned nSkipped, unsigned layer, const KalmanState *last_state, const TVectorD &x, const TMatrixD &pxx, const TMatrixD &K, const TMatrixD &dcov, Stub *stub, double chi2rphi, double chi2rz)
virtual const KalmanState * kalmanUpdate(unsigned nSkipped, unsigned layer, Stub *stub, const KalmanState *state, const TP *tp)
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
bool kalmanAddBeamConstr() const
static const unsigned int nKFlayer_
virtual bool kalmanAmbiguousLayer(unsigned int iEtaReg, unsigned int kfLayer)
virtual TMatrixD matrixV(const Stub *stub, const KalmanState *state) const =0
static constexpr unsigned int invalidKFlayer_
Abs< T >::type abs(const T &t)
virtual TVectorD seedX(const L1track3D &l1track3D) const =0
const KalmanState * doKF(const L1track3D &l1track3D, const std::vector< Stub *> &stubs, const TP *tpa)
const Settings * settings_
void printStub(const Stub *stub) const
double bApprox_gradient() const
unsigned int kalmanMinNumStubs() const
virtual TMatrixD seedC(const L1track3D &l1track3D) const =0
std::vector< DeviationSensor2D * > vd
unsigned int kalmanMaxSkipLayersEasy() const
virtual TMatrixD matrixH(const Stub *stub) const =0
TMatrixD matrixHCHt(const TMatrixD &h, const TMatrixD &c) const
virtual TVectorD trackParams_BeamConstr(const KalmanState *state, double &chi2rphi_bcon) const =0
virtual TVectorD residual(const Stub *stub, const TVectorD &x, double candQoverPt) const
unsigned int kalmanMaxNumStubs() const
static constexpr float d0
void setInfoKF(unsigned int nSkippedLayers, unsigned int numUpdateCalls)
TMatrixD matrixRinv(const TMatrixD &matH, const TMatrixD &matCref, const TMatrixD &matV) const
TMatrixD getKalmanGainMatrix(const TMatrixD &h, const TMatrixD &pxcov, const TMatrixD &covRinv) const
=== This is the base class for the linearised chi-squared track fit algorithms.
unsigned int kalmanMaxSkipLayersHard() const
const std::set< const TP * > & assocTPs() const
virtual bool isGoodState(const KalmanState &state) const =0
unsigned int numUpdateCalls_
unsigned int numStubs() const override
unsigned int kalmanHOprojZcorr() const
unsigned int kalmanChi2RphiScale() const
virtual TVectorD vectorM(const Stub *stub) const =0
const std::vector< double > & kfLayerVsChiSq5() const
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
unsigned int hitPattern() const
virtual TMatrixD matrixF(const Stub *stub=nullptr, const KalmanState *state=nullptr) const =0
Power< A, B >::type pow(const A &a, const B &b)
bool kfUseMaybeLayers() const
virtual void adjustChi2(const KalmanState *state, const TMatrixD &covRinv, const TVectorD &delta, double &chi2rphi, double &chi2rz) const
double invPtToInvR() const