41std::unique_ptr<Trk::FitQuality> buildFitQuality(
45 Trk::GaussianSumFitter::GSFTrajectory::const_iterator stateOnSurface =
46 smoothedTrajectory.begin();
47 for (; stateOnSurface != smoothedTrajectory.end(); ++stateOnSurface) {
51 if (!stateOnSurface->fitQualityOnSurface) {
54 chiSquared += stateOnSurface->fitQualityOnSurface.chiSquared();
55 numberDoF += stateOnSurface->fitQualityOnSurface.numberDoF();
57 if (std::isnan(chiSquared) || chiSquared <= 0.) {
60 return std::make_unique<Trk::FitQuality>(chiSquared, numberDoF);
68 std::unique_ptr<Trk::MeasurementBase>&& measurement,
70 bool combineToSingle,
bool useMode) {
71 if (combineToSingle) {
73 updatedState, useMode);
74 if (combinedLastState) {
75 return {
fitQuality, std::move(measurement), std::move(combinedLastState),
76 std::move(updatedState)};
79 return {
fitQuality, std::move(measurement),
nullptr, std::move(updatedState)};
89 bool reintegrateOutliers) {
103 measurementSet.push_back(meas);
107 if (addMeasurementSet) {
108 for (
const auto* meas : *addMeasurementSet) {
109 measurementSet.push_back(meas);
112 return measurementSet;
122 bool reintegrateOutliers) {
148 prepRawDataSet.push_back(prepRawData);
151 if (addPrepRawDataSet) {
152 for (
const auto* prepRawData : *addPrepRawDataSet) {
153 prepRawDataSet.push_back(prepRawData);
156 return prepRawDataSet;
162 const std::string& name,
163 const IInterface* parent)
167 declareInterface<ITrackFitter>(
this);
177 return StatusCode::FAILURE;
192 return StatusCode::SUCCESS;
199std::unique_ptr<Trk::Track>
201 const EventContext& ctx,
226 return fit(ctx, measurementSet, *paramNearestRef, outlierRemoval,
232 return fit(ctx, prepRawDataSet, *paramNearestRef, outlierRemoval,
239std::unique_ptr<Trk::Track>
262 return fit(ctx, prepRawDataSet, *paramNearestRef, runOutlier, matEffects);
268std::unique_ptr<Trk::Track>
270 const Track& inputTrack,
277 ATH_MSG_FATAL(
"No estimation of track parameters near origin!");
283 "Attempting to fit track to empty MeasurementBase "
294 return fit(ctx, measurementSet, *paramNearestRef, runOutlier, matEffects);
302 const EventContext& ctx,
311 "called to refit empty track or track with too little "
312 "information, reject fit");
317 "input #1 fails to provide track parameters for "
318 "seeding the GXF, reject fit");
329 for (
const auto* meas : measurementSet2) {
330 measurementSet1.push_back(meas);
333 return fit(ctx, measurementSet1, *minPar, runOutlier, matEffects);
340std::unique_ptr<Trk::Track>
342 const EventContext& ctx,
348 if (prepRawDataSet.size() < 3) {
349 ATH_MSG_WARNING(
"Requesting Fit with less than three prep Raw Data!!!");
356 estimatedParametersNearOrigin.
position(),
357 estimatedParametersNearOrigin.
momentum());
359 std::sort(sortedPrepRawDataSet.begin(), sortedPrepRawDataSet.end(),
360 prdComparisonFunction);
366 forwardFit(ctx, extrapolatorCache, sortedPrepRawDataSet,
367 estimatedParametersNearOrigin);
369 if (forwardTrajectory.empty()) {
374 ctx, extrapolatorCache, forwardTrajectory);
375 if (smoothedTrajectory.empty()) {
380 std::unique_ptr<FitQuality> fitQuality = buildFitQuality(smoothedTrajectory);
387 ctx, extrapolatorCache, smoothedTrajectory);
388 if (!perigeeMultiStateOnSurface.multiComponentState.empty()) {
389 smoothedTrajectory.push_back(std::move(perigeeMultiStateOnSurface));
396 std::reverse(smoothedTrajectory.begin(), smoothedTrajectory.end());
403 std::move(fitQuality));
410std::unique_ptr<Trk::Track>
412 const EventContext& ctx,
418 if (measurementSet.size() < 3) {
427 cleanedMeasurementSet.reserve(measurementSet.size());
429 for (
const auto* meas : measurementSet) {
437 cleanedMeasurementSet.push_back(meas);
446 measurementBaseComparisonFunction(
447 estimatedParametersNearOrigin.
position(),
448 estimatedParametersNearOrigin.
momentum());
449 sort(sortedMeasurementSet.begin(), sortedMeasurementSet.end(),
450 measurementBaseComparisonFunction);
457 forwardFit(ctx, extrapolatorCache, sortedMeasurementSet,
458 estimatedParametersNearOrigin);
460 if (forwardTrajectory.empty()) {
466 ctx, extrapolatorCache, forwardTrajectory, ccot);
467 if (smoothedTrajectory.empty()) {
472 std::unique_ptr<FitQuality> fitQuality = buildFitQuality(smoothedTrajectory);
479 ctx, extrapolatorCache, smoothedTrajectory);
480 if (!perigeeMultiStateOnSurface.multiComponentState.empty()) {
481 smoothedTrajectory.push_back(std::move(perigeeMultiStateOnSurface));
487 std::reverse(smoothedTrajectory.begin(), smoothedTrajectory.end());
494 std::move(fitQuality));
503 auto MTSOS = std::make_unique<MultiComponentStateOnSurfaceDV>();
504 MTSOS->reserve(trajectory.size());
505 for (
GSFTsos& state : trajectory) {
506 MTSOS->push_back(state.convert(slimTransientMTSOS));
516 const EventContext& ctx,
524 multiComponentStateOnSurfaceNearestOrigin = smoothedTrajectory.back();
533 *multiComponentState,
538 if (stateExtrapolatedToPerigee.empty()) {
543 std::unique_ptr<Trk::TrackParameters> combinedPerigee =
547 std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
551 if(std::abs(combinedPerigee->position().z())>5000.) {
552 ATH_MSG_WARNING(
"Pathological perigee well outside of tracking detector!! Returning {}");
556 if (std::abs(combinedPerigee->parameters()[
Trk::qOverP]) > 1e8) {
558 "makePerigee() about to return with 0 momentum!! Returning {}");
564 std::move(combinedPerigee),
565 std::move(stateExtrapolatedToPerigee),
586 const EventContext& ctx,
591 if (forwardTrajectory.empty()) {
593 "Attempting to smooth an empty forward trajectory... Exiting!");
598 smoothedTrajectory.reserve(forwardTrajectory.size());
602 auto trackStateOnSurfaceItr = forwardTrajectory.rbegin();
603 bool foundMeasurement =
false;
604 for (; trackStateOnSurfaceItr != forwardTrajectory.rend(); ++trackStateOnSurfaceItr) {
606 smoothedTrajectory.emplace_back(std::move(*trackStateOnSurfaceItr));
608 foundMeasurement =
true;
612 if(!foundMeasurement){
617 auto smootherPredictionMultiState = std::move(trackStateOnSurfaceItr->multiComponentState);
620 std::unique_ptr<Trk::MeasurementBase> firstSmootherMeasurementOnTrack =
621 std::move(trackStateOnSurfaceItr->measurementOnTrack);
622 if (!firstSmootherMeasurementOnTrack) {
624 "Initial state on surface in smoother does not have an associated "
625 "MeasurementBase object");
631 *firstSmootherMeasurementOnTrack,
633 if (firstSmoothedState.empty()) {
638 "Not all components have covariance. Rejecting smoothed state.");
644 std::unique_ptr<Trk::TrackParameters> combinedFirstSmoothedState =
647 smoothedTrajectory.emplace_back(
648 fitQuality, std::move(firstSmootherMeasurementOnTrack),
649 std::move(combinedFirstSmoothedState),
651 const auto& updatedFirstStateOnSurface = smoothedTrajectory.back();
668 std::move(smoothedStateWithScaledError),
669 *(updatedFirstStateOnSurface.measurementOnTrack),
670 fitQualityWithScaledErrors);
671 if (updatedState.empty()) {
678 ++trackStateOnSurfaceItr;
680 auto lasttrackStateOnSurface = forwardTrajectory.rend() - 1;
682 auto secondLastTrackStateOnSurface = forwardTrajectory.rend() - 2;
684 for (; trackStateOnSurfaceItr != forwardTrajectory.rend();++trackStateOnSurfaceItr) {
685 auto& trackStateOnSurface = (*trackStateOnSurfaceItr);
687 auto measurement = std::move(trackStateOnSurface.measurementOnTrack);
689 ATH_MSG_WARNING(
"MeasurementBase object could not be extracted from a "
690 "measurement TSOS...continuing");
697 ctx, extrapolatorCache, (*loopUpdatedState),
700 if (extrapolatedState.empty()) {
705 std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes>
type(
709 std::move(measurement),
nullptr,
710 std::move(extrapolatedState),
type);
711 loopUpdatedState = &(smoothedTrajectory.back().multiComponentState);
716 std::move(extrapolatedState), *measurement, fitQuality);
717 if (updatedState.empty()) {
722 const bool islast = (trackStateOnSurfaceItr == lasttrackStateOnSurface);
726 trackStateOnSurface.multiComponentState;
730 if (combinedfitterState.empty()) {
732 "Could not combine state from forward fit with "
737 combinedfitterState, *measurement);
738 smoothedTrajectory.emplace_back(
739 smootherHelper(std::move(combinedfitterState), std::move(measurement),
743 smoothedTrajectory.emplace_back(
744 smootherHelper(std::move(updatedState), std::move(measurement),
748 if (ccot && trackStateOnSurfaceItr == secondLastTrackStateOnSurface) {
749 if (!
addCCOT(ctx, ccot, smoothedTrajectory)) {
755 loopUpdatedState = &(smoothedTrajectory.back().multiComponentState);
757 return smoothedTrajectory;
766 const EventContext& ctx,
770 const GSFTsos& currentMultiStateOS = smoothedTrajectory.back();
785 ctx, currentMultiComponentState, ownCCOT->associatedSurface(),
788 if (extrapolatedToCaloState.empty()) {
795 *ownCCOT, fitQuality);
796 if (updatedStateAtCalo.empty()) {
805 if (improvedState.empty()) {
810 std::unique_ptr<Trk::TrackParameters> combinedSingleState =
816 covMatrix(0, 0) = 1e6;
820 std::move(locpars), std::move(covMatrix), currentSurface);
823 smoothedTrajectory.emplace_back(
827 std::move(updatedStateAtCalo));
830 smoothedTrajectory.emplace_back(
835 std::move(combinedSingleState),
836 std::move(improvedState));
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define AmgSymMatrix(dim)
Class for fitting according to the Gaussian Sum Filter Formalism Implements Algorithm C described in ...
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Class to handle Cluster On Tracks (ROT) for CaloClusters, it inherits from the common MeasurementBase...
std::unique_ptr< CaloCluster_OnTrack > uniqueClone() const
NVI Clone giving up unique pointer.
GSFTrajectory forwardFit(const EventContext &ctx, IMultiStateExtrapolator::Cache &cache, const T &inputSet, const TrackParameters &estimatedTrackParametersNearOrigin) const
Forward GSF fit.
std::unique_ptr< MultiComponentStateOnSurfaceDV > convertTrajToTrack(GSFTrajectory &trajectory) const
Helper to convert the GSFTrajectory to a Trk::Track.
ToolHandle< IMultiStateExtrapolator > m_extrapolator
Trk::ParticleHypothesis m_particleHypothesis
GSFTrajectory smootherFit(const EventContext &ctx, Trk::IMultiStateExtrapolator::Cache &, GSFTrajectory &forwardTrajectory, const CaloCluster_OnTrack *ccot=nullptr) const
Gsf smoothed trajectory.
GaussianSumFitter(const std::string &, const std::string &, const IInterface *)
Constructor with parameters to be passed to AlgTool.
bool addCCOT(const EventContext &ctx, const Trk::CaloCluster_OnTrack *ccot, GSFTrajectory &smoothedTrajectory) const
Methof to add the CaloCluster onto the track.
Gaudi::Property< bool > m_refitOnMeasurementBase
ToolHandle< IRIO_OnTrackCreator > m_rioOnTrackCreator
virtual StatusCode initialize() override final
AlgTool initialise method.
Gaudi::Property< unsigned int > m_maximumNumberOfComponents
GSFTsos makePerigee(const EventContext &ctx, Trk::IMultiStateExtrapolator::Cache &, const GSFTrajectory &smoothedTrajectory) const
Produces a perigee from a smoothed trajectory.
Gaudi::Property< bool > m_useMode
TrkParametersComparisonFunction m_trkParametersComparisonFunction
std::vector< GSFTsos > GSFTrajectory
DoubleArrayProperty m_smootherCovFactors
virtual std::unique_ptr< Track > fit(const EventContext &ctx, const PrepRawDataSet &, const TrackParameters &, const RunOutlierRemoval, const ParticleHypothesis) const override final
Fit a collection of 'PrepRawData' objects using the Gaussian Sum Filter.
Gaudi::Property< bool > m_slimTransientMTSOS
Gaudi::Property< bool > m_reintegrateOutliers
Gaudi::Property< bool > m_combineWithFitter
Class implementing a comparison function for sorting MeasurementBase objects.
This class is the pure abstract base class for all fittable tracking measurements.
virtual const Surface & associatedSurface() const =0
Interface method to get the associated Surface.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
const Amg::Vector3D & momentum() const
Access method for the momentum.
const Amg::Vector3D & position() const
Access method for the position.
Class describing the Line to which the Perigee refers to.
Class providing comparison function, or relational definition, for PrepRawData.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Abstract Base Class for tracking surfaces.
Contains information about the 'fitter' of this track.
@ GaussianSumFilter
Tracks from Gaussian Sum Filter.
@ BremFit
A brem fit was performed on this track.
@ BremFitSuccessful
A brem fit was performed on this track and this fit was successful.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const DataVector< const TrackParameters > * trackParameters() const
Return a pointer to a vector of TrackParameters.
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr int8_t maxNumberofStateComponents
The state is described by N Gaussian components The Beth Heitler Material effect are also described b...
float chiSquared(const U &p)
FitQualityOnSurface fitQuality(const MultiComponentState &, const MeasurementBase &)
Method for determining the chi2 of the multi-component state and the number of degrees of freedom.
MultiComponentState update(Trk::MultiComponentState &&, const Trk::MeasurementBase &, FitQualityOnSurface &fitQoS)
Method for updating the multi-state with a new measurement and calculate the fit qaulity at the same ...
std::unique_ptr< Trk::TrackParameters > combineToSingle(const MultiComponentState &, const bool useMode=false)
@bried Calculate combined state of many components
MultiComponentState WithScaledError(MultiComponentState &&in, double errorScaleLocX, double errorScaleLocY, double errorScalePhi, double errorScaleTheta, double errorScaleQoverP)
Scale the covariance matrix components by individual factors.
bool allHaveCovariance(const MultiComponentState &in)
Check to see if all components have covariance Matrix.
MultiComponentState clone(const MultiComponentState &in)
Clone TrackParameters method.
Trk::MultiComponentState combine(const Trk::MultiComponentState &forwardsMultiState, const Trk::MultiComponentState &smootherMultiState, unsigned int maximumNumberOfComponents)
Helper to combine forward with smoother MultiComponentStates.
std::vector< const MeasurementBase * > MeasurementSet
vector of fittable measurements
std::vector< ComponentParameters > MultiComponentState
ComparisonFunction< TrackParameters > TrkParametersComparisonFunction
bool RunOutlierRemoval
switch to toggle quality processing after fit
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters
std::vector< const PrepRawData * > PrepRawDataSet
vector of clusters and drift circles
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
void reverse(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of reverse for DataVector/List.
Trk::MultiComponentState multiComponentState
std::unique_ptr< Trk::MeasurementBase > measurementOnTrack