37 std::unique_ptr<Trk::FitQuality>
47 Trk::GaussianSumFitter::GSFTrajectory::const_iterator stateOnSurface =
48 smoothedTrajectory.begin();
49 for (; stateOnSurface != smoothedTrajectory.end(); ++stateOnSurface) {
53 if (!stateOnSurface->fitQualityOnSurface) {
56 chiSquared += stateOnSurface->fitQualityOnSurface.chiSquared();
57 numberDoF += stateOnSurface->fitQualityOnSurface.numberDoF();
62 return std::make_unique<Trk::FitQuality>(
chiSquared, numberDoF);
72 std::unique_ptr<Trk::MeasurementBase>&& measurement,
80 updatedState, useMode);
81 if (combinedLastState) {
82 return {
fitQuality, std::move(measurement), std::move(combinedLastState),
83 std::move(updatedState)};
86 return {
fitQuality, std::move(measurement),
nullptr, std::move(updatedState)};
92 const std::string&
name,
96 , m_trkParametersComparisonFunction{}
97 , m_sortingReferencePoint{ 0, 0, 0 }
99 declareInterface<ITrackFitter>(
this);
100 declareProperty(
"SortingReferencePoint", m_sortingReferencePoint);
110 return StatusCode::FAILURE;
118 if (!m_refitOnMeasurementBase) {
119 ATH_CHECK(m_rioOnTrackCreator.retrieve());
121 m_rioOnTrackCreator.disable();
125 m_sortingReferencePoint[1],
126 m_sortingReferencePoint[2]);
128 m_trkParametersComparisonFunction =
131 return StatusCode::SUCCESS;
140 std::unique_ptr<Trk::Track>
142 const EventContext& ctx,
161 m_trkParametersComparisonFunction));
166 if (m_refitOnMeasurementBase) {
180 measurementSet.push_back(meas);
181 }
else if (m_reintegrateOutliers &&
183 measurementSet.push_back(meas);
190 *parametersNearestReference,
216 prepRawDataSet.push_back(prepRawData);
221 *parametersNearestReference,
230 std::unique_ptr<Trk::Track>
232 const EventContext& ctx,
240 if (prepRawDataSet.empty()) {
249 estimatedParametersNearOrigin.
position(),
250 estimatedParametersNearOrigin.
momentum());
252 std::sort(sortedPrepRawDataSet.begin(),
253 sortedPrepRawDataSet.end(),
254 prdComparisonFunction);
260 forwardPRDfit(ctx, extrapolatorCache, sortedPrepRawDataSet,
261 estimatedParametersNearOrigin, particleHypothesis);
263 if (forwardTrajectory.empty()) {
268 smootherFit(ctx, extrapolatorCache, forwardTrajectory, particleHypothesis);
269 if (smoothedTrajectory.empty()) {
274 std::unique_ptr<FitQuality>
fitQuality = buildFitQuality(smoothedTrajectory);
280 auto perigeeMultiStateOnSurface =
281 makePerigee(ctx, extrapolatorCache, smoothedTrajectory, particleHypothesis);
282 if (!perigeeMultiStateOnSurface.multiComponentState.empty()) {
283 smoothedTrajectory.push_back(std::move(perigeeMultiStateOnSurface));
290 std::reverse(smoothedTrajectory.begin(), smoothedTrajectory.end());
296 return std::make_unique<Track>(
297 info, convertTrajToTrack(smoothedTrajectory),
305 std::unique_ptr<Trk::Track>
307 const EventContext& ctx,
315 if (measurementSet.empty()) {
325 cleanedMeasurementSet.reserve(measurementSet.size());
327 for (
const auto* meas : measurementSet) {
330 "There is an empty MeasurementBase object in the track! ");
336 cleanedMeasurementSet.push_back(meas);
345 estimatedParametersNearOrigin.
position(),
346 estimatedParametersNearOrigin.
momentum());
347 sort(sortedMeasurementSet.begin(),
348 sortedMeasurementSet.end(),
349 measurementBaseComparisonFunction);
356 forwardMeasurementFit(ctx, extrapolatorCache, sortedMeasurementSet,
357 estimatedParametersNearOrigin, particleHypothesis);
359 if (forwardTrajectory.empty()) {
365 ctx, extrapolatorCache, forwardTrajectory, particleHypothesis, ccot);
366 if (smoothedTrajectory.empty()) {
371 std::unique_ptr<FitQuality>
fitQuality = buildFitQuality(smoothedTrajectory);
377 auto perigeeMultiStateOnSurface =
378 makePerigee(ctx, extrapolatorCache, smoothedTrajectory, particleHypothesis);
379 if (!perigeeMultiStateOnSurface.multiComponentState.empty()) {
380 smoothedTrajectory.push_back(std::move(perigeeMultiStateOnSurface));
386 std::reverse(smoothedTrajectory.begin(), smoothedTrajectory.end());
392 return std::make_unique<Track>(
393 info, convertTrajToTrack(smoothedTrajectory),
401 std::unique_ptr<Trk::Track>
409 if (addPrdColl.empty()) {
411 "client tries to add an empty PrepRawDataSet to the track fit.");
412 return fit(ctx, intrk, runOutlier, matEffects);
418 m_trkParametersComparisonFunction));
422 intrk, addPrdColl,
false,
true);
425 return fit(ctx, PRDColl, *estimatedStartParameters, runOutlier, matEffects);
432 std::unique_ptr<Trk::Track>
434 const Track& inputTrack,
441 if (measurementSet.empty()) {
443 "Client tries to add an empty MeasurementSet to the track fit.");
444 return fit(ctx, inputTrack, runOutlier, matEffects);
448 ATH_MSG_FATAL(
"No estimation of track parameters near origin!");
453 ATH_MSG_FATAL(
"Attempting to fit track to empty MeasurementBase "
461 m_trkParametersComparisonFunction));
464 inputTrack, measurementSet);
468 ctx, combinedMS, *parametersNearestReference, runOutlier, matEffects);
475 std::unique_ptr<Trk::Track>
486 ATH_MSG_WARNING(
"called to refit empty track or track with too little "
487 "information, reject fit");
492 "seeding the GXF, reject fit");
504 if (tsos->measurementOnTrack()->type(
509 ms.push_back(tsos->measurementOnTrack());
519 if (tsos->measurementOnTrack()->type(
523 ms.push_back(tsos->measurementOnTrack());
526 return fit(ctx,
ms, *minPar, runOutlier, matEffects);
532 bool slimTransientMTSOS = m_slimTransientMTSOS;
533 auto MTSOS = std::make_unique<MultiComponentStateOnSurfaceDV>();
534 MTSOS->reserve(trajectory.size());
535 for (
GSFTsos& state : trajectory) {
536 MTSOS->push_back(state.convert(slimTransientMTSOS));
547 const EventContext& ctx,
556 multiComponentStateOnSurfaceNearestOrigin = smoothedTrajectory.back();
563 m_extrapolator->extrapolate(ctx,
565 *multiComponentState,
567 m_directionToPerigee,
571 if (stateExtrapolatedToPerigee.empty()) {
576 std::unique_ptr<Trk::TrackParameters> combinedPerigee =
580 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
584 if(std::abs(combinedPerigee->
position().z())>5000.) {
585 ATH_MSG_WARNING(
"Pathological perigee well outside of tracking detector!! Returning {}");
589 if (std::abs(combinedPerigee->parameters()[
Trk::qOverP]) > 1e8) {
591 "makePerigee() about to return with 0 momentum!! Returning {}");
597 std::move(combinedPerigee),
598 std::move(stateExtrapolatedToPerigee),
608 const EventContext& ctx,
618 for (
const auto* rawData : inputPrepRawDataSet) {
619 if (!(rawData->detectorElement())) {
622 prepRawDataSet.push_back(rawData);
627 const AmgVector(5)&
par = estimatedTrackParametersNearOrigin.parameters();
639 multiComponentStateNearOrigin.push_back(
640 std::move(componentParametersNearOrigin));
644 forwardTrajectory.reserve(prepRawDataSet.size());
645 for (
const auto* prepRawData : prepRawDataSet) {
647 bool stepIsValid = stepForwardFit(
653 prepRawData->detectorElement()->surface(prepRawData->identify()),
654 multiComponentStateNearOrigin,
661 return forwardTrajectory;
670 const EventContext& ctx,
677 if (inputMeasurementSet.empty()) {
678 ATH_MSG_ERROR(
"forwardMeasurementFit: Input MeasurementSet is empty!");
683 const AmgVector(5)&
par = estimatedTrackParametersNearOrigin.parameters();
694 multiComponentStateNearOrigin.push_back(
695 std::move(componentParametersNearOrigin));
698 forwardTrajectory.reserve(inputMeasurementSet.size());
699 for (
const auto* measurement : inputMeasurementSet) {
701 bool stepIsValid = stepForwardFit(ctx,
706 measurement->associatedSurface(),
707 multiComponentStateNearOrigin,
714 return forwardTrajectory;
723 const EventContext& ctx,
733 if (!originalPrepRawData && !originalMeasurement) {
739 if (!originalMeasurement && m_refitOnMeasurementBase) {
740 ATH_MSG_WARNING(
"No measurement base information passed to StepForwardFit");
747 m_extrapolator->extrapolate(ctx,
754 if (extrapolatedState.empty()) {
760 std::unique_ptr<Trk::MeasurementBase> measurement =
nullptr;
761 if (originalMeasurement) {
762 measurement.reset(originalMeasurement->
clone());
764 std::unique_ptr<Trk::TrackParameters> combinedState =
766 if (!combinedState) {
772 m_rioOnTrackCreator->correct(*originalPrepRawData, *combinedState, ctx));
773 combinedState.reset();
788 if (updatedState.empty()) {
798 std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
type(0);
800 forwardTrajectory.emplace_back(
802 std::move(measurement),
809 updatedState = std::move(extrapolatedState);
812 std::move(measurement),
814 std::move(extrapolatedState));
825 const EventContext& ctx,
831 if (forwardTrajectory.empty()) {
833 "Attempting to smooth an empty forward trajectory... Exiting!");
838 smoothedTrajectory.reserve(forwardTrajectory.size());
842 GSFTrajectory::reverse_iterator trackStateOnSurfaceItr =
843 forwardTrajectory.rbegin();
844 bool foundMeasurement =
false;
845 for (; trackStateOnSurfaceItr != forwardTrajectory.rend();
846 ++trackStateOnSurfaceItr) {
848 smoothedTrajectory.emplace_back(std::move(*trackStateOnSurfaceItr));
850 foundMeasurement =
true;
855 if(!foundMeasurement){
861 std::move(trackStateOnSurfaceItr->multiComponentState);
864 std::unique_ptr<Trk::MeasurementBase> firstSmootherMeasurementOnTrack =
865 std::move(trackStateOnSurfaceItr->measurementOnTrack);
866 if (!firstSmootherMeasurementOnTrack) {
868 "Initial state on surface in smoother does not have an associated "
869 "MeasurementBase object");
875 *firstSmootherMeasurementOnTrack,
877 if (firstSmoothedState.empty()) {
883 "Not all components have covariance. Rejecting smoothed state.");
888 std::unique_ptr<Trk::TrackParameters> combinedFirstSmoothedState =
890 smoothedTrajectory.emplace_back(
891 fitQuality, std::move(firstSmootherMeasurementOnTrack),
892 std::move(combinedFirstSmoothedState),
894 const auto& updatedFirstStateOnSurface = smoothedTrajectory.back();
898 ++trackStateOnSurfaceItr;
900 auto lasttrackStateOnSurface = forwardTrajectory.rend() - 1;
902 auto secondLastTrackStateOnSurface = forwardTrajectory.rend() - 2;
909 std::move(firstSmoothedState), 15., 5., 15., 5., 15.);
912 std::move(smoothedStateWithScaledError),
913 *(updatedFirstStateOnSurface.measurementOnTrack),
914 fitQualityWithScaledErrors);
915 if (updatedState.empty()) {
925 for (; trackStateOnSurfaceItr != forwardTrajectory.rend();
926 ++trackStateOnSurfaceItr) {
927 auto& trackStateOnSurface = (*trackStateOnSurfaceItr);
929 std::unique_ptr<Trk::MeasurementBase> measurement =
930 std::move(trackStateOnSurface.measurementOnTrack);
932 ATH_MSG_WARNING(
"MeasurementBase object could not be extracted from a "
933 "measurement TSOS... continuing");
940 m_extrapolator->extrapolate(ctx,
948 if (extrapolatedState.empty()) {
953 std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
type(
956 smoothedTrajectory.emplace_back(
958 std::move(measurement),
960 std::move(extrapolatedState),
962 loopUpdatedState = &(smoothedTrajectory.back().multiComponentState);
967 std::move(extrapolatedState), *measurement,
fitQuality);
968 if (updatedState.empty()) {
970 "Could not update the multi-component state... rejecting track!");
974 bool islast = (trackStateOnSurfaceItr == lasttrackStateOnSurface);
975 if (m_combineWithFitter) {
980 trackStateOnSurface.multiComponentState;
983 forwardsMultiState, updatedState, m_maximumNumberOfComponents);
985 if (combinedfitterState.empty()) {
991 combinedfitterState, *measurement);
992 smoothedTrajectory.emplace_back(
993 smootherHelper(std::move(combinedfitterState), std::move(measurement),
994 combinedFitQuality, islast, m_useMode));
997 smoothedTrajectory.emplace_back(
998 smootherHelper(std::move(updatedState), std::move(measurement),
1003 loopUpdatedState = &(smoothedTrajectory.back().multiComponentState);
1005 if (ccot && trackStateOnSurfaceItr == secondLastTrackStateOnSurface) {
1007 addCCOT(ctx, ccot, smoothedTrajectory);
1008 if (!ccotState.empty()) {
1009 (*loopUpdatedState) = std::move(ccotState);
1014 return smoothedTrajectory;
1023 const EventContext& ctx,
1027 const GSFTsos& currentMultiStateOS = smoothedTrajectory.back();
1039 if (currentSurface) {
1041 m_extrapolator->extrapolateDirectly(ctx,
1042 currentMultiComponentState,
1048 if (extrapolatedState.empty()) {
1054 std::move(extrapolatedState), *ccot,
fitQuality);
1055 if (updatedState.empty()) {
1060 extrapolatedState = m_extrapolator->extrapolateDirectly(ctx,
1066 if (extrapolatedState.empty()) {
1072 smoothedTrajectory.emplace_back(
1074 std::unique_ptr<Trk::CaloCluster_OnTrack>(ccot->
clone()),
1076 std::move(updatedState));
1091 std::move(locpars), std::move(
covMatrix), *currentSurface);
1094 std::unique_ptr<Trk::TrackParameters> combinedState =
1096 auto combinedFitQuality =
1100 smoothedTrajectory.emplace_back(
1103 std::move(combinedState),
1106 return extrapolatedState;