CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
tmtt::KFbase Class Referenceabstract

#include <KFbase.h>

Inheritance diagram for tmtt::KFbase:
tmtt::TrackFitGeneric tmtt::KFParamsComb

Public Types

enum  MEAS_IDS { PHI, Z }
 
enum  PAR_IDS {
  INV2R, PHI0, T, Z0,
  D0
}
 
enum  PAR_IDS_VAR { QOVERPT }
 

Public Member Functions

L1fittedTrack fit (const L1track3D &l1track3D) override
 
 KFbase (const Settings *settings, const uint nHelixPar, const std::string &fitterName="", const uint nMeas=2)
 
 KFbase (const KFbase &kf)=delete
 
 KFbase (KFbase &&kf)=delete
 
KFbaseoperator= (const KFbase &kf)=delete
 
KFbaseoperator= (KFbase &&kf)=delete
 
 ~KFbase () override
 
- Public Member Functions inherited from tmtt::TrackFitGeneric
 TrackFitGeneric (const Settings *settings, const std::string &fitterName="")
 
virtual ~TrackFitGeneric ()=default
 

Static Public Attributes

static constexpr unsigned int invalidKFlayer_ = nKFlayer_
 
static constexpr std::pair< unsigned, unsigned > layerMap_ [nEta_/2][nGPlayer_+1]
 
static const unsigned int nEta_ = 16
 
static const unsigned int nGPlayer_ = 7
 
static const unsigned int nKFlayer_ = 7
 

Protected Member Functions

virtual void adjustChi2 (const KalmanState *state, const TMatrixD &covRinv, const TVectorD &delta, double &chi2rphi, double &chi2rz) 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
 
float approxB (float z, float r) const
 
const KalmanStatedoKF (const L1track3D &l1track3D, const std::vector< Stub *> &stubs, const TP *tpa)
 
TMatrixD getKalmanGainMatrix (const TMatrixD &h, const TMatrixD &pxcov, const TMatrixD &covRinv) const
 
virtual bool isGoodState (const KalmanState &state) const =0
 
virtual bool isHLS ()
 
virtual bool kalmanAmbiguousLayer (unsigned int iEtaReg, unsigned int kfLayer)
 
std::set< unsigned > kalmanDeadLayers (bool &remove2PSCut) const
 
virtual unsigned int kalmanLayer (unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
 
virtual const KalmanStatekalmanUpdate (unsigned nSkipped, unsigned layer, Stub *stub, const KalmanState *state, const TP *tp)
 
virtual TMatrixD matrixF (const Stub *stub=nullptr, const KalmanState *state=nullptr) const =0
 
virtual TMatrixD matrixH (const Stub *stub) const =0
 
TMatrixD matrixHCHt (const TMatrixD &h, const TMatrixD &c) const
 
TMatrixD matrixRinv (const TMatrixD &matH, const TMatrixD &matCref, const TMatrixD &matV) const
 
virtual TMatrixD matrixV (const Stub *stub, const KalmanState *state) const =0
 
const KalmanStatemkState (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)
 
void printStub (const Stub *stub) const
 
void printStubLayers (const std::vector< Stub *> &stubs, unsigned int iEtaReg) const
 
void printStubs (const std::vector< Stub *> &stubs) const
 
void printTP (const TP *tp) const
 
void resetStates ()
 
virtual TVectorD residual (const Stub *stub, const TVectorD &x, double candQoverPt) const
 
double sectorPhi () const
 
virtual TMatrixD seedC (const L1track3D &l1track3D) const =0
 
virtual TVectorD seedX (const L1track3D &l1track3D) const =0
 
virtual TVectorD trackParams (const KalmanState *state) const =0
 
virtual TVectorD trackParams_BeamConstr (const KalmanState *state, double &chi2rphi_bcon) const =0
 
virtual TVectorD vectorM (const Stub *stub) const =0
 

Protected Attributes

unsigned int iEtaReg_
 
unsigned int iPhiSec_
 
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
 
unsigned nHelixPar_
 
unsigned nMeas_
 
unsigned numEtaRegions_
 
unsigned int numUpdateCalls_
 
const TPtpa_
 
- Protected Attributes inherited from tmtt::TrackFitGeneric
const std::string fitterName_
 
const Settingssettings_
 

Detailed Description

Definition at line 31 of file KFbase.h.

Member Enumeration Documentation

◆ MEAS_IDS

Enumerator
PHI 

Definition at line 35 of file KFbase.h.

◆ PAR_IDS

Enumerator
INV2R 
PHI0 
Z0 
D0 

Definition at line 33 of file KFbase.h.

◆ PAR_IDS_VAR

Enumerator
QOVERPT 

Definition at line 34 of file KFbase.h.

Constructor & Destructor Documentation

◆ KFbase() [1/3]

tmtt::KFbase::KFbase ( const Settings settings,
const uint  nHelixPar,
const std::string &  fitterName = "",
const uint  nMeas = 2 
)

◆ ~KFbase()

tmtt::KFbase::~KFbase ( )
inlineoverride

Definition at line 41 of file KFbase.h.

References resetStates().

41 { this->resetStates(); }
void resetStates()
Definition: KFbase.cc:679

◆ KFbase() [2/3]

tmtt::KFbase::KFbase ( const KFbase kf)
delete

◆ KFbase() [3/3]

tmtt::KFbase::KFbase ( KFbase &&  kf)
delete

Member Function Documentation

◆ adjustChi2()

void tmtt::KFbase::adjustChi2 ( const KalmanState state,
const TMatrixD &  covRinv,
const TVectorD &  delta,
double &  chi2rphi,
double &  chi2rz 
) const
protectedvirtual

Definition at line 660 of file KFbase.cc.

References dumpMFGeometry_cfg::delta, tmtt::Settings::kalmanDebugLevel(), PHI, tmtt::TrackFitGeneric::settings_, and Z.

Referenced by kalmanUpdate().

664  {
665  // Change in chi2 (with r-phi/r-z correlation term included in r-phi component)
666  double delChi2rphi = delta[PHI] * delta[PHI] * matRinv[PHI][PHI] + 2 * delta[PHI] * delta[Z] * matRinv[PHI][Z];
667  double delChi2rz = delta[Z] * delta[Z] * matRinv[Z][Z];
668 
669  if (settings_->kalmanDebugLevel() >= 4) {
670  PrintL1trk() << "delta(chi2rphi)=" << delChi2rphi << " delta(chi2rz)= " << delChi2rz;
671  }
672  chi2rphi = state->chi2rphi() + delChi2rphi;
673  chi2rz = state->chi2rz() + delChi2rz;
674  return;
675  }
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
const Settings * settings_

◆ adjustState()

void tmtt::KFbase::adjustState ( const TMatrixD &  K,
const TMatrixD &  pxcov,
const TVectorD &  x,
const TMatrixD &  h,
const TVectorD &  delta,
TVectorD &  new_x,
TMatrixD &  new_xcov 
) const
protected

Definition at line 645 of file KFbase.cc.

References dumpMFGeometry_cfg::delta, nHelixPar_, and createJobs::tmp.

Referenced by kalmanUpdate().

651  {
652  new_vecX = vecXref + matK * delta;
653  const TMatrixD unitMatrix(TMatrixD::kUnit, TMatrixD(nHelixPar_, nHelixPar_));
654  TMatrixD tmp = unitMatrix - matK * matH;
655  new_matC = tmp * matCref;
656  }
unsigned nHelixPar_
Definition: KFbase.h:174
tmp
align.sh
Definition: createJobs.py:716

◆ approxB()

float tmtt::KFbase::approxB ( float  z,
float  r 
) const
protected

Definition at line 836 of file KFbase.cc.

References funct::abs(), tmtt::Settings::bApprox_gradient(), tmtt::Settings::bApprox_intercept(), and tmtt::TrackFitGeneric::settings_.

Referenced by tmtt::KFParamsComb::matrixV().

836  {
838  }
double bApprox_intercept() const
Definition: Settings.h:105
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const Settings * settings_
double bApprox_gradient() const
Definition: Settings.h:104

◆ doKF()

const KalmanState * tmtt::KFbase::doKF ( const L1track3D l1track3D,
const std::vector< Stub *> &  stubs,
const TP tpa 
)
protected

Definition at line 174 of file KFbase.cc.

References a, b, electrons_cff::bool, tmtt::L1track3D::cellLocationHT(), D0, TauDecayModes::dec, alignBH_cfg::fixed, tmtt::KalmanState::hitPattern(), mps_fire::i, tmtt::L1track3D::iEtaReg(), invalidKFlayer_, tmtt::L1track3D::iPhiSec(), isGoodState(), align_cfg::iteration, kalmanAmbiguousLayer(), kalmanDeadLayers(), tmtt::Settings::kalmanDebugLevel(), kalmanLayer(), tmtt::Settings::kalmanMaxNumStubs(), tmtt::Settings::kalmanMaxSkipLayersEasy(), tmtt::Settings::kalmanMaxSkipLayersHard(), tmtt::Settings::kalmanMaxStubsEasy(), tmtt::Settings::kalmanMaxStubsPerLayer(), tmtt::Settings::kalmanMinNumStubs(), tmtt::Settings::kalmanRemove2PScut(), kalmanUpdate(), SiStripPI::max, HLT_2022v15_cff::maxIterations, mkState(), tmtt::KalmanState::nextLayer(), nHelixPar_, tmtt::KalmanState::nSkippedLayers(), tmtt::KalmanState::nStubLayers(), tmtt::L1track3D::numStubs(), AlCaHLTBitMon_ParallelJobs::p, PHI0, QOVERPT, seedC(), seedX(), tmtt::TrackFitGeneric::settings_, findQualityFiles::size, jetsAK4_CHS_cff::sort, T, submitPVValidationJobs::text, trackParams(), and Z0.

Referenced by fit().

174  {
175  const KalmanState *finished_state = nullptr;
176 
177  map<unsigned int, const KalmanState *, std::greater<unsigned int>>
178  best_state_by_nstubs; // Best state (if any) for each viable no. of stubs on track value.
179 
180  // seed helix params & their covariance.
181  TVectorD x0 = seedX(l1track3D);
182  TMatrixD pxx0 = seedC(l1track3D);
183  TMatrixD K(nHelixPar_, 2);
184  TMatrixD dcov(2, 2);
185 
186  const KalmanState *state0 = mkState(l1track3D, 0, -1, nullptr, x0, pxx0, K, dcov, nullptr, 0, 0);
187 
188  // internal containers - i.e. the state FIFO. Contains estimate of helix params in last/next layer, with multiple entries if there were multiple stubs, yielding multiple states.
189  vector<const KalmanState *> new_states;
190  vector<const KalmanState *> prev_states;
191  prev_states.push_back(state0);
192 
193  // Get dead layers, if any.
194  bool remove2PSCut = settings_->kalmanRemove2PScut();
195  set<unsigned> kfDeadLayers = kalmanDeadLayers(remove2PSCut);
196 
197  // arrange stubs into Kalman layers according to eta region
198  int etaReg = l1track3D.iEtaReg();
199  map<int, vector<Stub *>> layerStubs;
200 
201  for (auto stub : stubs) {
202  // Get Kalman encoded layer ID for this stub.
203  int kalmanLay = this->kalmanLayer(etaReg, stub->layerIdReduced(), stub->barrel(), stub->r(), stub->z());
204 
205  if (kalmanLay != invalidKFlayer_) {
206  if (layerStubs[kalmanLay].size() < settings_->kalmanMaxStubsPerLayer()) {
207  layerStubs[kalmanLay].push_back(stub);
208  } else {
209  // If too many stubs, FW keeps the last stub.
210  layerStubs[kalmanLay].back() = stub;
211  }
212  }
213  }
214 
215  // iterate using state->nextLayer() to determine next Kalman layer(s) to add stubs from
216  constexpr unsigned int nTypicalLayers = 6; // Number of tracker layers a typical track can pass through.
217  // If user asked to add up to 7 layers to track, increase number of iterations by 1.
218  const unsigned int maxIterations = std::max(nTypicalLayers, settings_->kalmanMaxNumStubs());
219  for (unsigned iteration = 0; iteration < maxIterations; iteration++) {
220  int combinations_per_iteration = 0;
221 
222  bool easy = (l1track3D.numStubs() < settings_->kalmanMaxStubsEasy());
223  unsigned int kalmanMaxSkipLayers =
225 
226  // update each state from previous iteration (or seed) using stubs in next Kalman layer
227  vector<const KalmanState *>::const_iterator i_state = prev_states.begin();
228  for (; i_state != prev_states.end(); i_state++) {
229  const KalmanState *the_state = *i_state;
230 
231  unsigned int layer = the_state->nextLayer(); // Get KF layer where stubs to be searched for next
232  unsigned nSkipped = the_state->nSkippedLayers();
233 
234  // If this layer is known to be dead, skip to the next layer (layer+1)
235  // The next_states_skipped will then look at layer+2
236  // However, if there are stubs in this layer, then don't skip (e.g. our phi/eta boundaries might not line up exactly with a dead region)
237  // Continue to skip until you reach a functioning layer (or a layer with stubs)
238  unsigned nSkippedDeadLayers = 0;
239  unsigned nSkippedAmbiguousLayers = 0;
240  while (kfDeadLayers.find(layer) != kfDeadLayers.end() && layerStubs[layer].empty()) {
241  layer += 1;
242  ++nSkippedDeadLayers;
243  }
244  while (this->kalmanAmbiguousLayer(etaReg, layer) && layerStubs[layer].empty()) {
245  layer += 1;
246  ++nSkippedAmbiguousLayers;
247  }
248 
249  // containers for updated state+stub combinations
250  vector<const KalmanState *> next_states;
251  vector<const KalmanState *> next_states_skipped;
252 
253  // find stubs for this layer
254  // (If layer > 6, this will return empty vector, so safe).
255  vector<Stub *> thislay_stubs = layerStubs[layer];
256 
257  // find stubs for next layer if we skip a layer, except when we are on the penultimate layer,
258  // or we have exceeded the max skipped layers
259  vector<Stub *> nextlay_stubs;
260 
261  // If the next layer (layer+1) is a dead layer, then proceed to the layer after next (layer+2), if possible
262  // Also note if we need to increase "skipped" by one more for these states
263  unsigned nSkippedDeadLayers_nextStubs = 0;
264  unsigned nSkippedAmbiguousLayers_nextStubs = 0;
265  if (nSkipped < kalmanMaxSkipLayers) {
266  if (kfDeadLayers.find(layer + 1) != kfDeadLayers.end() && layerStubs[layer + 1].empty()) {
267  nextlay_stubs = layerStubs[layer + 2];
268  nSkippedDeadLayers_nextStubs++;
269  } else if (this->kalmanAmbiguousLayer(etaReg, layer + 1) && layerStubs[layer + 1].empty()) {
270  nextlay_stubs = layerStubs[layer + 2];
271  nSkippedAmbiguousLayers_nextStubs++;
272  } else {
273  nextlay_stubs = layerStubs[layer + 1];
274  }
275  }
276 
277  // If track was not rejected by isGoodState() is previous iteration, failure here usually means the tracker ran out of layers to explore.
278  // (Due to "kalmanLay" not having unique ID for each layer within a given eta sector).
279  if (settings_->kalmanDebugLevel() >= 2 && best_state_by_nstubs.empty() && thislay_stubs.empty() &&
280  nextlay_stubs.empty())
281  PrintL1trk() << "State is lost by start of iteration " << iteration
282  << " : #thislay_stubs=" << thislay_stubs.size() << " #nextlay_stubs=" << nextlay_stubs.size()
283  << " layer=" << layer << " eta=" << l1track3D.iEtaReg();
284 
285  // If we skipped over a dead layer, only increment "nSkipped" after the stubs in next+1 layer have been obtained
286  nSkipped += nSkippedDeadLayers;
287  nSkipped += nSkippedAmbiguousLayers;
288 
289  // check to guarantee no fewer than 2PS hits per state at iteration 1
290  // (iteration 0 will always include a PS hit, but iteration 1 could use 2S hits
291  // unless we include this)
292  if (iteration == 1 && !remove2PSCut) {
293  vector<Stub *> temp_thislaystubs;
294  vector<Stub *> temp_nextlaystubs;
295  for (auto stub : thislay_stubs) {
296  if (stub->psModule())
297  temp_thislaystubs.push_back(stub);
298  }
299  for (auto stub : nextlay_stubs) {
300  if (stub->psModule())
301  temp_nextlaystubs.push_back(stub);
302  }
303  thislay_stubs = temp_thislaystubs;
304  nextlay_stubs = temp_nextlaystubs;
305  }
306 
307  combinations_per_iteration += thislay_stubs.size() + nextlay_stubs.size();
308 
309  // loop over each stub in this layer and check for compatibility with this state
310  for (unsigned i = 0; i < thislay_stubs.size(); i++) {
311  Stub *stub = thislay_stubs[i];
312 
313  // Update helix params by adding this stub.
314  const KalmanState *new_state = kalmanUpdate(nSkipped, layer, stub, the_state, tpa);
315 
316  // Cut on track chi2, pt etc.
317  if (isGoodState(*new_state))
318  next_states.push_back(new_state);
319  }
320 
321  // loop over each stub in next layer if we skip, and check for compatibility with this state
322  for (unsigned i = 0; i < nextlay_stubs.size(); i++) {
323  Stub *stub = nextlay_stubs[i];
324 
325  const KalmanState *new_state =
326  kalmanUpdate(nSkipped + 1 + nSkippedDeadLayers_nextStubs + nSkippedAmbiguousLayers_nextStubs,
327  layer + 1 + nSkippedDeadLayers_nextStubs + nSkippedAmbiguousLayers_nextStubs,
328  stub,
329  the_state,
330  tpa);
331 
332  if (isGoodState(*new_state))
333  next_states_skipped.push_back(new_state);
334  }
335 
336  // post Kalman filter local sorting per state
337  auto orderByChi2 = [](const KalmanState *a, const KalmanState *b) {
338  return bool(a->chi2scaled() < b->chi2scaled());
339  };
340  sort(next_states.begin(), next_states.end(), orderByChi2);
341  sort(next_states_skipped.begin(), next_states_skipped.end(), orderByChi2);
342 
343  new_states.insert(new_states.end(), next_states.begin(), next_states.end());
344  new_states.insert(new_states.end(), next_states_skipped.begin(), next_states_skipped.end());
345  } //end of state loop
346 
347  // copy new_states into prev_states for next iteration or end if we are on
348  // last iteration by clearing all states and making final state selection
349 
350  auto orderByMinSkipChi2 = [](const KalmanState *a, const KalmanState *b) {
351  return bool((a->chi2scaled()) * (a->nSkippedLayers() + 1) < (b->chi2scaled()) * (b->nSkippedLayers() + 1));
352  };
353  sort(new_states.begin(), new_states.end(), orderByMinSkipChi2); // Sort by chi2*(skippedLayers+1)
354 
355  unsigned int nStubs = iteration + 1;
356  // Success. We have at least one state that passes all cuts. Save best state found with this number of stubs.
357  if (nStubs >= settings_->kalmanMinNumStubs() && not new_states.empty())
358  best_state_by_nstubs[nStubs] = new_states[0];
359 
360  if (nStubs == settings_->kalmanMaxNumStubs()) {
361  // We're done.
362  prev_states.clear();
363  new_states.clear();
364  break;
365  } else {
366  // Continue iterating.
367  prev_states = new_states;
368  new_states.clear();
369  }
370  }
371 
372  if (not best_state_by_nstubs.empty()) {
373  // Select state with largest number of stubs.
374  finished_state = best_state_by_nstubs.begin()->second; // First element has largest number of stubs.
375  if (settings_->kalmanDebugLevel() >= 1) {
376  std::stringstream text;
377  text << std::fixed << std::setprecision(4);
378  text << "Track found! final state selection: nLay=" << finished_state->nStubLayers()
379  << " hitPattern=" << std::hex << finished_state->hitPattern() << std::dec
380  << " phiSec=" << l1track3D.iPhiSec() << " etaReg=" << l1track3D.iEtaReg() << " HT(m,c)=("
381  << l1track3D.cellLocationHT().first << "," << l1track3D.cellLocationHT().second << ")";
382  TVectorD y = trackParams(finished_state);
383  text << " q/pt=" << y[QOVERPT] << " tanL=" << y[T] << " z0=" << y[Z0] << " phi0=" << y[PHI0];
384  if (nHelixPar_ == 5)
385  text << " d0=" << y[D0];
386  text << " chosen from states:";
387  for (const auto &p : best_state_by_nstubs)
388  text << " " << p.second->chi2() << "/" << p.second->nStubLayers();
389  PrintL1trk() << text.str();
390  }
391  } else {
392  if (settings_->kalmanDebugLevel() >= 1) {
393  PrintL1trk() << "Track lost";
394  }
395  }
396 
397  return finished_state;
398  }
size
Write out results.
unsigned int kalmanMaxStubsPerLayer() const
Definition: Settings.h:322
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:683
bool kalmanRemove2PScut() const
Definition: Settings.h:305
std::set< unsigned > kalmanDeadLayers(bool &remove2PSCut) const
Definition: KFbase.cc:781
unsigned int kalmanMaxStubsEasy() const
Definition: Settings.h:310
virtual TVectorD trackParams(const KalmanState *state) const =0
constexpr std::array< uint8_t, layerIndexSize > layer
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
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)
Definition: KFbase.cc:522
virtual const KalmanState * kalmanUpdate(unsigned nSkipped, unsigned layer, Stub *stub, const KalmanState *state, const TP *tp)
Definition: KFbase.cc:402
virtual bool kalmanAmbiguousLayer(unsigned int iEtaReg, unsigned int kfLayer)
Definition: KFbase.cc:750
static constexpr unsigned int invalidKFlayer_
Definition: KFbase.h:54
virtual TVectorD seedX(const L1track3D &l1track3D) const =0
const Settings * settings_
unsigned int kalmanMinNumStubs() const
Definition: Settings.h:299
virtual TMatrixD seedC(const L1track3D &l1track3D) const =0
unsigned int kalmanMaxSkipLayersEasy() const
Definition: Settings.h:308
unsigned int kalmanMaxNumStubs() const
Definition: Settings.h:301
unsigned int kalmanMaxSkipLayersHard() const
Definition: Settings.h:307
virtual bool isGoodState(const KalmanState &state) const =0
double b
Definition: hdecay.h:118
unsigned nHelixPar_
Definition: KFbase.h:174
double a
Definition: hdecay.h:119

◆ fit()

L1fittedTrack tmtt::KFbase::fit ( const L1track3D l1track3D)
overridevirtual

Reimplemented from tmtt::TrackFitGeneric.

Definition at line 38 of file KFbase.cc.

References a, b, electrons_cff::bool, tmtt::L1track3D::cellLocationHT(), D0, d0, tmtt::L1track3D::d0(), doKF(), tmtt::Settings::enableDigitize(), alignBH_cfg::fixed, spr::goodTrack(), tmtt::Settings::hybrid(), tmtt::L1track3D::iEtaReg(), iEtaReg_, tmtt::L1track3D::iPhiSec(), iPhiSec_, tmtt::Settings::kalmanAddBeamConstr(), tmtt::Settings::kalmanChi2RphiScale(), tmtt::Settings::kalmanDebugLevel(), kalmanLayer(), tmtt::Settings::kfLayerVsChiSq5(), tmtt::L1track3D::matchedTP(), nHelixPar_, tmtt::L1track3D::numStubs(), numUpdateCalls_, PHI0, tmtt::L1track3D::phi0(), printStubLayers(), printStubs(), printTP(), tmtt::L1track3D::pt(), QOVERPT, tmtt::L1track3D::qOverPt(), resetStates(), tmtt::L1fittedTrack::setInfoKF(), tmtt::TrackFitGeneric::settings_, jetsAK4_CHS_cff::sort, tmtt::L1track3D::stubs(), T, tmtt::L1track3D::tanLambda(), submitPVValidationJobs::text, tpa_, trackParams(), trackParams_BeamConstr(), Z0, and tmtt::L1track3D::z0().

Referenced by trackingPlots.Iteration::modules().

38  {
39  iPhiSec_ = l1track3D.iPhiSec();
40  iEtaReg_ = l1track3D.iEtaReg();
41  resetStates();
42  numUpdateCalls_ = 0;
43 
44  vector<Stub *> stubs = l1track3D.stubs();
45 
46  auto orderByLayer = [](const Stub *a, const Stub *b) { return bool(a->layerId() < b->layerId()); };
47  sort(stubs.begin(), stubs.end(), orderByLayer); // Makes debug printout pretty.
48 
49  //TP
50  const TP *tpa(nullptr);
51  if (l1track3D.matchedTP()) {
52  tpa = l1track3D.matchedTP();
53  }
54  tpa_ = tpa;
55 
56  //track information dump
57  if (settings_->kalmanDebugLevel() >= 1) {
58  PrintL1trk() << "===============================================================================";
59  std::stringstream text;
60  text << std::fixed << std::setprecision(4);
61  text << "Input track cand: [phiSec,etaReg]=[" << l1track3D.iPhiSec() << "," << l1track3D.iEtaReg() << "]";
62  text << " HT(m,c)=(" << l1track3D.cellLocationHT().first << "," << l1track3D.cellLocationHT().second
63  << ") q/pt=" << l1track3D.qOverPt() << " tanL=" << l1track3D.tanLambda() << " z0=" << l1track3D.z0()
64  << " phi0=" << l1track3D.phi0() << " nStubs=" << l1track3D.numStubs() << " d0=" << l1track3D.d0();
65  PrintL1trk() << text.str();
66  if (not settings_->hybrid())
67  printTP(tpa);
68  if (settings_->kalmanDebugLevel() >= 2) {
69  printStubLayers(stubs, l1track3D.iEtaReg());
70  printStubs(stubs);
71  }
72  }
73 
74  //Kalman Filter
75  const KalmanState *cand = doKF(l1track3D, stubs, tpa);
76 
77  //return L1fittedTrk for the selected state (if KF produced one it was happy with).
78  if (cand != nullptr) {
79  // Get track helix params.
80  TVectorD trackPars = trackParams(cand);
81  double d0 = (nHelixPar_ == 5) ? trackPars[D0] : 0.;
82 
83  L1fittedTrack fitTrk(settings_,
84  &l1track3D,
85  cand->stubs(),
86  cand->hitPattern(),
87  trackPars[QOVERPT],
88  d0,
89  trackPars[PHI0],
90  trackPars[Z0],
91  trackPars[T],
92  cand->chi2rphi(),
93  cand->chi2rz(),
94  nHelixPar_);
95 
96  // Store supplementary info, specific to KF fitter.
97  fitTrk.setInfoKF(cand->nSkippedLayers(), numUpdateCalls_);
98 
99  // If doing 5 parameter fit, optionally also calculate helix params & chi2 with beam-spot constraint applied,
100  // and store inside L1fittedTrack object.
102  if (nHelixPar_ == 5) {
103  double chi2rphi_bcon = 0.;
104  TVectorD trackPars_bcon = trackParams_BeamConstr(cand, chi2rphi_bcon);
105 
106  // Check scaled chi2 cut
107  vector<double> kfLayerVsChiSqCut = settings_->kfLayerVsChiSq5();
108  double chi2scaled = chi2rphi_bcon / settings_->kalmanChi2RphiScale() + fitTrk.chi2rz();
109  bool accepted = true;
110  if (chi2scaled > kfLayerVsChiSqCut[cand->nStubLayers()])
111  accepted = false;
112 
113  fitTrk.setBeamConstr(trackPars_bcon[QOVERPT], trackPars_bcon[PHI0], chi2rphi_bcon, accepted);
114  }
115  }
116 
117  // Fitted track params must lie in same sector as HT originally found track in.
118  if (!settings_->hybrid()) { // consistentSector() function not yet working for Hybrid.
119 
120  // Bodge to take into account digitisation in sector consistency check.
121  if (settings_->enableDigitize())
122  fitTrk.digitizeTrack("KF4ParamsComb");
123 
124  if (!fitTrk.consistentSector()) {
125  if (settings_->kalmanDebugLevel() >= 1)
126  PrintL1trk() << "Track rejected by sector consistency test";
127  L1fittedTrack rejectedTrk;
128  return rejectedTrk;
129  }
130  }
131 
132  return fitTrk;
133 
134  } else { // Track rejected by fitter
135 
136  if (settings_->kalmanDebugLevel() >= 1) {
137  bool goodTrack = (tpa && tpa->useForAlgEff()); // Matches truth particle.
138  if (goodTrack) {
139  int tpin = tpa->index();
140  PrintL1trk() << "TRACK LOST: eta=" << l1track3D.iEtaReg() << " pt=" << l1track3D.pt() << " tp=" << tpin;
141 
142  for (auto stub : stubs) {
143  int kalmanLay =
144  this->kalmanLayer(l1track3D.iEtaReg(), stub->layerIdReduced(), stub->barrel(), stub->r(), stub->z());
145  std::stringstream text;
146  text << std::fixed << std::setprecision(4);
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();
151  PrintL1trk() << text.str();
152  if (stub->assocTPs().empty())
153  PrintL1trk() << " none";
154  }
155  PrintL1trk() << "=====================";
156  }
157  }
158 
159  //dump on the missed TP for efficiency calculation.
160  if (settings_->kalmanDebugLevel() >= 3) {
161  if (tpa && tpa->useForAlgEff()) {
162  PrintL1trk() << "TP for eff. missed addr. index : " << tpa << " " << tpa->index();
163  printStubs(stubs);
164  }
165  }
166 
167  L1fittedTrack rejectedTrk;
168  return rejectedTrk;
169  }
170  }
bool enableDigitize() const
Definition: Settings.h:80
void printStubLayers(const std::vector< Stub *> &stubs, unsigned int iEtaReg) const
Definition: KFbase.cc:870
void printTP(const TP *tp) const
Definition: KFbase.cc:842
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:683
void printStubs(const std::vector< Stub *> &stubs) const
Definition: KFbase.cc:918
unsigned int iEtaReg_
Definition: KFbase.h:179
virtual TVectorD trackParams(const KalmanState *state) const =0
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
bool kalmanAddBeamConstr() const
Definition: Settings.h:303
const TP * tpa_
Definition: KFbase.h:186
const KalmanState * doKF(const L1track3D &l1track3D, const std::vector< Stub *> &stubs, const TP *tpa)
Definition: KFbase.cc:174
const Settings * settings_
void resetStates()
Definition: KFbase.cc:679
virtual TVectorD trackParams_BeamConstr(const KalmanState *state, double &chi2rphi_bcon) const =0
static constexpr float d0
double b
Definition: hdecay.h:118
unsigned int numUpdateCalls_
Definition: KFbase.h:181
unsigned nHelixPar_
Definition: KFbase.h:174
double a
Definition: hdecay.h:119
bool hybrid() const
Definition: Settings.h:409
unsigned int iPhiSec_
Definition: KFbase.h:178
unsigned int kalmanChi2RphiScale() const
Definition: Settings.h:326
const std::vector< double > & kfLayerVsChiSq5() const
Definition: Settings.h:319

◆ getKalmanGainMatrix()

TMatrixD tmtt::KFbase::getKalmanGainMatrix ( const TMatrixD &  h,
const TMatrixD &  pxcov,
const TMatrixD &  covRinv 
) const
protected

Definition at line 573 of file KFbase.cc.

Referenced by kalmanUpdate().

573  {
574  TMatrixD matHtrans(TMatrixD::kTransposed, matH);
575  TMatrixD matCrefht = matCref * matHtrans;
576  TMatrixD matK = matCrefht * matRinv;
577  return matK;
578  }

◆ isGoodState()

virtual bool tmtt::KFbase::isGoodState ( const KalmanState state) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by doKF().

◆ isHLS()

virtual bool tmtt::KFbase::isHLS ( )
inlineprotectedvirtual

Definition at line 162 of file KFbase.h.

162 { return false; };

◆ kalmanAmbiguousLayer()

bool tmtt::KFbase::kalmanAmbiguousLayer ( unsigned int  iEtaReg,
unsigned int  kfLayer 
)
protectedvirtual

Definition at line 750 of file KFbase.cc.

References tmtt::Settings::kfUseMaybeLayers(), nEta_, nKFlayer_, numEtaRegions_, and tmtt::TrackFitGeneric::settings_.

Referenced by doKF().

750  {
751  // Only helps in extreme forward sector, and there not significantly.
752  // UNDERSTAND IF CAN BE USED ELSEWHERE.
753 
754  constexpr bool ambiguityMap[nEta_ / 2][nKFlayer_] = {
755  {false, false, false, false, false, false, false},
756  {false, false, false, false, false, false, false},
757  {false, false, false, false, false, false, false},
758  {false, false, false, false, false, false, false},
759  {false, false, false, false, false, false, false},
760  {false, false, true, false, false, false, false},
761  {true, true, false, false, false, false, false},
762  {true, false, false, false, false, false, false},
763  };
764 
765  unsigned int kfEtaReg; // KF VHDL eta sector def: small in barrel & large in endcap.
766  if (iEtaReg < numEtaRegions_ / 2) {
767  kfEtaReg = numEtaRegions_ / 2 - 1 - iEtaReg;
768  } else {
769  kfEtaReg = iEtaReg - numEtaRegions_ / 2;
770  }
771 
772  bool ambiguous = false;
773  if (settings_->kfUseMaybeLayers() && kfLayer < nKFlayer_)
774  ambiguous = ambiguityMap[kfEtaReg][kfLayer];
775 
776  return ambiguous;
777  }
unsigned numEtaRegions_
Definition: KFbase.h:176
static const unsigned int nEta_
Definition: KFbase.h:52
static const unsigned int nKFlayer_
Definition: KFbase.h:51
const Settings * settings_
bool kfUseMaybeLayers() const
Definition: Settings.h:312

◆ kalmanDeadLayers()

set< unsigned > tmtt::KFbase::kalmanDeadLayers ( bool &  remove2PSCut) const
protected

Definition at line 781 of file KFbase.cc.

References Reference_intrackfit_cff::barrel, iEtaReg_, iPhiSec_, kalmanLayer(), tmtt::Settings::killRecover(), tmtt::Settings::killScenario(), tmtt::StubKiller::layer1, tmtt::StubKiller::layer1disk1, tmtt::StubKiller::layer1layer2, tmtt::StubKiller::layer5, AlCaHLTBitMon_ParallelJobs::p, and tmtt::TrackFitGeneric::settings_.

Referenced by doKF().

781  {
782  // Kill scenarios described StubKiller.cc
783 
784  // By which Stress Test scenario (if any) are dead modules being emulated?
785  const StubKiller::KillOptions killScenario = static_cast<StubKiller::KillOptions>(settings_->killScenario());
786  // Should TMTT tracking be modified to reduce efficiency loss due to dead modules?
787  const bool killRecover = settings_->killRecover();
788 
789  set<pair<unsigned, bool>> deadGPlayers; // GP layer ID & boolean indicating if in barrel.
790 
791  // Range of sectors chosen to cover dead regions from StubKiller.
792  if (killRecover) {
793  if (killScenario == StubKiller::KillOptions::layer5) { // barrel layer 5
794  if (iEtaReg_ >= 3 && iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
795  deadGPlayers.insert(pair<unsigned, bool>(4, true));
796  }
797  } else if (killScenario == StubKiller::KillOptions::layer1) { // barrel layer 1
798  if (iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
799  deadGPlayers.insert(pair<unsigned, bool>(1, true));
800  }
801  remove2PSCut = true;
802  } else if (killScenario == StubKiller::KillOptions::layer1layer2) { // barrel layers 1 & 2
803  if (iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
804  deadGPlayers.insert(pair<unsigned, bool>(1, true));
805  }
806  if (iEtaReg_ >= 1 && iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
807  deadGPlayers.insert(pair<unsigned, bool>(2, true));
808  }
809  remove2PSCut = true;
810  } else if (killScenario == StubKiller::KillOptions::layer1disk1) { // barrel layer 1 & disk 1
811  if (iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
812  deadGPlayers.insert(pair<unsigned, bool>(1, true));
813  }
814  if (iEtaReg_ <= 3 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
815  deadGPlayers.insert(pair<unsigned, bool>(3, false));
816  }
817  remove2PSCut = true;
818  }
819  }
820 
821  set<unsigned> kfDeadLayers;
822  for (const auto &p : deadGPlayers) {
823  unsigned int layer = p.first;
824  bool barrel = p.second;
825  float r = 0.; // This fails for r-dependent parts of kalmanLayer(). FIX
826  float z = 999.;
827  unsigned int kalmanLay = this->kalmanLayer(iEtaReg_, layer, barrel, r, z);
828  kfDeadLayers.insert(kalmanLay);
829  }
830 
831  return kfDeadLayers;
832  }
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:683
unsigned int killScenario() const
Definition: Settings.h:343
unsigned int iEtaReg_
Definition: KFbase.h:179
bool killRecover() const
Definition: Settings.h:345
constexpr std::array< uint8_t, layerIndexSize > layer
const Settings * settings_
unsigned int iPhiSec_
Definition: KFbase.h:178

◆ kalmanLayer()

unsigned int tmtt::KFbase::kalmanLayer ( unsigned int  iEtaReg,
unsigned int  layerIDreduced,
bool  barrel,
float  r,
float  z 
) const
protectedvirtual

Definition at line 683 of file KFbase.cc.

References Reference_intrackfit_cff::barrel, Exception, tmtt::Settings::kfUseMaybeLayers(), layerMap_, nEta_, numEtaRegions_, and tmtt::TrackFitGeneric::settings_.

Referenced by doKF(), fit(), kalmanDeadLayers(), and printStubLayers().

684  {
685  if (nEta_ != numEtaRegions_)
686  throw cms::Exception("LogicError")
687  << "ERROR KFbase::getKalmanLayer hardwired value of nEta_ differs from NumEtaRegions cfg param";
688 
689  unsigned int kfEtaReg; // KF VHDL eta sector def: small in barrel & large in endcap.
690  if (iEtaReg < numEtaRegions_ / 2) {
691  kfEtaReg = numEtaRegions_ / 2 - 1 - iEtaReg;
692  } else {
693  kfEtaReg = iEtaReg - numEtaRegions_ / 2;
694  }
695 
696  unsigned int kalmanLay =
697  barrel ? layerMap_[kfEtaReg][layerIDreduced].first : layerMap_[kfEtaReg][layerIDreduced].second;
698 
699  // Switch back to the layermap that is consistent with current FW when "maybe layer" is not used
700  if (not settings_->kfUseMaybeLayers()) {
701  switch (kfEtaReg) {
702  case 6: //case 6: B1 B2+D1 D2 D3 D4 D5
703  if (layerIDreduced > 2) {
704  kalmanLay--;
705  }
706  break;
707  default:
708  break;
709  }
710  }
711 
712  /*
713  // Fix cases where a barrel layer only partially crosses the eta sector.
714  // (Logically should work, but actually reduces efficiency -- INVESTIGATE).
715 
716  const float barrelHalfLength = 120.;
717  const float barrel4Radius = 68.8;
718  const float barrel5Radius = 86.1;
719 
720  if ( not barrel) {
721  switch ( kfEtaReg ) {
722  case 4:
723  if (layerIDreduced==3) { // D1
724  float disk1_rCut = barrel5Radius*(std::abs(z)/barrelHalfLength);
725  if (r > disk1_rCut) kalmanLay++;
726  }
727  break;
728  case 5:
729  if (layerIDreduced==3) { // D1
730  float disk1_rCut = barrel4Radius*(std::abs(z)/barrelHalfLength);
731  if (r > disk1_rCut) kalmanLay++;
732  }
733  if (layerIDreduced==4) { // D2
734  float disk2_rCut = barrel4Radius*(std::abs(z)/barrelHalfLength);
735  if (r > disk2_rCut) kalmanLay++;
736  }
737  break;
738  default:
739  break;
740  }
741  }
742  */
743 
744  return kalmanLay;
745  }
static constexpr std::pair< unsigned, unsigned > layerMap_[nEta_/2][nGPlayer_+1]
Definition: KFbase.h:61
unsigned numEtaRegions_
Definition: KFbase.h:176
static const unsigned int nEta_
Definition: KFbase.h:52
const Settings * settings_
bool kfUseMaybeLayers() const
Definition: Settings.h:312

◆ kalmanUpdate()

const KalmanState * tmtt::KFbase::kalmanUpdate ( unsigned  nSkipped,
unsigned  layer,
Stub stub,
const KalmanState state,
const TP tp 
)
protectedvirtual

Definition at line 402 of file KFbase.cc.

References adjustChi2(), adjustState(), tmtt::Stub::barrel(), dumpMFGeometry_cfg::delta, getKalmanGainMatrix(), mps_fire::i, tmtt::Settings::kalmanDebugLevel(), matrixF(), matrixH(), matrixRinv(), matrixV(), mkState(), nHelixPar_, numUpdateCalls_, printStub(), residual(), and tmtt::TrackFitGeneric::settings_.

Referenced by doKF().

403  {
404  if (settings_->kalmanDebugLevel() >= 4) {
405  PrintL1trk() << "---------------";
406  PrintL1trk() << "kalmanUpdate";
407  PrintL1trk() << "---------------";
408  printStub(stub);
409  }
410 
411  numUpdateCalls_++; // For monitoring, count calls to updator per track.
412 
413  // Helix params & their covariance.
414  TVectorD vecX = state->vectorX();
415  TMatrixD matC = state->matrixC();
416  if (state->barrel() && !stub->barrel()) {
417  if (settings_->kalmanDebugLevel() >= 4) {
418  PrintL1trk() << "STATE BARREL TO ENDCAP BEFORE ";
419  PrintL1trk() << "state : " << vecX[0] << " " << vecX[1] << " " << vecX[2] << " " << vecX[3];
420  PrintL1trk() << "cov(x): ";
421  matC.Print();
422  }
423  if (settings_->kalmanDebugLevel() >= 4) {
424  PrintL1trk() << "STATE BARREL TO ENDCAP AFTER ";
425  PrintL1trk() << "state : " << vecX[0] << " " << vecX[1] << " " << vecX[2] << " " << vecX[3];
426  PrintL1trk() << "cov(x): ";
427  matC.Print();
428  }
429  }
430  // Matrix to propagate helix reference point from one layer to next.
431  TMatrixD matF = matrixF(stub, state);
432  TMatrixD matFtrans(TMatrixD::kTransposed, matF);
433  if (settings_->kalmanDebugLevel() >= 4) {
434  PrintL1trk() << "matF";
435  matF.Print();
436  }
437 
438  // Multiply matrices to get helix params relative to reference point at next layer.
439  TVectorD vecXref = matF * vecX;
440  if (settings_->kalmanDebugLevel() >= 4) {
441  PrintL1trk() << "vecFref = [";
442  for (unsigned i = 0; i < nHelixPar_; i++)
443  PrintL1trk() << vecXref[i] << ", ";
444  PrintL1trk() << "]";
445  }
446 
447  // Get stub residuals.
448  TVectorD delta = residual(stub, vecXref, state->candidate().qOverPt());
449  if (settings_->kalmanDebugLevel() >= 4) {
450  PrintL1trk() << "delta = " << delta[0] << ", " << delta[1];
451  }
452 
453  // Derivative of predicted (phi,z) intercept with layer w.r.t. helix params.
454  TMatrixD matH = matrixH(stub);
455  if (settings_->kalmanDebugLevel() >= 4) {
456  PrintL1trk() << "matH";
457  matH.Print();
458  }
459 
460  if (settings_->kalmanDebugLevel() >= 4) {
461  PrintL1trk() << "previous state covariance";
462  matC.Print();
463  }
464  // Get scattering contribution to helix parameter covariance (currently zero).
465  TMatrixD matScat(nHelixPar_, nHelixPar_);
466 
467  // Get covariance on helix parameters at new reference point including scattering..
468  TMatrixD matCref = matF * matC * matFtrans + matScat;
469  if (settings_->kalmanDebugLevel() >= 4) {
470  PrintL1trk() << "matCref";
471  matCref.Print();
472  }
473  // Get hit position covariance matrix.
474  TMatrixD matV = matrixV(stub, state);
475  if (settings_->kalmanDebugLevel() >= 4) {
476  PrintL1trk() << "matV";
477  matV.Print();
478  }
479 
480  TMatrixD matRinv = matrixRinv(matH, matCref, matV);
481  if (settings_->kalmanDebugLevel() >= 4) {
482  PrintL1trk() << "matRinv";
483  matRinv.Print();
484  }
485 
486  // Calculate Kalman Gain matrix.
487  TMatrixD matK = getKalmanGainMatrix(matH, matCref, matRinv);
488  if (settings_->kalmanDebugLevel() >= 4) {
489  PrintL1trk() << "matK";
490  matK.Print();
491  }
492 
493  // Update helix state & its covariance matrix with new stub.
494  TVectorD new_vecX(nHelixPar_);
495  TMatrixD new_matC(nHelixPar_, nHelixPar_);
496  adjustState(matK, matCref, vecXref, matH, delta, new_vecX, new_matC);
497 
498  // Update track fit chi2 with new stub.
499  double new_chi2rphi = 0, new_chi2rz = 0;
500  this->adjustChi2(state, matRinv, delta, new_chi2rphi, new_chi2rz);
501 
502  if (settings_->kalmanDebugLevel() >= 4) {
503  if (nHelixPar_ == 4)
504  PrintL1trk() << "adjusted x = " << new_vecX[0] << ", " << new_vecX[1] << ", " << new_vecX[2] << ", "
505  << new_vecX[3];
506  else if (nHelixPar_ == 5)
507  PrintL1trk() << "adjusted x = " << new_vecX[0] << ", " << new_vecX[1] << ", " << new_vecX[2] << ", "
508  << new_vecX[3] << ", " << new_vecX[4];
509  PrintL1trk() << "adjusted C ";
510  new_matC.Print();
511  PrintL1trk() << "adjust chi2rphi=" << new_chi2rphi << " chi2rz=" << new_chi2rz;
512  }
513 
514  const KalmanState *new_state = mkState(
515  state->candidate(), nSkipped, layer, state, new_vecX, new_matC, matK, matV, stub, new_chi2rphi, new_chi2rz);
516 
517  return new_state;
518  }
void adjustState(const TMatrixD &K, const TMatrixD &pxcov, const TVectorD &x, const TMatrixD &h, const TVectorD &delta, TVectorD &new_x, TMatrixD &new_xcov) const
Definition: KFbase.cc:645
constexpr std::array< uint8_t, layerIndexSize > layer
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
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)
Definition: KFbase.cc:522
virtual TMatrixD matrixV(const Stub *stub, const KalmanState *state) const =0
const Settings * settings_
void printStub(const Stub *stub) const
Definition: KFbase.cc:898
virtual TMatrixD matrixH(const Stub *stub) const =0
virtual TVectorD residual(const Stub *stub, const TVectorD &x, double candQoverPt) const
Definition: KFbase.cc:582
TMatrixD matrixRinv(const TMatrixD &matH, const TMatrixD &matCref, const TMatrixD &matV) const
Definition: KFbase.cc:550
TMatrixD getKalmanGainMatrix(const TMatrixD &h, const TMatrixD &pxcov, const TMatrixD &covRinv) const
Definition: KFbase.cc:573
unsigned int numUpdateCalls_
Definition: KFbase.h:181
unsigned nHelixPar_
Definition: KFbase.h:174
virtual TMatrixD matrixF(const Stub *stub=nullptr, const KalmanState *state=nullptr) const =0
virtual void adjustChi2(const KalmanState *state, const TMatrixD &covRinv, const TVectorD &delta, double &chi2rphi, double &chi2rz) const
Definition: KFbase.cc:660

◆ matrixF()

virtual TMatrixD tmtt::KFbase::matrixF ( const Stub stub = nullptr,
const KalmanState state = nullptr 
) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by kalmanUpdate().

◆ matrixH()

virtual TMatrixD tmtt::KFbase::matrixH ( const Stub stub) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by kalmanUpdate(), and residual().

◆ matrixHCHt()

TMatrixD tmtt::KFbase::matrixHCHt ( const TMatrixD &  h,
const TMatrixD &  c 
) const
protected

Definition at line 543 of file KFbase.cc.

Referenced by matrixRinv().

543  {
544  TMatrixD matHtrans(TMatrixD::kTransposed, matH);
545  return matH * matC * matHtrans;
546  }

◆ matrixRinv()

TMatrixD tmtt::KFbase::matrixRinv ( const TMatrixD &  matH,
const TMatrixD &  matCref,
const TMatrixD &  matV 
) const
protected

Definition at line 550 of file KFbase.cc.

References tmtt::Settings::kalmanDebugLevel(), matrixHCHt(), nHelixPar_, and tmtt::TrackFitGeneric::settings_.

Referenced by kalmanUpdate().

550  {
551  TMatrixD matHCHt = matrixHCHt(matH, matCref);
552  TMatrixD matR = matV + matHCHt;
553  TMatrixD matRinv(2, 2);
554  if (matR.Determinant() > 0) {
555  matRinv = TMatrixD(TMatrixD::kInverted, matR);
556  } else {
557  // Protection against rare maths instability.
558  const TMatrixD unitMatrix(TMatrixD::kUnit, TMatrixD(nHelixPar_, nHelixPar_));
559  const double big = 9.9e9;
560  matRinv = big * unitMatrix;
561  }
562  if (settings_->kalmanDebugLevel() >= 4) {
563  PrintL1trk() << "matHCHt";
564  matHCHt.Print();
565  PrintL1trk() << "matR";
566  matR.Print();
567  }
568  return matRinv;
569  }
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
const Settings * settings_
TMatrixD matrixHCHt(const TMatrixD &h, const TMatrixD &c) const
Definition: KFbase.cc:543
unsigned nHelixPar_
Definition: KFbase.h:174
Definition: big.h:8

◆ matrixV()

virtual TMatrixD tmtt::KFbase::matrixV ( const Stub stub,
const KalmanState state 
) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by kalmanUpdate().

◆ mkState()

const KalmanState * tmtt::KFbase::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 
)
protected

Definition at line 522 of file KFbase.cc.

References listAllStates_, eostools::move(), and tmtt::TrackFitGeneric::settings_.

Referenced by doKF(), and kalmanUpdate().

532  {
533  auto new_state = std::make_unique<const KalmanState>(
534  settings_, candidate, nSkipped, layer, last_state, vecX, matC, matK, matV, stub, chi2rphi, chi2rz);
535 
536  const KalmanState *p_new_state = new_state.get();
537  listAllStates_.push_back(std::move(new_state)); // Vector keeps ownership of all states.
538  return p_new_state;
539  }
constexpr std::array< uint8_t, layerIndexSize > layer
const Settings * settings_
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
Definition: KFbase.h:184
def move(src, dest)
Definition: eostools.py:511

◆ operator=() [1/2]

KFbase& tmtt::KFbase::operator= ( const KFbase kf)
delete

◆ operator=() [2/2]

KFbase& tmtt::KFbase::operator= ( KFbase &&  kf)
delete

◆ printStub()

void tmtt::KFbase::printStub ( const Stub stub) const
protected

Definition at line 898 of file KFbase.cc.

References tmtt::Stub::assocTPs(), alignBH_cfg::fixed, tmtt::Stub::index(), tmtt::Stub::layerId(), tmtt::Stub::phi(), tmtt::Stub::r(), tmtt::Stub::sigmaPar(), tmtt::Stub::sigmaPerp(), submitPVValidationJobs::text, cmsswSequenceInfo::tp, and tmtt::Stub::z().

Referenced by kalmanUpdate(), and printStubs().

898  {
899  std::stringstream text;
900  text << std::fixed << std::setprecision(4);
901  text << "stub ";
902  text << "index=" << stub->index() << " ";
903  text << "layerId=" << stub->layerId() << " ";
904  text << "r=" << stub->r() << " ";
905  text << "phi=" << stub->phi() << " ";
906  text << "z=" << stub->z() << " ";
907  text << "sigmaX=" << stub->sigmaPerp() << " ";
908  text << "sigmaZ=" << stub->sigmaPar() << " ";
909  text << "TPids=";
910  std::set<const TP *> tps = stub->assocTPs();
911  for (auto tp : tps)
912  text << tp->index() << ",";
913  PrintL1trk() << text.str();
914  }

◆ printStubLayers()

void tmtt::KFbase::printStubLayers ( const std::vector< Stub *> &  stubs,
unsigned int  iEtaReg 
) const
protected

Definition at line 870 of file KFbase.cc.

References Reference_intrackfit_cff::barrel, alignBH_cfg::fixed, mps_fire::i, dqmiolumiharvest::j, kalmanLayer(), and submitPVValidationJobs::text.

Referenced by fit().

870  {
871  std::stringstream text;
872  text << std::fixed << std::setprecision(4);
873  if (stubs.empty())
874  text << "stub layers = []\n";
875  else {
876  text << "stub layers = [ ";
877  for (unsigned i = 0; i < stubs.size(); i++) {
878  text << stubs[i]->layerId();
879  if (i != stubs.size() - 1)
880  text << ", ";
881  }
882  text << " ] ";
883  text << "KF stub layers = [ ";
884  for (unsigned j = 0; j < stubs.size(); j++) {
885  unsigned int kalmanLay =
886  this->kalmanLayer(iEtaReg, stubs[j]->layerIdReduced(), stubs[j]->barrel(), stubs[j]->r(), stubs[j]->z());
887  text << kalmanLay;
888  if (j != stubs.size() - 1)
889  text << ", ";
890  }
891  text << " ]\n";
892  }
893  PrintL1trk() << text.str();
894  }
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:683

◆ printStubs()

void tmtt::KFbase::printStubs ( const std::vector< Stub *> &  stubs) const
protected

Definition at line 918 of file KFbase.cc.

References printStub().

Referenced by fit().

918  {
919  for (auto &stub : stubs) {
920  printStub(stub);
921  }
922  }
void printStub(const Stub *stub) const
Definition: KFbase.cc:898

◆ printTP()

void tmtt::KFbase::printTP ( const TP tp) const
protected

Definition at line 842 of file KFbase.cc.

References D0, alignBH_cfg::fixed, mps_fire::i, tmtt::Settings::invPtToInvR(), PHI0, QOVERPT, tmtt::TrackFitGeneric::settings_, T, submitPVValidationJobs::text, cmsswSequenceInfo::tp, and Z0.

Referenced by fit().

842  {
843  TVectorD tpParams(5);
844  bool useForAlgEff(false);
845  if (tp) {
846  useForAlgEff = tp->useForAlgEff();
847  tpParams[QOVERPT] = tp->qOverPt();
848  tpParams[PHI0] = tp->phi0();
849  tpParams[Z0] = tp->z0();
850  tpParams[T] = tp->tanLambda();
851  tpParams[D0] = tp->d0();
852  }
853  std::stringstream text;
854  text << std::fixed << std::setprecision(4);
855  if (tp) {
856  text << " TP index = " << tp->index() << " useForAlgEff = " << useForAlgEff << " ";
857  const string helixNames[5] = {"qOverPt", "phi0", "z0", "tanL", "d0"};
858  for (int i = 0; i < tpParams.GetNrows(); i++) {
859  text << helixNames[i] << ":" << tpParams[i] << ", ";
860  }
861  text << " inv2R = " << tp->qOverPt() * settings_->invPtToInvR() * 0.5;
862  } else {
863  text << " Fake";
864  }
865  PrintL1trk() << text.str();
866  }
const Settings * settings_
double invPtToInvR() const
Definition: Settings.h:395

◆ resetStates()

void tmtt::KFbase::resetStates ( )
protected

Definition at line 679 of file KFbase.cc.

References listAllStates_.

Referenced by fit(), and ~KFbase().

679 { listAllStates_.clear(); }
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
Definition: KFbase.h:184

◆ residual()

TVectorD tmtt::KFbase::residual ( const Stub stub,
const TVectorD &  x,
double  candQoverPt 
) const
protectedvirtual

Definition at line 582 of file KFbase.cc.

References tmtt::Stub::alpha(), tmtt::Stub::barrel(), alignCSCRings::corr, pfMETCorrectionType0_cfi::correction, D0, d0, dumpMFGeometry_cfg::delta, reco::deltaPhi(), h, tmtt::Settings::invPtToInvR(), tmtt::Settings::kalmanHOalpha(), tmtt::Settings::kalmanHOfw(), tmtt::Settings::kalmanHOhelixExp(), tmtt::Settings::kalmanHOprojZcorr(), matrixH(), nHelixPar_, funct::pow(), tmtt::Stub::psModule(), tmtt::Stub::r(), tmtt::TrackFitGeneric::settings_, T, vectorM(), tmtt::Stub::z(), and Z0.

Referenced by kalmanUpdate().

582  {
583  TVectorD vd = vectorM(stub); // Get (phi relative to sector, z) of hit.
584  TMatrixD h = matrixH(stub);
585  TVectorD hx = h * vecX; // Get intercept of helix with layer (linear approx).
586  TVectorD delta = vd - hx;
587 
588  // Calculate higher order corrections to residuals.
589  // TO DO: Check if these could be determined using Tracklet/HT input track helix params,
590  // so only need applying at input to KF, instead of very iteration?
591 
592  if (not settings_->kalmanHOfw()) {
593  TVectorD correction(2);
594 
595  float inv2R = (settings_->invPtToInvR()) * 0.5 * candQoverPt;
596  float tanL = vecX[T];
597  float z0 = vecX[Z0];
598 
599  float deltaS = 0.;
600  if (settings_->kalmanHOhelixExp()) {
601  // Higher order correction correction to circle expansion for improved accuracy at low Pt.
602  double corr = stub->r() * inv2R;
603 
604  // N.B. In endcap 2S, this correction to correction[0] is exactly cancelled by the deltaS-dependent correction to it below.
605  correction[0] += (1. / 6.) * pow(corr, 3);
606 
607  deltaS = (1. / 6.) * (stub->r()) * pow(corr, 2);
608  correction[1] -= deltaS * tanL;
609 
610  if (nHelixPar_ == 5) {
611  float d0 = vecX[D0];
612  correction[0] += (1. / 6.) * pow(d0 / stub->r(), 3); // Division by r hard in FPGA?
613  }
614  }
615 
616  if ((not stub->barrel()) && not(stub->psModule())) {
617  // These corrections rely on inside --> outside tracking, so r-z track params in 2S modules known.
618  float rShift = (stub->z() - z0) / tanL - stub->r();
619 
621  rShift -= deltaS;
622 
623  if (settings_->kalmanHOprojZcorr() == 1) {
624  // Add correlation term related to conversion of stub residuals from (r,phi) to (z,phi).
625  correction[0] += inv2R * rShift;
626  }
627 
628  if (settings_->kalmanHOalpha() == 1) {
629  // Add alpha correction for non-radial 2S endcap strips..
630  correction[0] += stub->alpha() * rShift;
631  }
632  }
633 
634  // Apply correction to residuals.
635  delta += correction;
636  }
637 
638  delta[0] = reco::deltaPhi(delta[0], 0.);
639 
640  return delta;
641  }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
bool kalmanHOhelixExp() const
Definition: Settings.h:331
unsigned int kalmanHOalpha() const
Definition: Settings.h:333
dictionary corr
const Settings * settings_
std::vector< DeviationSensor2D * > vd
virtual TMatrixD matrixH(const Stub *stub) const =0
static constexpr float d0
bool kalmanHOfw() const
Definition: Settings.h:337
unsigned nHelixPar_
Definition: KFbase.h:174
unsigned int kalmanHOprojZcorr() const
Definition: Settings.h:335
virtual TVectorD vectorM(const Stub *stub) const =0
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
double invPtToInvR() const
Definition: Settings.h:395

◆ sectorPhi()

double tmtt::KFbase::sectorPhi ( ) const
inlineprotected

Definition at line 145 of file KFbase.h.

References dqmMemoryStats::float, iPhiSec_, M_PI, tmtt::Settings::numPhiNonants(), tmtt::Settings::numPhiSectors(), and tmtt::TrackFitGeneric::settings_.

Referenced by tmtt::KFParamsComb::seedX(), tmtt::KFParamsComb::trackParams(), tmtt::KFParamsComb::trackParams_BeamConstr(), and tmtt::KFParamsComb::vectorM().

145  {
146  float phiCentreSec0 = -M_PI / float(settings_->numPhiNonants()) + M_PI / float(settings_->numPhiSectors());
147  return 2. * M_PI * float(iPhiSec_) / float(settings_->numPhiSectors()) + phiCentreSec0;
148  }
unsigned int numPhiNonants() const
Definition: Settings.h:109
const Settings * settings_
#define M_PI
unsigned int iPhiSec_
Definition: KFbase.h:178
unsigned int numPhiSectors() const
Definition: Settings.h:110

◆ seedC()

virtual TMatrixD tmtt::KFbase::seedC ( const L1track3D l1track3D) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by doKF().

◆ seedX()

virtual TVectorD tmtt::KFbase::seedX ( const L1track3D l1track3D) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by doKF().

◆ trackParams()

virtual TVectorD tmtt::KFbase::trackParams ( const KalmanState state) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by doKF(), and fit().

◆ trackParams_BeamConstr()

virtual TVectorD tmtt::KFbase::trackParams_BeamConstr ( const KalmanState state,
double &  chi2rphi_bcon 
) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by fit().

◆ vectorM()

virtual TVectorD tmtt::KFbase::vectorM ( const Stub stub) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by residual().

Member Data Documentation

◆ iEtaReg_

unsigned int tmtt::KFbase::iEtaReg_
protected

Definition at line 179 of file KFbase.h.

Referenced by fit(), and kalmanDeadLayers().

◆ invalidKFlayer_

constexpr unsigned int tmtt::KFbase::invalidKFlayer_ = nKFlayer_
static

Definition at line 54 of file KFbase.h.

Referenced by doKF().

◆ iPhiSec_

unsigned int tmtt::KFbase::iPhiSec_
protected

Definition at line 178 of file KFbase.h.

Referenced by fit(), kalmanDeadLayers(), and sectorPhi().

◆ layerMap_

constexpr std::pair<unsigned, unsigned> tmtt::KFbase::layerMap_[nEta_/2][nGPlayer_+1]
static
Initial value:
= {
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}},
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}},
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}},
{{7, 7}, {0, 7}, {1, 7}, {5, 7}, {4, 7}, {3, 7}, {7, 7}, {2, 7}},
{{7, 7}, {0, 7}, {1, 7}, {5, 4}, {4, 5}, {3, 6}, {7, 7}, {2, 7}},
{{7, 7}, {0, 7}, {1, 7}, {7, 3}, {7, 4}, {2, 5}, {7, 6}, {2, 6}},
{{7, 7}, {0, 7}, {1, 7}, {7, 2}, {7, 3}, {7, 4}, {7, 5}, {7, 6}},
{{7, 7}, {0, 7}, {7, 7}, {7, 1}, {7, 2}, {7, 3}, {7, 4}, {7, 5}},
}

Definition at line 61 of file KFbase.h.

Referenced by kalmanLayer(), and hph::Setup::Setup().

◆ listAllStates_

std::vector<std::unique_ptr<const KalmanState> > tmtt::KFbase::listAllStates_
protected

Definition at line 184 of file KFbase.h.

Referenced by mkState(), and resetStates().

◆ nEta_

const unsigned int tmtt::KFbase::nEta_ = 16
static

Definition at line 52 of file KFbase.h.

Referenced by kalmanAmbiguousLayer(), and kalmanLayer().

◆ nGPlayer_

const unsigned int tmtt::KFbase::nGPlayer_ = 7
static

Definition at line 53 of file KFbase.h.

◆ nHelixPar_

unsigned tmtt::KFbase::nHelixPar_
protected

◆ nKFlayer_

const unsigned int tmtt::KFbase::nKFlayer_ = 7
static

Definition at line 51 of file KFbase.h.

Referenced by kalmanAmbiguousLayer().

◆ nMeas_

unsigned tmtt::KFbase::nMeas_
protected

Definition at line 175 of file KFbase.h.

◆ numEtaRegions_

unsigned tmtt::KFbase::numEtaRegions_
protected

Definition at line 176 of file KFbase.h.

Referenced by kalmanAmbiguousLayer(), and kalmanLayer().

◆ numUpdateCalls_

unsigned int tmtt::KFbase::numUpdateCalls_
protected

Definition at line 181 of file KFbase.h.

Referenced by fit(), and kalmanUpdate().

◆ tpa_

const TP* tmtt::KFbase::tpa_
protected

Definition at line 186 of file KFbase.h.

Referenced by fit(), and tmtt::KFParamsComb::isGoodState().