SND@LHC Software
Loading...
Searching...
No Matches
genfit::AbsKalmanFitter Class Reference

Abstract base class for Kalman fitter and derived fitting algorithms. More...

#include <AbsKalmanFitter.h>

Inheritance diagram for genfit::AbsKalmanFitter:
Collaboration diagram for genfit::AbsKalmanFitter:

Public Member Functions

 AbsKalmanFitter (unsigned int maxIterations=4, double deltaPval=1e-3, double blowUpFactor=1e3)
 
virtual ~AbsKalmanFitter ()
 
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
 
eMultipleMeasurementHandling getMultipleMeasurementHandling () 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.
 
void setRelChi2Change (double relChi2Change)
 
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.
 
- Public Member Functions inherited from genfit::AbsFitter
 AbsFitter ()
 
virtual ~AbsFitter ()
 
virtual void processTrackWithRep (Track *, const AbsTrackRep *, bool resortHits=false)=0
 
void processTrack (Track *, bool resortHits=true)
 
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.
 
double relChi2Change_
 
double blowUpFactor_
 Blow up the covariance of the forward (backward) fit by this factor before seeding the backward (forward) fit.
 
eMultipleMeasurementHandling multipleMeasurementHandling_
 How to handle if there are multiple MeasurementsOnPlane.
 
int maxFailedHits_
 
- Protected Attributes inherited from genfit::AbsFitter
unsigned int debugLvl_
 

Detailed Description

Abstract base class for Kalman fitter and derived fitting algorithms.

Definition at line 51 of file AbsKalmanFitter.h.

Constructor & Destructor Documentation

◆ AbsKalmanFitter()

genfit::AbsKalmanFitter::AbsKalmanFitter ( unsigned int  maxIterations = 4,
double  deltaPval = 1e-3,
double  blowUpFactor = 1e3 
)
inline

Definition at line 55 of file AbsKalmanFitter.h.

56 : AbsFitter(), minIterations_(2), maxIterations_(maxIterations), deltaPval_(deltaPval), relChi2Change_(0.2),
58 maxFailedHits_(-1) {
61 }
double blowUpFactor_
Blow up the covariance of the forward (backward) fit by this factor before seeding the backward (forw...
unsigned int maxIterations_
Maximum number of iterations to attempt. Forward and backward are counted as one iteration.
double deltaPval_
Convergence criterion.
unsigned int minIterations_
Minimum number of iterations to attempt. Forward and backward are counted as one iteration.
eMultipleMeasurementHandling multipleMeasurementHandling_
How to handle if there are multiple MeasurementsOnPlane.
@ unweightedClosestToPredictionWire

◆ ~AbsKalmanFitter()

virtual genfit::AbsKalmanFitter::~AbsKalmanFitter ( )
inlinevirtual

Definition at line 63 of file AbsKalmanFitter.h.

63{;}

Member Function Documentation

◆ canIgnoreWeights()

bool AbsKalmanFitter::canIgnoreWeights ( ) const

returns if the fitter can ignore the weights and handle the MeasurementOnPlanes as if they had weight 1.

Definition at line 256 of file AbsKalmanFitter.cc.

256 {
258 case unweightedAverage :
263 return true;
264
265 case weightedAverage :
270 return false;
271
272 default:
273 {
274 Exception e("AbsKalmanFitter::canIgnoreWeights: choice not valid.", __LINE__,__FILE__);
275 e.setFatal();
276 throw e;
277 }
278 }
279}
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition Exception.h:48
@ weightedClosestToPrediction
@ weightedClosestToReference
@ weightedClosestToReferenceWire
@ unweightedClosestToReference
@ weightedClosestToPredictionWire
@ unweightedClosestToPrediction
@ unweightedClosestToReferenceWire
@ unweightedAverage

◆ getChiSqu()

double AbsKalmanFitter::getChiSqu ( const Track tr,
const AbsTrackRep rep,
int  direction = -1 
) const

Definition at line 84 of file AbsKalmanFitter.cc.

84 {
85 double bChi2(0), fChi2(0), bNdf(0), fNdf(0);
86
87 getChiSquNdf(tr, rep, bChi2, fChi2, bNdf, fNdf);
88
89 if (direction < 0)
90 return bChi2;
91 return fChi2;
92}
void getChiSquNdf(const Track *tr, const AbsTrackRep *rep, double &bChi2, double &fChi2, double &bNdf, double &fNdf) const

◆ getChiSquNdf()

void AbsKalmanFitter::getChiSquNdf ( const Track tr,
const AbsTrackRep rep,
double &  bChi2,
double &  fChi2,
double &  bNdf,
double &  fNdf 
) const

Definition at line 40 of file AbsKalmanFitter.cc.

42 {
43
44 bChi2 = 0;
45 fChi2 = 0;
46 bNdf = -1. * rep->getDim();
47 fNdf = -1. * rep->getDim();
48
49 const std::vector<TrackPoint*>& pointsWM = tr->getPointsWithMeasurement();
50 for (std::vector<TrackPoint*>::const_iterator tpIter = pointsWM.begin(), endIter = pointsWM.end(); tpIter != endIter; ++tpIter) {
51 if (! (*tpIter)->hasFitterInfo(rep))
52 continue;
53
54 AbsFitterInfo* afi = (*tpIter)->getFitterInfo(rep);
55 KalmanFitterInfo* fi = dynamic_cast<KalmanFitterInfo*>(afi);
56 if (!fi) {
57 Exception exc("AbsKalmanFitter::getChiSqu(): fitterInfo is not a KalmanFitterInfo", __LINE__,__FILE__);
58 throw exc;
59 }
60
63
64 if (fup == NULL || bup == NULL) {
65 Exception exc("AbsKalmanFitter::getChiSqu(): fup == NULL || bup == NULL", __LINE__,__FILE__);
66 throw exc;
67 }
68
69 bChi2 += bup->getChiSquareIncrement();
70 fChi2 += fup->getChiSquareIncrement();
71
72 bNdf += bup->getNdf();
73 fNdf += fup->getNdf();
74 }
75
76 if (bNdf < 0)
77 bNdf = 0;
78
79 if (fNdf < 0)
80 fNdf = 0;
81}
This class collects all information needed and produced by a specific AbsFitter and is specific to on...
virtual unsigned int getDim() const =0
Get the dimension of the state vector used by the track representation.
MeasuredStateOnPlane with additional info produced by a Kalman filter or DAF.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
KalmanFittedStateOnPlane * getBackwardUpdate() const
KalmanFittedStateOnPlane * getForwardUpdate() const
const std::vector< genfit::TrackPoint * > & getPointsWithMeasurement() const
Definition Track.h:111

◆ getMeasurements()

const std::vector< MeasurementOnPlane * > AbsKalmanFitter::getMeasurements ( const KalmanFitterInfo fi,
const TrackPoint tp,
int  direction 
) const
protected

get the measurementsOnPlane taking the multipleMeasurementHandling_ into account

Definition at line 177 of file AbsKalmanFitter.cc.

177 {
178
180 case weightedAverage :
181 case unweightedAverage :
182 return fi->getMeasurementsOnPlane();
183
186 {
187 if (!fi->hasReferenceState()) {
188 Exception e("AbsKalmanFitter::getMeasurement: no ReferenceState.", __LINE__,__FILE__);
189 e.setFatal();
190 throw e;
191 }
192 std::vector<MeasurementOnPlane *> retVal;
193 retVal.push_back(fi->getClosestMeasurementOnPlane(fi->getReferenceState()));
194 return retVal;
195 }
196
199 {
200 if (!fi->hasPrediction(direction)) {
201 Exception e("AbsKalmanFitter::getMeasurement: no prediction.", __LINE__,__FILE__);
202 e.setFatal();
203 throw e;
204 }
205 std::vector<MeasurementOnPlane *> retVal;
206 retVal.push_back(fi->getClosestMeasurementOnPlane(fi->getPrediction(direction)));
207 return retVal;
208 }
209
210
213 {
214 if (tp->getNumRawMeasurements() == 1 && dynamic_cast<WireMeasurement*>(tp->getRawMeasurement()) != NULL) {
215 if (!fi->hasReferenceState()) {
216 Exception e("AbsKalmanFitter::getMeasurement: no ReferenceState.", __LINE__,__FILE__);
217 e.setFatal();
218 throw e;
219 }
220 std::vector<MeasurementOnPlane *> retVal;
221 retVal.push_back(fi->getClosestMeasurementOnPlane(fi->getReferenceState()));
222 return retVal;
223 }
224 else
225 return fi->getMeasurementsOnPlane();
226 }
227
230 {
231 if (tp->getNumRawMeasurements() == 1 && dynamic_cast<WireMeasurement*>(tp->getRawMeasurement()) != NULL) {
232 if (!fi->hasPrediction(direction)) {
233 Exception e("AbsKalmanFitter::getMeasurement: no prediction.", __LINE__,__FILE__);
234 e.setFatal();
235 throw e;
236 }
237 std::vector<MeasurementOnPlane *> retVal;
238 retVal.push_back(fi->getClosestMeasurementOnPlane(fi->getPrediction(direction)));
239 return retVal;
240 }
241 else
242 return fi->getMeasurementsOnPlane();
243 }
244
245
246 default:
247 {
248 Exception e("AbsKalmanFitter::getMeasurement: choice not valid.", __LINE__,__FILE__);
249 e.setFatal();
250 throw e;
251 }
252 }
253}
virtual bool hasPrediction(int direction) const
ReferenceStateOnPlane * getReferenceState() const
const std::vector< genfit::MeasurementOnPlane * > & getMeasurementsOnPlane() const
MeasurementOnPlane * getClosestMeasurementOnPlane(const StateOnPlane *) const
Get measurements which is closest to state.
MeasuredStateOnPlane * getPrediction(int direction) const
Class for measurements in wire detectors (Straw tubes and drift chambers) which do not measure the co...

◆ getMultipleMeasurementHandling()

eMultipleMeasurementHandling genfit::AbsKalmanFitter::getMultipleMeasurementHandling ( ) const
inline

Definition at line 72 of file AbsKalmanFitter.h.

◆ getNdf()

double AbsKalmanFitter::getNdf ( const Track tr,
const AbsTrackRep rep,
int  direction = -1 
) const

Definition at line 94 of file AbsKalmanFitter.cc.

94 {
95 double bChi2(0), fChi2(0), bNdf(0), fNdf(0);
96
97 getChiSquNdf(tr, rep, bChi2, fChi2, bNdf, fNdf);
98
99 if (direction < 0)
100 return bNdf;
101 return fNdf;
102}

◆ getPVal()

double AbsKalmanFitter::getPVal ( const Track tr,
const AbsTrackRep rep,
int  direction = -1 
) const

Definition at line 114 of file AbsKalmanFitter.cc.

114 {
115 double bChi2(0), fChi2(0), bNdf(0), fNdf(0);
116
117 getChiSquNdf(tr, rep, bChi2, fChi2, bNdf, fNdf);
118
119 if (direction < 0)
120 return ROOT::Math::chisquared_cdf_c(bChi2, bNdf);
121 return ROOT::Math::chisquared_cdf_c(fChi2, fNdf);
122}

◆ getRedChiSqu()

double AbsKalmanFitter::getRedChiSqu ( const Track tr,
const AbsTrackRep rep,
int  direction = -1 
) const

Definition at line 104 of file AbsKalmanFitter.cc.

104 {
105 double bChi2(0), fChi2(0), bNdf(0), fNdf(0);
106
107 getChiSquNdf(tr, rep, bChi2, fChi2, bNdf, fNdf);
108
109 if (direction < 0)
110 return bChi2/bNdf;
111 return fChi2/fNdf;
112}

◆ isTrackFitted()

bool AbsKalmanFitter::isTrackFitted ( const Track tr,
const AbsTrackRep rep 
) const

Definition at line 147 of file AbsKalmanFitter.cc.

147 {
148 if (! tr->getFitStatus(rep)->isFitted())
149 return false;
150
151 // in depth check
152
153 const std::vector< TrackPoint* >& points = tr->getPointsWithMeasurement();
154
155 if (points.size() == 0)
156 return true;
157
158 for (std::vector<TrackPoint*>::const_iterator pIt = points.begin(), pEnd = points.end(); pIt != pEnd; ++pIt) {
159 KalmanFitterInfo* fi = dynamic_cast<KalmanFitterInfo*>((*pIt)->getFitterInfo(rep));
160 if (!fi)
161 return false;
162
163 if (!(fi->checkConsistency()))
164 return false;
165
166 if (!(fi->hasForwardUpdate()))
167 return false;
168
169 if (!(fi->hasBackwardUpdate()))
170 return false;
171 }
172
173 return true;
174}
bool isFitted() const
Has the track been fitted?
Definition FitStatus.h:50
virtual bool checkConsistency() const
FitStatus * getFitStatus(const AbsTrackRep *rep=NULL) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
Definition Track.h:149

◆ isTrackPrepared()

bool AbsKalmanFitter::isTrackPrepared ( const Track tr,
const AbsTrackRep rep 
) const

Definition at line 125 of file AbsKalmanFitter.cc.

125 {
126 const std::vector<TrackPoint*>& points = tr->getPointsWithMeasurement();
127
128 if (points.size() == 0)
129 return true;
130
131 for (std::vector<TrackPoint*>::const_iterator pIt = points.begin(), pEnd = points.end(); pIt != pEnd; ++pIt) {
132 KalmanFitterInfo* fi = dynamic_cast<KalmanFitterInfo*>((*pIt)->getFitterInfo(rep));
133
134 if (!fi)
135 continue;
136
137 if (!(fi->checkConsistency()))
138 return false;
139
140 if (!(fi->hasReferenceState()))
141 return false;
142 }
143
144 return true;
145}

◆ setDeltaPval()

void genfit::AbsKalmanFitter::setDeltaPval ( double  deltaPval)
inline

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 85 of file AbsKalmanFitter.h.

85{deltaPval_ = deltaPval;}

◆ setMaxFailedHits()

virtual void genfit::AbsKalmanFitter::setMaxFailedHits ( int  val)
inlinevirtual

Reimplemented in genfit::DAF.

Definition at line 101 of file AbsKalmanFitter.h.

◆ setMaxIterations()

virtual void genfit::AbsKalmanFitter::setMaxIterations ( unsigned int  n)
inlinevirtual

Set the maximum number of iterations.

Reimplemented in genfit::DAF.

Definition at line 77 of file AbsKalmanFitter.h.

◆ setMinIterations()

virtual void genfit::AbsKalmanFitter::setMinIterations ( unsigned int  n)
inlinevirtual

Set the minimum number of iterations.

Definition at line 75 of file AbsKalmanFitter.h.

75{minIterations_ = std::max((unsigned int)1,n); if (maxIterations_ < minIterations_) maxIterations_ = minIterations_;}

◆ setMultipleMeasurementHandling()

void genfit::AbsKalmanFitter::setMultipleMeasurementHandling ( eMultipleMeasurementHandling  mmh)
inline

How should multiple measurements be handled?

Definition at line 99 of file AbsKalmanFitter.h.

◆ setRelChi2Change()

void genfit::AbsKalmanFitter::setRelChi2Change ( double  relChi2Change)
inline

@ 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 96 of file AbsKalmanFitter.h.

96{relChi2Change_ = relChi2Change;}

Member Data Documentation

◆ blowUpFactor_

double genfit::AbsKalmanFitter::blowUpFactor_
protected

Blow up the covariance of the forward (backward) fit by this factor before seeding the backward (forward) fit.

Definition at line 137 of file AbsKalmanFitter.h.

◆ deltaPval_

double genfit::AbsKalmanFitter::deltaPval_
protected

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 125 of file AbsKalmanFitter.h.

◆ maxFailedHits_

int genfit::AbsKalmanFitter::maxFailedHits_
protected

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 144 of file AbsKalmanFitter.h.

◆ maxIterations_

unsigned int genfit::AbsKalmanFitter::maxIterations_
protected

Maximum number of iterations to attempt. Forward and backward are counted as one iteration.

Definition at line 118 of file AbsKalmanFitter.h.

◆ minIterations_

unsigned int genfit::AbsKalmanFitter::minIterations_
protected

Minimum number of iterations to attempt. Forward and backward are counted as one iteration.

Definition at line 115 of file AbsKalmanFitter.h.

◆ multipleMeasurementHandling_

eMultipleMeasurementHandling genfit::AbsKalmanFitter::multipleMeasurementHandling_
protected

How to handle if there are multiple MeasurementsOnPlane.

Definition at line 140 of file AbsKalmanFitter.h.

◆ relChi2Change_

double genfit::AbsKalmanFitter::relChi2Change_
protected

@ 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 135 of file AbsKalmanFitter.h.


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