diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h index f09fe123478b76620f6e5eab53417eabc2bd35c9..280e4b06008dc067728ec891120d9f78b612e80f 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** @@ -210,8 +210,6 @@ private: "Combine with forwards state during Smoothing" }; - // Measurement updator - GsfMeasurementUpdator m_updator; PropDirection m_directionToPerigee; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx index ec0fe8e53bf7eb1e0f97c4966154a4ba47d262bf..06c7666fd726c46865a6c5b37c5915a2ef191d6d 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** @@ -64,7 +64,6 @@ Trk::GaussianSumFitter::GaussianSumFitter(const std::string& type, const std::string& name, const IInterface* parent) : AthAlgTool(type, name, parent) - , m_updator{} , m_directionToPerigee(Trk::oppositeMomentum) , m_trkParametersComparisonFunction{} , m_inputPreparator(nullptr) @@ -932,7 +931,7 @@ Trk::GaussianSumFitter::stepForwardFit( // Here we need to clone as the extrapolated state can be used // afterwards updatedState = - m_updator.update(MultiComponentStateHelpers::clone(extrapolatedState), + Trk::GsfMeasurementUpdator::update(MultiComponentStateHelpers::clone(extrapolatedState), *measurement, *fitQuality); if (updatedState.empty()) { @@ -1055,7 +1054,7 @@ Trk::GaussianSumFitter::fit( return Trk::SmoothedTrajectory(); } Trk::MultiComponentState firstSmoothedState = - m_updator.update(std::move(smootherPredictionMultiState), + Trk::GsfMeasurementUpdator::update(std::move(smootherPredictionMultiState), *firstSmootherMeasurementOnTrack, fitQuality); @@ -1098,7 +1097,7 @@ Trk::GaussianSumFitter::fit( // Perform a measurement update on this new state before loop Trk::MultiComponentState updatedState = - m_updator.update(std::move(smoothedStateWithScaledError), + Trk::GsfMeasurementUpdator::update(std::move(smoothedStateWithScaledError), *(updatedFirstStateOnSurface->measurementOnTrack())); if (updatedState.empty()) { @@ -1179,7 +1178,7 @@ Trk::GaussianSumFitter::fit( } (*loopUpdatedState) = - m_updator.update(std::move(extrapolatedState), *measurement, fitQuality); + Trk::GsfMeasurementUpdator::update(std::move(extrapolatedState), *measurement, fitQuality); if (loopUpdatedState->empty()) { ATH_MSG_WARNING( "Could not update the multi-component state... rejecting track!"); @@ -1222,7 +1221,7 @@ Trk::GaussianSumFitter::fit( return Trk::SmoothedTrajectory(); } auto combinedFitQuality = std::make_unique<Trk::FitQualityOnSurface>( - m_updator.fitQuality(combinedState2, *measurement)); + Trk::GsfMeasurementUpdator::fitQuality(combinedState2, *measurement)); // In the case of combination with forwards state - push back the combined // state Trk::MultiComponentStateOnSurface* combinedStateOnSurface = @@ -1427,7 +1426,7 @@ Trk::GaussianSumFitter::addCCOT( // Update newly extrapolated state with MeasurementBase measurement Trk::FitQualityOnSurface fitQuality; Trk::MultiComponentState updatedState = - m_updator.update(std::move(extrapolatedState), *ccot, fitQuality); + Trk::GsfMeasurementUpdator::update(std::move(extrapolatedState), *ccot, fitQuality); if (updatedState.empty()) { return {}; @@ -1472,7 +1471,7 @@ Trk::GaussianSumFitter::addCCOT( std::unique_ptr<Trk::TrackParameters> combinedState = MultiComponentStateCombiner::combine(extrapolatedState, true); auto combinedFitQuality = std::make_unique<Trk::FitQualityOnSurface>( - m_updator.fitQuality(extrapolatedState, *ccot)); + Trk::GsfMeasurementUpdator::fitQuality(extrapolatedState, *ccot)); // Build a TSOS using the dummy measurement and combined state auto finalSOS = std::make_unique<Trk::MultiComponentStateOnSurface>( diff --git a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/GsfMeasurementUpdator.h b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/GsfMeasurementUpdator.h index 113ca39a147c5825b2f5f405bfccd633a534268a..62182b01b2a872a744dfc95cc5a1dae2b468ca84 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/GsfMeasurementUpdator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/GsfMeasurementUpdator.h @@ -1,12 +1,12 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** * @file GsfMeasurementUpdator.h * @date Friday 25th February 2005 * @author Tom Athkinson, Anthony Morley, Christos Anastopoulos - * @brief Class for performing updates on multi-component states for the + * @brief Cde for performing updates on multi-component states for the * gaussian-sum filter. */ @@ -22,38 +22,24 @@ namespace Trk { -class GsfMeasurementUpdator -{ -public: - /** Method for updating the multi-state with a new measurement */ - MultiComponentState update(MultiComponentState&&, const MeasurementBase&) - const; - - /** Method for updating the multi-state with a new measurement and calculate - * the fit qaulity at the same time*/ - MultiComponentState update( - Trk::MultiComponentState&&, - const Trk::MeasurementBase&, - FitQualityOnSurface& fitQoS) const; - - /** Method for determining the chi2 of the multi-component state and the - * number of degrees of freedom */ - FitQualityOnSurface fitQuality( - const MultiComponentState&, - const MeasurementBase&) const; - -private: - MultiComponentState calculateFilterStep( - MultiComponentState&&, - const MeasurementBase&, - int addRemoveFlag) const; - - MultiComponentState calculateFilterStep( - MultiComponentState&&, - const MeasurementBase&, - FitQualityOnSurface& fitQoS) const; - -}; -} +namespace GsfMeasurementUpdator { +/** @brief Method for updating the multi-state with a new measurement */ +MultiComponentState +update(MultiComponentState&&, const MeasurementBase&); + +/** @brief Method for updating the multi-state with a new measurement and + * calculate the fit qaulity at the same time*/ +MultiComponentState +update(Trk::MultiComponentState&&, + const Trk::MeasurementBase&, + FitQualityOnSurface& fitQoS); + +/** @brief Method for determining the chi2 of the multi-component state and the + * number of degrees of freedom */ +FitQualityOnSurface +fitQuality(const MultiComponentState&, const MeasurementBase&); + +} // end of anonymous namespace +} // end of namespace Trk #endif diff --git a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/KalmanParameterUpdator.h b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/KalmanParameterUpdator.h index e39033cb36f34342f446862da371305bcdb14846..3ca53ad6c1ba2819386befd320485ab980ef735e 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/KalmanParameterUpdator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/KalmanParameterUpdator.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** @@ -10,7 +10,7 @@ * Implementation of the gain formalist for Kalman filters * allowing updating of parameters. * - * Started from /based on KalmanUpdatorAmg + * Started from/based on KalmanUpdatorAmg */ #ifndef TRK_KALMANPARAMETERUPDATOR_H @@ -24,27 +24,27 @@ namespace Trk { -class KalmanParameterUpdator -{ -public: - /// calling the appropriate implementation for this rank of the measurement - /// perform a filter step. - /// Updates (in place) the current TrackParameters and FitQualityOnSurface - /// to represent the predicted state containing - /// the measurement LocalParameters and covariance. - /// For prediction sign should be 1 for smoothing -1. - static bool filterStep(TrackParameters& trackParameters, - FitQualityOnSurface& fitQos, - const LocalParameters& measurement, - const Amg::MatrixX& measCovariance, - const int sign) ; - - static bool stateFitQuality(FitQualityOnSurface& updatedFitQoS, - const TrackParameters& trkPar, - const LocalParameters& position, - const Amg::MatrixX& covariance, - int predFull) ; -}; +namespace KalmanParameterUpdator { +/// calling the appropriate implementation for this rank of the measurement +/// perform a filter step. +/// Updates (in place) the current TrackParameters and FitQualityOnSurface +/// to represent the predicted state containing +/// the measurement LocalParameters and covariance. +/// For prediction sign should be 1 for smoothing -1. +bool +filterStep(TrackParameters& trackParameters, + FitQualityOnSurface& fitQos, + const LocalParameters& measurement, + const Amg::MatrixX& measCovariance, + const int sign); + +bool +stateFitQuality(FitQualityOnSurface& updatedFitQoS, + const TrackParameters& trkPar, + const LocalParameters& position, + const Amg::MatrixX& covariance, + int predFull); +} // end of namespace KalmanParameterUpdator } // end of namespace Trk diff --git a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/MultiComponentStateAssembler.h b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/MultiComponentStateAssembler.h index 517269f6530639e0a85f157e5d5bc0992a83347b..761439abf55897e425d7fe81baf79cf5fec7afcc 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/MultiComponentStateAssembler.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/TrkGaussianSumFilterUtils/MultiComponentStateAssembler.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** @@ -69,25 +69,12 @@ addMultiState( MultiComponentStateAssembler::Cache& cache, Trk::MultiComponentState&& multiComponentState); -/** Method to include the weights of states that are invalid */ -bool -addInvalidComponentWeight( - MultiComponentStateAssembler::Cache& cache, - const double invalidComponentWeight); - /** Method to return the cached state object - * it performs a reweighting before returning the object based on the * valid and invaid weights */ MultiComponentState assembledState(MultiComponentStateAssembler::Cache&& cache); -/** Method to return the cached state object - - * it performs a reweighting based on the input parameter */ -MultiComponentState -assembledState( - MultiComponentStateAssembler::Cache&& cache, - const double newWeight); - } // End MultiComponentStateAssembler namespace } // End Trk namepace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/GsfMeasurementUpdator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/GsfMeasurementUpdator.cxx index 5cc750636134a42d8319a43583208f191076ff94..fd5e7aa8c8f4163f3e176b44368c9ea376979977 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/GsfMeasurementUpdator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/GsfMeasurementUpdator.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** * @file GsfMeasurementUpdator.cxx @@ -53,129 +53,29 @@ rebuildState(Trk::MultiComponentState&& stateBeforeUpdate) bigNewCovarianceMatrix(2, 2) = 0.25; bigNewCovarianceMatrix(3, 3) = 0.25; bigNewCovarianceMatrix(4, 4) = 0.001 * 0.001; - component.first->updateParameters( - trackParameters->parameters(), bigNewCovarianceMatrix); + component.first->updateParameters(trackParameters->parameters(), + bigNewCovarianceMatrix); } } return stateWithInsertedErrors; } -} // end of anonymous namespace - -Trk::MultiComponentState -Trk::GsfMeasurementUpdator::update( - Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement) const -{ - // Check all components have associated error matricies - Trk::MultiComponentState::iterator component = stateBeforeUpdate.begin(); - bool rebuildStateWithErrors = false; - // Perform initial check of state awaiting update. If all states have - // associated error matricies then no need to perform the rebuild - for (; component != stateBeforeUpdate.end(); ++component) { - rebuildStateWithErrors = - rebuildStateWithErrors || invalidComponent(component->first.get()); - } - - if (rebuildStateWithErrors) { - Trk::MultiComponentState stateWithInsertedErrors = - rebuildState(std::move(stateBeforeUpdate)); - // Perform the measurement update with the modified state - return calculateFilterStep( - std::move(stateWithInsertedErrors), measurement, 1); - } - - // Perform the measurement update - return calculateFilterStep(std::move(stateBeforeUpdate), measurement, 1); -} - -Trk::MultiComponentState -Trk::GsfMeasurementUpdator::update( - Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement, - FitQualityOnSurface& fitQoS) const -{ - - // Check all components have associated error matricies - Trk::MultiComponentState::iterator component = stateBeforeUpdate.begin(); - - bool rebuildStateWithErrors = false; - - // Perform initial check of state awaiting update. If all states have - // associated error matricies then no need to perform the rebuild - for (; component != stateBeforeUpdate.end(); ++component) { - rebuildStateWithErrors = - rebuildStateWithErrors || invalidComponent(component->first.get()); - } - - if (rebuildStateWithErrors) { - Trk::MultiComponentState stateWithInsertedErrors = - rebuildState(std::move(stateBeforeUpdate)); - // Perform the measurement update with the modified state - - Trk::MultiComponentState updatedState = calculateFilterStep( - std::move(stateWithInsertedErrors), measurement, fitQoS); - if (updatedState.empty()) { - return {}; - } - return updatedState; - } - - // Perform the measurement update - Trk::MultiComponentState updatedState = - calculateFilterStep(std::move(stateBeforeUpdate), measurement, fitQoS); - - if (updatedState.empty()) { - return {}; - } - return updatedState; -} - -Trk::FitQualityOnSurface -Trk::GsfMeasurementUpdator::fitQuality( - const MultiComponentState& updatedState, - const MeasurementBase& measurement) const -{ - double chi2 = 0; - int degreesOfFreedom = 0; - Trk::MultiComponentState::const_iterator component = updatedState.begin(); - - for (; component != updatedState.end(); ++component) { - const Trk::TrackParameters* trackParameters = component->first.get(); - Trk::FitQualityOnSurface componentFitQuality; - Trk::KalmanParameterUpdator::stateFitQuality( - componentFitQuality, - *trackParameters, - measurement.localParameters(), - measurement.localCovariance(), - 1); - - double componentChi2 = componentFitQuality.chiSquared(); - chi2 += component->second * componentChi2; - // The same measurement is included in each update - if (component == updatedState.begin()) { - degreesOfFreedom = componentFitQuality.numberDoF(); - } - } - return {chi2, degreesOfFreedom}; -} - Trk::MultiComponentState -Trk::GsfMeasurementUpdator::calculateFilterStep( - Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement, - int addRemoveFlag) const +calculateFilterStep(Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement, + int addRemoveFlag) { if (stateBeforeUpdate.empty()) { return {}; } // state Assembler cache - MultiComponentStateAssembler::Cache cache; + Trk::MultiComponentStateAssembler::Cache cache; // Calculate the weight of each component after the measurement - MultiComponentState stateWithNewWeights = PosteriorWeightsCalculator::weights( - std::move(stateBeforeUpdate), measurement); + Trk::MultiComponentState stateWithNewWeights = + Trk::PosteriorWeightsCalculator::weights(std::move(stateBeforeUpdate), + measurement); if (stateWithNewWeights.empty()) { return {}; @@ -185,47 +85,48 @@ Trk::GsfMeasurementUpdator::calculateFilterStep( Trk::FitQualityOnSurface fitQuality{}; /// Update the component in place - bool updateSuccess = Trk::KalmanParameterUpdator::filterStep( - *(component.first), - fitQuality, - measurement.localParameters(), - measurement.localCovariance(), - addRemoveFlag); + bool updateSuccess = + Trk::KalmanParameterUpdator::filterStep(*(component.first), + fitQuality, + measurement.localParameters(), + measurement.localCovariance(), + addRemoveFlag); // If we fail we need to erase the element if (!updateSuccess || fitQuality.chiSquared() <= 0.) { continue; } // Move component to state being prepared for assembly - MultiComponentStateAssembler::addComponent(cache, std::move(component)); + Trk::MultiComponentStateAssembler::addComponent(cache, + std::move(component)); } Trk::MultiComponentState assembledUpdatedState = - MultiComponentStateAssembler::assembledState(std::move(cache)); + Trk::MultiComponentStateAssembler::assembledState(std::move(cache)); if (assembledUpdatedState.empty()) { return {}; } // Renormalise state - MultiComponentStateHelpers::renormaliseState(assembledUpdatedState); + Trk::MultiComponentStateHelpers::renormaliseState(assembledUpdatedState); return assembledUpdatedState; } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::calculateFilterStep( - Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement, - FitQualityOnSurface& fitQoS) const +calculateFilterStep(Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement, + Trk::FitQualityOnSurface& fitQoS) { // state Assembler cache - MultiComponentStateAssembler::Cache cache; + Trk::MultiComponentStateAssembler::Cache cache; if (stateBeforeUpdate.empty()) { return {}; } // Calculate the weight of each component after the measurement - MultiComponentState stateWithNewWeights = PosteriorWeightsCalculator::weights( - std::move(stateBeforeUpdate), measurement); + Trk::MultiComponentState stateWithNewWeights = + Trk::PosteriorWeightsCalculator::weights(std::move(stateBeforeUpdate), + measurement); if (stateWithNewWeights.empty()) { return {}; @@ -234,19 +135,18 @@ Trk::GsfMeasurementUpdator::calculateFilterStep( double chiSquared = 0; int degreesOfFreedom = 0; for (Trk::ComponentParameters& component : stateWithNewWeights) { - if ( - stateWithNewWeights.size() > 1 && - std::abs(component.first->parameters()[Trk::qOverP]) > 0.033333) { + if (stateWithNewWeights.size() > 1 && + std::abs(component.first->parameters()[Trk::qOverP]) > 0.033333) { continue; } Trk::FitQualityOnSurface componentFitQuality; /// Update the component in place - bool updateSuccess = Trk::KalmanParameterUpdator::filterStep( - *(component.first), - componentFitQuality, - measurement.localParameters(), - measurement.localCovariance(), - 1); + bool updateSuccess = + Trk::KalmanParameterUpdator::filterStep(*(component.first), + componentFitQuality, + measurement.localParameters(), + measurement.localCovariance(), + 1); if (!updateSuccess) { continue; } @@ -269,11 +169,12 @@ Trk::GsfMeasurementUpdator::calculateFilterStep( } // Add component to state being prepared for assembly - MultiComponentStateAssembler::addComponent(cache, std::move(component)); + Trk::MultiComponentStateAssembler::addComponent(cache, + std::move(component)); } Trk::MultiComponentState assembledUpdatedState = - MultiComponentStateAssembler::assembledState(std::move(cache)); + Trk::MultiComponentStateAssembler::assembledState(std::move(cache)); if (assembledUpdatedState.empty()) { return {}; @@ -282,7 +183,103 @@ Trk::GsfMeasurementUpdator::calculateFilterStep( fitQoS.setChiSquared(chiSquared); fitQoS.setNumberDoF(degreesOfFreedom); // Renormalise state - MultiComponentStateHelpers::renormaliseState(assembledUpdatedState); + Trk::MultiComponentStateHelpers::renormaliseState(assembledUpdatedState); return assembledUpdatedState; } +} // end of anonymous namespace + +Trk::MultiComponentState +Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement) +{ + // Check all components have associated error matricies + Trk::MultiComponentState::iterator component = stateBeforeUpdate.begin(); + bool rebuildStateWithErrors = false; + // Perform initial check of state awaiting update. If all states have + // associated error matricies then no need to perform the rebuild + for (; component != stateBeforeUpdate.end(); ++component) { + rebuildStateWithErrors = + rebuildStateWithErrors || invalidComponent(component->first.get()); + } + + if (rebuildStateWithErrors) { + Trk::MultiComponentState stateWithInsertedErrors = + rebuildState(std::move(stateBeforeUpdate)); + // Perform the measurement update with the modified state + return calculateFilterStep( + std::move(stateWithInsertedErrors), measurement, 1); + } + + // Perform the measurement update + return calculateFilterStep(std::move(stateBeforeUpdate), measurement, 1); +} + +Trk::MultiComponentState +Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement, + FitQualityOnSurface& fitQoS) +{ + + // Check all components have associated error matricies + Trk::MultiComponentState::iterator component = stateBeforeUpdate.begin(); + + bool rebuildStateWithErrors = false; + + // Perform initial check of state awaiting update. If all states have + // associated error matricies then no need to perform the rebuild + for (; component != stateBeforeUpdate.end(); ++component) { + rebuildStateWithErrors = + rebuildStateWithErrors || invalidComponent(component->first.get()); + } + + if (rebuildStateWithErrors) { + Trk::MultiComponentState stateWithInsertedErrors = + rebuildState(std::move(stateBeforeUpdate)); + // Perform the measurement update with the modified state + + Trk::MultiComponentState updatedState = calculateFilterStep( + std::move(stateWithInsertedErrors), measurement, fitQoS); + if (updatedState.empty()) { + return {}; + } + return updatedState; + } + + // Perform the measurement update + Trk::MultiComponentState updatedState = + calculateFilterStep(std::move(stateBeforeUpdate), measurement, fitQoS); + + if (updatedState.empty()) { + return {}; + } + return updatedState; +} + +Trk::FitQualityOnSurface +Trk::GsfMeasurementUpdator::fitQuality(const MultiComponentState& updatedState, + const MeasurementBase& measurement) +{ + double chi2 = 0; + int degreesOfFreedom = 0; + Trk::MultiComponentState::const_iterator component = updatedState.begin(); + + for (; component != updatedState.end(); ++component) { + const Trk::TrackParameters* trackParameters = component->first.get(); + Trk::FitQualityOnSurface componentFitQuality; + Trk::KalmanParameterUpdator::stateFitQuality(componentFitQuality, + *trackParameters, + measurement.localParameters(), + measurement.localCovariance(), + 1); + + double componentChi2 = componentFitQuality.chiSquared(); + chi2 += component->second * componentChi2; + // The same measurement is included in each update + if (component == updatedState.begin()) { + degreesOfFreedom = componentFitQuality.numberDoF(); + } + } + return { chi2, degreesOfFreedom }; +} + diff --git a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/KalmanParameterUpdator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/KalmanParameterUpdator.cxx index 5af43077aa33d508775c4fcee16a758a4edd018f..766580a5eaf6014b65acf3182508fb10456acda9 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/KalmanParameterUpdator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/KalmanParameterUpdator.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ #include "TrkGaussianSumFilterUtils/KalmanParameterUpdator.h" @@ -348,7 +348,7 @@ Trk::KalmanParameterUpdator::filterStep(TrackParameters& trackParameters, Trk::FitQualityOnSurface& fitQos, const LocalParameters& measurement, const Amg::MatrixX& measCovariance, - const int sign) + const int sign) { const AmgSymMatrix(5)* trkCov = trackParameters.covariance(); @@ -418,7 +418,7 @@ Trk::KalmanParameterUpdator::stateFitQuality( const TrackParameters& trkPar, const LocalParameters& position, const Amg::MatrixX& covariance, - int predFull) + int predFull) { if (!trkPar.covariance()) { return false; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/MultiComponentStateAssembler.cxx b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/MultiComponentStateAssembler.cxx index ac47a068de8c322010e599d4dfcd5170bbddb18a..e83c122053e6e7ecfcf611d64452232d950270c4 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/MultiComponentStateAssembler.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilterUtils/src/MultiComponentStateAssembler.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration */ /** @@ -24,22 +24,21 @@ class SortByLargerSimpleComponentWeight { public: SortByLargerSimpleComponentWeight() = default; - bool operator()( - const Trk::ComponentParameters& firstComponent, - const Trk::ComponentParameters& secondComponent) const + bool operator()(const Trk::ComponentParameters& firstComponent, + const Trk::ComponentParameters& secondComponent) const { return firstComponent.second > secondComponent.second; } }; -/** Method to check the validity of of the cached state */ +/** @bried Method to check the validity of of the cached state */ inline bool isStateValid(const Cache& cache) { return !cache.multiComponentState.empty(); } -/** Method to assemble state with correct weightings */ +/** @bried Method to assemble state with correct weightings */ Trk::MultiComponentState doStateAssembly(Cache&& cache, const double newWeight) { @@ -71,6 +70,7 @@ doStateAssembly(Cache&& cache, const double newWeight) return assembledState; } +/** @bried Method to Check component entries before full assembly */ bool prepareStateForAssembly(Cache& cache) { @@ -82,9 +82,8 @@ prepareStateForAssembly(Cache& cache) // Check for minimum fraction of valid states double den = cache.validWeightSum + cache.invalidWeightSum; double validWeightFraction = den > 0 ? cache.validWeightSum / den : 0; - if ( - cache.invalidWeightSum > 0. && - validWeightFraction < cache.minimumValidFraction) { + if (cache.invalidWeightSum > 0. && + validWeightFraction < cache.minimumValidFraction) { return false; } // Check to see assembly has not already been done @@ -92,10 +91,9 @@ prepareStateForAssembly(Cache& cache) return true; } // Sort Multi-Component State by weights - std::sort( - cache.multiComponentState.begin(), - cache.multiComponentState.end(), - SortByLargerSimpleComponentWeight()); + std::sort(cache.multiComponentState.begin(), + cache.multiComponentState.end(), + SortByLargerSimpleComponentWeight()); double totalWeight(cache.validWeightSum + cache.invalidWeightSum); if (totalWeight != 0.) { @@ -103,17 +101,16 @@ prepareStateForAssembly(Cache& cache) // ordered in descending order // return the 1st element where (element<value) - const double minimumWeight = std::max( - cache.minimumFractionalWeight * totalWeight, - std::numeric_limits<double>::min()); + const double minimumWeight = + std::max(cache.minimumFractionalWeight * totalWeight, + std::numeric_limits<double>::min()); const Trk::ComponentParameters dummySmallestWeight(nullptr, minimumWeight); - auto lower_than = std::upper_bound( - cache.multiComponentState.begin(), - cache.multiComponentState.end(), - dummySmallestWeight, - SortByLargerSimpleComponentWeight()); + auto lower_than = std::upper_bound(cache.multiComponentState.begin(), + cache.multiComponentState.end(), + dummySmallestWeight, + SortByLargerSimpleComponentWeight()); // reverse iterate , so as to delete removing the last auto lower_than_reverse = std::make_reverse_iterator(lower_than); @@ -155,8 +152,8 @@ Trk::MultiComponentStateAssembler::addComponent( return false; } cache.validWeightSum += componentParameters.second; - cache.multiComponentState.emplace_back( - std::move(componentParameters.first), componentParameters.second); + cache.multiComponentState.emplace_back(std::move(componentParameters.first), + componentParameters.second); return true; } @@ -171,23 +168,14 @@ Trk::MultiComponentStateAssembler::addMultiState( double sumW(0.); for (auto& component : multiComponentState) { sumW += component.second; - cache.multiComponentState.emplace_back( - std::move(component.first), component.second); + cache.multiComponentState.emplace_back(std::move(component.first), + component.second); } multiComponentState.clear(); cache.validWeightSum += sumW; return true; } -bool -Trk::MultiComponentStateAssembler::addInvalidComponentWeight( - Cache& cache, - const double invalidComponentWeight) -{ - cache.invalidWeightSum += invalidComponentWeight; - return true; -} - Trk::MultiComponentState Trk::MultiComponentStateAssembler::assembledState( MultiComponentStateAssembler::Cache&& cache) @@ -203,13 +191,3 @@ Trk::MultiComponentStateAssembler::assembledState( return doStateAssembly(std::move(cache), totalWeight); } -Trk::MultiComponentState -Trk::MultiComponentStateAssembler::assembledState( - Cache&& cache, - const double newWeight) -{ - if (!prepareStateForAssembly(cache)) { - return {}; - } - return doStateAssembly(std::move(cache), newWeight); -}