CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | 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
 

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

Enumerator
PHI 
Z 

Definition at line 35 of file KFbase.h.

35 { PHI, Z };
Enumerator
INV2R 
PHI0 
T 
Z0 
D0 

Definition at line 33 of file KFbase.h.

Enumerator
QOVERPT 

Definition at line 34 of file KFbase.h.

Constructor & Destructor Documentation

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

Definition at line 41 of file KFbase.h.

References resetStates().

41 { this->resetStates(); }
void resetStates()
Definition: KFbase.cc:686
tmtt::KFbase::KFbase ( const KFbase kf)
delete
tmtt::KFbase::KFbase ( KFbase &&  kf)
delete

Member Function Documentation

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

Definition at line 667 of file KFbase.cc.

References tmtt::KalmanState::chi2rphi(), tmtt::KalmanState::chi2rz(), tmtt::Settings::kalmanDebugLevel(), PHI, tmtt::TrackFitGeneric::settings_, and Z.

Referenced by kalmanUpdate().

671  {
672  // Change in chi2 (with r-phi/r-z correlation term included in r-phi component)
673  double delChi2rphi = delta[PHI] * delta[PHI] * matRinv[PHI][PHI] + 2 * delta[PHI] * delta[Z] * matRinv[PHI][Z];
674  double delChi2rz = delta[Z] * delta[Z] * matRinv[Z][Z];
675 
676  if (settings_->kalmanDebugLevel() >= 4) {
677  PrintL1trk() << "delta(chi2rphi)=" << delChi2rphi << " delta(chi2rz)= " << delChi2rz;
678  }
679  chi2rphi = state->chi2rphi() + delChi2rphi;
680  chi2rz = state->chi2rz() + delChi2rz;
681  return;
682  }
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
const Settings * settings_
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 652 of file KFbase.cc.

References CommonMethods::delta(), nHelixPar_, and createJobs::tmp.

Referenced by kalmanUpdate().

658  {
659  new_vecX = vecXref + matK * delta;
660  const TMatrixD unitMatrix(TMatrixD::kUnit, TMatrixD(nHelixPar_, nHelixPar_));
661  TMatrixD tmp = unitMatrix - matK * matH;
662  new_matC = tmp * matCref;
663  }
unsigned nHelixPar_
Definition: KFbase.h:153
tmp
align.sh
Definition: createJobs.py:716
float tmtt::KFbase::approxB ( float  z,
float  r 
) const
protected

Definition at line 899 of file KFbase.cc.

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

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

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

Reimplemented from tmtt::TrackFitGeneric.

Definition at line 38 of file KFbase.cc.

References a, b, tmtt::L1track3D::cellLocationHT(), tmtt::KalmanState::chi2rphi(), tmtt::KalmanState::chi2rz(), D0, d0, tmtt::L1track3D::d0(), doKF(), tmtt::Settings::enableDigitize(), spr::goodTrack(), tmtt::KalmanState::hitPattern(), 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::Stub::layerId(), tmtt::L1track3D::matchedTP(), nHelixPar_, tmtt::KalmanState::nSkippedLayers(), tmtt::KalmanState::nStubLayers(), 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_, tmtt::KalmanState::stubs(), tmtt::L1track3D::stubs(), T, tmtt::L1track3D::tanLambda(), runonSM::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 printStubs(const std::vector< Stub * > &stubs) const
Definition: KFbase.cc:981
bool hybrid() const
Definition: Settings.h:409
unsigned int kalmanChi2RphiScale() const
Definition: Settings.h:326
unsigned int iEtaReg_
Definition: KFbase.h:158
virtual TVectorD trackParams(const KalmanState *state) const =0
const std::vector< double > & kfLayerVsChiSq5() const
Definition: Settings.h:319
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
bool goodTrack(const reco::Track *pTrack, math::XYZPoint leadPV, trackSelectionParameters parameters, bool debug=false)
const TP * tpa_
Definition: KFbase.h:165
tuple text
Definition: runonSM.py:43
const Settings * settings_
void resetStates()
Definition: KFbase.cc:686
void printTP(const TP *tp) const
Definition: KFbase.cc:905
virtual TVectorD trackParams_BeamConstr(const KalmanState *state, double &chi2rphi_bcon) const =0
static constexpr float d0
void printStubLayers(const std::vector< Stub * > &stubs, unsigned int iEtaReg) const
Definition: KFbase.cc:933
double b
Definition: hdecay.h:118
unsigned int numUpdateCalls_
Definition: KFbase.h:160
unsigned nHelixPar_
Definition: KFbase.h:153
double a
Definition: hdecay.h:119
const KalmanState * doKF(const L1track3D &l1track3D, const std::vector< Stub * > &stubs, const TP *tpa)
Definition: KFbase.cc:174
unsigned int iPhiSec_
Definition: KFbase.h:157
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:690
bool kalmanAddBeamConstr() const
Definition: Settings.h:303
TMatrixD tmtt::KFbase::getKalmanGainMatrix ( const TMatrixD &  h,
const TMatrixD &  pxcov,
const TMatrixD &  covRinv 
) const
protected

Definition at line 587 of file KFbase.cc.

Referenced by kalmanUpdate().

587  {
588  TMatrixD matHtrans(TMatrixD::kTransposed, matH);
589  TMatrixD matCrefht = matCref * matHtrans;
590  TMatrixD matK = matCrefht * matRinv;
591  return matK;
592  }
virtual bool tmtt::KFbase::isGoodState ( const KalmanState state) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by doKF().

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

Definition at line 141 of file KFbase.h.

141 { return false; };
bool tmtt::KFbase::kalmanAmbiguousLayer ( unsigned int  iEtaReg,
unsigned int  kfLayer 
)
protectedvirtual

Definition at line 811 of file KFbase.cc.

References tmtt::Settings::kfUseMaybeLayers(), HLT_FULL_cff::nEta, numEtaRegions_, and tmtt::TrackFitGeneric::settings_.

Referenced by doKF().

811  {
812  // Only helps in extreme forward sector, and there not significantly.
813  // UNDERSTAND IF CAN BE USED ELSEWHERE.
814 
815  const unsigned int nEta = 16;
816  const unsigned int nKFlayer = 7;
817  constexpr bool ambiguityMap[nEta / 2][nKFlayer] = {
818  {false, false, false, false, false, false, false},
819  {false, false, false, false, false, false, false},
820  {false, false, false, false, false, false, false},
821  {false, false, false, false, false, false, false},
822  {false, false, false, false, false, false, false},
823  {false, false, true, false, false, false, false},
824  {true, true, false, false, false, false, false},
825  {true, false, false, false, false, false, false},
826  };
827 
828  unsigned int kfEtaReg; // KF VHDL eta sector def: small in barrel & large in endcap.
829  if (iEtaReg < numEtaRegions_ / 2) {
830  kfEtaReg = numEtaRegions_ / 2 - 1 - iEtaReg;
831  } else {
832  kfEtaReg = iEtaReg - numEtaRegions_ / 2;
833  }
834 
835  bool ambiguous = false;
837  ambiguous = ambiguityMap[kfEtaReg][kfLayer];
838 
839  return ambiguous;
840  }
unsigned numEtaRegions_
Definition: KFbase.h:155
bool kfUseMaybeLayers() const
Definition: Settings.h:312
const Settings * settings_
set< unsigned > tmtt::KFbase::kalmanDeadLayers ( bool &  remove2PSCut) const
protected

Definition at line 844 of file KFbase.cc.

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

Referenced by doKF().

844  {
845  // Kill scenarios described StubKiller.cc
846 
847  // By which Stress Test scenario (if any) are dead modules being emulated?
848  const StubKiller::KillOptions killScenario = static_cast<StubKiller::KillOptions>(settings_->killScenario());
849  // Should TMTT tracking be modified to reduce efficiency loss due to dead modules?
850  const bool killRecover = settings_->killRecover();
851 
852  set<pair<unsigned, bool>> deadGPlayers; // GP layer ID & boolean indicating if in barrel.
853 
854  // Range of sectors chosen to cover dead regions from StubKiller.
855  if (killRecover) {
856  if (killScenario == StubKiller::KillOptions::layer5) { // barrel layer 5
857  if (iEtaReg_ >= 3 && iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
858  deadGPlayers.insert(pair<unsigned, bool>(4, true));
859  }
860  } else if (killScenario == StubKiller::KillOptions::layer1) { // barrel layer 1
861  if (iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
862  deadGPlayers.insert(pair<unsigned, bool>(1, true));
863  }
864  remove2PSCut = true;
865  } else if (killScenario == StubKiller::KillOptions::layer1layer2) { // barrel layers 1 & 2
866  if (iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
867  deadGPlayers.insert(pair<unsigned, bool>(1, true));
868  }
869  if (iEtaReg_ >= 1 && iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
870  deadGPlayers.insert(pair<unsigned, bool>(2, true));
871  }
872  remove2PSCut = true;
873  } else if (killScenario == StubKiller::KillOptions::layer1disk1) { // barrel layer 1 & disk 1
874  if (iEtaReg_ <= 7 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
875  deadGPlayers.insert(pair<unsigned, bool>(1, true));
876  }
877  if (iEtaReg_ <= 3 && iPhiSec_ >= 1 && iPhiSec_ <= 5) {
878  deadGPlayers.insert(pair<unsigned, bool>(3, false));
879  }
880  remove2PSCut = true;
881  }
882  }
883 
884  set<unsigned> kfDeadLayers;
885  for (const auto &p : deadGPlayers) {
886  unsigned int layer = p.first;
887  bool barrel = p.second;
888  float r = 0.; // This fails for r-dependent parts of kalmanLayer(). FIX
889  float z = 999.;
890  unsigned int kalmanLay = this->kalmanLayer(iEtaReg_, layer, barrel, r, z);
891  kfDeadLayers.insert(kalmanLay);
892  }
893 
894  return kfDeadLayers;
895  }
unsigned int killScenario() const
Definition: Settings.h:343
unsigned int iEtaReg_
Definition: KFbase.h:158
constexpr std::array< uint8_t, layerIndexSize > layer
const Settings * settings_
unsigned int iPhiSec_
Definition: KFbase.h:157
bool killRecover() const
Definition: Settings.h:345
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:690
unsigned int tmtt::KFbase::kalmanLayer ( unsigned int  iEtaReg,
unsigned int  layerIDreduced,
bool  barrel,
float  r,
float  z 
) const
protectedvirtual

Definition at line 690 of file KFbase.cc.

References Exception, tmtt::Settings::kfUseMaybeLayers(), HLT_FULL_cff::nEta, numEtaRegions_, and tmtt::TrackFitGeneric::settings_.

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

691  {
692  // index across is GP encoded layer ID (where barrel layers=1,2,7,5,4,3 & endcap wheels=3,4,5,6,7 & 0 never occurs)
693  // index down is eta reg
694  // element is kalman layer, where 7 is invalid
695 
696  // If stub with given GP encoded layer ID can have different KF layer ID depending on whether it
697  // is barrel or endcap, then in layerMap, the the barrel case is assumed.
698  // The endcap case is fixed by hand later in this function.
699 
700  const unsigned int nEta = 16;
701  const unsigned int nGPlayID = 7;
702 
703  if (nEta != numEtaRegions_)
704  throw cms::Exception("LogicError")
705  << "ERROR KFbase::getKalmanLayer hardwired value of nEta differs from NumEtaRegions cfg param";
706 
707  // In cases where identical GP encoded layer ID present in this sector from both barrel & endcap, this array filled considering barrel. The endcap is fixed by subsequent code.
708 
709  constexpr unsigned layerMap[nEta / 2][nGPlayID + 1] = {
710  {7, 0, 1, 5, 4, 3, 7, 2}, // B1 B2 B3 B4 B5 B6 -- current FW
711  {7, 0, 1, 5, 4, 3, 7, 2}, // B1 B2 B3 B4 B5 B6
712  {7, 0, 1, 5, 4, 3, 7, 2}, // B1 B2 B3 B4 B5 B6
713  {7, 0, 1, 5, 4, 3, 7, 2}, // B1 B2 B3 B4 B5 B6
714  {7, 0, 1, 5, 4, 3, 7, 2}, // B1 B2 B3 B4(/D3) B5(/D2) B6(/D1)
715  {7, 0, 1, 3, 4, 2, 6, 2}, // B1 B2 B3(/D5)+B4(/D3) D1 D2 X D4
716  {7, 0, 1, 1, 2, 3, 4, 5}, // B1 B2+D1 D2 D3 D5 D6
717  {7, 0, 7, 1, 2, 3, 4, 5}, // B1 D1 D2 D3 D4 D5
718  };
719 
720  unsigned int kfEtaReg; // KF VHDL eta sector def: small in barrel & large in endcap.
721  if (iEtaReg < numEtaRegions_ / 2) {
722  kfEtaReg = numEtaRegions_ / 2 - 1 - iEtaReg;
723  } else {
724  kfEtaReg = iEtaReg - numEtaRegions_ / 2;
725  }
726 
727  unsigned int kalmanLay = layerMap[kfEtaReg][layerIDreduced];
728 
729  // Fixes to layermap when "maybe layer" used
730  if (settings_->kfUseMaybeLayers()) {
731  switch (kfEtaReg) {
732  case 5: //case 5: B1 B2 (B3+B4)* D1 D2 D3+D4 D5+D6 -- B3 is combined with B4 and is flagged as "maybe layer"
733  if (layerIDreduced == 6) {
734  kalmanLay = 5;
735  }
736  break;
737  case 6: //case 6: B1* B2* D1 D2 D3 D4 D5 -- B1 and B2 are flagged as "maybe layer"
738  if (layerIDreduced > 2) {
739  kalmanLay++;
740  }
741  break;
742  default:
743  break;
744  }
745  }
746 
747  // Fixes to endcap stubs, for cases where identical GP encoded layer ID present in this sector from both barrel & endcap.
748 
749  if (not barrel) {
750  switch (kfEtaReg) {
751  case 4: // B1 B2 B3 B4 B5/D1 B6/D2 D3
752  if (layerIDreduced == 3) {
753  kalmanLay = 4;
754  } else if (layerIDreduced == 4) {
755  kalmanLay = 5;
756  } else if (layerIDreduced == 5) {
757  kalmanLay = 6;
758  }
759  break;
760  //case 5: // B1 B2 B3+B4 D1 D2 D3 D4/D5
761  case 5: // B1 B2 B3 D1+B4 D2 D3 D4/D5
762  if (layerIDreduced == 5) {
763  kalmanLay = 5;
764  } else if (layerIDreduced == 7) {
765  kalmanLay = 6;
766  }
767  break;
768  default:
769  break;
770  }
771  }
772 
773  /*
774  // Fix cases where a barrel layer only partially crosses the eta sector.
775  // (Logically should work, but actually reduces efficiency -- INVESTIGATE).
776 
777  const float barrelHalfLength = 120.;
778  const float barrel4Radius = 68.8;
779  const float barrel5Radius = 86.1;
780 
781  if ( not barrel) {
782  switch ( kfEtaReg ) {
783  case 4:
784  if (layerIDreduced==3) { // D1
785  float disk1_rCut = barrel5Radius*(std::abs(z)/barrelHalfLength);
786  if (r > disk1_rCut) kalmanLay++;
787  }
788  break;
789  case 5:
790  if (layerIDreduced==3) { // D1
791  float disk1_rCut = barrel4Radius*(std::abs(z)/barrelHalfLength);
792  if (r > disk1_rCut) kalmanLay++;
793  }
794  if (layerIDreduced==4) { // D2
795  float disk2_rCut = barrel4Radius*(std::abs(z)/barrelHalfLength);
796  if (r > disk2_rCut) kalmanLay++;
797  }
798  break;
799  default:
800  break;
801  }
802  }
803  */
804 
805  return kalmanLay;
806  }
unsigned numEtaRegions_
Definition: KFbase.h:155
bool kfUseMaybeLayers() const
Definition: Settings.h:312
const Settings * settings_
const KalmanState * tmtt::KFbase::kalmanUpdate ( unsigned  nSkipped,
unsigned  layer,
Stub stub,
const KalmanState state,
const TP tp 
)
protectedvirtual

Definition at line 416 of file KFbase.cc.

References adjustChi2(), adjustState(), tmtt::KalmanState::barrel(), tmtt::Stub::barrel(), tmtt::KalmanState::candidate(), CommonMethods::delta(), getKalmanGainMatrix(), mps_fire::i, tmtt::Settings::kalmanDebugLevel(), phase1PixelTopology::layer, tmtt::KalmanState::matrixC(), matrixF(), matrixH(), matrixRinv(), matrixV(), mkState(), nHelixPar_, numUpdateCalls_, printStub(), tmtt::L1track3D::qOverPt(), residual(), tmtt::TrackFitGeneric::settings_, and tmtt::KalmanState::vectorX().

Referenced by doKF().

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

Implemented in tmtt::KFParamsComb.

Referenced by kalmanUpdate().

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

Implemented in tmtt::KFParamsComb.

Referenced by kalmanUpdate(), and residual().

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

Definition at line 557 of file KFbase.cc.

Referenced by matrixRinv().

557  {
558  TMatrixD matHtrans(TMatrixD::kTransposed, matH);
559  return matH * matC * matHtrans;
560  }
TMatrixD tmtt::KFbase::matrixRinv ( const TMatrixD &  matH,
const TMatrixD &  matCref,
const TMatrixD &  matV 
) const
protected

Definition at line 564 of file KFbase.cc.

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

Referenced by kalmanUpdate().

564  {
565  TMatrixD matHCHt = matrixHCHt(matH, matCref);
566  TMatrixD matR = matV + matHCHt;
567  TMatrixD matRinv(2, 2);
568  if (matR.Determinant() > 0) {
569  matRinv = TMatrixD(TMatrixD::kInverted, matR);
570  } else {
571  // Protection against rare maths instability.
572  const TMatrixD unitMatrix(TMatrixD::kUnit, TMatrixD(nHelixPar_, nHelixPar_));
573  const double big = 9.9e9;
574  matRinv = big * unitMatrix;
575  }
576  if (settings_->kalmanDebugLevel() >= 4) {
577  PrintL1trk() << "matHCHt";
578  matHCHt.Print();
579  PrintL1trk() << "matR";
580  matR.Print();
581  }
582  return matRinv;
583  }
unsigned kalmanDebugLevel() const
Definition: Settings.h:297
const Settings * settings_
TMatrixD matrixHCHt(const TMatrixD &h, const TMatrixD &c) const
Definition: KFbase.cc:557
unsigned nHelixPar_
Definition: KFbase.h:153
Definition: big.h:8
virtual TMatrixD tmtt::KFbase::matrixV ( const Stub stub,
const KalmanState state 
) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by kalmanUpdate().

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 536 of file KFbase.cc.

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

Referenced by doKF(), and kalmanUpdate().

546  {
547  auto new_state = std::make_unique<const KalmanState>(
548  settings_, candidate, nSkipped, layer, last_state, vecX, matC, matK, matV, stub, chi2rphi, chi2rz);
549 
550  const KalmanState *p_new_state = new_state.get();
551  listAllStates_.push_back(std::move(new_state)); // Vector keeps ownership of all states.
552  return p_new_state;
553  }
constexpr std::array< uint8_t, layerIndexSize > layer
def move
Definition: eostools.py:511
const Settings * settings_
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
Definition: KFbase.h:163
KFbase& tmtt::KFbase::operator= ( const KFbase kf)
delete
KFbase& tmtt::KFbase::operator= ( KFbase &&  kf)
delete
void tmtt::KFbase::printStub ( const Stub stub) const
protected

Definition at line 961 of file KFbase.cc.

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

Referenced by kalmanUpdate(), and printStubs().

961  {
962  std::stringstream text;
963  text << std::fixed << std::setprecision(4);
964  text << "stub ";
965  text << "index=" << stub->index() << " ";
966  text << "layerId=" << stub->layerId() << " ";
967  text << "r=" << stub->r() << " ";
968  text << "phi=" << stub->phi() << " ";
969  text << "z=" << stub->z() << " ";
970  text << "sigmaX=" << stub->sigmaPerp() << " ";
971  text << "sigmaZ=" << stub->sigmaPar() << " ";
972  text << "TPids=";
973  std::set<const TP *> tps = stub->assocTPs();
974  for (auto tp : tps)
975  text << tp->index() << ",";
976  PrintL1trk() << text.str();
977  }
tuple text
Definition: runonSM.py:43
void tmtt::KFbase::printStubLayers ( const std::vector< Stub * > &  stubs,
unsigned int  iEtaReg 
) const
protected

Definition at line 933 of file KFbase.cc.

References Reference_intrackfit_cff::barrel, mps_fire::i, dqmiolumiharvest::j, kalmanLayer(), alignCSCRings::r, and runonSM::text.

Referenced by fit().

933  {
934  std::stringstream text;
935  text << std::fixed << std::setprecision(4);
936  if (stubs.empty())
937  text << "stub layers = []\n";
938  else {
939  text << "stub layers = [ ";
940  for (unsigned i = 0; i < stubs.size(); i++) {
941  text << stubs[i]->layerId();
942  if (i != stubs.size() - 1)
943  text << ", ";
944  }
945  text << " ] ";
946  text << "KF stub layers = [ ";
947  for (unsigned j = 0; j < stubs.size(); j++) {
948  unsigned int kalmanLay =
949  this->kalmanLayer(iEtaReg, stubs[j]->layerIdReduced(), stubs[j]->barrel(), stubs[j]->r(), stubs[j]->z());
950  text << kalmanLay;
951  if (j != stubs.size() - 1)
952  text << ", ";
953  }
954  text << " ]\n";
955  }
956  PrintL1trk() << text.str();
957  }
tuple text
Definition: runonSM.py:43
virtual unsigned int kalmanLayer(unsigned int iEtaReg, unsigned int layerIDreduced, bool barrel, float r, float z) const
Definition: KFbase.cc:690
void tmtt::KFbase::printStubs ( const std::vector< Stub * > &  stubs) const
protected

Definition at line 981 of file KFbase.cc.

References printStub().

Referenced by fit().

981  {
982  for (auto &stub : stubs) {
983  printStub(stub);
984  }
985  }
void printStub(const Stub *stub) const
Definition: KFbase.cc:961
void tmtt::KFbase::printTP ( const TP tp) const
protected

Definition at line 905 of file KFbase.cc.

References D0, tmtt::TP::d0(), mps_fire::i, tmtt::TP::index(), tmtt::Settings::invPtToInvR(), PHI0, tmtt::TP::phi0(), QOVERPT, tmtt::TP::qOverPt(), tmtt::TrackFitGeneric::settings_, T, tmtt::TP::tanLambda(), runonSM::text, tmtt::TP::useForAlgEff(), Z0, and tmtt::TP::z0().

Referenced by fit().

905  {
906  TVectorD tpParams(5);
907  bool useForAlgEff(false);
908  if (tp) {
909  useForAlgEff = tp->useForAlgEff();
910  tpParams[QOVERPT] = tp->qOverPt();
911  tpParams[PHI0] = tp->phi0();
912  tpParams[Z0] = tp->z0();
913  tpParams[T] = tp->tanLambda();
914  tpParams[D0] = tp->d0();
915  }
916  std::stringstream text;
917  text << std::fixed << std::setprecision(4);
918  if (tp) {
919  text << " TP index = " << tp->index() << " useForAlgEff = " << useForAlgEff << " ";
920  const string helixNames[5] = {"qOverPt", "phi0", "z0", "tanL", "d0"};
921  for (int i = 0; i < tpParams.GetNrows(); i++) {
922  text << helixNames[i] << ":" << tpParams[i] << ", ";
923  }
924  text << " inv2R = " << tp->qOverPt() * settings_->invPtToInvR() * 0.5;
925  } else {
926  text << " Fake";
927  }
928  PrintL1trk() << text.str();
929  }
double invPtToInvR() const
Definition: Settings.h:395
tuple text
Definition: runonSM.py:43
const Settings * settings_
void tmtt::KFbase::resetStates ( )
protected

Definition at line 686 of file KFbase.cc.

References listAllStates_.

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

686 { listAllStates_.clear(); }
std::vector< std::unique_ptr< const KalmanState > > listAllStates_
Definition: KFbase.h:163
TVectorD tmtt::KFbase::residual ( const Stub stub,
const TVectorD &  x,
double  candQoverPt 
) const
protectedvirtual

Definition at line 596 of file KFbase.cc.

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

Referenced by kalmanUpdate().

596  {
597  TVectorD vd = vectorM(stub); // Get (phi relative to sector, z) of hit.
598  TMatrixD h = matrixH(stub);
599  TVectorD hx = h * vecX; // Get intercept of helix with layer (linear approx).
600  TVectorD delta = vd - hx;
601 
602  // Calculate higher order corrections to residuals.
603 
604  if (not settings_->kalmanHOfw()) {
605  TVectorD correction(2);
606 
607  float inv2R = (settings_->invPtToInvR()) * 0.5 * candQoverPt;
608  float tanL = vecX[T];
609  float z0 = vecX[Z0];
610 
611  float deltaS = 0.;
612  if (settings_->kalmanHOhelixExp()) {
613  // Higher order correction correction to circle expansion for improved accuracy at low Pt.
614  double corr = stub->r() * inv2R;
615 
616  // N.B. In endcap 2S, this correction to correction[0] is exactly cancelled by the deltaS-dependent correction to it below.
617  correction[0] += (1. / 6.) * pow(corr, 3);
618 
619  deltaS = (1. / 6.) * (stub->r()) * pow(corr, 2);
620  correction[1] -= deltaS * tanL;
621  }
622 
623  if ((not stub->barrel()) && not(stub->psModule())) {
624  // These corrections rely on inside --> outside tracking, so r-z track params in 2S modules known.
625  float rShift = (stub->z() - z0) / tanL - stub->r();
626 
628  rShift -= deltaS;
629 
630  if (settings_->kalmanHOprojZcorr() == 1) {
631  // Add correlation term related to conversion of stub residuals from (r,phi) to (z,phi).
632  correction[0] += inv2R * rShift;
633  }
634 
635  if (settings_->kalmanHOalpha() == 1) {
636  // Add alpha correction for non-radial 2S endcap strips..
637  correction[0] += stub->alpha() * rShift;
638  }
639  }
640 
641  // Apply correction to residuals.
642  delta += correction;
643  }
644 
645  delta[0] = reco::deltaPhi(delta[0], 0.);
646 
647  return delta;
648  }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
double invPtToInvR() const
Definition: Settings.h:395
bool kalmanHOhelixExp() const
Definition: Settings.h:331
const Settings * settings_
std::vector< DeviationSensor2D * > vd
virtual TMatrixD matrixH(const Stub *stub) const =0
unsigned int kalmanHOalpha() const
Definition: Settings.h:333
constexpr float correction(int sizeM1, int q_f, int q_l, uint16_t upper_edge_first_pix, uint16_t lower_edge_last_pix, float lorentz_shift, float theThickness, float cot_angle, float pitch, bool first_is_big, bool last_is_big)
virtual TVectorD vectorM(const Stub *stub) const =0
unsigned int kalmanHOprojZcorr() const
Definition: Settings.h:335
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
bool kalmanHOfw() const
Definition: Settings.h:337
double tmtt::KFbase::sectorPhi ( ) const
inlineprotected

Definition at line 124 of file KFbase.h.

References 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().

124  {
125  float phiCentreSec0 = -M_PI / float(settings_->numPhiNonants()) + M_PI / float(settings_->numPhiSectors());
126  return 2. * M_PI * float(iPhiSec_) / float(settings_->numPhiSectors()) + phiCentreSec0;
127  }
unsigned int numPhiNonants() const
Definition: Settings.h:109
const Settings * settings_
#define M_PI
unsigned int iPhiSec_
Definition: KFbase.h:157
unsigned int numPhiSectors() const
Definition: Settings.h:110
virtual TMatrixD tmtt::KFbase::seedC ( const L1track3D l1track3D) const
protectedpure virtual

Implemented in tmtt::KFParamsComb.

Referenced by doKF().

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

Implemented in tmtt::KFParamsComb.

Referenced by doKF().

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

Implemented in tmtt::KFParamsComb.

Referenced by doKF(), and fit().

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

Implemented in tmtt::KFParamsComb.

Referenced by fit().

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

Implemented in tmtt::KFParamsComb.

Referenced by residual().

Member Data Documentation

unsigned int tmtt::KFbase::iEtaReg_
protected

Definition at line 158 of file KFbase.h.

Referenced by fit(), and kalmanDeadLayers().

unsigned int tmtt::KFbase::iPhiSec_
protected

Definition at line 157 of file KFbase.h.

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

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

Definition at line 163 of file KFbase.h.

Referenced by mkState(), and resetStates().

unsigned tmtt::KFbase::nHelixPar_
protected
unsigned tmtt::KFbase::nMeas_
protected

Definition at line 154 of file KFbase.h.

unsigned tmtt::KFbase::numEtaRegions_
protected

Definition at line 155 of file KFbase.h.

Referenced by kalmanAmbiguousLayer(), and kalmanLayer().

unsigned int tmtt::KFbase::numUpdateCalls_
protected

Definition at line 160 of file KFbase.h.

Referenced by fit(), and kalmanUpdate().

const TP* tmtt::KFbase::tpa_
protected

Definition at line 165 of file KFbase.h.

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