381{
382 assert(direction == -1 || direction == +1);
383
384 if (!
tp->hasRawMeasurements())
385 return;
386
387 bool newFi(false);
388
390 if (!
tp->hasFitterInfo(rep)) {
392 tp->setFitterInfo(fi);
393 newFi = true;
394 }
395 else
397
399 bool oldWeightsFixed(false);
400 std::vector<double> oldWeights;
401
402
403 if (newFi) {
404
407
408
412
413
414 const std::vector< genfit::AbsMeasurement* >& rawMeasurements =
tp->getRawMeasurements();
416 }
417 else
419
420
421
422
425
427 std::cout << "extrapolated by " << extLen << std::endl;
428 }
429
430
431
432
434
435
436
437 if (newFi) {
438 const std::vector< genfit::AbsMeasurement* >& rawMeasurements =
tp->getRawMeasurements();
439 for (std::vector< genfit::AbsMeasurement* >::const_iterator it = rawMeasurements.begin(); it != rawMeasurements.end(); ++it) {
441 }
446 std::cout << "set old weights \n";
447 }
448 }
451 }
452
454 std::cout << "its plane is at R = " << plane->getO().Perp()
455 << " with normal pointing along (" << plane->getNormal().X() << ", " << plane->getNormal().Y() << ", " << plane->getNormal().Z() << ")" << std::endl;
456 }
457
458
459
460 TVectorD stateVector(state->
getState());
461 TMatrixDSym cov(state->
getCov());
462
463 double chi2inc = 0;
464 double ndfInc = 0;
465 const std::vector<MeasurementOnPlane *> measurements =
getMeasurements(fi, tp, direction);
466 for (std::vector<MeasurementOnPlane *>::const_iterator it = measurements.begin(); it != measurements.end(); ++it) {
468 const double weight = mOnPlane.
getWeight();
469
471 std::cout << "Weight of measurement: " << weight << "\n";
472 }
473
476 std::cout << "Weight of measurement is almost 0, continue ... \n";
477 }
478 continue;
479 }
480
481 const TVectorD& measurement(mOnPlane.
getState());
483
485 1./weight * mOnPlane.
getCov() :
486 mOnPlane.getCov());
488 std::cout << "\033[31m";
489 std::cout << "State prediction: "; stateVector.Print();
490 std::cout <<
"Cov prediction: "; state->
getCov().Print();
491 std::cout << "\033[0m";
492 std::cout << "\033[34m";
493 std::cout << "measurement: "; measurement.Print();
494 std::cout <<
"measurement covariance V: ";
V.Print();
495
496
497 }
498
499 TVectorD res(measurement -
H->Hv(stateVector));
501 std::cout << "Residual = (" << res(0);
502 if (res.GetNrows() > 1)
503 std::cout << ", " << res(1);
504 std::cout << ")" << std::endl;
505 std::cout << "\033[0m";
506 }
507
508
510 {
511
512
513
514
515
516
517
518
520 TMatrixDSym noise;
521 TVectorD deltaState;
524
525
526
527
528
529
530
531
532
533
534
535 TMatrixDSymEigen eig(noise);
536 TMatrixD Q(eig.GetEigenVectors());
537 const TVectorD& evs(eig.GetEigenValues());
538
539
540 int iCol = 0;
541 for (; iCol < Q.GetNcols(); ++iCol) {
542 double ev = evs(iCol) > 0 ? sqrt(evs(iCol)) : 0;
543 if (ev == 0)
544 break;
545 for (
int j = 0;
j < Q.GetNrows(); ++
j)
546 Q(j,iCol) *= ev;
547 }
548 if (iCol < Q.GetNrows()) {
549
550 Q.ResizeTo(iCol, Q.GetNcols());
551 }
552
553
554
555
556 TDecompChol oldCovDecomp(oldCov);
557 oldCovDecomp.Decompose();
558 const TMatrixD&
S(oldCovDecomp.GetU());
559
560 TDecompChol decompR(V);
561 decompR.Decompose();
562
563 TMatrixD pre(
S.GetNrows() + Q.GetNrows() +
V.GetNrows(),
564 S.GetNcols() +
V.GetNcols());
565 TMatrixD SFt(S, TMatrixD::kMultTranspose, F);
566 pre.SetSub( 0, 0,decompR.GetU());
567 pre.SetSub(
V.GetNrows(), 0,
H->MHt(SFt)); pre.SetSub(
V.GetNrows(),
V.GetNcols(),SFt);
568 if (Q.GetNrows() > 0) {
569 pre.SetSub(
S.GetNrows()+
V.GetNrows(),0,
H->MHt(Q)); pre.SetSub(
S.GetNrows()+
V.GetNrows(),
V.GetNcols(), Q);
570 }
571
573 const TMatrixD&
r = pre;
574
575 TMatrixD
R(
r.GetSub(0,
V.GetNrows()-1, 0,
V.GetNcols()-1));
576
577 TMatrixD K(TMatrixD::kTransposed,
r.GetSub(0,
V.GetNrows()-1,
V.GetNcols(), pre.GetNcols()-1));
578
579
580 TMatrixD Snew(
r.GetSub(
V.GetNrows(),
V.GetNrows() +
S.GetNrows() - 1,
581 V.GetNcols(), pre.GetNcols()-1));
582
583
584 TVectorD update(res);
586 update *= K;
587 stateVector += update;
588 cov = TMatrixDSym(TMatrixDSym::kAtA, Snew);
589 }
590 else
591 {
592
593
594 TMatrixDSym covSumInv(cov);
598
599 TMatrixD CHt(
H->MHt(cov));
600 TVectorD update(TMatrixD(CHt, TMatrixD::kMult, covSumInv) * res);
601
602
604
605
606 std::cout << "\033[32m";
607 std::cout << "Update: "; update.Print();
608 std::cout << "\033[0m";
609
610 }
611
612 stateVector += update;
613 covSumInv.Similarity(CHt);
614 cov -= covSumInv;
615 }
616
618 std::cout << "\033[32m";
619 std::cout << "updated state: "; stateVector.Print();
620 std::cout << "updated cov: "; cov.Print();
621 }
622
623 TVectorD resNew(measurement -
H->Hv(stateVector));
625 std::cout << "Residual New = (" << resNew(0);
626
627 if (resNew.GetNrows() > 1)
628 std::cout << ", " << resNew(1);
629 std::cout << ")" << std::endl;
630 std::cout << "\033[0m";
631 }
632
633
634
635
636
637
638
639
640
641
642
643 TMatrixDSym HCHt(cov);
646 HCHt *= -1;
647
649
650 chi2inc += HCHt.Similarity(resNew);
651
653 ndfInc += weight * measurement.GetNrows();
654 }
655 else
656 ndfInc += measurement.GetNrows();
657
659 std::cout << "chi² increment = " << chi2inc << std::endl;
660 }
661 }
662
665
666 chi2 += chi2inc;
667 ndf += ndfInc;
668
669
672}
const SharedPlanePtr & getPlane() const
HMatrix for projecting from AbsTrackRep parameters to measured parameters in a DetPlane.
bool canIgnoreWeights() const
returns if the fitter can ignore the weights and handle the MeasurementOnPlanes as if they had weight...
const std::vector< MeasurementOnPlane * > getMeasurements(const KalmanFitterInfo *fi, const TrackPoint *tp, int direction) const
get the measurementsOnPlane taking the multipleMeasurementHandling_ into account
virtual double extrapolateToPlane(StateOnPlane &state, const genfit::SharedPlanePtr &plane, bool stopAtBoundary=false, bool calcJacobianNoise=false) const =0
Extrapolates the state to plane, and returns the extrapolation length and, via reference,...
virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation.
MeasuredStateOnPlane with additional info produced by a Kalman filter or DAF.
virtual bool checkConsistency() const
void setWeights(const std::vector< double > &)
Set weights of measurements.
void addMeasurementsOnPlane(const std::vector< genfit::MeasurementOnPlane * > &measurementsOnPlane)
void deleteBackwardInfo()
std::vector< double > getWeights() const
Get weights of measurements.
void setPrediction(MeasuredStateOnPlane *prediction, int direction)
unsigned int getNumMeasurements() const
void fixWeights(bool arg=true)
bool areWeightsFixed() const
Are the weights fixed?
void setUpdate(KalmanFittedStateOnPlane *update, int direction)
void deleteMeasurementInfo()
const TMatrixDSym & getCov() const
Measured coordinates on a plane.
const AbsHMatrix * getHMatrix() const
const TVectorD & getState() const
const TVectorD & getAuxInfo() const
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.