22 #include "Exception.h"
24 #include "KalmanFitterInfo.h"
25 #include "KalmanFitStatus.h"
26 #include "PlanarMeasurement.h"
27 #include "AbsMeasurement.h"
29 #include "WireTrackCandHit.h"
34 #include <TDatabasePDG.h>
46 cardinalRep_(0), fitStatuses_(), mcTrackId_(-1), timeSeed_(0), stateSeed_(6), covSeed_(6)
53 cardinalRep_(0), fitStatuses_(), stateSeed_(6), covSeed_(6)
59 createMeasurements(trackCand, factory);
69 fillPointsWithMeasurement();
78 std::vector <AbsMeasurement*> factoryHits = factory.
createMany(trackCand);
80 if (factoryHits.size() != trackCand.getNHits()) {
81 Exception exc(
"Track::Track ==> factoryHits.size() != trackCand->getNHits()", __LINE__, __FILE__);
87 for (
unsigned int i = 0; i < factoryHits.size(); ++i) {
88 TrackPoint* tp =
new TrackPoint(factoryHits[i],
this);
89 tp->setSortingParameter(trackCand.getHit(i)->getSortingParameter());
95 Track::Track(AbsTrackRep* trackRep,
const TVectorD& stateSeed) :
96 cardinalRep_(0), fitStatuses_(), mcTrackId_(-1), timeSeed_(0), stateSeed_(stateSeed),
97 covSeed_(TMatrixDSym::kUnit, TMatrixDSym(6))
99 addTrackRep(trackRep);
103 Track::Track(AbsTrackRep* trackRep,
const TVector3& posSeed,
const TVector3& momSeed) :
104 cardinalRep_(0), fitStatuses_(), mcTrackId_(-1), timeSeed_(0), stateSeed_(6),
105 covSeed_(TMatrixDSym::kUnit, TMatrixDSym(6))
107 addTrackRep(trackRep);
108 setStateSeed(posSeed, momSeed);
112 Track::Track(AbsTrackRep* trackRep,
const TVectorD& stateSeed,
const TMatrixDSym& covSeed) :
113 cardinalRep_(0), fitStatuses_(), mcTrackId_(-1), timeSeed_(0), stateSeed_(stateSeed),
116 addTrackRep(trackRep);
120 Track::Track(
const Track& rhs) :
122 cardinalRep_(rhs.cardinalRep_), mcTrackId_(rhs.mcTrackId_), timeSeed_(rhs.timeSeed_),
123 stateSeed_(rhs.stateSeed_), covSeed_(rhs.covSeed_)
125 rhs.checkConsistency();
127 std::map<const AbsTrackRep*, AbsTrackRep*> oldRepNewRep;
129 for (std::vector<AbsTrackRep*>::const_iterator it = rhs.trackReps_.begin(); it != rhs.trackReps_.end(); ++it) {
130 AbsTrackRep* newRep = (*it)->clone();
132 oldRepNewRep[(*it)] = newRep;
135 trackPoints_.reserve(rhs.trackPoints_.size());
136 for (std::vector<TrackPoint*>::const_iterator it = rhs.trackPoints_.begin(); it != rhs.trackPoints_.end(); ++it) {
137 trackPoints_.push_back(
new TrackPoint(**it, oldRepNewRep));
138 trackPoints_.back()->setTrack(
this);
141 for (std::map< const AbsTrackRep*, FitStatus* >::const_iterator it = rhs.fitStatuses_.begin(); it != rhs.fitStatuses_.end(); ++it) {
142 setFitStatus(it->second->clone(), oldRepNewRep[it->first]);
145 fillPointsWithMeasurement();
150 Track& Track::operator=(Track other)
154 for (std::vector<TrackPoint*>::const_iterator it = trackPoints_.begin(); it != trackPoints_.end(); ++it) {
155 (*it)->setTrack(
this);
158 fillPointsWithMeasurement();
165 void Track::swap(Track& other)
167 std::swap(this->trackReps_, other.trackReps_);
168 std::swap(this->cardinalRep_, other.cardinalRep_);
169 std::swap(this->trackPoints_, other.trackPoints_);
170 std::swap(this->trackPointsWithMeasurement_, other.trackPointsWithMeasurement_);
172 std::swap(this->
mcTrackId_, other.mcTrackId_);
173 std::swap(this->timeSeed_, other.timeSeed_);
174 std::swap(this->stateSeed_, other.stateSeed_);
175 std::swap(this->covSeed_, other.covSeed_);
184 void Track::Clear(Option_t*)
188 for (
size_t i = 0; i < trackPoints_.size(); ++i)
189 delete trackPoints_[i];
191 trackPoints_.clear();
192 trackPointsWithMeasurement_.clear();
194 for (std::map< const AbsTrackRep*, FitStatus* >::iterator it =
fitStatuses_.begin(); it !=
fitStatuses_.end(); ++it)
198 for (
size_t i = 0; i < trackReps_.size(); ++i)
199 delete trackReps_[i];
212 TrackPoint* Track::getPoint(
int id)
const
215 id += trackPoints_.size();
217 return trackPoints_.at(
id);
221 TrackPoint* Track::getPointWithMeasurement(
int id)
const
224 id += trackPointsWithMeasurement_.size();
226 return trackPointsWithMeasurement_.at(
id);
230 TrackPoint* Track::getPointWithMeasurementAndFitterInfo(
int id,
const AbsTrackRep* rep)
const
237 for (std::vector<TrackPoint*>::const_iterator it = trackPointsWithMeasurement_.begin(); it != trackPointsWithMeasurement_.end();
239 if ((*it)->hasFitterInfo(rep)) {
248 for (std::vector<TrackPoint*>::const_reverse_iterator it = trackPointsWithMeasurement_.rbegin();
249 it != trackPointsWithMeasurement_.rend(); ++it) {
250 if ((*it)->hasFitterInfo(rep)) {
263 TrackPoint* Track::getPointWithFitterInfo(
int id,
const AbsTrackRep* rep)
const
270 for (std::vector<TrackPoint*>::const_iterator it = trackPoints_.begin(); it != trackPoints_.end(); ++it) {
271 if ((*it)->hasFitterInfo(rep)) {
280 for (std::vector<TrackPoint*>::const_reverse_iterator it = trackPoints_.rbegin(); it != trackPoints_.rend(); ++it) {
281 if ((*it)->hasFitterInfo(rep)) {
299 TrackPoint* point = getPointWithFitterInfo(
id, rep);
300 if (point ==
nullptr) {
301 Exception exc(
"Track::getFittedState ==> no trackPoint with fitterInfo for rep", __LINE__, __FILE__);
311 for (
size_t i = 0; i < trackReps_.size(); ++i)
312 if (trackReps_[i] == rep)
315 Exception exc(
"Track::getIdForRep ==> cannot find TrackRep in Track", __LINE__, __FILE__);
360 void Track::setStateSeed(
const TVector3& pos,
const TVector3& mom)
362 stateSeed_.ResizeTo(6);
364 stateSeed_(0) = pos.X();
365 stateSeed_(1) = pos.Y();
366 stateSeed_(2) = pos.Z();
368 stateSeed_(3) = mom.X();
369 stateSeed_(4) = mom.Y();
370 stateSeed_(5) = mom.Z();
378 point->setTrack(
this);
381 debugOut <<
"Track::insertPoint at position " <<
id <<
"\n";
383 assert(point !=
nullptr);
386 point->setTrack(
this);
388 if (trackPoints_.size() == 0) {
389 trackPoints_.push_back(point);
391 if (point->hasRawMeasurements())
392 trackPointsWithMeasurement_.push_back(point);
397 if (
id == -1 ||
id == (
int)trackPoints_.size()) {
398 trackPoints_.push_back(point);
400 if (point->hasRawMeasurements())
401 trackPointsWithMeasurement_.push_back(point);
403 deleteReferenceInfo(std::max(0, (
int)trackPoints_.size() - 2), (
int)trackPoints_.size() - 1);
406 if (point->hasRawMeasurements()) {
407 deleteForwardInfo(-1, -1);
408 deleteBackwardInfo(0, -2);
415 assert(
id < (ssize_t)trackPoints_.size() || -
id - 1 <= (ssize_t)trackPoints_.size());
418 id += trackPoints_.size() + 1;
421 trackPoints_.insert(trackPoints_.begin() +
id, point);
424 if (point->hasRawMeasurements()) {
425 deleteForwardInfo(
id, -1);
426 deleteBackwardInfo(0,
id);
430 deleteReferenceInfo(std::max(0,
id - 1), std::min((
int)trackPoints_.size() - 1,
id + 1));
432 fillPointsWithMeasurement();
439 int nBefore = getNumPoints();
440 int n = points.size();
449 for (std::vector<TrackPoint*>::iterator p = points.begin(); p != points.end(); ++p)
450 (*p)->setTrack(
this);
452 if (
id == -1 ||
id == (
int)trackPoints_.size()) {
453 trackPoints_.insert(trackPoints_.end(), points.begin(), points.end());
455 deleteReferenceInfo(std::max(0, nBefore - 1), nBefore);
457 deleteForwardInfo(nBefore, -1);
458 deleteBackwardInfo(0, std::max(0, nBefore - 1));
460 fillPointsWithMeasurement();
466 assert(
id < (ssize_t)trackPoints_.size() || -
id - 1 <= (ssize_t)trackPoints_.size());
469 id += trackPoints_.size() + 1;
473 trackPoints_.insert(trackPoints_.begin() +
id, points.begin(), points.end());
476 deleteForwardInfo(
id, -1);
477 deleteBackwardInfo(0,
id + n);
480 deleteReferenceInfo(std::max(0,
id - 1), std::min((
int)trackPoints_.size() - 1,
id));
481 deleteReferenceInfo(std::max(0,
id + n - 1), std::min((
int)trackPoints_.size() - 1,
id + n));
483 fillPointsWithMeasurement();
487 void Track::deletePoint(
int id)
491 debugOut <<
"Track::deletePoint at position " <<
id <<
"\n";
497 id += trackPoints_.size();
502 if (trackPoints_[
id]->hasRawMeasurements()) {
503 deleteForwardInfo(
id, -1);
504 deleteBackwardInfo(0,
id - 1);
508 deleteReferenceInfo(std::max(0,
id - 1), std::min((
int)trackPoints_.size() - 1,
id + 1));
511 std::vector<TrackPoint*>::iterator it = std::find(trackPointsWithMeasurement_.begin(), trackPointsWithMeasurement_.end(),
513 if (it != trackPointsWithMeasurement_.end())
514 trackPointsWithMeasurement_.erase(it);
516 delete trackPoints_[id];
517 trackPoints_.erase(trackPoints_.begin() +
id);
519 fillPointsWithMeasurement();
537 for (
const auto& trackPoint : trackPoints_) {
538 if (trackPoint->hasFitterInfo(rep)) {
539 trackPoint->deleteFitterInfo(rep);
552 if (other->getNumPoints() == 0)
555 std::map<const AbsTrackRep*, AbsTrackRep*> otherRepThisRep;
556 std::vector<const AbsTrackRep*> otherRepsToRemove;
558 for (std::vector<AbsTrackRep*>::const_iterator otherRep = other->trackReps_.begin(); otherRep != other->trackReps_.end();
561 for (std::vector<AbsTrackRep*>::const_iterator thisRep = trackReps_.begin(); thisRep != trackReps_.end(); ++thisRep) {
562 if ((*thisRep)->isSame(*otherRep)) {
563 otherRepThisRep[*otherRep] = *thisRep;
565 debugOut <<
" map other rep " << *otherRep <<
" to " << (*thisRep) <<
"\n";
568 Exception exc(
"Track::mergeTrack ==> more than one matching rep.", __LINE__, __FILE__);
577 otherRepsToRemove.push_back(*otherRep);
579 debugOut <<
" remove other rep " << *otherRep <<
"\n";
585 std::vector<TrackPoint*> points;
586 points.reserve(other->getNumPoints());
588 for (std::vector<TrackPoint*>::const_iterator otherTp = other->trackPoints_.begin(); otherTp != other->trackPoints_.end();
590 points.push_back(
new TrackPoint(**otherTp, otherRepThisRep, &otherRepsToRemove));
599 trackReps_.push_back(trackRep);
607 id += trackReps_.size();
612 if (
int(cardinalRep_) ==
id)
614 else if (
int(cardinalRep_) >
id)
618 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin(); pointIt != trackPoints_.end(); ++pointIt) {
619 (*pointIt)->deleteFitterInfo(rep);
628 trackReps_.erase(trackReps_.begin() +
id);
632 void Track::setCardinalRep(
int id)
636 id += trackReps_.size();
638 if (
id >= 0 && (
unsigned int)
id < trackReps_.size())
642 errorOut <<
"Track::setCardinalRep: Attempted to set cardinalRep_ to a value out of bounds. Resetting cardinalRep_ to 0." <<
653 if (trackReps_.size() <= 1)
656 double minChi2(9.E99);
659 for (std::map< const AbsTrackRep*, FitStatus* >::const_iterator it =
fitStatuses_.begin(); it !=
fitStatuses_.end(); ++it) {
660 if (it->second->isFitConverged()) {
661 if (it->second->getChi2() < minChi2) {
662 minChi2 = it->second->getChi2();
668 if (bestRep !=
nullptr) {
680 int nPoints(trackPoints_.size());
682 std::vector<TrackPoint*> pointsBefore(trackPoints_);
688 int equalUntil(-1), equalFrom(nPoints);
689 for (
int i = 0; i < nPoints; ++i) {
690 if (pointsBefore[i] == trackPoints_[i])
696 if (equalUntil == nPoints - 1)
702 for (
int i = nPoints - 1; i > equalUntil; --i) {
703 if (pointsBefore[i] == trackPoints_[i])
710 debugOut <<
"Track::sort. Equal up to (including) hit " << equalUntil <<
" and from (including) hit " << equalFrom <<
" \n";
713 deleteForwardInfo(equalUntil + 1, -1);
714 deleteBackwardInfo(0, equalFrom - 1);
716 deleteReferenceInfo(std::max(0, equalUntil + 1), std::min((
int)trackPoints_.size() - 1, equalFrom - 1));
718 fillPointsWithMeasurement();
728 setTimeSeed(fittedState.getTime());
729 setStateSeed(fittedState.get6DState());
730 setCovSeed(fittedState.get6DCov());
732 double fittedCharge = fittedState.getCharge();
734 for (
unsigned int i = 0; i < trackReps_.size(); ++i) {
735 if (trackReps_[i]->getPDGCharge() * fittedCharge < 0) {
736 trackReps_[i]->switchPDGSign();
750 std::reverse(trackPoints_.begin(), trackPoints_.end());
752 deleteForwardInfo(0, -1);
753 deleteBackwardInfo(0, -1);
754 deleteReferenceInfo(0, -1);
756 fillPointsWithMeasurement();
762 if (rep !=
nullptr) {
767 for (
unsigned int i = 0; i < trackReps_.size(); ++i) {
768 trackReps_[i]->switchPDGSign();
782 void Track::deleteForwardInfo(
int startId,
int endId,
const AbsTrackRep* rep)
785 debugOut <<
"Track::deleteForwardInfo from position " << startId <<
" to " << endId <<
"\n";
791 startId += trackPoints_.size();
793 endId += trackPoints_.size();
796 assert(endId >= startId);
798 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin() + startId; pointIt != trackPoints_.begin() + endId;
800 if (rep !=
nullptr) {
801 if ((*pointIt)->hasFitterInfo(rep))
802 (*pointIt)->getFitterInfo(rep)->deleteForwardInfo();
804 const std::vector<AbsFitterInfo*> fitterInfos = (*pointIt)->getFitterInfos();
805 for (std::vector<AbsFitterInfo*>::const_iterator fitterInfoIt = fitterInfos.begin(); fitterInfoIt != fitterInfos.end();
807 (*fitterInfoIt)->deleteForwardInfo();
813 void Track::deleteBackwardInfo(
int startId,
int endId,
const AbsTrackRep* rep)
817 debugOut <<
"Track::deleteBackwardInfo from position " << startId <<
" to " << endId <<
"\n";
823 startId += trackPoints_.size();
825 endId += trackPoints_.size();
828 assert(endId >= startId);
831 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin() + startId; pointIt != trackPoints_.begin() + endId;
833 if (rep !=
nullptr) {
834 if ((*pointIt)->hasFitterInfo(rep))
835 (*pointIt)->getFitterInfo(rep)->deleteBackwardInfo();
837 const std::vector<AbsFitterInfo*> fitterInfos = (*pointIt)->getFitterInfos();
838 for (std::vector<AbsFitterInfo*>::const_iterator fitterInfoIt = fitterInfos.begin(); fitterInfoIt != fitterInfos.end();
840 (*fitterInfoIt)->deleteBackwardInfo();
846 void Track::deleteReferenceInfo(
int startId,
int endId,
const AbsTrackRep* rep)
850 debugOut <<
"Track::deleteReferenceInfo from position " << startId <<
" to " << endId <<
"\n";
856 startId += trackPoints_.size();
858 endId += trackPoints_.size();
861 assert(endId >= startId);
863 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin() + startId; pointIt != trackPoints_.begin() + endId;
865 if (rep !=
nullptr) {
866 if ((*pointIt)->hasFitterInfo(rep))
867 (*pointIt)->getFitterInfo(rep)->deleteReferenceInfo();
869 std::vector<AbsFitterInfo*> fitterInfos = (*pointIt)->getFitterInfos();
870 for (std::vector<AbsFitterInfo*>::const_iterator fitterInfoIt = fitterInfos.begin(); fitterInfoIt != fitterInfos.end();
872 (*fitterInfoIt)->deleteReferenceInfo();
878 void Track::deleteMeasurementInfo(
int startId,
int endId,
const AbsTrackRep* rep)
882 debugOut <<
"Track::deleteMeasurementInfo from position " << startId <<
" to " << endId <<
"\n";
888 startId += trackPoints_.size();
890 endId += trackPoints_.size();
893 assert(endId >= startId);
895 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin() + startId; pointIt != trackPoints_.begin() + endId;
897 if (rep !=
nullptr) {
898 if ((*pointIt)->hasFitterInfo(rep))
899 (*pointIt)->getFitterInfo(rep)->deleteMeasurementInfo();
901 std::vector<AbsFitterInfo*> fitterInfos = (*pointIt)->getFitterInfos();
902 for (std::vector<AbsFitterInfo*>::const_iterator fitterInfoIt = fitterInfos.begin(); fitterInfoIt != fitterInfos.end();
904 (*fitterInfoIt)->deleteMeasurementInfo();
910 void Track::deleteFitterInfo(
int startId,
int endId,
const AbsTrackRep* rep)
914 debugOut <<
"Track::deleteFitterInfo from position " << startId <<
" to " << endId <<
"\n";
920 startId += trackPoints_.size();
922 endId += trackPoints_.size();
925 assert(endId >= startId);
927 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin() + startId; pointIt != trackPoints_.begin() + endId;
929 if (rep !=
nullptr) {
930 if ((*pointIt)->hasFitterInfo(rep))
931 (*pointIt)->deleteFitterInfo(rep);
933 for (std::vector<AbsTrackRep*>::const_iterator repIt = trackReps_.begin(); repIt != trackReps_.end(); ++repIt) {
934 if ((*pointIt)->hasFitterInfo(*repIt))
935 (*pointIt)->deleteFitterInfo(*repIt);
946 startId += trackPoints_.size();
948 endId += trackPoints_.size();
950 bool backwards(
false);
951 if (startId > endId) {
952 double temp = startId;
966 for (std::vector<TrackPoint*>::const_iterator pointIt = trackPoints_.begin() + startId; pointIt != trackPoints_.begin() + endId;
968 if (!(*pointIt)->hasFitterInfo(rep)) {
969 Exception e(
"Track::getTracklength: trackPoint has no fitterInfo", __LINE__, __FILE__);
973 if (pointIt != trackPoints_.begin() + startId) {
974 trackLen += rep->
extrapolateToPlane(state, (*pointIt)->getFitterInfo(rep)->getPlane());
977 state = (*pointIt)->getFitterInfo(rep)->getFittedState();
995 for (
unsigned int i = 0; i < trackPointsWithMeasurement_.size(); ++i) {
996 const TrackPoint* tp = trackPointsWithMeasurement_[i];
997 const std::vector< AbsMeasurement* >& measurements = tp->getRawMeasurements();
999 for (
unsigned int j = 0; j < measurements.size(); ++j) {
1008 if (m->isLeftRightMeasurement()) {
1010 tp->getSortingParameter(), m->getLeftRightResolution());
1012 tch =
new TrackCandHit(m->getDetId(), m->getHitId(), planeId,
1013 tp->getSortingParameter());
1027 startId += trackPoints_.size();
1029 endId += trackPoints_.size();
1031 if (startId > endId) {
1032 std::swap(startId, endId);
1042 const TrackPoint* startPoint(trackPoints_[startId]);
1043 const TrackPoint* endPoint(trackPoints_[endId]);
1045 if (!startPoint->hasFitterInfo(rep)
1046 || !endPoint->hasFitterInfo(rep)) {
1047 Exception e(
"Track::getTOF: trackPoint has no fitterInfo", __LINE__, __FILE__);
1061 startId += trackPoints_.size();
1063 endId += trackPoints_.size();
1065 assert(startId >= 0);
1066 assert(startId <= endId);
1067 assert(endId <= (
int)trackPoints_.size());
1069 std::vector< AbsFitterInfo* > fis;
1071 for (std::vector<TrackPoint*>::iterator tp = trackPoints_.begin() + startId; tp != trackPoints_.begin() + endId; ++tp) {
1073 if (rep ==
nullptr) {
1074 fis = (*tp)->getFitterInfos();
1075 }
else if ((*tp)->hasFitterInfo(rep)) {
1076 fis.push_back((*tp)->getFitterInfo(rep));
1079 for (std::vector< AbsFitterInfo* >::iterator fi = fis.begin(); fi != fis.end(); ++fi) {
1096 for (std::map< const AbsTrackRep*, FitStatus* >::const_iterator it =
fitStatuses_.begin(); it !=
fitStatuses_.end(); ++it) {
1097 it->second->getPruneFlags().setFlags(option);
1101 if (f.hasFlags(
"F") || f.hasFlags(
"L")) {
1102 TrackPoint* firstPoint = getPointWithFitterInfo(0);
1103 TrackPoint* lastPoint = getPointWithFitterInfo(-1);
1104 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1105 if (trackPoints_[i] == firstPoint && f.hasFlags(
"F"))
1108 if (trackPoints_[i] == lastPoint && f.hasFlags(
"L"))
1111 delete trackPoints_[i];
1112 trackPoints_.erase(trackPoints_.begin() + i);
1118 if (f.hasFlags(
"C")) {
1119 for (
unsigned int i = 0; i < trackReps_.size(); ++i) {
1120 if (i != cardinalRep_) {
1129 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1130 if (f.hasFlags(
"W"))
1131 trackPoints_[i]->deleteRawMeasurements();
1133 std::vector< AbsFitterInfo* > fis = trackPoints_[i]->getFitterInfos();
1134 for (
unsigned int j = 0; j < fis.size(); ++j) {
1136 if (i == 0 && f.hasFlags(
"FLI"))
1137 fis[j]->deleteForwardInfo();
1138 else if (i == trackPoints_.size() - 1 && f.hasFlags(
"FLI"))
1139 fis[j]->deleteBackwardInfo();
1140 else if (f.hasFlags(
"FI"))
1141 fis[j]->deleteForwardInfo();
1142 else if (f.hasFlags(
"LI"))
1143 fis[j]->deleteBackwardInfo();
1145 if (f.hasFlags(
"U") &&
dynamic_cast<KalmanFitterInfo*
>(fis[j]) !=
nullptr) {
1150 if (f.hasFlags(
"R") or f.hasFlags(
"F") or f.hasFlags(
"L"))
1151 fis[j]->deleteReferenceInfo();
1152 if (f.hasFlags(
"M"))
1153 fis[j]->deleteMeasurementInfo();
1157 fillPointsWithMeasurement();
1160 debugOut <<
"pruned Track: "; Print();
1166 void Track::Print(
const Option_t* option)
const
1168 TString opt = option;
1170 if (opt.Contains(
"C")) {
1173 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1175 int color = 32 * (size_t)(trackPoints_[i]) % 15;
1222 printOut << trackPoints_[i] <<
"\033[00m ";
1227 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1228 printf(
"% -9.3g ", trackPoints_[i]->getSortingParameter());
1231 for (std::vector<AbsTrackRep*>::const_iterator rep = trackReps_.begin(); rep != trackReps_.end(); ++rep) {
1233 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1234 if (! trackPoints_[i]->hasFitterInfo(*rep)) {
1238 AbsFitterInfo* fi = trackPoints_[i]->getFitterInfo(*rep);
1239 if (fi->hasMeasurements())
1244 if (fi->hasReferenceState())
1254 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1255 if (! trackPoints_[i]->hasFitterInfo(*rep)) {
1259 AbsFitterInfo* fi = trackPoints_[i]->getFitterInfo(*rep);
1260 if (fi->hasForwardPrediction())
1265 if (fi->hasForwardUpdate())
1275 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1276 if (! trackPoints_[i]->hasFitterInfo(*rep)) {
1280 AbsFitterInfo* fi = trackPoints_[i]->getFitterInfo(*rep);
1281 if (fi->hasBackwardPrediction())
1286 if (fi->hasBackwardUpdate())
1304 printOut <<
"=======================================================================================\n";
1305 printOut <<
"genfit::Track, containing " << trackPoints_.size() <<
" TrackPoints and " << trackReps_.size() <<
" TrackReps.\n";
1306 printOut <<
" Seed state: "; stateSeed_.Print();
1308 for (
unsigned int i = 0; i < trackReps_.size(); ++i) {
1310 if (i == cardinalRep_)
1311 printOut <<
" (This is the cardinal rep)";
1313 trackReps_[i]->Print();
1316 printOut <<
"---------------------------------------------------------------------------------------\n";
1318 for (
unsigned int i = 0; i < trackPoints_.size(); ++i) {
1319 printOut <<
"TrackPoint Nr. " << i <<
"\n";
1320 trackPoints_[i]->Print();
1321 printOut <<
"..........................................................................\n";
1324 for (std::map< const AbsTrackRep*, FitStatus* >::const_iterator it =
fitStatuses_.begin(); it !=
fitStatuses_.end(); ++it) {
1325 it->second->Print();
1328 printOut <<
"=======================================================================================\n";
1333 void Track::checkConsistency()
const
1337 bool consistent =
true;
1338 std::stringstream failures;
1340 std::map<const AbsTrackRep*, const KalmanFitterInfo*> prevFis;
1343 if (stateSeed_.GetNrows() != 6) {
1344 failures <<
"Track::checkConsistency(): stateSeed_ dimension != 6" << std::endl;
1349 if (covSeed_.GetNrows() != 6) {
1350 failures <<
"Track::checkConsistency(): covSeed_ dimension != 6" << std::endl;
1355 if (covSeed_.Max() == 0.) {
1358 failures <<
"Track::checkConsistency(): Warning: covSeed_ is zero" << std::endl;
1363 failures <<
"Track::checkConsistency(): Number of fitStatuses is != number of TrackReps " << std::endl;
1369 if (trackReps_.size() && cardinalRep_ >= trackReps_.size()) {
1370 failures <<
"Track::checkConsistency(): cardinalRep id " << cardinalRep_ <<
" out of bounds" << std::endl;
1375 for (std::vector<AbsTrackRep*>::const_iterator rep = trackReps_.begin(); rep != trackReps_.end(); ++rep) {
1377 if ((*rep) ==
nullptr) {
1378 failures <<
"Track::checkConsistency(): TrackRep is nullptr" << std::endl;
1384 TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle((*rep)->getPDG());
1385 if (particle ==
nullptr) {
1386 failures <<
"Track::checkConsistency(): TrackRep pdg ID " << (*rep)->getPDG() <<
" is not valid" << std::endl;
1393 failures <<
"Track::checkConsistency(): No FitStatus for Rep or FitStatus is nullptr" << std::endl;
1400 for (std::vector<TrackPoint*>::const_iterator tp = trackPoints_.begin(); tp != trackPoints_.end(); ++tp) {
1402 if ((*tp) ==
nullptr) {
1403 failures <<
"Track::checkConsistency(): TrackPoint is nullptr" << std::endl;
1408 if ((*tp)->getTrack() !=
this) {
1409 failures <<
"Track::checkConsistency(): TrackPoint does not point back to this track" << std::endl;
1415 const std::vector<AbsMeasurement*>& rawMeasurements = (*tp)->getRawMeasurements();
1416 for (std::vector<AbsMeasurement*>::const_iterator m = rawMeasurements.begin(); m != rawMeasurements.end(); ++m) {
1418 if ((*m) ==
nullptr) {
1419 failures <<
"Track::checkConsistency(): Measurement is nullptr" << std::endl;
1424 if ((*m)->getTrackPoint() != *tp) {
1425 failures <<
"Track::checkConsistency(): Measurement does not point back to correct TrackPoint" << std::endl;
1432 std::vector<AbsFitterInfo*> fitterInfos = (*tp)->getFitterInfos();
1433 for (std::vector<AbsFitterInfo*>::const_iterator fi = fitterInfos.begin(); fi != fitterInfos.end(); ++fi) {
1435 if ((*fi) ==
nullptr) {
1436 failures <<
"Track::checkConsistency(): FitterInfo is nullptr. TrackPoint: " << *tp << std::endl;
1443 for (std::vector<AbsTrackRep*>::const_iterator rep = trackReps_.begin(); rep != trackReps_.end(); ++rep) {
1444 if ((*rep) == (*fi)->getRep()) {
1449 failures <<
"Track::checkConsistency(): fitterInfo points to TrackRep which is not in Track" << std::endl;
1454 if (!((*fi)->checkConsistency(&(this->getFitStatus((*fi)->getRep())->getPruneFlags())))) {
1455 failures <<
"Track::checkConsistency(): FitterInfo not consistent. TrackPoint: " << *tp << std::endl;
1460 if (
dynamic_cast<KalmanFitterInfo*
>(*fi) !=
nullptr) {
1461 if (prevFis[(*fi)->getRep()] !=
nullptr &&
1462 static_cast<KalmanFitterInfo*
>(*fi)->hasReferenceState() &&
1463 prevFis[(*fi)->getRep()]->hasReferenceState()) {
1464 double len =
static_cast<KalmanFitterInfo*
>(*fi)->getReferenceState()->getForwardSegmentLength();
1465 double prevLen = prevFis[(*fi)->getRep()]->getReferenceState()->getBackwardSegmentLength();
1466 if (fabs(prevLen + len) > 1
E-10) {
1467 failures <<
"Track::checkConsistency(): segment lengths of reference states for rep " << (*fi)->getRep() <<
" (id " <<
getIdForRep((
1468 *fi)->getRep()) <<
") at TrackPoint " << (*tp) <<
" don't match" << std::endl;
1469 failures << prevLen <<
" + " << len <<
" = " << prevLen + len << std::endl;
1470 failures <<
"TrackPoint " << *tp <<
", FitterInfo " << *fi <<
", rep " <<
getIdForRep((*fi)->getRep()) << std::endl;
1476 prevFis[(*fi)->getRep()] =
static_cast<KalmanFitterInfo*
>(*fi);
1478 prevFis[(*fi)->getRep()] =
nullptr;
1486 std::vector<TrackPoint*> trackPointsWithMeasurement;
1488 for (std::vector<TrackPoint*>::const_iterator it = trackPoints_.begin(); it != trackPoints_.end(); ++it) {
1489 if ((*it)->hasRawMeasurements()) {
1490 trackPointsWithMeasurement.push_back(*it);
1494 if (trackPointsWithMeasurement.size() != trackPointsWithMeasurement_.size()) {
1495 failures <<
"Track::checkConsistency(): trackPointsWithMeasurement_ has incorrect size" << std::endl;
1500 for (
unsigned int i = 0; i < trackPointsWithMeasurement.size(); ++i) {
1501 if (trackPointsWithMeasurement[i] != trackPointsWithMeasurement_[i]) {
1502 failures <<
"Track::checkConsistency(): trackPointsWithMeasurement_ is not correct" << std::endl;
1503 failures <<
"has id " << i <<
", address " << trackPointsWithMeasurement_[i] << std::endl;
1504 failures <<
"should have id " << i <<
", address " << trackPointsWithMeasurement[i] << std::endl;
1510 if (not consistent) {
1516 void Track::trackHasChanged()
1520 debugOut <<
"Track::trackHasChanged \n";
1526 for (std::map< const AbsTrackRep*, FitStatus* >::const_iterator it =
fitStatuses_.begin(); it !=
fitStatuses_.end(); ++it) {
1527 it->second->setHasTrackChanged();
1532 void Track::fillPointsWithMeasurement()
1534 trackPointsWithMeasurement_.clear();
1535 trackPointsWithMeasurement_.reserve(trackPoints_.size());
1537 for (std::vector<TrackPoint*>::const_iterator it = trackPoints_.begin(); it != trackPoints_.end(); ++it) {
1538 if ((*it)->hasRawMeasurements()) {
1539 trackPointsWithMeasurement_.push_back(*it);
1545 void Track::Streamer(TBuffer& R__b)
1548 const bool streamTrackPoints =
true;
1550 typedef ::genfit::Track thisClass;
1552 if (R__b.IsReading()) {
1554 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
1556 TObject::Streamer(R__b);
1558 std::vector<AbsTrackRep*>& R__stl = trackReps_;
1562 Error(
"trackReps_ streamer",
"Missing the TClass object for genfit::AbsTrackRep!");
1567 R__stl.reserve(R__n);
1568 for (R__i = 0; R__i < R__n; R__i++) {
1571 R__stl.push_back(R__t);
1574 R__b >> cardinalRep_;
1575 if (streamTrackPoints) {
1576 std::vector<TrackPoint*>& R__stl = trackPoints_;
1580 Error(
"trackPoints_ streamer",
"Missing the TClass object for genfit::TrackPoint!");
1585 R__stl.reserve(R__n);
1586 for (R__i = 0; R__i < R__n; R__i++) {
1589 R__t->setTrack(
this);
1591 R__stl.push_back(R__t);
1595 std::map<const AbsTrackRep*, FitStatus*>& R__stl =
fitStatuses_;
1599 Error(
"fitStatuses_ streamer",
"Missing the TClass object for genfit::AbsTrackRep!");
1604 Error(
"fitStatuses_ streamer",
"Missing the TClass object for genfit::FitStatus!");
1609 for (R__i = 0; R__i < R__n; R__i++) {
1615 R__stl[this->getTrackRep(
id)] = R__t2;
1625 stateSeed_.Streamer(R__b);
1626 covSeed_.Streamer(R__b);
1627 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
1629 fillPointsWithMeasurement();
1631 R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
1632 TObject::Streamer(R__b);
1634 std::vector<AbsTrackRep*>& R__stl = trackReps_;
1635 int R__n = int(R__stl.size());
1640 Error(
"trackReps_ streamer",
"Missing the TClass object for genfit::AbsTrackRep!");
1643 std::vector<AbsTrackRep*>::iterator R__k;
1644 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1649 R__b << cardinalRep_;
1650 if (streamTrackPoints) {
1651 std::vector<TrackPoint*>& R__stl = trackPoints_;
1652 int R__n = int(R__stl.size());
1655 std::vector<TrackPoint*>::iterator R__k;
1656 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1662 std::map<const AbsTrackRep*, FitStatus*>& R__stl =
fitStatuses_;
1663 int R__n = int(R__stl.size());
1668 Error(
"fitStatuses_ streamer",
"Missing the TClass object for genfit::AbsTrackRep!");
1673 Error(
"fitStatuses_ streamer",
"Missing the TClass object for genfit::FitStatus!");
1676 std::map<const AbsTrackRep*, FitStatus*>::iterator R__k;
1677 for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
1680 R__b << ((*R__k).second);
1685 stateSeed_.Streamer(R__b);
1686 covSeed_.Streamer(R__b);
1687 R__b.SetByteCount(R__c, kTRUE);
1693 for (
size_t i = 0; i < trackPoints_.size(); ++i)
1694 delete trackPoints_[i];
1696 trackPoints_.clear();
1697 trackPointsWithMeasurement_.clear();
1699 for (std::map< const AbsTrackRep*, FitStatus* >::iterator it =
fitStatuses_.begin(); it !=
fitStatuses_.end(); ++it)
Contains the measurement and covariance in raw detector coordinates.
Abstract base class for a track representation.
virtual double getTime(const StateOnPlane &) const =0
Get the time corresponding to the StateOnPlane. Extrapolation.
bool switchPDGSign()
try to multiply pdg code with -1. (Switch from particle to anti-particle and vice versa).
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,...
Exception class for error handling in GENFIT (provides storage for diagnostic information)
void setFatal(bool b=true)
Set fatal flag.
Class where important numbers and properties of a fit can be stored.
FitStatus for use with AbsKalmanFitter implementations.
Collects information needed and produced by a AbsKalmanFitter implementations and is specific to one ...
#StateOnPlane with additional covariance matrix.
Factory object to create AbsMeasurement objects from digitized and clustered data.
std::vector< measurement_T * > createMany(const TrackCand &cand) const
Create a collection of Measurements.
Measurement class implementing a planar hit geometry (1 or 2D).
A state with arbitrary dimension defined in a DetPlane.
Hit object for use in TrackCand.
Track candidate – seed values and indices.
int getMcTrackId() const
Get the MCT track id, for MC simulations - default value = -1.
void setCovSeed(const TMatrixDSym &cov6D)
set the covariance matrix seed (6D).
void setMcTrackId(int i)
Set the MCT track id, for MC simulations.
const TMatrixDSym & getCovSeed() const
get the covariance matrix seed (6D).
const TVectorD & getStateSeed() const
Returns the 6D seed state; should be in global coordinates.
void setTime6DSeedAndPdgCode(double time, const TVectorD &state6D, const int pdgCode)
This function works the same as set6DSeed but instead of a charge hypothesis you can set a pdg code w...
double getTimeSeed() const
Get the time at which the seed state is defined.
Helper class for TrackPoint sorting, used in Track::sort().
Object containing AbsMeasurement and AbsFitterInfo objects.
AbsFitterInfo * getFitterInfo(const AbsTrackRep *rep=nullptr) const
Get fitterInfo for rep. Per default, use cardinal rep.
void fixupRepsForReading()
This function is used when reading the TrackPoint and is called by the owner in order to build fitter...
Collection of TrackPoint objects, AbsTrackRep objects and FitStatus objects.
void determineCardinalRep()
See with which AbsTrackRep the track was fitted best (converged fit w/ smallest chi2) and set the car...
bool sort()
Sort TrackPoint and according to their sorting parameters.
KalmanFitStatus * getKalmanFitStatus(const AbsTrackRep *rep=nullptr) const
If FitStatus is a KalmanFitStatus, return it. Otherwise return nullptr.
void deleteFittedState(const genfit::AbsTrackRep *rep)
Delete the fit status and all the FitStates of the TrackPoints for the given hypothesis.
double getTOF(AbsTrackRep *rep=nullptr, int startId=0, int endId=-1) const
get time of flight in ns between to trackPoints (if nullptr, for cardinal rep)
void insertPoints(std::vector< genfit::TrackPoint * > points, int id=-1)
Insert TrackPoints BEFORE TrackPoint with position id, if id >= 0.
TrackCand * constructTrackCand() const
Construct a new TrackCand containing the hit IDs of the measurements.
void insertPoint(TrackPoint *point, int id=-1)
Insert TrackPoint BEFORE TrackPoint with position id, if id >= 0.
bool udpateSeed(int id=0, AbsTrackRep *rep=nullptr, bool biased=true)
Try to set the fitted state as seed.
int mcTrackId_
if MC simulation, store the mc track id here
void fixWeights(AbsTrackRep *rep=nullptr, int startId=0, int endId=-1)
Helper function: For all KalmanFitterInfos belonging to rep (if nullptr, for all reps),...
bool hasFitStatus(const AbsTrackRep *rep=nullptr) const
Check if track has a FitStatus for given AbsTrackRep. Per default, check for cardinal rep.
double getTrackLen(AbsTrackRep *rep=nullptr, int startId=0, int endId=-1) const
get TrackLength between to trackPoints (if nullptr, for cardinal rep)
void reverseMomSeed()
Flip direction of momentum seed.
FitStatus * getFitStatus(const AbsTrackRep *rep=nullptr) const
Get FitStatus for a AbsTrackRep. Per default, return FitStatus for cardinalRep.
void insertMeasurement(AbsMeasurement *measurement, int id=-1)
Creates a new TrackPoint containing the measurement, and adds it to the track.
const MeasuredStateOnPlane & getFittedState(int id=0, const AbsTrackRep *rep=nullptr, bool biased=true) const
Shortcut to get FittedStates.
bool hasKalmanFitStatus(const AbsTrackRep *rep=nullptr) const
Check if track has a KalmanFitStatus for given AbsTrackRep. Per default, check for cardinal rep.
std::map< const AbsTrackRep *, FitStatus * > fitStatuses_
helper
void reverseTrackPoints()
Flip the ordering of the TrackPoints.
void prune(const Option_t *="CFLWRMIU")
Delete unneeded information from the Track.
void mergeTrack(const Track *other, int id=-1)
Merge two tracks.
void switchPDGSigns(AbsTrackRep *rep=nullptr)
Switch the pdg signs of specified rep (of all reps if rep == nullptr).
void deleteTrackPointsAndFitStatus()
Delete all measurement information and the track points of the track. Does not delete track represent...
void reverseTrack()
Make track ready to be fitted in reverse direction.
AbsTrackRep * getCardinalRep() const
Get cardinal track representation.
void deleteTrackRep(int id)
Delete a AbsTrackRep and all corresponding AbsFitterInfo objects in every TrackPoint.
int getIdForRep(const AbsTrackRep *rep) const
This is used when streaming TrackPoints.
Hit object for use in TrackCand.
Defines for I/O streams used for error and debug printing.
std::ostream debugOut
Default stream for debug output.
std::ostream printOut
Default stream for output of Print calls.
std::ostream errorOut
Default stream for error output.
Info which information has been pruned from the Track.