35#include <Math/QuantFuncMathCore.h>
42DAF::DAF(
bool useRefKalman,
double deltaPval,
double deltaWeight)
78 std::cout<<
"DAF::processTrack //////////////////////////////////////////////////////////////// \n";
82 bool oneLastIter =
false;
86 for(
unsigned int iBeta = 0;; ++iBeta) {
89 std::cout<<
"DAF::processTrack, trackRep " << rep <<
", iteration " << iBeta+1 <<
", beta = " <<
betas_.at(iBeta) <<
"\n";
92 kalman_->processTrackWithRep(tr, rep, resortHits);
95 status->setIsFittedWithDaf();
96 status->setNumIterations(iBeta+1);
101 if (! status->isFitted()){
103 std::cout <<
"DAF::Kalman could not fit!\n";
105 status->setIsFitted(
false);
109 if( oneLastIter ==
true){
111 std::cout <<
"DAF::break after one last iteration\n";
113 status->setIsFitConvergedFully(status->getNFailedPoints() == 0);
114 status->setIsFitConvergedPartially();
119 status->setIsFitConvergedFully(
false);
120 status->setIsFitConvergedPartially(
false);
122 std::cout <<
"DAF::number of max iterations reached!\n";
129 bool converged(
false);
133 status->getBackwardPVal() != 0 && fabs(lastPval - status->getBackwardPVal()) < this->deltaPval_) {
135 std::cout <<
"converged by Pval = " << status->getBackwardPVal() <<
" even though weights changed at iBeta = " << iBeta << std::endl;
139 lastPval = status->getBackwardPVal();
145 status->setIsFitted(
false);
146 status->setIsFitConvergedFully(
false);
147 status->setIsFitConvergedPartially(
false);
154 std::cout <<
"DAF::convergence reached in iteration " << iBeta+1 <<
" -> Do one last iteration with updated weights.\n";
157 status->setIsFitConvergedFully(status->getNFailedPoints() == 0);
158 status->setIsFitConvergedPartially();
164 if (status->getForwardPVal() == 0. &&
165 status->getBackwardPVal() == 0.) {
166 status->setIsFitConvergedFully(
false);
167 status->setIsFitConvergedPartially(
false);
174 for (
int i = 1; i != 6; ++i){
180 if ( prob_cut > 1.0 || prob_cut < 0.0){
181 Exception exc(
"DAF::addProbCut prob_cut is not between 0 and 1",__LINE__,__FILE__);
186 Exception exc(
"DAF::addProbCut measDim must be > 0",__LINE__,__FILE__);
190 chi2Cuts_[measDim] = ROOT::Math::chisquared_quantile_c( prob_cut, measDim);
194void DAF::setBetas(
double b1,
double b2,
double b3,
double b4,
double b5,
double b6,
double b7,
double b8,
double b9,
double b10){
196 assert(b1>0);
betas_.push_back(b1);
198 assert(b2<=b1);
betas_.push_back(b2);
200 assert(b3<=b2);
betas_.push_back(b3);
202 assert(b4<=b3);
betas_.push_back(b4);
204 assert(b5<=b4);
betas_.push_back(b5);
206 assert(b6<=b5);
betas_.push_back(b6);
208 assert(b7<=b6);
betas_.push_back(b7);
210 assert(b8<=b7);
betas_.push_back(b8);
212 assert(b9<=b8);
betas_.push_back(b9);
214 assert(b10<=b9);
betas_.push_back(b10);
233 assert(bStart > bFinal);
234 assert(bFinal > 1.E-10);
242 for (
unsigned int i=0; i<nSteps; ++i) {
243 betas_.push_back(bStart * pow(bFinal / bStart, i / (nSteps - 1.)));
257 std::cout<<
"DAF::calcWeights \n";
260 bool converged(
true);
261 double maxAbsChange(0);
264 for (std::vector< TrackPoint* >::const_iterator tp = trackPoints.begin(); tp != trackPoints.end(); ++tp) {
265 if (! (*tp)->hasFitterInfo(rep)) {
270 Exception exc(
"DAF::getWeights ==> can only use KalmanFitterInfos",__LINE__,__FILE__);
277 std::cout<<
"weights are fixed, continue \n";
284 std::vector<double> phi(nMeas, 0.);
287 for(
unsigned int j=0; j<nMeas; j++) {
291 const TVectorD& resid(residual.
getState());
292 TMatrixDSym Vinv(residual.
getCov());
295 int hitDim = resid.GetNrows();
299 double twoPiN = 2.*M_PI;
303 twoPiN = pow(twoPiN, hitDim);
305 double chi2 = Vinv.Similarity(resid);
307 std::cout<<
"chi2 = " << chi2 <<
"\n";
310 double norm = 1./sqrt(twoPiN * detV);
312 phi[j] = norm*exp(-0.5*chi2/beta);
316 assert(cutVal>1.E-6);
318 phi_cut += norm*exp(-0.5*cutVal/beta);
321 std::cerr << e.
what();
326 for(
unsigned int j=0; j<nMeas; j++) {
327 double weight = phi[j]/(phi_sum+phi_cut);
333 if (absChange > maxAbsChange)
334 maxAbsChange = absChange;
340 std::cout<<
"\t new weight: " << weight;
350 std::cout <<
"max abs weight change = " << maxAbsChange <<
"\n";
358void DAF::Streamer(TBuffer &R__b)
365 if (R__b.IsReading()) {
366 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v) { }
369 baseClass0::Streamer(R__b);
373 std::vector<double> &R__stl =
betas_;
377 R__stl.reserve(R__n);
378 for (R__i = 0; R__i < R__n; R__i++) {
381 R__stl.push_back(R__t);
385 std::map<int,double> &R__stl =
chi2Cuts_;
389 for (R__i = 0; R__i < R__n; R__i++) {
395 std::pair<Value_t const, double > R__t3(R__t,R__t2);
396 R__stl.insert(R__t3);
402 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
404 R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
407 baseClass0::Streamer(R__b);
410 std::vector<double> &R__stl =
betas_;
411 int R__n=
int(R__stl.size());
414 std::vector<double>::iterator R__k;
415 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
421 std::map<int,double> &R__stl =
chi2Cuts_;
422 int R__n=
int(R__stl.size());
425 std::map<int,double>::iterator R__k;
426 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
427 R__b << ((*R__k).first );
428 R__b << ((*R__k).second);
433 R__b.SetByteCount(R__c, kTRUE);
This class collects all information needed and produced by a specific AbsFitter and is specific to on...
Abstract base class for Kalman fitter and derived fitting algorithms.
unsigned int maxIterations_
Maximum number of iterations to attempt. Forward and backward are counted as one iteration.
void setMultipleMeasurementHandling(eMultipleMeasurementHandling mmh)
How should multiple measurements be handled?
unsigned int minIterations_
Minimum number of iterations to attempt. Forward and backward are counted as one iteration.
AbsKalmanFitter(unsigned int maxIterations=4, double deltaPval=1e-3, double blowUpFactor=1e3)
Abstract base class for a track representation.
Determinstic Annealing Filter (DAF) implementation.
std::vector< double > betas_
void setBetas(double b1, double b2=-1, double b3=-1., double b4=-1., double b5=-1., double b6=-1., double b7=-1., double b8=-1., double b9=-1., double b10=-1.)
Configure the annealing scheme.
bool calcWeights(Track *trk, const AbsTrackRep *rep, double beta)
Calculate and set the weights for the next fitting pass. Return if convergence is met....
void setAnnealingScheme(double bStart, double bFinal, unsigned int nSteps)
Configure the annealing scheme.
void addProbCut(const double prob_cut, const int measDim)
Set the probability cut for the weight calculation for the hits for a specific measurement dimensiona...
std::map< int, double > chi2Cuts_
void setProbCut(const double prob_cut)
Set the probability cut for the weight calculation for the hits.
void processTrackWithRep(Track *tr, const AbsTrackRep *rep, bool resortHits=false)
Process a track using the DAF.
boost::scoped_ptr< AbsKalmanFitter > kalman_
Exception class for error handling in GENFIT (provides storage for diagnostic information)
void setFatal(bool b=true)
Set fatal flag.
virtual const char * what() const
Standard error message handling for exceptions. use like "std::cerr << e.what();".
void info()
Print information in the exception object.
FitStatus for use with AbsKalmanFitter implementations.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
MeasurementOnPlane getResidual(unsigned int iMeasurement=0, bool biased=false, bool onlyMeasurementErrors=true) const
Get unbiased (default) or biased residual from ith measurement.
unsigned int getNumMeasurements() const
bool areWeightsFixed() const
Are the weights fixed?
MeasurementOnPlane * getMeasurementOnPlane(int i=0) const
Kalman filter implementation with linearization around a reference track.
Simple Kalman filter implementation.
const TMatrixDSym & getCov() const
Measured coordinates on a plane.
void setWeight(double weight)
const TVectorD & getState() const
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
const std::vector< genfit::TrackPoint * > & getPointsWithMeasurement() const
FitStatus * getFitStatus(const AbsTrackRep *rep=NULL) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.