Belle II Software  release-08-01-10
KalmanFitterRefTrack Class Reference

Kalman filter implementation with linearization around a reference track. More...

#include <KalmanFitterRefTrack.h>

Inheritance diagram for KalmanFitterRefTrack:
Collaboration diagram for KalmanFitterRefTrack:

Public Member Functions

 KalmanFitterRefTrack (unsigned int maxIterations=4, double deltaPval=1e-3, double blowUpFactor=1e3, bool squareRootFormalism=false)
 
TrackPointfitTrack (Track *tr, const AbsTrackRep *rep, double &chi2, double &ndf, int direction)
 Fit the track. More...
 
void processTrackWithRep (Track *tr, const AbsTrackRep *rep, bool resortHits=false) override
 Process Track with one AbsTrackRep of the Track. More...
 
bool prepareTrack (Track *tr, const AbsTrackRep *rep, bool setSortingParams, int &nFailedHits)
 Prepare the track. More...
 
void setRefitAll (bool refit=true)
 If true always refit all points, otherwise fit points only if reference states have changed.
 
void setDeltaChi2Ref (double dChi2)
 When will the reference track be updated? If (smoothedState - referenceState) * smoothedCov^(-1) * (smoothedState - referenceState)^T >= deltaChi2Ref_.
 
void getChiSquNdf (const Track *tr, const AbsTrackRep *rep, double &bChi2, double &fChi2, double &bNdf, double &fNdf) const
 
double getChiSqu (const Track *tr, const AbsTrackRep *rep, int direction=-1) const
 
double getNdf (const Track *tr, const AbsTrackRep *rep, int direction=-1) const
 
double getRedChiSqu (const Track *tr, const AbsTrackRep *rep, int direction=-1) const
 
double getPVal (const Track *tr, const AbsTrackRep *rep, int direction=-1) const
 
unsigned int getMinIterations () const
 
unsigned int getMaxIterations () const
 
double getDeltaPval () const
 
double getRelChi2Change () const
 
double getBlowUpFactor () const
 
bool getResetOffDiagonals () const
 
double getBlowUpMaxVal () const
 
eMultipleMeasurementHandling getMultipleMeasurementHandling () const
 
int getMaxFailedHits () const
 
virtual void setMinIterations (unsigned int n)
 Set the minimum number of iterations.
 
virtual void setMaxIterations (unsigned int n)
 Set the maximum number of iterations.
 
void setDeltaPval (double deltaPval)
 Set Convergence criterion. More...
 
void setRelChi2Change (double relChi2Change)
 @ brief Set Non-convergence criterion More...
 
void setBlowUpFactor (double blowUpFactor)
 
void setResetOffDiagonals (bool resetOffDiagonals)
 
void setBlowUpMaxVal (double blowUpMaxVal)
 Limit the cov entries to this maximum value when blowing up the cov. Set to negative value to disable. Default is 1.E6. More...
 
void setMultipleMeasurementHandling (eMultipleMeasurementHandling mmh)
 How should multiple measurements be handled?
 
virtual void setMaxFailedHits (int val)
 
bool isTrackPrepared (const Track *tr, const AbsTrackRep *rep) const
 
bool isTrackFitted (const Track *tr, const AbsTrackRep *rep) const
 
bool canIgnoreWeights () const
 returns if the fitter can ignore the weights and handle the MeasurementOnPlanes as if they had weight 1.
 
void processTrack (Track *, bool resortHits=false)
 Process all reps. More...
 
virtual void setDebugLvl (unsigned int lvl=1)
 

Protected Member Functions

const std::vector< MeasurementOnPlane * > getMeasurements (const KalmanFitterInfo *fi, const TrackPoint *tp, int direction) const
 get the measurementsOnPlane taking the multipleMeasurementHandling_ into account
 

Protected Attributes

unsigned int minIterations_
 Minimum number of iterations to attempt. Forward and backward are counted as one iteration.
 
unsigned int maxIterations_
 Maximum number of iterations to attempt. Forward and backward are counted as one iteration.
 
double deltaPval_
 Convergence criterion. More...
 
double relChi2Change_
 @ brief Non-convergence criterion More...
 
double blowUpFactor_
 Blow up the covariance of the forward (backward) fit by this factor before seeding the backward (forward) fit.
 
bool resetOffDiagonals_
 Reset the off-diagonals to 0 when blowing up the cov.
 
double blowUpMaxVal_
 Limit the cov entries to this maxuimum value when blowing up the cov.
 
eMultipleMeasurementHandling multipleMeasurementHandling_
 How to handle if there are multiple MeasurementsOnPlane.
 
int maxFailedHits_
 after how many failed hits (exception during construction of plane, extrapolation etc.) should the fit be cancelled. More...
 
unsigned int debugLvl_
 

Private Member Functions

void processTrackPoint (KalmanFitterInfo *fi, const KalmanFitterInfo *prevFi, const TrackPoint *tp, double &chi2, double &ndf, int direction)
 
void processTrackPointSqrt (KalmanFitterInfo *fi, const KalmanFitterInfo *prevFi, const TrackPoint *tp, double &chi2, double &ndf, int direction)
 
bool removeOutdated (Track *tr, const AbsTrackRep *rep, int &notChangedUntil, int &notChangedFrom)
 Remove referenceStates if they are too far from smoothed states. More...
 
void removeForwardBackwardInfo (Track *tr, const AbsTrackRep *rep, int notChangedUntil, int notChangedFrom) const
 If refitAll_, remove all information.
 

Private Attributes

bool refitAll_
 
double deltaChi2Ref_
 
TMatrixD FTransportMatrix_
 
TMatrixD BTransportMatrix_
 
TMatrixDSym FNoiseMatrix_
 
TMatrixDSym BNoiseMatrix_
 
TVectorD forwardDeltaState_
 
TVectorD backwardDeltaState_
 
TVectorD p_
 
TMatrixDSym C_
 
TMatrixDSym covSumInv_
 
TMatrixDSym Rinv_
 
TVectorD res_
 
TVectorD resM_
 
bool squareRootFormalism_
 

Detailed Description

Kalman filter implementation with linearization around a reference track.

Definition at line 37 of file KalmanFitterRefTrack.h.

Member Function Documentation

◆ fitTrack()

TrackPoint * fitTrack ( Track tr,
const AbsTrackRep rep,
double &  chi2,
double &  ndf,
int  direction 
)

Fit the track.

Needs a prepared track! Return last TrackPoint that has been processed.

Definition at line 39 of file KalmanFitterRefTrack.cc.

40 {
41 
42  //if (!isTrackPrepared(tr, rep)) {
43  // Exception exc("KalmanFitterRefTrack::fitTrack ==> track is not properly prepared.",__LINE__,__FILE__);
44  // throw exc;
45  //}
46 
47  unsigned int dim = rep->getDim();
48 
49  chi2 = 0;
50  ndf = -1. * dim;
51  KalmanFitterInfo* prevFi(nullptr);
52 
53  TrackPoint* retVal(nullptr);
54 
55  if (debugLvl_ > 0) {
56  debugOut << tr->getNumPoints() << " TrackPoints with measurements in this track." << std::endl;
57  }
58 
59  bool alreadyFitted(!refitAll_);
60 
61  p_.ResizeTo(dim);
62  C_.ResizeTo(dim, dim);
63 
64  for (size_t i = 0; i < tr->getNumPointsWithMeasurement(); ++i) {
65  TrackPoint *tp = 0;
66  assert(direction == +1 || direction == -1);
67  if (direction == +1)
68  tp = tr->getPointWithMeasurement(i);
69  else if (direction == -1)
70  tp = tr->getPointWithMeasurement(-i-1);
71 
72  if (! tp->hasFitterInfo(rep)) {
73  if (debugLvl_ > 0) {
74  debugOut << "TrackPoint " << i << " has no fitterInfo -> continue. \n";
75  }
76  continue;
77  }
78 
79  KalmanFitterInfo* fi = static_cast<KalmanFitterInfo*>(tp->getFitterInfo(rep));
80 
81  if (alreadyFitted && fi->hasUpdate(direction)) {
82  if (debugLvl_ > 0) {
83  debugOut << "TrackPoint " << i << " is already fitted -> continue. \n";
84  }
85  prevFi = fi;
86  chi2 += fi->getUpdate(direction)->getChiSquareIncrement();
87  ndf += fi->getUpdate(direction)->getNdf();
88  continue;
89  }
90 
91  alreadyFitted = false;
92 
93  if (debugLvl_ > 0) {
94  debugOut << " process TrackPoint nr. " << i << "\n";
95  }
96  processTrackPoint(fi, prevFi, tp, chi2, ndf, direction);
97  retVal = tp;
98 
99  prevFi = fi;
100  }
101 
102  return retVal;
103 }
virtual unsigned int getDim() const =0
Get the dimension of the state vector used by the track representation.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
Object containing AbsMeasurement and AbsFitterInfo objects.
Definition: TrackPoint.h:46
AbsFitterInfo * getFitterInfo(const AbsTrackRep *rep=nullptr) const
Get fitterInfo for rep. Per default, use cardinal rep.
Definition: TrackPoint.cc:170
std::ostream debugOut
Default stream for debug output.

◆ prepareTrack()

bool prepareTrack ( Track tr,
const AbsTrackRep rep,
bool  setSortingParams,
int &  nFailedHits 
)

Prepare the track.

Calc all reference states. If setSortingParams is true, the extrapolation lengths will be set as sorting parameters of the TrackPoints. Returns if the track has been changed.

Definition at line 328 of file KalmanFitterRefTrack.cc.

◆ processTrack()

void processTrack ( Track tr,
bool  resortHits = false 
)
inherited

Process all reps.

Start with the cardinalRep and resort the hits if necessary (and supported by the fitter)

Definition at line 25 of file AbsFitter.cc.

◆ processTrackWithRep()

void processTrackWithRep ( Track ,
const AbsTrackRep ,
bool  resortHits = false 
)
overridevirtual

Process Track with one AbsTrackRep of the Track.

Optionally resort the hits if necessary (and supported by the fitter)

Implements AbsFitter.

Definition at line 106 of file KalmanFitterRefTrack.cc.

◆ removeOutdated()

bool removeOutdated ( Track tr,
const AbsTrackRep rep,
int &  notChangedUntil,
int &  notChangedFrom 
)
private

Remove referenceStates if they are too far from smoothed states.

Does NOT remove forward and backward info, but returns from/to where they have to be removed later Return if anything has changed.

Definition at line 805 of file KalmanFitterRefTrack.cc.

◆ setBlowUpMaxVal()

void setBlowUpMaxVal ( double  blowUpMaxVal)
inlineinherited

Limit the cov entries to this maximum value when blowing up the cov. Set to negative value to disable. Default is 1.E6.

This is especially useful for fits where the measurements do not constrain one direction, e.g. parallel wire measurements. The fit will not be constrained along the wire direction. This also means that the covariance along the wire direction will not get smaller during the fit. However, it will be blown up before the next iteration, leading to an exponential growth of the covariance element(s) corresponding to the wire direction. This can then lead to numerical problems. To prevent this, the maximum value of the covariance elements after blowing up can be limited.

Definition at line 119 of file AbsKalmanFitter.h.

◆ setDeltaPval()

void setDeltaPval ( double  deltaPval)
inlineinherited

Set Convergence criterion.

if track total P-value changes less than this between consecutive iterations, consider the track converged. chiĀ² from the backwards fit is used.

Definition at line 95 of file AbsKalmanFitter.h.

◆ setRelChi2Change()

void setRelChi2Change ( double  relChi2Change)
inlineinherited

@ brief Set Non-convergence criterion

if the relative chi^2 between two iterations is larger than relChi2Change_, the fit is NOT converged and further iterations will be done, even if the deltaPval_ convergence criterium is met. This is especially useful for fits which have a p-value of almost 0 (possibly due to bad start values), where the p-value from one iteration to the next might not change much. However, a significant change in chi^2 tells us, that the fit might not yet be converged.

Definition at line 106 of file AbsKalmanFitter.h.

Member Data Documentation

◆ deltaPval_

double deltaPval_
protectedinherited

Convergence criterion.

if track total P-value changes less than this between consecutive iterations, consider the track converged. chiĀ² from the backwards fit is used.

Definition at line 148 of file AbsKalmanFitter.h.

◆ maxFailedHits_

int maxFailedHits_
protectedinherited

after how many failed hits (exception during construction of plane, extrapolation etc.) should the fit be cancelled.

-1 means don't cancel

Definition at line 172 of file AbsKalmanFitter.h.

◆ relChi2Change_

double relChi2Change_
protectedinherited

@ brief Non-convergence criterion

if the relative chi^2 between two iterations is larger than relChi2Change_, the fit is NOT converged and further iterations will be done, even if the deltaPval_ convergence criterium is met. This is especially useful for fits which have a p-value of almost 0 (possibly due to bad start values), where the p-value from one iteration to the next might not change much. However, a significant change in chi^2 tells us, that the fit might not yet be converged.

Definition at line 158 of file AbsKalmanFitter.h.


The documentation for this class was generated from the following files: