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.
329 {
330
332 std::cout << "KalmanFitterRefTrack::prepareTrack \n";
333 }
334
335 int notChangedUntil, notChangedFrom;
336
337
338 bool changedSmthg =
removeOutdated(tr, rep, notChangedUntil, notChangedFrom);
339
340
341
345
348
351
352
354 boost::scoped_ptr<MeasuredStateOnPlane> firstBackwardUpdate;
355
358
361
362 double trackLen(0);
363
364 bool newRefState(false);
365 bool prevNewRefState(false);
366
368
369
371 nFailedHits = 0;
372
373
374
376
377 try {
378
380 std::cout <<
"Prepare TrackPoint " <<
i <<
"\n";
381 }
382
384
385
388 std::cout << "TrackPoint has no rawMeasurements -> continue \n";
389 }
390 continue;
391 }
392
393 newRefState = false;
394
395
396
400
401
402 if (fitterInfo == NULL) {
404 std::cout << "create new KalmanFitterInfo \n";
405 }
406 changedSmthg = true;
409 }
410 else {
412 std::cout <<
"TrackPoint " <<
i <<
" (" << trackPoint <<
") already has KalmanFitterInfo \n";
413 }
414
415 if (prevFitterInfo == NULL) {
416 if (fitterInfo->hasBackwardUpdate())
418 }
419 }
420
421
422 if (fitterInfo->hasPredictionsAndUpdates()) {
423 smoothedState = &(fitterInfo->getFittedState(true));
425 std::cout << "got smoothed state \n";
426
427 }
428 }
429 else {
430 smoothedState = NULL;
431 }
432
433
434 if (fitterInfo->hasReferenceState()) {
435
436 referenceState = fitterInfo->getReferenceState();
437
438
439 if (!prevNewRefState) {
441 std::cout << "TrackPoint already has referenceState and previous referenceState has not been altered -> continue \n";
442 }
443 trackLen += referenceState->getForwardSegmentLength();
444 if (setSortingParams)
446
447 prevNewRefState = newRefState;
448 prevReferenceState = referenceState;
449 prevFitterInfo = fitterInfo;
450 prevSmoothedState = smoothedState;
451
452 continue;
453 }
454
455
456 if (prevReferenceState == NULL) {
458 std::cout << "TrackPoint already has referenceState but previous referenceState is NULL -> reset forward info of current reference state and continue \n";
459 }
460
461 referenceState->resetForward();
462
463 if (setSortingParams)
465
466 prevNewRefState = newRefState;
467 prevReferenceState = referenceState;
468 prevFitterInfo = fitterInfo;
469 prevSmoothedState = smoothedState;
470
471 continue;
472 }
473
474
476 std::cout << "TrackPoint already has referenceState but previous referenceState has been altered -> update transport matrices and continue \n";
477 }
479
480
481 prevReferenceState->resetBackward();
482 referenceState->resetForward();
483
484 double segmentLen = rep->
extrapolateToPlane(stateToExtrapolate, fitterInfo->getReferenceState()->getPlane(),
false,
true);
486 std::cout << "extrapolated stateToExtrapolate (prevReferenceState) by " << segmentLen << " cm.\n";
487 }
488 trackLen += segmentLen;
489
490 if (segmentLen == 0) {
497 }
498 else {
501 }
502
503 prevReferenceState->setBackwardSegmentLength(-segmentLen);
507
508 referenceState->setForwardSegmentLength(segmentLen);
512
513 newRefState = true;
514
515 if (setSortingParams)
517
518 prevNewRefState = newRefState;
519 prevReferenceState = referenceState;
520 prevFitterInfo = fitterInfo;
521 prevSmoothedState = smoothedState;
522
523 continue;
524 }
525
526
527
529 if (smoothedState != NULL) {
531 std::cout << "construct plane with smoothedState \n";
533 }
534 else if (prevSmoothedState != NULL) {
536 std::cout << "construct plane with prevSmoothedState \n";
537
538 }
540 }
541 else if (prevReferenceState != NULL) {
543 std::cout << "construct plane with prevReferenceState \n";
544 }
546 }
552 std::cout << "construct plane with smoothed state of cardinal rep fit \n";
553 }
561 }
562 else {
564 std::cout << "construct plane with state from track \n";
565 }
569 }
570
571 if (plane.get() == NULL) {
572 Exception exc(
"KalmanFitterRefTrack::prepareTrack ==> construced plane is NULL!",__LINE__,__FILE__);
573 exc.setFatal();
574 throw exc;
575 }
576
577
578
579
580 boost::scoped_ptr<StateOnPlane> stateToExtrapolate(NULL);
581 if (prevFitterInfo == NULL) {
583 std::cout << "prevFitterInfo == NULL \n";
584 }
585 if (smoothedState != NULL) {
587 std::cout << "extrapolate smoothedState to plane\n";
588 }
589 stateToExtrapolate.reset(
new StateOnPlane(*smoothedState));
590 }
591 else if (referenceState != NULL) {
593 std::cout << "extrapolate referenceState to plane\n";
594 }
595 stateToExtrapolate.reset(
new StateOnPlane(*referenceState));
596 }
602 std::cout << "extrapolate smoothed state of cardinal rep fit to plane\n";
603 }
608 rep->
setPosMom(*stateToExtrapolate, pos, mom);
610 }
611 else {
613 std::cout << "extrapolate seed from track to plane\n";
614 }
617 }
618 }
619 else {
620 if (prevSmoothedState != NULL) {
622 std::cout << "extrapolate prevSmoothedState to plane \n";
623 }
624 stateToExtrapolate.reset(
new StateOnPlane(*prevSmoothedState));
625 }
626 else {
627 assert (prevReferenceState != NULL);
629 std::cout << "extrapolate prevReferenceState to plane \n";
630 }
631 stateToExtrapolate.reset(
new StateOnPlane(*prevReferenceState));
632 }
633 }
634
635
636 if (prevReferenceState != NULL)
637 prevReferenceState->resetBackward();
638 fitterInfo->deleteReferenceInfo();
639
640 if (prevFitterInfo != NULL) {
643 std::cout << "extrapolated stateToExtrapolate to plane of prevFitterInfo (plane could have changed!) \n";
644 }
645 }
646
648 trackLen += segmentLen;
650 std::cout << "extrapolated stateToExtrapolate by " << segmentLen << " cm.\t";
651 std::cout <<
"charge of stateToExtrapolate: " << rep->
getCharge(*stateToExtrapolate) <<
" \n";
652 }
653
654
655 if (segmentLen == 0) {
662 }
663 else {
664 if (i>0)
667 }
668
669
670 if (i==0) {
671
672 segmentLen = 0;
673 trackLen = 0;
674 }
675 if (setSortingParams)
677
678
679
680 if (prevReferenceState != NULL) {
681 prevReferenceState->setBackwardSegmentLength(-segmentLen);
685 }
686
687
688
689 newRefState = true;
690 changedSmthg = true;
692 stateToExtrapolate->getPlane(),
693 stateToExtrapolate->getRep(),
694 stateToExtrapolate->getAuxInfo());
695 referenceState->setForwardSegmentLength(segmentLen);
699
700 referenceState->resetBackward();
701
702 fitterInfo->setReferenceState(referenceState);
703
704
705
706 std::vector<double> oldWeights = fitterInfo->getWeights();
707 bool oldWeightsFixed = fitterInfo->areWeightsFixed();
708 fitterInfo->deleteMeasurementInfo();
709 const std::vector<AbsMeasurement*>& rawMeasurements = trackPoint->
getRawMeasurements();
710 for ( std::vector< genfit::AbsMeasurement* >::const_iterator measurement = rawMeasurements.begin(), lastMeasurement = rawMeasurements.end(); measurement != lastMeasurement; ++measurement) {
711 assert((*measurement) != NULL);
712 fitterInfo->addMeasurementsOnPlane((*measurement)->constructMeasurementsOnPlane(*referenceState));
713 }
714 if (oldWeights.size() == fitterInfo->getNumMeasurements()) {
715 fitterInfo->setWeights(oldWeights);
716 fitterInfo->fixWeights(oldWeightsFixed);
717 }
718
719
720
721 prevNewRefState = newRefState;
722 prevReferenceState = referenceState;
723 prevFitterInfo = fitterInfo;
724 prevSmoothedState = smoothedState;
725
726 }
728
730 std::cout <<
"exception at hit " <<
i <<
"\n";
731 std::cerr << e.
what();
732 }
733
734
735 ++nFailedHits;
737 prevNewRefState = true;
738 referenceState = NULL;
739 smoothedState = NULL;
741
742 if (setSortingParams)
744
746 std::cout <<
"There was an exception, try to continue with next TrackPoint " <<
i+1 <<
" \n";
747 }
748
749 continue;
750 }
751
752
753
755
756
759
760 if (setSortingParams)
762
764 }
765 return true;
766
767 }
768
769 }
770
771
772
773
775
780 std::cout << "set backwards update of first point as forward prediction (with blown up cov) \n";
781 }
782 if (fi->
getPlane() != firstBackwardUpdate->getPlane()) {
784 }
787 }
788 }
789
791 if (fitStatus != NULL)
793
795 std::cout << "trackLen of reference track = " << trackLen << "\n";
796 }
797
798
799
801
802 return changedSmthg;
803}
const SharedPlanePtr & getPlane() const
double blowUpFactor_
Blow up the covariance of the forward (backward) fit by this factor before seeding the backward (forw...
bool isTrackPrepared(const Track *tr, const AbsTrackRep *rep) const
virtual SharedPlanePtr constructPlane(const StateOnPlane &state) const =0
virtual void getPosMom(const StateOnPlane &state, TVector3 &pos, TVector3 &mom) const =0
Get cartesian position and momentum vector of a state.
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 double getQop(const StateOnPlane &state) const =0
Get charge over momentum.
virtual void setPosMom(StateOnPlane &state, const TVector3 &pos, const TVector3 &mom) const =0
Set position and momentum of state.
virtual double getCharge(const StateOnPlane &state) const =0
Get the (fitted) charge of a state. This is not always equal the pdg charge (e.g. if the charge sign ...
virtual void getForwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation.
virtual void setQop(StateOnPlane &state, double qop) const =0
Set charge/momentum.
virtual void getBackwardJacobianAndNoise(TMatrixD &jacobian, TMatrixDSym &noise, TVectorD &deltaState) const =0
Get the jacobian and noise matrix of the last extrapolation if it would have been done in opposite di...
Exception class for error handling in GENFIT (provides storage for diagnostic information)
virtual const char * what() const
Standard error message handling for exceptions. use like "std::cerr << e.what();".
FitStatus for use with AbsKalmanFitter implementations.
void setTrackLen(double trackLen)
bool hasPredictionsAndUpdates() const
bool hasForwardPrediction() const
void setForwardPrediction(MeasuredStateOnPlane *forwardPrediction)
TVectorD backwardDeltaState_
TMatrixDSym BNoiseMatrix_
void removeForwardBackwardInfo(Track *tr, const AbsTrackRep *rep, int notChangedUntil, int notChangedFrom) const
If refitAll_, remove all information.
bool removeOutdated(Track *tr, const AbsTrackRep *rep, int ¬ChangedUntil, int ¬ChangedFrom)
Remove referenceStates if they are too far from smoothed states.
TVectorD forwardDeltaState_
TMatrixD BTransportMatrix_
TMatrixD FTransportMatrix_
TMatrixDSym FNoiseMatrix_
StateOnPlane with additional covariance matrix.
StateOnPlane with linearized transport to that ReferenceStateOnPlane from previous and next Reference...
A state with arbitrary dimension defined in a DetPlane.
bool hasFitterInfo(const AbsTrackRep *rep) const
void deleteFitterInfo(const AbsTrackRep *rep)
AbsFitterInfo * getFitterInfo(const AbsTrackRep *rep=NULL) const
Get fitterInfo for rep. Per default, use cardinal rep.
bool hasRawMeasurements() const
const std::vector< genfit::AbsMeasurement * > & getRawMeasurements() const
void setSortingParameter(double sortingParameter)
void setFitterInfo(genfit::AbsFitterInfo *fitterInfo)
Takes Ownership.
AbsMeasurement * getRawMeasurement(int i=0) const
TrackPoint * getPoint(int id) const
const TVectorD & getStateSeed() const
FitStatus * getFitStatus(const AbsTrackRep *rep=NULL) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
AbsTrackRep * getCardinalRep() const
Get cardinal track representation.
TrackPoint * getPointWithMeasurementAndFitterInfo(int id, const AbsTrackRep *rep) const
boost::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.