diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.h index 260653f83c01ae18401d83eedb43211d296bfacc..83a41352d7d85d33a9164d33ab4caa92d7d02be8 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.h @@ -20,7 +20,7 @@ template<typename T, size_t Alignment> * https://en.cppreference.com/w/cpp/memory/c/aligned_alloc * * Provides - * - Additional RAII functionality + * - Additional RAII functionality * - Default initialization of elements * - Initialization with copies of elements with value value. */ diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.icc b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.icc index 51e68450d5c450f326d0a57af1b149f73c39b913..d42c8583b3ae9ebf9564f5ef327686a854a90c4e 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.icc +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/AlignedDynArray.icc @@ -19,7 +19,7 @@ inline AlignedDynArray<T, Alignment>::AlignedDynArray(size_t n) { const size_t bufferSize = n * sizeof(T); m_buffer = static_cast<T*>(std::aligned_alloc(Alignment, bufferSize)); - std::uninitialized_default_construct(m_buffer,m_buffer+m_size); + std::uninitialized_default_construct(m_buffer, m_buffer + m_size); } template<typename T, size_t Alignment> @@ -29,7 +29,7 @@ inline AlignedDynArray<T, Alignment>::AlignedDynArray(size_t n, const T& value) { const size_t bufferSize = n * sizeof(T); m_buffer = static_cast<T*>(std::aligned_alloc(Alignment, bufferSize)); - std::uninitialized_fill(m_buffer,m_buffer+m_size,value); + std::uninitialized_fill(m_buffer, m_buffer + m_size, value); } template<typename T, size_t Alignment> @@ -88,7 +88,8 @@ inline T& AlignedDynArray<T, Alignment>::operator[](const std::size_t pos) } template<typename T, size_t Alignment> -inline const T& AlignedDynArray<T, Alignment>::operator[](const std::size_t pos) const +inline const T& AlignedDynArray<T, Alignment>::operator[]( + const std::size_t pos) const { return m_buffer[pos]; } @@ -113,4 +114,3 @@ AlignedDynArray<T, Alignment>::cleanup() } } // namespace GSFUtils - diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/ForwardGsfFitter.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/ForwardGsfFitter.h index f198aa219a59a9166c80da1d964ba53d28ba8a4e..91b98ac3fc2f1876b5ac7c1a79e9704cfe6079f8 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/ForwardGsfFitter.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/ForwardGsfFitter.h @@ -9,7 +9,8 @@ begin : Wednesday 9th March 2005 author : atkinson email : Tom.Atkinson@cern.ch decription : Class definition for the forward GSF fitter -********************************************************************************** */ +********************************************************************************** +*/ #ifndef TrkForwardGsfFitter_H #define TrkForwardGsfFitter_H @@ -52,33 +53,37 @@ public: - Configure the extrapolator - Configure the measurement updator - Configure the RIO_OnTrack creator */ - virtual StatusCode configureTools(const ToolHandle<Trk::IMultiStateExtrapolator>&, - const ToolHandle<Trk::IMultiStateMeasurementUpdator>&, - const ToolHandle<Trk::IRIO_OnTrackCreator>&) override final; + virtual StatusCode configureTools( + const ToolHandle<Trk::IMultiStateExtrapolator>&, + const ToolHandle<Trk::IMultiStateMeasurementUpdator>&, + const ToolHandle<Trk::IRIO_OnTrackCreator>&) override final; /** Forward GSF fit using PrepRawData */ virtual std::unique_ptr<ForwardTrajectory> fitPRD( const PrepRawDataSet&, const TrackParameters&, - const ParticleHypothesis particleHypothesis = nonInteracting) const override final; + const ParticleHypothesis particleHypothesis = + nonInteracting) const override final; /** Forward GSF fit using MeasurementSet */ virtual std::unique_ptr<ForwardTrajectory> fitMeasurements( const MeasurementSet&, const TrackParameters&, - const ParticleHypothesis particleHypothesis = nonInteracting) const override final; + const ParticleHypothesis particleHypothesis = + nonInteracting) const override final; /** The interface will later be extended so that the initial * state can be additionally a MultiComponentState object! */ private: /** Progress one step along the fit */ - bool stepForwardFit(ForwardTrajectory*, - const PrepRawData*, - const MeasurementBase*, - const Surface&, - MultiComponentState&, - const ParticleHypothesis particleHypothesis = nonInteracting) const; + bool stepForwardFit( + ForwardTrajectory*, + const PrepRawData*, + const MeasurementBase*, + const Surface&, + MultiComponentState&, + const ParticleHypothesis particleHypothesis = nonInteracting) const; private: /**These are passed via the configure tools so not retrieved from this tool*/ diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h index b9786dd38b912abc355cd80dab98b7c7002da0ef..f200f6049d0fbe6c72b4619d4ca3149d5f6484bf 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GaussianSumFitter.h @@ -10,7 +10,8 @@ author : amorley, atkinson email : Anthony.Morley@cern.ch, Tom.Atkinson@cern.ch decription : Class for fitting according to the Gaussian Sum Filter formalisation. -********************************************************************************** */ +********************************************************************************** +*/ #include "TrkEventPrimitives/PropDirection.h" #include "TrkEventUtils/TrkParametersComparisonFunction.h" @@ -62,68 +63,88 @@ public: virtual Track* fit(const Track&, const RunOutlierRemoval outlierRemoval = false, - const ParticleHypothesis particleHypothesis = nonInteracting) const override final; + const ParticleHypothesis particleHypothesis = + nonInteracting) const override final; /** Fit a collection of 'PrepRawData' objects using the Gaussian Sum Filter - - This requires that an trackParameters object be supplied also as an initial guess */ + - This requires that an trackParameters object be supplied also as an + initial guess */ virtual Track* fit(const PrepRawDataSet&, const TrackParameters&, const RunOutlierRemoval outlierRemoval = false, - const ParticleHypothesis particleHypothesis = nonInteracting) const override final; + const ParticleHypothesis particleHypothesis = + nonInteracting) const override final; /** Fit a collection of 'RIO_OnTrack' objects using the Gaussian Sum Filter - - This requires that an trackParameters object be supplied also as an initial guess */ + - This requires that an trackParameters object be supplied also as an + initial guess */ virtual Track* fit(const MeasurementSet&, const TrackParameters&, const RunOutlierRemoval outlierRemoval = false, - const ParticleHypothesis particleHypothesis = nonInteracting) const override final; + const ParticleHypothesis particleHypothesis = + nonInteracting) const override final; /** Refit a track adding a PrepRawDataSet - Not done! */ - virtual Track* fit(const Track&, - const PrepRawDataSet&, - const RunOutlierRemoval runOutlier = false, - const ParticleHypothesis matEffects = nonInteracting) const override final; + virtual Track* fit( + const Track&, + const PrepRawDataSet&, + const RunOutlierRemoval runOutlier = false, + const ParticleHypothesis matEffects = nonInteracting) const override final; /** Refit a track adding a RIO_OnTrack set - - This has no form of outlier rejection and will use all hits on orginal track... - i.e. very basic impleneation at the moment*/ - virtual Track* fit(const Track&, - const MeasurementSet&, - const RunOutlierRemoval runOutlier = false, - const ParticleHypothesis matEffects = nonInteracting) const override final; + - This has no form of outlier rejection and will use all hits on orginal + track... i.e. very basic impleneation at the moment*/ + virtual Track* fit( + const Track&, + const MeasurementSet&, + const RunOutlierRemoval runOutlier = false, + const ParticleHypothesis matEffects = nonInteracting) const override final; /** Combine two tracks by refitting - Not done! */ - virtual Track* fit(const Track&, - const Track&, - const RunOutlierRemoval runOutlier = false, - const ParticleHypothesis matEffects = nonInteracting) const override final; + virtual Track* fit( + const Track&, + const Track&, + const RunOutlierRemoval runOutlier = false, + const ParticleHypothesis matEffects = nonInteracting) const override final; private: /** Produces a perigee from a smoothed trajectory */ - const MultiComponentStateOnSurface* makePerigee(const SmoothedTrajectory*, - const ParticleHypothesis particleHypothesis = nonInteracting) const; + const MultiComponentStateOnSurface* makePerigee( + const SmoothedTrajectory*, + const ParticleHypothesis particleHypothesis = nonInteracting) const; //* Calculate the fit quality */ const Trk::FitQuality* buildFitQuality(const Trk::SmoothedTrajectory&) const; private: - ToolHandle<IMultiStateExtrapolator> m_extrapolator{ this, - "ToolForExtrapolation", - "Trk::GsfExtrapolator/GsfExtrapolator", - "" }; - ToolHandle<IMultiStateMeasurementUpdator> m_updator{ this, - "MeasurementUpdatorType", - "Trk::GsfMeasurementUpdator/GsfMeasurementUpdator", - "" }; - ToolHandle<IRIO_OnTrackCreator> m_rioOnTrackCreator{ this, - "ToolForROTCreation", - "Trk::RioOnTrackCreator/RIO_OnTrackCreator", - "" }; - ToolHandle<IForwardGsfFitter> m_forwardGsfFitter{ this, - "ForwardGsfFitter", - "Trk::ForwardGsfFitter/ForwardGsfFitter", - "" }; - ToolHandle<IGsfSmoother> m_gsfSmoother{ this, "GsfSmoother", "Trk::GsfSmoother/GsfSmoother", "" }; + ToolHandle<IMultiStateExtrapolator> m_extrapolator{ + this, + "ToolForExtrapolation", + "Trk::GsfExtrapolator/GsfExtrapolator", + "" + }; + ToolHandle<IMultiStateMeasurementUpdator> m_updator{ + this, + "MeasurementUpdatorType", + "Trk::GsfMeasurementUpdator/GsfMeasurementUpdator", + "" + }; + ToolHandle<IRIO_OnTrackCreator> m_rioOnTrackCreator{ + this, + "ToolForROTCreation", + "Trk::RioOnTrackCreator/RIO_OnTrackCreator", + "" + }; + ToolHandle<IForwardGsfFitter> m_forwardGsfFitter{ + this, + "ForwardGsfFitter", + "Trk::ForwardGsfFitter/ForwardGsfFitter", + "" + }; + ToolHandle<IGsfSmoother> m_gsfSmoother{ this, + "GsfSmoother", + "Trk::GsfSmoother/GsfSmoother", + "" }; bool m_reintegrateOutliers; bool m_makePerigee; @@ -136,12 +157,14 @@ private: TrackFitInputPreparator* m_inputPreparator; // GSF Fit Statistics - mutable std::atomic<int> m_FitPRD; // Number of Fit PrepRawData Calls - mutable std::atomic<int> m_FitMeasurementBase; // Number of Fit MeasurementBase Calls - mutable std::atomic<int> m_ForwardFailure; // Number of Foward Fit Failures - mutable std::atomic<int> m_SmootherFailure; // Number of Smoother Failures - mutable std::atomic<int> m_PerigeeFailure; // Number of MakePerigee Failures - mutable std::atomic<int> m_fitQualityFailure; // Number of Tracks that fail fit Quailty test + mutable std::atomic<int> m_FitPRD; // Number of Fit PrepRawData Calls + mutable std::atomic<int> + m_FitMeasurementBase; // Number of Fit MeasurementBase Calls + mutable std::atomic<int> m_ForwardFailure; // Number of Foward Fit Failures + mutable std::atomic<int> m_SmootherFailure; // Number of Smoother Failures + mutable std::atomic<int> m_PerigeeFailure; // Number of MakePerigee Failures + mutable std::atomic<int> + m_fitQualityFailure; // Number of Tracks that fail fit Quailty test }; } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfBetheHeitlerEffects.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfBetheHeitlerEffects.h index 9511aeca28e3a75e27e44dcbc9e7e71512d00f4b..64c4415b778ca8eac17201419f2690153e647a39 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfBetheHeitlerEffects.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfBetheHeitlerEffects.h @@ -29,7 +29,6 @@ class GsfBetheHeitlerEffects { private: - /** Helper class for construction and evaluation of polynomial */ class Polynomial { @@ -37,7 +36,8 @@ private: // Default constructor Polynomial() = default; - /** Constructor from a vector of coefficients (in decreasing order of powers of x */ + /** Constructor from a vector of coefficients (in decreasing order of powers + * of x */ Polynomial(const std::vector<double>& coefficients) : m_coefficients(coefficients){}; @@ -47,16 +47,17 @@ private: double sum(0.); std::vector<double>::const_iterator coefficient = m_coefficients.begin(); - for (; coefficient != m_coefficients.end(); ++coefficient) + for (; coefficient != m_coefficients.end(); ++coefficient) { sum = t * sum + (*coefficient); + } return sum; } + private: std::vector<double> m_coefficients; }; - struct ComponentValues { // Default ctors/dtor/assignment operators @@ -77,9 +78,10 @@ private: double variance; }; - public: - GsfBetheHeitlerEffects(const std::string&, const std::string&, const IInterface*); + GsfBetheHeitlerEffects(const std::string&, + const std::string&, + const IInterface*); virtual ~GsfBetheHeitlerEffects() = default; @@ -94,7 +96,8 @@ public: const MaterialProperties&, double, PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; private: typedef std::vector<ComponentValues> MixtureParameters; @@ -121,13 +124,22 @@ private: double correctedFirstVariance(const double, const MixtureParameters&) const; // Logistic function - needed for transformation of weight and mean - inline double logisticFunction(const double x) const { return (double)1. / (1. + exp(-x)); } + inline double logisticFunction(const double x) const + { + return (double)1. / (1. + exp(-x)); + } // First moment of the Bethe-Heitler distribution - inline double betheHeitlerMean(const double r) const { return (double)exp(-r); } + inline double betheHeitlerMean(const double r) const + { + return (double)exp(-r); + } // Second moment of the Bethe-Heitler distribution - inline double betheHeitlerVariance(const double r) const { return (double)exp(-r * log(3.) / log(2.)) - exp(-2 * r); } + inline double betheHeitlerVariance(const double r) const + { + return (double)exp(-r * log(3.) / log(2.)) - exp(-2 * r); + } private: std::string m_parameterisationFileName; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfCombinedMaterialEffects.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfCombinedMaterialEffects.h index 273ae852fa927a57c28e47e9d9c2978690a9ebe9..416ff54b121390a42ce6b1cdf4f220163e0421c9 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfCombinedMaterialEffects.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfCombinedMaterialEffects.h @@ -8,8 +8,8 @@ begin : Friday 11th January 2005 author : atkinson email : Tom.Atkinson@cern.ch -decription : Class definition for consideration of multiple scatter and - energy loss effects from material simultaneously. +decription : Class definition for consideration of multiple scatter +and energy loss effects from material simultaneously. *********************************************************************************/ #ifndef TrkGsfCombinedMaterialEffects_H @@ -17,9 +17,9 @@ decription : Class definition for consideration of multiple scatter an #include "AthenaBaseComps/AthAlgTool.h" #include "GaudiKernel/ToolHandle.h" -#include "TrkGaussianSumFilter/IMultiStateMaterialEffects.h" -#include "TrkExInterfaces/IMultipleScatteringUpdator.h" #include "TrkExInterfaces/IEnergyLossUpdator.h" +#include "TrkExInterfaces/IMultipleScatteringUpdator.h" +#include "TrkGaussianSumFilter/IMultiStateMaterialEffects.h" namespace Trk { class GsfCombinedMaterialEffects @@ -28,7 +28,9 @@ class GsfCombinedMaterialEffects { public: /** Constructor with AlgTool parameters*/ - GsfCombinedMaterialEffects(const std::string&, const std::string&, const IInterface*); + GsfCombinedMaterialEffects(const std::string&, + const std::string&, + const IInterface*); /** Virtual destructor */ virtual ~GsfCombinedMaterialEffects() override; @@ -39,16 +41,15 @@ public: /** AlgTool finalise method */ StatusCode finalize() override; - virtual void compute(IMultiStateMaterialEffects::Cache&, - const ComponentParameters&, - const MaterialProperties&, - double, - PropDirection = anyDirection, - ParticleHypothesis = nonInteracting) const override final; + virtual void compute( + IMultiStateMaterialEffects::Cache&, + const ComponentParameters&, + const MaterialProperties&, + double, + PropDirection = anyDirection, + ParticleHypothesis = nonInteracting) const override final; private: - - void scattering(IMultiStateMaterialEffects::Cache&, const ComponentParameters&, const MaterialProperties&, diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.h index 60c8eb22e45955ae21ccfd58dd3f721fe84592f0..a2bddfdbd0e4efc1cb768de1a8172f7cdae911c2 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.h @@ -49,7 +49,8 @@ class IMultiComponentStateMerger; class IMaterialMixtureConvolution; class IMultipleScatteringUpdator; /** @struct StateAtBoundarySurface - - Structure to contain information about a state at the interface between tracking volumes + - Structure to contain information about a state at the interface between + tracking volumes */ struct StateAtBoundarySurface @@ -100,39 +101,43 @@ public: /** Configured AlgTool extrapolation method (1) */ virtual MultiComponentState extrapolate( - const EventContext& ctx, + const EventContext& ctx, const MultiComponentState&, const Surface&, PropDirection direction = anyDirection, const BoundaryCheck& boundaryCheck = true, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; /** Configured AlgTool extrapolation without material effects method (2) */ virtual MultiComponentState extrapolateDirectly( - const EventContext& ctx, + const EventContext& ctx, const MultiComponentState&, const Surface&, PropDirection direction = anyDirection, const BoundaryCheck& boundaryCheck = true, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; - virtual std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> extrapolateM( - const EventContext& ctx, - const MultiComponentState&, - const Surface& sf, - PropDirection dir, - const BoundaryCheck& bcheck, - ParticleHypothesis particle) const override final; + virtual std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> + extrapolateM(const EventContext& ctx, + const MultiComponentState&, + const Surface& sf, + PropDirection dir, + const BoundaryCheck& bcheck, + ParticleHypothesis particle) const override final; private: struct Cache { - bool m_recall; //!< Flag the recall solution - const Surface* m_recallSurface; //!< Surface for recall - const Layer* m_recallLayer; //!< Layer for recall - const TrackingVolume* m_recallTrackingVolume; //!< Tracking volume for recall - StateAtBoundarySurface m_stateAtBoundarySurface; //!< Instance of structure describing the state - //!< at a boundary of tracking volumes + bool m_recall; //!< Flag the recall solution + const Surface* m_recallSurface; //!< Surface for recall + const Layer* m_recallLayer; //!< Layer for recall + const TrackingVolume* + m_recallTrackingVolume; //!< Tracking volume for recall + StateAtBoundarySurface + m_stateAtBoundarySurface; //!< Instance of structure describing the state + //!< at a boundary of tracking volumes std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> m_matstates; std::vector<std::unique_ptr<const MultiComponentState>> m_mcsGarbageBin; //!< Garbage bin for MultiComponentState objects @@ -151,7 +156,8 @@ private: {} }; - /** These are the methods that do the actual heavy lifting when extrapolating with a cache */ + /** These are the methods that do the actual heavy lifting when extrapolating + * with a cache */ MultiComponentState extrapolateImpl( const EventContext& ctx, Cache& cache, @@ -164,7 +170,7 @@ private: /** Configured AlgTool extrapolation without material effects method (2) */ MultiComponentState extrapolateDirectlyImpl( - const EventContext& ctx, + const EventContext& ctx, const IPropagator&, const MultiComponentState&, const Surface&, @@ -172,12 +178,12 @@ private: const BoundaryCheck& boundaryCheck = true, ParticleHypothesis particleHypothesis = nonInteracting) const; - /** Two primary private extrapolation methods - - extrapolateToVolumeBoundary - extrapolates to the exit of the destination tracking volume + - extrapolateToVolumeBoundary - extrapolates to the exit of the destination + tracking volume - Exit layer surface will be hit in this method. - - extrapolateInsideVolume - extrapolates to the destination surface in the final tracking - volume + - extrapolateInsideVolume - extrapolates to the destination surface in + the final tracking volume */ void extrapolateToVolumeBoundary( @@ -206,7 +212,7 @@ private: /** Layer stepping, stopping at the last layer before destination */ MultiComponentState extrapolateFromLayerToLayer( - const EventContext& ctx, + const EventContext& ctx, Cache& cache, const IPropagator&, const MultiComponentState&, @@ -217,7 +223,7 @@ private: ParticleHypothesis particleHypothesis = nonInteracting) const; /** Single extrapolation step to an intermediate layer */ - MultiComponentState extrapolateToIntermediateLayer( + MultiComponentState extrapolateToIntermediateLayer( const EventContext& ctx, Cache& cache, const IPropagator&, @@ -241,8 +247,8 @@ private: const BoundaryCheck& boundaryCheck = true, ParticleHypothesis particleHypothesis = nonInteracting) const; - /** Extrapolation to consider material effects assuming all material on active sensor elements - - * CTB method */ + /** Extrapolation to consider material effects assuming all material on active + * sensor elements - CTB method */ Trk::MultiComponentState extrapolateSurfaceBasedMaterialEffects( const EventContext& ctx, const IPropagator&, @@ -265,8 +271,8 @@ private: /** Method to choose propagator type */ unsigned int propagatorType(const TrackingVolume& trackingVolume) const; - /** Method to initialise navigation parameters including starting state, layer and volume, and - * destination volume */ + /** Method to initialise navigation parameters including starting state, layer + * and volume, and destination volume */ void initialiseNavigation(const EventContext& ctx, Cache& cache, const IPropagator& propagator, @@ -286,7 +292,6 @@ private: PropDirection dir, ParticleHypothesis particle) const; - /** Method to set the recall information */ void setRecallInformation(Cache& cache, const Surface&, @@ -305,20 +310,25 @@ private: /** Private method to empty garbage bins */ void emptyGarbageBins(Cache& cache) const; /** Add material to vector*/ - void addMaterialtoVector(Cache& cache, - const Trk::Layer* nextLayer, - const Trk::TrackParameters* nextPar, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const; + void addMaterialtoVector( + Cache& cache, + const Trk::Layer* nextLayer, + const Trk::TrackParameters* nextPar, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const; std::string layerRZoutput(const Trk::Layer* lay) const; std::string positionOutput(const Amg::Vector3D& pos) const; - int radialDirection(const Trk::MultiComponentState& pars, PropDirection dir) const; + int radialDirection(const Trk::MultiComponentState& pars, + PropDirection dir) const; ToolHandleArray<IPropagator> m_propagators{ this, "Propagators", {}, "" }; - ToolHandle<INavigator> m_navigator{ this, "Navigator", "Trk::Navigator/Navigator", "" }; + ToolHandle<INavigator> m_navigator{ this, + "Navigator", + "Trk::Navigator/Navigator", + "" }; ToolHandle<IMaterialMixtureConvolution> m_materialUpdator{ this, "GsfMaterialConvolution", @@ -331,36 +341,52 @@ private: "Trk::MultipleScatteringUpdator/AtlasMultipleScatteringUpdator", "" }; - ToolHandle<IEnergyLossUpdator> m_elossupdators{ this, - "EnergyLossUpdator", - "Trk::EnergyLossUpdator/AtlasEnergyLossUpdator", - "" }; + ToolHandle<IEnergyLossUpdator> m_elossupdators{ + this, + "EnergyLossUpdator", + "Trk::EnergyLossUpdator/AtlasEnergyLossUpdator", + "" + }; - bool m_propagatorStickyConfiguration; //!< Switch between simple and full configured propagators - bool m_surfaceBasedMaterialEffects; //!< Switch to turn on/off surface based material effects + bool m_propagatorStickyConfiguration; //!< Switch between simple and full + //!< configured propagators + bool m_surfaceBasedMaterialEffects; //!< Switch to turn on/off surface based + //!< material effects bool m_fastField; - unsigned int m_propagatorConfigurationLevel; //!< Configuration level of the propagator - unsigned int m_propagatorSearchLevel; //!< Search level of the propagator + unsigned int + m_propagatorConfigurationLevel; //!< Configuration level of the propagator + unsigned int m_propagatorSearchLevel; //!< Search level of the propagator Trk::MagneticFieldProperties m_fieldProperties; - mutable Gaudi::Accumulators::Counter<int, Gaudi::Accumulators::atomicity::full> - m_extrapolateCalls; //!< Statistics: Number of calls to the main extrapolate method - mutable Gaudi::Accumulators::Counter<int, Gaudi::Accumulators::atomicity::full> - m_extrapolateDirectlyCalls; //!< Statistics: Number of calls to the extrapolate directly method - mutable Gaudi::Accumulators::Counter<int, Gaudi::Accumulators::atomicity::full> - m_extrapolateDirectlyFallbacks; //!< Statistics: Number of calls to the extrapolate directly - //!< fallback - mutable Gaudi::Accumulators::Counter<int, Gaudi::Accumulators::atomicity::full> - m_navigationDistanceIncreaseBreaks; //!< Statistics: Number of times navigation stepping fails - //!< to go the right way - mutable Gaudi::Accumulators::Counter<int, Gaudi::Accumulators::atomicity::full> - m_oscillationBreaks; //!< Statistics: Number of times a tracking volume oscillation is detected - mutable Gaudi::Accumulators::Counter<int, Gaudi::Accumulators::atomicity::full> - m_missedVolumeBoundary; //!< Statistics: Number of times the volume boundary is missed + mutable Gaudi::Accumulators::Counter<int, + Gaudi::Accumulators::atomicity::full> + m_extrapolateCalls; //!< Statistics: Number of calls to the main extrapolate + //!< method + mutable Gaudi::Accumulators::Counter<int, + Gaudi::Accumulators::atomicity::full> + m_extrapolateDirectlyCalls; //!< Statistics: Number of calls to the + //!< extrapolate directly method + mutable Gaudi::Accumulators::Counter<int, + Gaudi::Accumulators::atomicity::full> + m_extrapolateDirectlyFallbacks; //!< Statistics: Number of calls to the + //!< extrapolate directly fallback + mutable Gaudi::Accumulators::Counter<int, + Gaudi::Accumulators::atomicity::full> + m_navigationDistanceIncreaseBreaks; //!< Statistics: Number of times + //!< navigation stepping fails to go the + //!< right way + mutable Gaudi::Accumulators::Counter<int, + Gaudi::Accumulators::atomicity::full> + m_oscillationBreaks; //!< Statistics: Number of times a tracking volume + //!< oscillation is detected + mutable Gaudi::Accumulators::Counter<int, + Gaudi::Accumulators::atomicity::full> + m_missedVolumeBoundary; //!< Statistics: Number of times the volume boundary + //!< is missed }; } // end namespace Trk -//for the inline implementations +// for the inline implementations #include "GsfExtrapolator.icc" #endif diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.icc b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.icc index 929f6913ce8412b15719a1494305e48e1effa06b..55109aa68bbfd7f155a5c08dc7fa94654edc8afd 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.icc +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfExtrapolator.icc @@ -3,10 +3,11 @@ */ inline void -Trk::GsfExtrapolator::setRecallInformation(Cache& cache, - const Trk::Surface& recallSurface, - const Trk::Layer& recallLayer, - const Trk::TrackingVolume& recallTrackingVolume) const +Trk::GsfExtrapolator::setRecallInformation( + Cache& cache, + const Trk::Surface& recallSurface, + const Trk::Layer& recallLayer, + const Trk::TrackingVolume& recallTrackingVolume) const { cache.m_recall = true; cache.m_recallSurface = &recallSurface; @@ -24,8 +25,9 @@ Trk::GsfExtrapolator::resetRecallInformation(Cache& cache) const } inline void -Trk::GsfExtrapolator::throwIntoGarbageBin(Cache& cache, - const Trk::MultiComponentState* garbage) const +Trk::GsfExtrapolator::throwIntoGarbageBin( + Cache& cache, + const Trk::MultiComponentState* garbage) const { if (garbage) { std::unique_ptr<const Trk::MultiComponentState> sink(garbage); @@ -34,7 +36,9 @@ Trk::GsfExtrapolator::throwIntoGarbageBin(Cache& cache, } inline void -Trk::GsfExtrapolator::throwIntoGarbageBin(Cache& cache, const Trk::TrackParameters* garbage) const +Trk::GsfExtrapolator::throwIntoGarbageBin( + Cache& cache, + const Trk::TrackParameters* garbage) const { if (garbage) { std::unique_ptr<const Trk::TrackParameters> sink(garbage); @@ -52,6 +56,3 @@ Trk::GsfExtrapolator::emptyGarbageBins(Cache& cache) const cache.m_tpGarbageBin.clear(); cache.m_matstates.reset(nullptr); } - - - diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialEffectsUpdator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialEffectsUpdator.h index 481277df4bd7b7a5478341d63eabdab1fad9b7ae..f13c4bcf2f0b9021d129c8a124ae3b7d0cc82716 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialEffectsUpdator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialEffectsUpdator.h @@ -30,7 +30,9 @@ class GsfMaterialEffectsUpdator public: /** Constructor with AlgTool parameters */ - GsfMaterialEffectsUpdator(const std::string&, const std::string&, const IInterface*); + GsfMaterialEffectsUpdator(const std::string&, + const std::string&, + const IInterface*); /** Virtual destructor */ virtual ~GsfMaterialEffectsUpdator(); @@ -41,15 +43,16 @@ public: /** AlgTool finalisation*/ StatusCode finalize(); - /** Method for updating the state with material effects provided by the layer object */ + /** Method for updating the state with material effects provided by the layer + * object */ virtual Trk::MultiComponentState updateState( const ComponentParameters&, const Layer&, PropDirection direction = anyDirection, ParticleHypothesis particleHypothesis = nonInteracting) const; - /** Method for updating the state with material effects provided by a material properties object - * and a pathlength */ + /** Method for updating the state with material effects provided by a material + * properties object and a pathlength */ virtual Trk::MultiComponentState updateState( const ComponentParameters&, const MaterialProperties&, @@ -57,7 +60,8 @@ public: PropDirection direction = anyDirection, ParticleHypothesis particleHypothesis = nonInteracting) const; - /** Method for the state with material effects provided by the layer object prior to propagation + /** Method for the state with material effects provided by the layer object + * prior to propagation */ virtual Trk::MultiComponentState preUpdateState( const ComponentParameters&, @@ -65,7 +69,8 @@ public: PropDirection direction = anyDirection, ParticleHypothesis particleHypothesis = nonInteracting) const; - /** Method for the state with material effects provided by the layer object after propagation */ + /** Method for the state with material effects provided by the layer object + * after propagation */ virtual Trk::MultiComponentState postUpdateState( const ComponentParameters&, const Layer&, @@ -74,18 +79,23 @@ public: private: /** Method to perform centralised calculation of updated state */ - Trk::MultiComponentState compute(const ComponentParameters&, - const MaterialProperties&, - double, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const; + Trk::MultiComponentState compute( + const ComponentParameters&, + const MaterialProperties&, + double, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const; /** Method to calculate the updated momentum based on material effects */ bool updateP(AmgVector(5) &, double) const; private: - ToolHandle<IMultiStateMaterialEffects> - m_materialEffects{ this, "MaterialEffects", "Trk::GsfCombinedMaterialEffects/GsfCombinedMaterialEffects", "" }; + ToolHandle<IMultiStateMaterialEffects> m_materialEffects{ + this, + "MaterialEffects", + "Trk::GsfCombinedMaterialEffects/GsfCombinedMaterialEffects", + "" + }; bool m_useReferenceMaterial; double m_momentumCut; }; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialMixtureConvolution.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialMixtureConvolution.h index 96576d8dee199f16619e740c8405a71ef242e4f0..bdc93e3f8a761a736121f920bc1f66ae528da5c8 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialMixtureConvolution.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMaterialMixtureConvolution.h @@ -32,7 +32,9 @@ class GsfMaterialMixtureConvolution public: //!< Constructor with AlgTool parameters - GsfMaterialMixtureConvolution(const std::string&, const std::string&, const IInterface*); + GsfMaterialMixtureConvolution(const std::string&, + const std::string&, + const IInterface*); //!< Destructor virtual ~GsfMaterialMixtureConvolution(); @@ -44,43 +46,47 @@ public: virtual StatusCode finalize() override; //!< Convolution with full material properties - virtual MultiComponentState update( - const MultiComponentState&, - const Layer&, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + virtual MultiComponentState update(const MultiComponentState&, + const Layer&, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; //!< Convolution with pre-measurement-update material properties virtual MultiComponentState preUpdate(const MultiComponentState&, const Layer&, PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; //!< Convolution with post-measurement-update material properties virtual MultiComponentState postUpdate(const MultiComponentState&, const Layer&, PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; //!< Retain for now redundant simplified material effects virtual MultiComponentState simplifiedMaterialUpdate( const MultiComponentState& multiComponentState, PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const override final; + ParticleHypothesis particleHypothesis = + nonInteracting) const override final; private: - - Gaudi::Property<unsigned int> m_maximumNumberOfComponents{ this, - "MaximumNumberOfComponents", - 12, - "Maximum number of components" }; - - - ToolHandle<IMultiStateMaterialEffectsUpdator> m_updator{ this, - "MaterialEffectsUpdator", - "Trk::GsfMaterialEffectsUpdator/GsfMaterialEffectsUpdator", - "" }; - + Gaudi::Property<unsigned int> m_maximumNumberOfComponents{ + this, + "MaximumNumberOfComponents", + 12, + "Maximum number of components" + }; + + ToolHandle<IMultiStateMaterialEffectsUpdator> m_updator{ + this, + "MaterialEffectsUpdator", + "Trk::GsfMaterialEffectsUpdator/GsfMaterialEffectsUpdator", + "" + }; }; } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMeasurementUpdator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMeasurementUpdator.h index 15ab30c8ac1a1228faebd65b69e567df3fae11a5..7325b7d56940c55ac48e5dd4471a59b7649f5e02 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMeasurementUpdator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfMeasurementUpdator.h @@ -8,8 +8,8 @@ begin : Friday 25th February 2005 author : atkinson email : Tom.Atkinson@cern.ch -decription : Class for performing updates on multi-component states for - the gaussian-sum filter. Now an AlgTool +decription : Class for performing updates on multi-component states +for the gaussian-sum filter. Now an AlgTool *********************************************************************************/ #ifndef TrkGsfMeasurementUpdator_H @@ -36,16 +36,19 @@ class GsfMeasurementUpdator { private: - /** Private typedef for calling the correct updator member function depending of direction of - * fitting */ - typedef Trk::TrackParameters* (Trk::IUpdator::*Updator)(const Trk::TrackParameters&, - const LocalParameters&, - const Amg::MatrixX&, - FitQualityOnSurface*&)const; + /** Private typedef for calling the correct updator member function depending + * of direction of fitting */ + typedef Trk::TrackParameters* (Trk::IUpdator::*Updator)( + const Trk::TrackParameters&, + const LocalParameters&, + const Amg::MatrixX&, + FitQualityOnSurface*&)const; public: /** Constructor with parameters to be passed to AlgTool */ - GsfMeasurementUpdator(const std::string&, const std::string&, const IInterface*); + GsfMeasurementUpdator(const std::string&, + const std::string&, + const IInterface*); /** Virtual destructor */ virtual ~GsfMeasurementUpdator() = default; @@ -57,39 +60,49 @@ public: StatusCode finalize() override; /** Method for updating the multi-state with a new measurement */ - virtual MultiComponentState update(MultiComponentState&&, - const MeasurementBase&) const override final; + virtual MultiComponentState update( + MultiComponentState&&, + const MeasurementBase&) const override final; - /** Method for updating the multi-state with a new measurement and calculate the fit qaulity at - * the same time*/ + /** Method for updating the multi-state with a new measurement and calculate + * the fit qaulity at the same time*/ virtual MultiComponentState update( Trk::MultiComponentState&&, const Trk::MeasurementBase&, std::unique_ptr<FitQualityOnSurface>& fitQoS) const override final; - /** Method for GSF smoother to calculate unbiased parameters of the multi-component state */ - virtual MultiComponentState getUnbiasedTrackParameters(MultiComponentState&&, - const MeasurementBase&) const override final; + /** Method for GSF smoother to calculate unbiased parameters of the + * multi-component state */ + virtual MultiComponentState getUnbiasedTrackParameters( + MultiComponentState&&, + const MeasurementBase&) const override final; - /** Method for determining the chi2 of the multi-component state and the number of degrees of - * freedom */ - virtual const FitQualityOnSurface* fitQuality(const MultiComponentState&, const MeasurementBase&) const override; + /** Method for determining the chi2 of the multi-component state and the + * number of degrees of freedom */ + virtual const FitQualityOnSurface* fitQuality( + const MultiComponentState&, + const MeasurementBase&) const override; private: MultiComponentState calculateFilterStep(MultiComponentState&&, const MeasurementBase&, const Updator) const; - MultiComponentState calculateFilterStep(MultiComponentState&&, - const MeasurementBase&, - std::unique_ptr<FitQualityOnSurface>& fitQoS) const; + MultiComponentState calculateFilterStep( + MultiComponentState&&, + const MeasurementBase&, + std::unique_ptr<FitQualityOnSurface>& fitQoS) const; bool invalidComponent(const Trk::TrackParameters* trackParameters) const; - MultiComponentState rebuildState(Trk::MultiComponentState&& stateBeforeUpdate) const; + MultiComponentState rebuildState( + Trk::MultiComponentState&& stateBeforeUpdate) const; private: - ToolHandle<IUpdator> m_updator{ this, "Updator", "Trk::KalmanUpdator/KalmanUpdator", "" }; + ToolHandle<IUpdator> m_updator{ this, + "Updator", + "Trk::KalmanUpdator/KalmanUpdator", + "" }; }; } diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfSmoother.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfSmoother.h index 39a17bbdb42c5920f6d7a00e98df2297a4163a20..4158cebf49cf019784c62629cd7e9ba02c881405 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfSmoother.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/GsfSmoother.h @@ -9,18 +9,19 @@ begin : Wednesday 9th March 2005 author : atkinson email : Tom.Atkinson@cern.ch decription : Class definition for the GSF smoother -********************************************************************************** */ +********************************************************************************** +*/ #ifndef TrkGsfSmoother_H #define TrkGsfSmoother_H #include "TrkGaussianSumFilter/IGsfSmoother.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" #include "TrkEventPrimitives/ParticleHypothesis.h" #include "TrkFitterUtils/FitterTypes.h" #include "TrkMultiComponentStateOnSurface/MultiComponentState.h" -#include "AthenaBaseComps/AthAlgTool.h" -#include "GaudiKernel/ToolHandle.h" namespace Trk { @@ -49,30 +50,36 @@ public: /** Configure the GSF smoother - Configure the extrapolator - Configure the measurement updator */ - virtual StatusCode configureTools(const ToolHandle<IMultiStateExtrapolator>&, - const ToolHandle<IMultiStateMeasurementUpdator>&); + virtual StatusCode configureTools( + const ToolHandle<IMultiStateExtrapolator>&, + const ToolHandle<IMultiStateMeasurementUpdator>&); /** Gsf smoother method */ - virtual SmoothedTrajectory* fit(const ForwardTrajectory&, - const ParticleHypothesis particleHypothesis = nonInteracting, - const CaloCluster_OnTrack* ccot = nullptr) const; + virtual SmoothedTrajectory* fit( + const ForwardTrajectory&, + const ParticleHypothesis particleHypothesis = nonInteracting, + const CaloCluster_OnTrack* ccot = nullptr) const; private: /** Method for combining the forwards fitted state and the smoothed state */ - MultiComponentState combine(const MultiComponentState&, const MultiComponentState&) const; + MultiComponentState combine(const MultiComponentState&, + const MultiComponentState&) const; /** Methof to add the CaloCluster onto the track */ - MultiComponentState addCCOT(const Trk::TrackStateOnSurface* currentState, - const Trk::CaloCluster_OnTrack* ccot, - Trk::SmoothedTrajectory* smoothedTrajectory) const; + MultiComponentState addCCOT( + const Trk::TrackStateOnSurface* currentState, + const Trk::CaloCluster_OnTrack* ccot, + Trk::SmoothedTrajectory* smoothedTrajectory) const; private: bool m_combineWithFitter; - Gaudi::Property<unsigned int> m_maximumNumberOfComponents{ this, - "MaximumNumberOfComponents", - 12, - "Maximum number of components" }; + Gaudi::Property<unsigned int> m_maximumNumberOfComponents{ + this, + "MaximumNumberOfComponents", + 12, + "Maximum number of components" + }; /* * Special Tool Handles set by the configureTools */ diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IForwardGsfFitter.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IForwardGsfFitter.h index 8354dcf618a6fb5bb3344db4ea641766b6d5718e..0193e7adb93726d41bbb82967453b7922e354c38 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IForwardGsfFitter.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IForwardGsfFitter.h @@ -9,7 +9,8 @@ created : Thursday 8th January 2009 authors : amorley,christos email : Anthony.Morley@cern.ch decription : Abstract interface for the forward GSF fitter -********************************************************************************** */ +********************************************************************************** +*/ #ifndef TrkIForwardGsfFitter_H #define TrkIForwardGsfFitter_H @@ -36,7 +37,10 @@ class IForwardGsfFitter : virtual public IAlgTool public: /** AlgTool interface method */ - static const InterfaceID& interfaceID() { return InterfaceID_ForwardGsfFitter; }; + static const InterfaceID& interfaceID() + { + return InterfaceID_ForwardGsfFitter; + }; /** Virtual destructor */ virtual ~IForwardGsfFitter() = default; @@ -45,9 +49,10 @@ public: - Configure the extrapolator - Configure the measurement updator - Configure the RIO_OnTrack creator */ - virtual StatusCode configureTools(const ToolHandle<Trk::IMultiStateExtrapolator>&, - const ToolHandle<Trk::IMultiStateMeasurementUpdator>&, - const ToolHandle<Trk::IRIO_OnTrackCreator>&) = 0; + virtual StatusCode configureTools( + const ToolHandle<Trk::IMultiStateExtrapolator>&, + const ToolHandle<Trk::IMultiStateMeasurementUpdator>&, + const ToolHandle<Trk::IRIO_OnTrackCreator>&) = 0; /** Forward GSF fit using PrepRawData */ virtual std::unique_ptr<ForwardTrajectory> fitPRD( @@ -61,8 +66,8 @@ public: const TrackParameters&, const ParticleHypothesis particleHypothesis = nonInteracting) const = 0; - /** The interface will later be extended so that the initial state can be additionally a - * MultiComponentState object! + /** The interface will later be extended so that the initial state can be + * additionally a MultiComponentState object! */ }; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IGsfSmoother.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IGsfSmoother.h index b60d348354d33f24c2322946189dd30ff2c71d04..aa20ac008a75bc3b63d0f3d329e1af05d55dd403 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IGsfSmoother.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IGsfSmoother.h @@ -9,7 +9,8 @@ created : Thursday 8th January 2009 author : amorley email : Anthony.Morley@cern.ch decription : Abstract interface for the GSF smoother -********************************************************************************** */ +********************************************************************************** +*/ #ifndef TrkIGsfSmoother_H #define TrkIGsfSmoother_H @@ -42,13 +43,15 @@ public: /** Configure the GSF smoother - Configure the extrapolator - Configure the measurement updator */ - virtual StatusCode configureTools(const ToolHandle<IMultiStateExtrapolator>&, - const ToolHandle<IMultiStateMeasurementUpdator>&) = 0; + virtual StatusCode configureTools( + const ToolHandle<IMultiStateExtrapolator>&, + const ToolHandle<IMultiStateMeasurementUpdator>&) = 0; /** Gsf smoother method */ - virtual SmoothedTrajectory* fit(const ForwardTrajectory&, - const ParticleHypothesis particleHypothesis = nonInteracting, - const CaloCluster_OnTrack* ccot = nullptr) const = 0; + virtual SmoothedTrajectory* fit( + const ForwardTrajectory&, + const ParticleHypothesis particleHypothesis = nonInteracting, + const CaloCluster_OnTrack* ccot = nullptr) const = 0; }; } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMaterialMixtureConvolution.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMaterialMixtureConvolution.h index d92d16f7da2283f6fa8e8d57966368e6b053d9aa..19906cd287913ddfbc4c0556a8b70e7ae3ca27e7 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMaterialMixtureConvolution.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMaterialMixtureConvolution.h @@ -21,35 +21,42 @@ decription : Abstract base class for convolution of material effects namespace Trk { class Layer; -static const InterfaceID IID_IMaterialMixtureConvolution("IMaterialMixtureConvolution", 1, 0); +static const InterfaceID + IID_IMaterialMixtureConvolution("IMaterialMixtureConvolution", 1, 0); class IMaterialMixtureConvolution : virtual public IAlgTool { public: //!< IAlgTool and AlgTool interface method - static const InterfaceID& interfaceID() { return IID_IMaterialMixtureConvolution; }; + static const InterfaceID& interfaceID() + { + return IID_IMaterialMixtureConvolution; + }; //!< Virtual destructor virtual ~IMaterialMixtureConvolution() = default; //!< Convolution with full material properties - virtual MultiComponentState update(const MultiComponentState&, - const Layer&, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const = 0; + virtual MultiComponentState update( + const MultiComponentState&, + const Layer&, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const = 0; //!< Convolution with pre-measurement-update material properties - virtual MultiComponentState preUpdate(const MultiComponentState&, - const Layer&, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const = 0; + virtual MultiComponentState preUpdate( + const MultiComponentState&, + const Layer&, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const = 0; //!< Convolution with post-measurement-update material properties - virtual MultiComponentState postUpdate(const MultiComponentState&, - const Layer&, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const = 0; + virtual MultiComponentState postUpdate( + const MultiComponentState&, + const Layer&, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const = 0; //!< Retain for now redundant simplified material effects virtual MultiComponentState simplifiedMaterialUpdate( diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateExtrapolator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateExtrapolator.h index e9e1694b5180bc746c646a2deec26e20d6f6a3d2..84406c0487bd6bc4308c8658a3ebdcf2d726591e 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateExtrapolator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateExtrapolator.h @@ -9,7 +9,8 @@ begin : Tuesday 25th January 2005 author : atkinson,Morley,Anastopoulos decription : Extrapolation of a MultiComponentState to a destination surface -================================================================================= */ +================================================================================= +*/ #ifndef TrkIMultiStateExtrapolator_H #define TrkIMultiStateExtrapolator_H @@ -22,8 +23,8 @@ decription : Extrapolation of a MultiComponentState to a destination #include "TrkParameters/TrackParameters.h" #include "TrkSurfaces/BoundaryCheck.h" -#include "GaudiKernel/IAlgTool.h" #include "GaudiKernel/EventContext.h" +#include "GaudiKernel/IAlgTool.h" #include <memory> #include <vector> @@ -36,7 +37,9 @@ class Track; class TrackingVolume; class TrackStateOnSurface; -static const InterfaceID IID_IMultiStateExtrapolator("IMultiStateExtrapolator", 1, 0); +static const InterfaceID IID_IMultiStateExtrapolator("IMultiStateExtrapolator", + 1, + 0); class IMultiStateExtrapolator : virtual public IAlgTool { @@ -45,11 +48,14 @@ public: virtual ~IMultiStateExtrapolator() = default; /** AlgTool interface method */ - static const InterfaceID& interfaceID() { return IID_IMultiStateExtrapolator; }; + static const InterfaceID& interfaceID() + { + return IID_IMultiStateExtrapolator; + }; /** Configured AlgTool extrapolation method (1) */ virtual MultiComponentState extrapolate( - const EventContext& ctx, + const EventContext& ctx, const MultiComponentState&, const Surface&, PropDirection direction = anyDirection, @@ -58,20 +64,20 @@ public: /** Configured AlgTool extrapolation without material effects method (2) */ virtual MultiComponentState extrapolateDirectly( - const EventContext& ctx, + const EventContext& ctx, const MultiComponentState&, const Surface&, PropDirection direction = anyDirection, const BoundaryCheck& boundaryCheck = true, ParticleHypothesis particleHypothesis = nonInteracting) const = 0; - virtual std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> extrapolateM( - const EventContext& ctx, - const MultiComponentState&, - const Surface&, - PropDirection dir = anyDirection, - const BoundaryCheck& bcheck = true, - ParticleHypothesis particle = nonInteracting) const = 0; + virtual std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> + extrapolateM(const EventContext& ctx, + const MultiComponentState&, + const Surface&, + PropDirection dir = anyDirection, + const BoundaryCheck& bcheck = true, + ParticleHypothesis particle = nonInteracting) const = 0; }; } // end trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffects.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffects.h index 1858ed4be01d39098128a169520f40fd01864036..3ed6d6c547c1417a694190404be5bc25f6a1c064 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffects.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffects.h @@ -11,7 +11,8 @@ email : Tom.Atkinson@cern.ch decription : (Non-pure) abstract base class for defining material effects including energy loss and multiple scattering for use in the multi-component state environment. These - material effects will produce multi-component state outputs + material effects will produce multi-component state +outputs ************************************************************************************/ #ifndef Trk_IMultiStateMaterialEffects_H @@ -26,14 +27,15 @@ decription : (Non-pure) abstract base class for defining material #include "TrkExInterfaces/IMaterialEffectsUpdator.h" -#include<Eigen/StdVector> +#include <Eigen/StdVector> #include <memory> namespace Trk { class MaterialProperties; -static const InterfaceID IID_IMultiStateMaterialEffects("IMultiStateMaterialEffects", 1, 0); +static const InterfaceID + IID_IMultiStateMaterialEffects("IMultiStateMaterialEffects", 1, 0); class IMultiStateMaterialEffects : virtual public IAlgTool { @@ -56,12 +58,13 @@ public: std::vector<double> weights; std::vector<double> deltaPs; /* - * Suggested + * Suggested * by Eigen 3.3.7 manual - * "you must use the Eigen::aligned_allocator (not another aligned allocator), - * and #include <Eigen/StdVector>." + * "you must use the Eigen::aligned_allocator (not another aligned + * allocator), and #include <Eigen/StdVector>." */ - std::vector<AmgSymMatrix(5),Eigen::aligned_allocator<AmgSymMatrix(5)> > deltaCovariances; + std::vector<AmgSymMatrix(5), Eigen::aligned_allocator<AmgSymMatrix(5)>> + deltaCovariances; void reset() { weights.clear(); @@ -71,17 +74,21 @@ public: }; /** Alg tool and IAlgTool interface method */ - static const InterfaceID& interfaceID() { return IID_IMultiStateMaterialEffects; }; + static const InterfaceID& interfaceID() + { + return IID_IMultiStateMaterialEffects; + }; /** virtual destructor */ virtual ~IMultiStateMaterialEffects() = default; - virtual void compute(IMultiStateMaterialEffects::Cache&, - const ComponentParameters&, - const MaterialProperties&, - double, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const = 0; + virtual void compute( + IMultiStateMaterialEffects::Cache&, + const ComponentParameters&, + const MaterialProperties&, + double, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const = 0; }; } #endif diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffectsUpdator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffectsUpdator.h index 376ceb9a5c011a0d0caffda836c5140b6712c277..89db28e7a8130743a0741bfc68ee5f3d8624657b 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffectsUpdator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMaterialEffectsUpdator.h @@ -27,44 +27,57 @@ namespace Trk { class MaterialProperties; class Layer; -static const InterfaceID IID_IMultiStateMaterialEffectsUpdator("IMultiStateMaterialEffectsUpdator", 1, 0); +static const InterfaceID IID_IMultiStateMaterialEffectsUpdator( + "IMultiStateMaterialEffectsUpdator", + 1, + 0); class IMultiStateMaterialEffectsUpdator : virtual public IAlgTool { public: /** AlgTool interface method */ - static const InterfaceID& interfaceID() { return IID_IMultiStateMaterialEffectsUpdator; }; + static const InterfaceID& interfaceID() + { + return IID_IMultiStateMaterialEffectsUpdator; + }; /** Virtual destructor */ virtual ~IMultiStateMaterialEffectsUpdator() = default; - /** Method for updating the state with material effects provided by the layer object */ - virtual Trk::MultiComponentState updateState(const ComponentParameters&, - const Layer&, - PropDirection direction = alongMomentum, - ParticleHypothesis = nonInteracting) const = 0; - - /** Method for updating the state with material effects provided by a material properties object - * and a pathlength */ - virtual Trk::MultiComponentState updateState(const ComponentParameters&, - const MaterialProperties&, - double, - PropDirection = alongMomentum, - ParticleHypothesis = nonInteracting) const = 0; - - /** Method for the state with material effects provided by the layer object prior to propagation + /** Method for updating the state with material effects provided by the layer + * object */ + virtual Trk::MultiComponentState updateState( + const ComponentParameters&, + const Layer&, + PropDirection direction = alongMomentum, + ParticleHypothesis = nonInteracting) const = 0; + + /** Method for updating the state with material effects provided by a material + * properties object and a pathlength */ + virtual Trk::MultiComponentState updateState( + const ComponentParameters&, + const MaterialProperties&, + double, + PropDirection = alongMomentum, + ParticleHypothesis = nonInteracting) const = 0; + + /** Method for the state with material effects provided by the layer object + * prior to propagation */ - virtual Trk::MultiComponentState preUpdateState(const ComponentParameters&, - const Layer&, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const = 0; - - /** Method for the state with material effects provided by the layer object after propagation */ - virtual Trk::MultiComponentState postUpdateState(const ComponentParameters&, - const Layer&, - PropDirection direction = anyDirection, - ParticleHypothesis particleHypothesis = nonInteracting) const = 0; + virtual Trk::MultiComponentState preUpdateState( + const ComponentParameters&, + const Layer&, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const = 0; + + /** Method for the state with material effects provided by the layer object + * after propagation */ + virtual Trk::MultiComponentState postUpdateState( + const ComponentParameters&, + const Layer&, + PropDirection direction = anyDirection, + ParticleHypothesis particleHypothesis = nonInteracting) const = 0; }; } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMeasurementUpdator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMeasurementUpdator.h index 246129e4a238bc8d092ff53d71fff8c5f8820236..2965b0d6d0856bbfe71d7b4f772ada623306d347 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMeasurementUpdator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/IMultiStateMeasurementUpdator.h @@ -24,33 +24,44 @@ namespace Trk { class MeasurementBase; -static const InterfaceID IID_IMultiStateMeasurementUpdator("IMultiStateMeasurementUpdator", 1, 0); +static const InterfaceID + IID_IMultiStateMeasurementUpdator("IMultiStateMeasurementUpdator", 1, 0); class IMultiStateMeasurementUpdator : virtual public IAlgTool { public: /** IAlgTool and AlgTool interface method */ - static const InterfaceID& interfaceID() { return IID_IMultiStateMeasurementUpdator; }; + static const InterfaceID& interfaceID() + { + return IID_IMultiStateMeasurementUpdator; + }; /** Virtual destructor */ virtual ~IMultiStateMeasurementUpdator() = default; /** Method for forward filters to incorporate measurement updates */ - virtual MultiComponentState update(MultiComponentState&&, const MeasurementBase&) const = 0; + virtual MultiComponentState update(MultiComponentState&&, + const MeasurementBase&) const = 0; - /** Method for updating the multi-state with a new measurement and calculate the fit qaulity at - * the same time*/ - virtual MultiComponentState update(Trk::MultiComponentState&&, - const Trk::MeasurementBase&, - std::unique_ptr<FitQualityOnSurface>& fitQoS) const = 0; + /** Method for updating the multi-state with a new measurement and calculate + * the fit qaulity at the same time*/ + virtual MultiComponentState update( + Trk::MultiComponentState&&, + const Trk::MeasurementBase&, + std::unique_ptr<FitQualityOnSurface>& fitQoS) const = 0; - /** Method for reverse filters (smoothers) to determine the unbiased track parameters */ - virtual MultiComponentState getUnbiasedTrackParameters(MultiComponentState&&, - const MeasurementBase&) const = 0; + /** Method for reverse filters (smoothers) to determine the unbiased track + * parameters */ + virtual MultiComponentState getUnbiasedTrackParameters( + MultiComponentState&&, + const MeasurementBase&) const = 0; - /** Method for determining the chi2 of the track and the number of degrees of freedom */ - virtual const FitQualityOnSurface* fitQuality(const MultiComponentState&, const MeasurementBase&) const = 0; + /** Method for determining the chi2 of the track and the number of degrees of + * freedom */ + virtual const FitQualityOnSurface* fitQuality( + const MultiComponentState&, + const MeasurementBase&) const = 0; }; } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/KLGaussianMixtureReduction.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/KLGaussianMixtureReduction.h index a17d7a6786ef5cbe433d011213054c897a7c628e..2525c5632efd681aafa7d8e97d75786be35c91fb 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/KLGaussianMixtureReduction.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/KLGaussianMixtureReduction.h @@ -3,53 +3,54 @@ */ /** -* @file KLGaussianMixtureReduction.h -* @author amorley -* @author Anastopoulos -* @date 26th November 2019 -* @brief Function that help implement component merging . -*/ + * @file KLGaussianMixtureReduction.h + * @author amorley + * @author Anastopoulos + * @date 26th November 2019 + * @brief Function that help implement component merging . + */ #ifndef KLGaussianMixReductionUtils_H #define KLGaussianMixReductionUtils_H -#include "CxxUtils/restrict.h" #include "CxxUtils/features.h" -#include <vector> -#include <utility> +#include "CxxUtils/restrict.h" #include <cstdint> +#include <utility> +#include <vector> namespace GSFUtils { /** * Alignment used for SIMD */ -constexpr size_t alignment =32; +constexpr size_t alignment = 32; /** * The main pupropse of the utilities here - * are to facilitate the calculation of the - * divergence between components of the mixture + * are to facilitate the calculation of the + * divergence between components of the mixture * and the merging of similar componets. * - * For a revies of available methods look + * For a revies of available methods look * https://arxiv.org/pdf/2001.00727.pdf * - * Here we opt for formula 10. - * For an 1D Normal distributions this becomes: + * Here we opt for formula 10. + * For an 1D Normal distributions this becomes: * - * (variance1-variance2) (1/variance1 - 1/variance2) - + * (variance1-variance2) (1/variance1 - 1/variance2) - * (mean1-mean2)(1/variance+1/variance)(mean1-mean2) * * We use doubles for the intermediate calculations * but we store the final distances to short in an array * of floats. * -*/ -struct Component1D{ - double mean=0.; - double cov=0.; - double invCov=1e10; - double weight=0.; + */ +struct Component1D +{ + double mean = 0.; + double cov = 0.; + double invCov = 1e10; + double weight = 0.; }; /** @@ -63,45 +64,46 @@ struct Component1D{ * [............................. * [(N-1,0),(N-1,1),(N-1,2),(N-1,3).......(N-1,N-2)] * - * With size + * With size * 1+2+3+ .... (N-1) = N*(N-1)/2 * * The lexicographical storage allocation function is - * Loc(i,j) = i*(i-1)/2 + j + * Loc(i,j) = i*(i-1)/2 + j * e.g - * (1,0) --> 1 *(1-1)/2 + 0 --> 0 + * (1,0) --> 1 *(1-1)/2 + 0 --> 0 * (2,0) --> 2 *(2-1)/2 + 0 --> 1 * (2,1) --> 2 *(2-1)/2 + 1 --> 2 * (3,0) --> 3 * (3-1)/2 +0 --> 3 - * Leading to + * Leading to * [(1,0),(2,0),(2,1),(3,0),(3,1),(3,2)...... (N-1,N-2)] - * + * * * The N-1 Rows map to value K of the 1st element in the pair. - * K=1,2,3,...N-1 and each one has size K. + * K=1,2,3,...N-1 and each one has size K. * Each Row starts at array positions K*(K-1)/2 - * e.g + * e.g * The row for element 1 starts at array position 0. * The row for element 2 starts at array position 1. * The row for element N-1 starts at array positon (N-1)*(N-2)/2 - * - * The N-1 Columns map to the value K of the second element in the pair + * + * The N-1 Columns map to the value K of the second element in the pair * 0,1,2 ... N-2 * The array position follow (i-1)*i/2+K; * where i : K+1 .... N-1 [for(i=K+1;i<N;++i) - * e.g - * 0 appears as 2nd element in the pair at array positions + * e.g + * 0 appears as 2nd element in the pair at array positions * [0,1,3,6...] * 1 appears as 2nd element in the pair at array positions - * [2,4,7...] + * [2,4,7...] * 2 appears as 2nd element in the pair at array positions - * [5,8,12....] + * [5,8,12....] * N-2 appears as 2nd element once at position [N(N-1)/2-1] * */ -struct triangularToIJ{ - int32_t I=-1; - int32_t J=-1; +struct triangularToIJ +{ + int32_t I = -1; + int32_t J = -1; }; /** @@ -111,12 +113,12 @@ typedef float* ATH_RESTRICT floatPtrRestrict; typedef Component1D* ATH_RESTRICT componentPtrRestrict; /** - * Merge the componentsIn and return + * Merge the componentsIn and return * which componets got merged */ std::vector<std::pair<int32_t, int32_t>> -findMerges(componentPtrRestrict componentsIn, - const int32_t inputSize, +findMerges(componentPtrRestrict componentsIn, + const int32_t inputSize, const int32_t reducedSize); /** @@ -125,24 +127,18 @@ findMerges(componentPtrRestrict componentsIn, */ #if HAVE_FUNCTION_MULTIVERSIONING #if defined(__x86_64__) -__attribute__((target("avx2"))) -std::pair<int32_t,float> +__attribute__((target("avx2"))) std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int32_t n); -__attribute__((target("sse4.1"))) -std::pair<int32_t,float> +__attribute__((target("sse4.1"))) std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int32_t n); -__attribute__((target("sse2"))) -std::pair<int32_t,float> +__attribute__((target("sse2"))) std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int32_t n); -#endif //x86_64 specific targets +#endif // x86_64 specific targets __attribute__((target("default"))) -#endif// function multiversioning -std::pair<int32_t,float> +#endif // function multiversioning +std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int32_t n); } // namespace KLGaussianMixtureReduction - - - #endif diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateAssembler.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateAssembler.h index 902c027c6e5d27ed9a6329a8cc9ad4fa61a5e2d0..f92bf819fef786132c12c502918a8b3c9880bb88 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateAssembler.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateAssembler.h @@ -52,13 +52,13 @@ struct Cache void reset(Cache& cache); -/** Method to add a single set of Trk::ComponentParameters to the cached Trk::MultiComponentState - * object under construction */ +/** Method to add a single set of Trk::ComponentParameters to the cached + * Trk::MultiComponentState object under construction */ bool addComponent(Cache& cache, ComponentParameters&&); -/** Method to add a new Trk::MultiComponentState to the cached Trk::MultiComponentState o - * bject under construction */ +/** Method to add a new Trk::MultiComponentState to the cached + * Trk::MultiComponentState o bject under construction */ bool addMultiState(Cache& cache, Trk::MultiComponentState&&); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateCombiner.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateCombiner.h index ad65f1117fb85c1ecfb1e4cbb7aa1edc339673a7..c6bc1accc8198fb4003a09e2c1d28a7a1ffe85ef 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateCombiner.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateCombiner.h @@ -23,18 +23,25 @@ namespace MultiComponentStateCombiner { /** Calculate combined state of many components */ std::unique_ptr<Trk::TrackParameters> -combine(const MultiComponentState&, const bool useMode = false, const double fractionPDFused = 1.0); +combine(const MultiComponentState&, + const bool useMode = false, + const double fractionPDFused = 1.0); /** Combined/merge a component to another one */ void -combineWithWeight(Trk::ComponentParameters& mergeTo, const Trk::ComponentParameters& addThis); +combineWithWeight(Trk::ComponentParameters& mergeTo, + const Trk::ComponentParameters& addThis); /** Calculate combined state and weight of many components */ std::unique_ptr<Trk::ComponentParameters> -combineWithWeight(const MultiComponentState&, const bool useMode = false, const double fractionPDFused = 1.0); +combineWithWeight(const MultiComponentState&, + const bool useMode = false, + const double fractionPDFused = 1.0); std::unique_ptr<Trk::ComponentParameters> -compute(const MultiComponentState*, const bool useMode = false, const double fractionPDFused = 1.0); +compute(const MultiComponentState*, + const bool useMode = false, + const double fractionPDFused = 1.0); } } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateModeCalculator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateModeCalculator.h index 7a21a20efeff8d0fb2bfcff31af360c08397840b..d1892ae88c1f55719f1bb1bf38a4284fe3baa529 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateModeCalculator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/MultiComponentStateModeCalculator.h @@ -8,7 +8,8 @@ begin : Thursday 6th July 2006 author : atkinson email : Tom.Atkinson@cern.ch -description : Class to calculate the mode (q/p) of a gaussian mixtureArray +description : Class to calculate the mode (q/p) of a gaussian +mixtureArray ***********************************************************************************/ #ifndef Trk_MultiComponentStateModeCalculator_H @@ -45,11 +46,14 @@ struct Component std::array<double, 10> calculateMode(const MultiComponentState&); -//!< method to extract the weight, mean and sigma values from the multi-component state +//!< method to extract the weight, mean and sigma values from the +//!< multi-component state void -fillMixture(const MultiComponentState&, std::array<std::vector<Component>, 5>& mixture); +fillMixture(const MultiComponentState&, + std::array<std::vector<Component>, 5>& mixture); -//!< method to find the mode using the Newton-Raphson method based on a starting guess +//!< method to find the mode using the Newton-Raphson method based on a +//!< starting guess double findMode(double, int, const std::array<std::vector<Component>, 5>& mixture); @@ -61,16 +65,20 @@ pdf(double, int, const std::array<std::vector<Component>, 5>& mixture); double d1pdf(double, int, const std::array<std::vector<Component>, 5>& mixture); -//!< method to determine the second order derivative of the pdf at a given value +//!< method to determine the second order derivative of the pdf at a given +//!< value double d2pdf(double, int, const std::array<std::vector<Component>, 5>& mixture); -//!< method to determine the value of the a gaussian distribution at a given value +//!< method to determine the value of the a gaussian distribution at a given +//!< value double gaus(double x, double mean, double sigma); double -findModeGlobal(double, int, const std::array<std::vector<Component>, 5>& mixture); +findModeGlobal(double, + int, + const std::array<std::vector<Component>, 5>& mixture); double width(int i, const std::array<std::vector<Component>, 5>& mixture); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/PosteriorWeightsCalculator.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/PosteriorWeightsCalculator.h index 6de5445a03a8f24cee9cfbece1759cf2170a61cf..78c1d5edea01038b7a32003aaa9ce849ff02adfc 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/PosteriorWeightsCalculator.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/PosteriorWeightsCalculator.h @@ -28,61 +28,72 @@ namespace Trk { class PosteriorWeightsCalculator { public: - std::vector<Trk::ComponentParameters> weights(MultiComponentState&&, const MeasurementBase&) const; + std::vector<Trk::ComponentParameters> weights(MultiComponentState&&, + const MeasurementBase&) const; private: - /** Function to calculate the determinant and chi2 of a measurement for a 1D hit */ - std::pair<double, double> calculateWeight_1D(const TrackParameters* componentTrackParameters, - const AmgSymMatrix(5) * predictedCov, - const double measPar, - const double measCov, - int paramKey) const; - - /** Function to calculate the determinant and chi2 of a measurement for a 2D hit - specially when the measurements are when local x and local y */ - std::pair<double, double> calculateWeight_2D_3(const TrackParameters* componentTrackParameters, - const AmgSymMatrix(5) * predictedCov, - const AmgVector(2) & measPar, - const AmgSymMatrix(2) & measCov) const; - - /** Tempplated Function to calculate the determinant and chi2 of a measurement for a N'D hit */ + /** Function to calculate the determinant and chi2 of a measurement for a 1D + * hit */ + std::pair<double, double> calculateWeight_1D( + const TrackParameters* componentTrackParameters, + const AmgSymMatrix(5) * predictedCov, + const double measPar, + const double measCov, + int paramKey) const; + + /** Function to calculate the determinant and chi2 of a measurement for a 2D + hit specially when the measurements are when local x and local y */ + std::pair<double, double> calculateWeight_2D_3( + const TrackParameters* componentTrackParameters, + const AmgSymMatrix(5) * predictedCov, + const AmgVector(2) & measPar, + const AmgSymMatrix(2) & measCov) const; + + /** Tempplated Function to calculate the determinant and chi2 of a + * measurement for a N'D hit */ template<int DIM> - std::pair<double, double> calculateWeight_T(const TrackParameters* componentTrackParameters, - const AmgSymMatrix(5) * predictedCov, - const AmgVector(DIM) & measPar, - const AmgSymMatrix(DIM) & measCov, - int paramKey) const; + std::pair<double, double> calculateWeight_T( + const TrackParameters* componentTrackParameters, + const AmgSymMatrix(5) * predictedCov, + const AmgVector(DIM) & measPar, + const AmgSymMatrix(DIM) & measCov, + int paramKey) const; }; template<int DIM> std::pair<double, double> -PosteriorWeightsCalculator::calculateWeight_T(const TrackParameters* componentTrackParameters, - const AmgSymMatrix(5) * predictedCov, - const AmgVector(DIM) & measPar, - const AmgSymMatrix(DIM) & measCov, - int paramKey) const +PosteriorWeightsCalculator::calculateWeight_T( + const TrackParameters* componentTrackParameters, + const AmgSymMatrix(5) * predictedCov, + const AmgVector(DIM) & measPar, + const AmgSymMatrix(DIM) & measCov, + int paramKey) const { - static const ProjectionMatricesSet reMatrices(5); //!< expansion and reduction matrices set + static const ProjectionMatricesSet reMatrices( + 5); //!< expansion and reduction matrices set // Define the expansion matrix - const AmgMatrix(DIM, 5) H = reMatrices.expansionMatrix(paramKey).block<DIM, 5>(0, 0); + const AmgMatrix(DIM, 5) H = + reMatrices.expansionMatrix(paramKey).block<DIM, 5>(0, 0); // Calculate the residual AmgVector(DIM) r = measPar - H * componentTrackParameters->parameters(); - // Residual covariance. Posterior weights is calculated used predicted state and measurement. - // Therefore add covariances + // Residual covariance. Posterior weights is calculated used predicted state + // and measurement. Therefore add covariances AmgSymMatrix(DIM) R(measCov + H * (*predictedCov) * H.transpose()); // compute determinant of residual const double det = R.determinant(); if (det == 0) { - // ATH_MSG_WARNING( "Determinant is 0, cannot invert matrix... Ignoring component" ); + // ATH_MSG_WARNING( "Determinant is 0, cannot invert matrix... Ignoring + // component" ); return std::pair<double, double>(0, 0); } // Compute Chi2 - return std::pair<double, double>(det, (1. / (double)DIM) * ((r.transpose() * R.inverse() * r)(0, 0))); + return std::pair<double, double>( + det, (1. / (double)DIM) * ((r.transpose() * R.inverse() * r)(0, 0))); } } // end Trk namespace diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h index 2515056819b2e4fbf5edb2b72d83f7176c52cf76..69e3582be5f0de983609e6aadd6056b0e1e4737a 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h @@ -22,9 +22,8 @@ decription : Class for merging components of a multi-state based on namespace Trk { class IMultiComponentStateCombiner; class TrackStateOnSurface; -namespace QuickCloseComponentsMultiStateMerger -{ - /** Method for merging components - ownership of objects is passed */ +namespace QuickCloseComponentsMultiStateMerger { +/** Method for merging components - ownership of objects is passed */ MultiComponentState merge(Trk::MultiComponentState&&, const unsigned int maximumNumberOfComponents); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/ForwardGsfFitter.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/ForwardGsfFitter.cxx index 13251988c1fe02a91ee87c6508a000c4a497372f..8d3b574cca28536d15d0874d04d520eb92a3f264 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/ForwardGsfFitter.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/ForwardGsfFitter.cxx @@ -9,7 +9,8 @@ begin : Wednesday 9th March 2005 author : amorley, atkinson email : Anthony.Morley@cern.ch, Tom.Atkinson@cern.ch decription : Implementation code for ForwardGsfFitter class -********************************************************************************** */ +********************************************************************************** +*/ #include "TrkGaussianSumFilter/ForwardGsfFitter.h" @@ -27,7 +28,9 @@ decription : Implementation code for ForwardGsfFitter class #include "TrkSurfaces/Surface.h" #include "TrkToolInterfaces/IRIO_OnTrackCreator.h" -Trk::ForwardGsfFitter::ForwardGsfFitter(const std::string& type, const std::string& name, const IInterface* parent) +Trk::ForwardGsfFitter::ForwardGsfFitter(const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) , m_cutChiSquaredPerNumberDOF(50.) , m_overideMaterialEffects(4) @@ -37,7 +40,8 @@ Trk::ForwardGsfFitter::ForwardGsfFitter(const std::string& type, const std::stri declareInterface<IForwardGsfFitter>(this); declareProperty("StateChi2PerNDOFCut", m_cutChiSquaredPerNumberDOF); - declareProperty("OverideForwardsMaterialEffects", m_overideMaterialEffectsSwitch); + declareProperty("OverideForwardsMaterialEffects", + m_overideMaterialEffectsSwitch); declareProperty("MaterialEffectsInForwardFitter", m_overideMaterialEffects); } @@ -45,12 +49,15 @@ StatusCode Trk::ForwardGsfFitter::initialize() { - ATH_MSG_DEBUG("A cut on Chi2 / NDOF: " << m_cutChiSquaredPerNumberDOF << " will be applied"); + ATH_MSG_DEBUG("A cut on Chi2 / NDOF: " << m_cutChiSquaredPerNumberDOF + << " will be applied"); Trk::ParticleSwitcher particleSwitcher; - m_overideParticleHypothesis = particleSwitcher.particle[m_overideMaterialEffects]; + m_overideParticleHypothesis = + particleSwitcher.particle[m_overideMaterialEffects]; if (m_overideMaterialEffectsSwitch) { - ATH_MSG_INFO("Material effects in forwards fitter have been overiden by jobOptions... New " + ATH_MSG_INFO("Material effects in forwards fitter have been overiden by " + "jobOptions... New " "Trk::ParticleHypothesis: " << m_overideMaterialEffects); } @@ -68,9 +75,10 @@ Trk::ForwardGsfFitter::finalize() } StatusCode -Trk::ForwardGsfFitter::configureTools(const ToolHandle<IMultiStateExtrapolator>& extrapolator, - const ToolHandle<IMultiStateMeasurementUpdator>& measurementUpdator, - const ToolHandle<IRIO_OnTrackCreator>& rioOnTrackCreator) +Trk::ForwardGsfFitter::configureTools( + const ToolHandle<IMultiStateExtrapolator>& extrapolator, + const ToolHandle<IMultiStateMeasurementUpdator>& measurementUpdator, + const ToolHandle<IRIO_OnTrackCreator>& rioOnTrackCreator) { m_extrapolator = extrapolator; m_updator = measurementUpdator; @@ -85,9 +93,10 @@ Trk::ForwardGsfFitter::configureTools(const ToolHandle<IMultiStateExtrapolator>& =============================================================================================================*/ std::unique_ptr<Trk::ForwardTrajectory> -Trk::ForwardGsfFitter::fitPRD(const Trk::PrepRawDataSet& inputPrepRawDataSet, - const Trk::TrackParameters& estimatedTrackParametersNearOrigin, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::ForwardGsfFitter::fitPRD( + const Trk::PrepRawDataSet& inputPrepRawDataSet, + const Trk::TrackParameters& estimatedTrackParametersNearOrigin, + const Trk::ParticleHypothesis particleHypothesis) const { // Check that the updator is instansiated @@ -102,7 +111,8 @@ Trk::ForwardGsfFitter::fitPRD(const Trk::PrepRawDataSet& inputPrepRawDataSet, } if (!m_rioOnTrackCreator) { - ATH_MSG_ERROR("The RIO_OnTrackCreator is not configured for use with the PrepRawData set... Exiting!"); + ATH_MSG_ERROR("The RIO_OnTrackCreator is not configured for use with the " + "PrepRawData set... Exiting!"); return nullptr; } @@ -120,8 +130,8 @@ Trk::ForwardGsfFitter::fitPRD(const Trk::PrepRawDataSet& inputPrepRawDataSet, configuredParticleHypothesis = particleHypothesis; } - // Extract PrepRawDataSet into new local object and check that the PrepRawData is associated with - // a detector element + // Extract PrepRawDataSet into new local object and check that the PrepRawData + // is associated with a detector element Trk::PrepRawDataSet prepRawDataSet; Trk::PrepRawDataSet::const_iterator prepRawData = inputPrepRawDataSet.begin(); @@ -137,29 +147,38 @@ Trk::ForwardGsfFitter::fitPRD(const Trk::PrepRawDataSet& inputPrepRawDataSet, // Create new trajectory auto forwardTrajectory = std::make_unique<Trk::ForwardTrajectory>(); - // Prepare the multi-component state. For starting guess this has single component, weight 1 + // Prepare the multi-component state. For starting guess this has single + // component, weight 1 const AmgVector(5)& par = estimatedTrackParametersNearOrigin.parameters(); Trk::ComponentParameters componentParametersNearOrigin( - estimatedTrackParametersNearOrigin.associatedSurface().createTrackParameters( - par[Trk::loc1], par[Trk::loc2], par[Trk::phi], par[Trk::theta], par[Trk::qOverP], nullptr /*no errors*/), + estimatedTrackParametersNearOrigin.associatedSurface() + .createTrackParameters(par[Trk::loc1], + par[Trk::loc2], + par[Trk::phi], + par[Trk::theta], + par[Trk::qOverP], + nullptr /*no errors*/), 1.); Trk::MultiComponentState multiComponentStateNearOrigin{}; - multiComponentStateNearOrigin.push_back(std::move(componentParametersNearOrigin)); + multiComponentStateNearOrigin.push_back( + std::move(componentParametersNearOrigin)); // Loop over all PrepRawData measurements prepRawData = prepRawDataSet.begin(); for (; prepRawData != prepRawDataSet.end(); ++prepRawData) { - // Every valid step the ForwardTrajectory object passed to the stepForwardFit method is updated - bool stepIsValid = stepForwardFit(forwardTrajectory.get(), - *prepRawData, - nullptr, - (*prepRawData)->detectorElement()->surface((*prepRawData)->identify()), - multiComponentStateNearOrigin, - configuredParticleHypothesis); + // Every valid step the ForwardTrajectory object passed to the + // stepForwardFit method is updated + bool stepIsValid = stepForwardFit( + forwardTrajectory.get(), + *prepRawData, + nullptr, + (*prepRawData)->detectorElement()->surface((*prepRawData)->identify()), + multiComponentStateNearOrigin, + configuredParticleHypothesis); if (!stepIsValid) { ATH_MSG_DEBUG("Fitter step is not valid... Exiting!"); @@ -175,9 +194,10 @@ Trk::ForwardGsfFitter::fitPRD(const Trk::PrepRawDataSet& inputPrepRawDataSet, */ std::unique_ptr<Trk::ForwardTrajectory> -Trk::ForwardGsfFitter::fitMeasurements(const Trk::MeasurementSet& inputMeasurementSet, - const Trk::TrackParameters& estimatedTrackParametersNearOrigin, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::ForwardGsfFitter::fitMeasurements( + const Trk::MeasurementSet& inputMeasurementSet, + const Trk::TrackParameters& estimatedTrackParametersNearOrigin, + const Trk::ParticleHypothesis particleHypothesis) const { // Check that the updator is instansiated if (!m_updator) { @@ -207,18 +227,25 @@ Trk::ForwardGsfFitter::fitMeasurements(const Trk::MeasurementSet& inputMeasureme // This memory should be freed by the fitter / smoother master method auto forwardTrajectory = std::make_unique<Trk::ForwardTrajectory>(); - // Prepare the multi-component state. For starting guess this has single component, weight 1 + // Prepare the multi-component state. For starting guess this has single + // component, weight 1 const AmgVector(5)& par = estimatedTrackParametersNearOrigin.parameters(); AmgSymMatrix(5)* covariance = nullptr; Trk::ComponentParameters componentParametersNearOrigin( - estimatedTrackParametersNearOrigin.associatedSurface().createTrackParameters( - par[Trk::loc1], par[Trk::loc2], par[Trk::phi], par[Trk::theta], par[Trk::qOverP], covariance /*no errors*/), + estimatedTrackParametersNearOrigin.associatedSurface() + .createTrackParameters(par[Trk::loc1], + par[Trk::loc2], + par[Trk::phi], + par[Trk::theta], + par[Trk::qOverP], + covariance /*no errors*/), 1.); Trk::MultiComponentState multiComponentStateNearOrigin{}; - multiComponentStateNearOrigin.push_back(std::move(componentParametersNearOrigin)); + multiComponentStateNearOrigin.push_back( + std::move(componentParametersNearOrigin)); // Loop over all MeasurementBase objects in set Trk::MeasurementSet::const_iterator measurement = inputMeasurementSet.begin(); @@ -245,16 +272,18 @@ Trk::ForwardGsfFitter::fitMeasurements(const Trk::MeasurementSet& inputMeasureme */ bool -Trk::ForwardGsfFitter::stepForwardFit(ForwardTrajectory* forwardTrajectory, - const Trk::PrepRawData* originalPrepRawData, - const Trk::MeasurementBase* originalMeasurement, - const Trk::Surface& surface, - Trk::MultiComponentState& updatedState, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::ForwardGsfFitter::stepForwardFit( + ForwardTrajectory* forwardTrajectory, + const Trk::PrepRawData* originalPrepRawData, + const Trk::MeasurementBase* originalMeasurement, + const Trk::Surface& surface, + Trk::MultiComponentState& updatedState, + const Trk::ParticleHypothesis particleHypothesis) const { // Protect against undefined Measurement or PrepRawData if (!originalPrepRawData && !originalMeasurement) { - ATH_MSG_WARNING("No measurement information passed to StepForwardFit... Exiting!"); + ATH_MSG_WARNING( + "No measurement information passed to StepForwardFit... Exiting!"); return false; } @@ -291,48 +320,60 @@ Trk::ForwardGsfFitter::stepForwardFit(ForwardTrajectory* forwardTrajectory, ATH_MSG_WARNING("State combination failed... exiting"); return false; } - // Create a new MeasurementBase object from PrepRawData using new calibration - measurement.reset(m_rioOnTrackCreator->correct(*originalPrepRawData, *combinedState)); + // Create a new MeasurementBase object from PrepRawData using new + // calibration + measurement.reset( + m_rioOnTrackCreator->correct(*originalPrepRawData, *combinedState)); combinedState.reset(); } // ========================== // Perform measurement update // ========================== if (!measurement) { - ATH_MSG_WARNING("Cannot use MeasurementBase for measurement update, it is not defined... Exiting!"); + ATH_MSG_WARNING("Cannot use MeasurementBase for measurement update, it is " + "not defined... Exiting!"); return false; } std::unique_ptr<Trk::FitQualityOnSurface> fitQuality; - updatedState = - m_updator->update(std::move(*(MultiComponentStateHelpers::clone(extrapolatedState))), *measurement, fitQuality); + updatedState = m_updator->update( + std::move(*(MultiComponentStateHelpers::clone(extrapolatedState))), + *measurement, + fitQuality); if (updatedState.empty()) { ATH_MSG_DEBUG("Measurement update of the state failed... Exiting!"); return false; } - // Bail if the fit quality is not defined: + // Bail if the fit quality is not defined: if (!fitQuality) { - ATH_MSG_DEBUG("Failed to make fit quality... rejecting forwards trajectory"); + ATH_MSG_DEBUG( + "Failed to make fit quality... rejecting forwards trajectory"); return false; } // Reject hits with excessive Chi2 - else if (fitQuality->chiSquared() > m_cutChiSquaredPerNumberDOF * fitQuality->numberDoF()) { - ATH_MSG_DEBUG("Update with new measurement caused track to fail Chi Squared test, removing the object"); + if (fitQuality->chiSquared() > + m_cutChiSquaredPerNumberDOF * fitQuality->numberDoF()) { + ATH_MSG_DEBUG("Update with new measurement caused track to fail Chi " + "Squared test, removing the object"); fitQuality = std::make_unique<FitQuality>(1, 1); std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> type(0); type.set(TrackStateOnSurface::Outlier); const Trk::MultiComponentStateOnSurface* multiComponentStateOnSurface = - new MultiComponentStateOnSurface(measurement.release(), - MultiComponentStateHelpers::clone(extrapolatedState).release(), - fitQuality.release(), - nullptr, - type); + new MultiComponentStateOnSurface( + measurement.release(), + MultiComponentStateHelpers::clone(extrapolatedState).release(), + fitQuality.release(), + nullptr, + type); forwardTrajectory->push_back(multiComponentStateOnSurface); // Clean up objects associated with removed measurement updatedState = std::move(extrapolatedState); } else { - const Trk::MultiComponentStateOnSurface* multiComponentStateOnSurface = new MultiComponentStateOnSurface( - measurement.release(), MultiComponentStateHelpers::clone(extrapolatedState).release(), fitQuality.release()); + const Trk::MultiComponentStateOnSurface* multiComponentStateOnSurface = + new MultiComponentStateOnSurface( + measurement.release(), + MultiComponentStateHelpers::clone(extrapolatedState).release(), + fitQuality.release()); forwardTrajectory->push_back(multiComponentStateOnSurface); } return true; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx index 50a86685833429525b867461aea5aee7dac92432..65be4c549ec523ee3bc5ffd9175aeea32656bb9f 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GaussianSumFitter.cxx @@ -9,7 +9,8 @@ begin : Monday 7th March 2005 author : amorley atkinson email : Anthony.Morley@cern.ch Tom.Atkinson@cern.ch decription : Implementation code for Gaussian Sum Fitter class -********************************************************************************** */ +********************************************************************************** +*/ #include "TrkGaussianSumFilter/GaussianSumFitter.h" #include "TrkGaussianSumFilter/IForwardGsfFitter.h" @@ -40,7 +41,9 @@ decription : Implementation code for Gaussian Sum Fitter class #include <algorithm> #include <vector> -Trk::GaussianSumFitter::GaussianSumFitter(const std::string& type, const std::string& name, const IInterface* parent) +Trk::GaussianSumFitter::GaussianSumFitter(const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) , m_reintegrateOutliers(false) , m_makePerigee(true) @@ -80,43 +83,52 @@ Trk::GaussianSumFitter::initialize() // Request the Chrono Service ATH_CHECK(m_chronoSvc.retrieve()); - // Request the GSF forward fitter - hardwired type and instanace name for the GSF + // Request the GSF forward fitter - hardwired type and instanace name for the + // GSF ATH_CHECK(m_forwardGsfFitter.retrieve()); // Request the GSF smoother - hardwired type and instance name for the GSF ATH_CHECK(m_gsfSmoother.retrieve()); - // Request the GSF measurement updator - hardwired type and instance name for the GSF + // Request the GSF measurement updator - hardwired type and instance name for + // the GSF ATH_CHECK(m_updator.retrieve()); // Request the GSF extrapolator ATH_CHECK(m_extrapolator.retrieve()); // Request the RIO_OnTrack creator - // No need to return if RioOnTrack creator tool, only if PrepRawData is used in fit + // No need to return if RioOnTrack creator tool, only if PrepRawData is used + // in fit if (m_rioOnTrackCreator.retrieve().isFailure()) { if (!m_refitOnMeasurementBase) { - ATH_MSG_FATAL("Attempting to use PrepRawData with no RIO_OnTrack creator tool provided... Exiting!"); + ATH_MSG_FATAL("Attempting to use PrepRawData with no RIO_OnTrack creator " + "tool provided... Exiting!"); return StatusCode::FAILURE; - } else { - ATH_MSG_INFO("Request to retrieve the RIO_OnTrack Creator" - << "failed but track is fit at the MeasurementBase level... Continuing!"); } + ATH_MSG_INFO( + "Request to retrieve the RIO_OnTrack Creator" + << "failed but track is fit at the MeasurementBase level... Continuing!"); } // Initialise the closest track parameters search algorithm - Amg::Vector3D referencePosition(m_sortingReferencePoint[0], m_sortingReferencePoint[1], m_sortingReferencePoint[2]); + Amg::Vector3D referencePosition(m_sortingReferencePoint[0], + m_sortingReferencePoint[1], + m_sortingReferencePoint[2]); - m_trkParametersComparisonFunction = new Trk::TrkParametersComparisonFunction(referencePosition); + m_trkParametersComparisonFunction = + new Trk::TrkParametersComparisonFunction(referencePosition); if (!m_trkParametersComparisonFunction) { - ATH_MSG_FATAL("Request to instansiate the ClosestTrackParametersFinder object failed... Exiting!"); + ATH_MSG_FATAL("Request to instansiate the ClosestTrackParametersFinder " + "object failed... Exiting!"); return StatusCode::FAILURE; } // Configure forward fitter - sc = m_forwardGsfFitter->configureTools(m_extrapolator, m_updator, m_rioOnTrackCreator); + sc = m_forwardGsfFitter->configureTools( + m_extrapolator, m_updator, m_rioOnTrackCreator); if (sc.isFailure()) { ATH_MSG_FATAL("Could not configure the forwards GSF fitter... Exiting!"); @@ -158,12 +170,18 @@ Trk::GaussianSumFitter::finalize() msg(MSG::INFO) << " Some Brief GSF Statistics " << endmsg; msg(MSG::INFO) << "-----------------------------------------------" << endmsg; - msg(MSG::INFO) << "Number of Fit PrepRawData Calls: " << m_FitPRD << endmsg; - msg(MSG::INFO) << "Number of Fit MeasurementBase Calls: " << m_FitMeasurementBase << endmsg; - msg(MSG::INFO) << "Number of Forward Fit Failures: " << m_ForwardFailure << endmsg; - msg(MSG::INFO) << "Number of Smoother Failures: " << m_SmootherFailure << endmsg; - msg(MSG::INFO) << "Number of MakePerigee Failures: " << m_PerigeeFailure << endmsg; - msg(MSG::INFO) << "Number of Trks that fail fitquality test: " << m_fitQualityFailure << endmsg; + msg(MSG::INFO) << "Number of Fit PrepRawData Calls: " << m_FitPRD + << endmsg; + msg(MSG::INFO) << "Number of Fit MeasurementBase Calls: " + << m_FitMeasurementBase << endmsg; + msg(MSG::INFO) << "Number of Forward Fit Failures: " + << m_ForwardFailure << endmsg; + msg(MSG::INFO) << "Number of Smoother Failures: " + << m_SmootherFailure << endmsg; + msg(MSG::INFO) << "Number of MakePerigee Failures: " + << m_PerigeeFailure << endmsg; + msg(MSG::INFO) << "Number of Trks that fail fitquality test: " + << m_fitQualityFailure << endmsg; msg(MSG::INFO) << "-----------------------------------------------" << endmsg; msg(MSG::INFO) << "Finalisation of " << name() << " was successful" << endmsg; @@ -177,35 +195,44 @@ Trk::GaussianSumFitter::finalize() */ Trk::Track* -Trk::GaussianSumFitter::fit(const Trk::Track& inputTrack, - const Trk::RunOutlierRemoval outlierRemoval, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::GaussianSumFitter::fit( + const Trk::Track& inputTrack, + const Trk::RunOutlierRemoval outlierRemoval, + const Trk::ParticleHypothesis particleHypothesis) const { - if (msgLvl(MSG::VERBOSE)) + if (msgLvl(MSG::VERBOSE)) { msg() << "Trk::GaussianSumFilter::fit() - Refitting a track" << endmsg; + } // Start the timer Chrono chrono(&(*m_chronoSvc), name()); // Check that the input track has well defined parameters if (inputTrack.trackParameters()->empty()) { - msg(MSG::FATAL) << "No estimation of track parameters near origin... Exiting!" << endmsg; + msg(MSG::FATAL) + << "No estimation of track parameters near origin... Exiting!" << endmsg; return nullptr; } // Check that the input track has associated MeasurementBase objects if (inputTrack.trackStateOnSurfaces()->empty()) { - msg(MSG::FATAL) << "Attempting to fit track to empty MeasurementBase collection... Exiting!" << endmsg; + msg(MSG::FATAL) << "Attempting to fit track to empty MeasurementBase " + "collection... Exiting!" + << endmsg; return nullptr; } // Retrieve the set of track parameters closest to the reference point - const Trk::TrackParameters* parametersNearestReference = *(std::min_element( - inputTrack.trackParameters()->begin(), inputTrack.trackParameters()->end(), *m_trkParametersComparisonFunction)); + const Trk::TrackParameters* parametersNearestReference = + *(std::min_element(inputTrack.trackParameters()->begin(), + inputTrack.trackParameters()->end(), + *m_trkParametersComparisonFunction)); - if (msgLvl(MSG::VERBOSE)) - msg() << "Estimation parameters near reference point: " << *parametersNearestReference << endmsg; + if (msgLvl(MSG::VERBOSE)) { + msg() << "Estimation parameters near reference point: " + << *parametersNearestReference << endmsg; + } // If refitting of track is at the MeasurementBase level // extract the MeasurementBase from the input track and create a new vector @@ -213,70 +240,82 @@ Trk::GaussianSumFitter::fit(const Trk::Track& inputTrack, MeasurementSet measurementSet; - DataVector<const Trk::TrackStateOnSurface>::const_iterator trackStateOnSurface = - inputTrack.trackStateOnSurfaces()->begin(); - for (; trackStateOnSurface != inputTrack.trackStateOnSurfaces()->end(); ++trackStateOnSurface) { + DataVector<const Trk::TrackStateOnSurface>::const_iterator + trackStateOnSurface = inputTrack.trackStateOnSurfaces()->begin(); + for (; trackStateOnSurface != inputTrack.trackStateOnSurfaces()->end(); + ++trackStateOnSurface) { if (!(*trackStateOnSurface)) { - ATH_MSG_WARNING("This track contains an empty MeasurementBase object that won't be included in the fit"); + ATH_MSG_WARNING("This track contains an empty MeasurementBase object " + "that won't be included in the fit"); continue; } if ((*trackStateOnSurface)->measurementOnTrack()) { if ((*trackStateOnSurface)->type(TrackStateOnSurface::Measurement)) { - measurementSet.push_back((*trackStateOnSurface)->measurementOnTrack()); - } else if (m_reintegrateOutliers && (*trackStateOnSurface)->type(TrackStateOnSurface::Outlier)) { - measurementSet.push_back((*trackStateOnSurface)->measurementOnTrack()); + measurementSet.push_back( + (*trackStateOnSurface)->measurementOnTrack()); + } else if (m_reintegrateOutliers && + (*trackStateOnSurface)->type(TrackStateOnSurface::Outlier)) { + measurementSet.push_back( + (*trackStateOnSurface)->measurementOnTrack()); } } } // Apply GSF fit to MeasurementBase objects - return fit(measurementSet, *parametersNearestReference, outlierRemoval, particleHypothesis); - + return fit(measurementSet, + *parametersNearestReference, + outlierRemoval, + particleHypothesis); } - // If refitting of the track is at the PrepRawData level then extract the PrepRawData objects from - // the input track - else { - - PrepRawDataSet prepRawDataSet; + // If refitting of the track is at the PrepRawData level then extract the + // PrepRawData objects from the input track - DataVector<const Trk::MeasurementBase>::const_iterator measurementOnTrack = - inputTrack.measurementsOnTrack()->begin(); + PrepRawDataSet prepRawDataSet; - for (; measurementOnTrack != inputTrack.measurementsOnTrack()->end(); ++measurementOnTrack) { + DataVector<const Trk::MeasurementBase>::const_iterator measurementOnTrack = + inputTrack.measurementsOnTrack()->begin(); - if (!(*measurementOnTrack)) { - ATH_MSG_DEBUG("This track contains an empty MeasurementBase object... Ignoring object"); - continue; - } + for (; measurementOnTrack != inputTrack.measurementsOnTrack()->end(); + ++measurementOnTrack) { - // Dynamic cast to a RIO_OnTrack object - const Trk::RIO_OnTrack* rioOnTrack = nullptr; - if ((*measurementOnTrack)->type(Trk::MeasurementBaseType::RIO_OnTrack)) { - rioOnTrack = static_cast<const Trk::RIO_OnTrack*>(*measurementOnTrack); - } + if (!(*measurementOnTrack)) { + ATH_MSG_DEBUG("This track contains an empty MeasurementBase object... " + "Ignoring object"); + continue; + } - if (!rioOnTrack) { - ATH_MSG_DEBUG("Measurement could not be cast as a RIO_OnTrack object... continuing"); - continue; - } + // Dynamic cast to a RIO_OnTrack object + const Trk::RIO_OnTrack* rioOnTrack = nullptr; + if ((*measurementOnTrack)->type(Trk::MeasurementBaseType::RIO_OnTrack)) { + rioOnTrack = static_cast<const Trk::RIO_OnTrack*>(*measurementOnTrack); + } - const PrepRawData* prepRawData = rioOnTrack->prepRawData(); + if (!rioOnTrack) { + ATH_MSG_DEBUG( + "Measurement could not be cast as a RIO_OnTrack object... continuing"); + continue; + } - if (!prepRawData) { - ATH_MSG_DEBUG("Defined RIO_OnTrack object has no associated PrepRawData object..." - << "this object will be ignored in fit"); - continue; - } + const PrepRawData* prepRawData = rioOnTrack->prepRawData(); - prepRawDataSet.push_back(prepRawData); + if (!prepRawData) { + ATH_MSG_DEBUG( + "Defined RIO_OnTrack object has no associated PrepRawData object..." + << "this object will be ignored in fit"); + continue; } - // Apply GSF fit to PrepRawData objects - return fit(prepRawDataSet, *parametersNearestReference, outlierRemoval, particleHypothesis); + prepRawDataSet.push_back(prepRawData); } + + // Apply GSF fit to PrepRawData objects + return fit(prepRawDataSet, + *parametersNearestReference, + outlierRemoval, + particleHypothesis); } /* ================================================================================================================== @@ -285,16 +324,18 @@ Trk::GaussianSumFitter::fit(const Trk::Track& inputTrack, */ Trk::Track* -Trk::GaussianSumFitter::fit(const Trk::PrepRawDataSet& prepRawDataSet, - const Trk::TrackParameters& estimatedParametersNearOrigin, - const Trk::RunOutlierRemoval outlierRemoval, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::GaussianSumFitter::fit( + const Trk::PrepRawDataSet& prepRawDataSet, + const Trk::TrackParameters& estimatedParametersNearOrigin, + const Trk::RunOutlierRemoval outlierRemoval, + const Trk::ParticleHypothesis particleHypothesis) const { - ATH_MSG_VERBOSE("Trk::GaussianSumFilter::fit() - Fitting a set of PrepRawData objects" - << '\n' - << "Material effects switch: " << particleHypothesis << '\n' - << "Outlier removal switch: " << outlierRemoval); + ATH_MSG_VERBOSE( + "Trk::GaussianSumFilter::fit() - Fitting a set of PrepRawData objects" + << '\n' + << "Material effects switch: " << particleHypothesis << '\n' + << "Outlier removal switch: " << outlierRemoval); ++m_FitPRD; @@ -307,20 +348,28 @@ Trk::GaussianSumFitter::fit(const Trk::PrepRawDataSet& prepRawDataSet, return nullptr; } - // A const stl container cannot be sorted. This will re-cast it so that it can. + // A const stl container cannot be sorted. This will re-cast it so that it + // can. Trk::PrepRawDataSet sortedPrepRawDataSet = PrepRawDataSet(prepRawDataSet); if (m_doHitSorting) { - Trk::PrepRawDataComparisonFunction* prdComparisonFunction = new Trk::PrepRawDataComparisonFunction( - estimatedParametersNearOrigin.position(), estimatedParametersNearOrigin.momentum()); - std::sort(sortedPrepRawDataSet.begin(), sortedPrepRawDataSet.end(), *prdComparisonFunction); + Trk::PrepRawDataComparisonFunction* prdComparisonFunction = + new Trk::PrepRawDataComparisonFunction( + estimatedParametersNearOrigin.position(), + estimatedParametersNearOrigin.momentum()); + std::sort(sortedPrepRawDataSet.begin(), + sortedPrepRawDataSet.end(), + *prdComparisonFunction); delete prdComparisonFunction; } // Perform GSF forwards fit ForwardTrajectory* forwardTrajectory = - m_forwardGsfFitter->fitPRD(sortedPrepRawDataSet, estimatedParametersNearOrigin, particleHypothesis).release(); + m_forwardGsfFitter + ->fitPRD( + sortedPrepRawDataSet, estimatedParametersNearOrigin, particleHypothesis) + .release(); if (!forwardTrajectory) { ATH_MSG_DEBUG("Forward GSF fit failed... Exiting!"); @@ -338,7 +387,8 @@ Trk::GaussianSumFitter::fit(const Trk::PrepRawDataSet& prepRawDataSet, ATH_MSG_VERBOSE("*** Forward GSF fit passed! ***"); // Perform GSF smoother operation - SmoothedTrajectory* smoothedTrajectory = m_gsfSmoother->fit(*forwardTrajectory, particleHypothesis); + SmoothedTrajectory* smoothedTrajectory = + m_gsfSmoother->fit(*forwardTrajectory, particleHypothesis); // Protect against failed smoother fit if (!smoothedTrajectory) { @@ -364,16 +414,18 @@ Trk::GaussianSumFitter::fit(const Trk::PrepRawDataSet& prepRawDataSet, Track* fittedTrack = nullptr; if (outlierRemoval) { - ATH_MSG_DEBUG("Outlier removal not yet implemented for the Gaussian Sum Filter"); + ATH_MSG_DEBUG( + "Outlier removal not yet implemented for the Gaussian Sum Filter"); } if (m_makePerigee) { const Trk::MultiComponentStateOnSurface* perigeeMultiStateOnSurface = this->makePerigee(smoothedTrajectory, particleHypothesis); - ATH_MSG_DEBUG("perigeeMultiStateOnSurface :" << perigeeMultiStateOnSurface); - if (perigeeMultiStateOnSurface) + ATH_MSG_DEBUG( + "perigeeMultiStateOnSurface :" << perigeeMultiStateOnSurface); + if (perigeeMultiStateOnSurface) { smoothedTrajectory->push_back(perigeeMultiStateOnSurface); - else { + } else { ATH_MSG_DEBUG("Perigee asked to be created but failed.....Exiting"); ++m_PerigeeFailure; delete smoothedTrajectory; @@ -397,8 +449,10 @@ Trk::GaussianSumFitter::fit(const Trk::PrepRawDataSet& prepRawDataSet, if (fittedTrack) { ATH_MSG_VERBOSE("Fitting of a set of PrepRawData objects is successful" << '\n' - << "Track fit chi squared... " << fitQuality->chiSquared() << '\n' - << "Track fit number of degrees of freedom... " << fitQuality->numberDoF()); + << "Track fit chi squared... " << fitQuality->chiSquared() + << '\n' + << "Track fit number of degrees of freedom... " + << fitQuality->numberDoF()); } else { ATH_MSG_DEBUG("Trk::GaussianSumFilter::fit() failed!"); } @@ -407,23 +461,26 @@ Trk::GaussianSumFitter::fit(const Trk::PrepRawDataSet& prepRawDataSet, /* ================================================================================================ Fitting of a set of MeasurementBase objects -============== ==================================================================================== +============== +==================================================================================== */ Trk::Track* -Trk::GaussianSumFitter::fit(const Trk::MeasurementSet& measurementSet, - const Trk::TrackParameters& estimatedParametersNearOrigin, - const Trk::RunOutlierRemoval outlierRemoval, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::GaussianSumFitter::fit( + const Trk::MeasurementSet& measurementSet, + const Trk::TrackParameters& estimatedParametersNearOrigin, + const Trk::RunOutlierRemoval outlierRemoval, + const Trk::ParticleHypothesis particleHypothesis) const { // Start the timer Chrono chrono(&(*m_chronoSvc), name()); - ATH_MSG_VERBOSE("Trk::GaussianSumFilter::fit() - Fitting a set of MeasurementBase objects" - << '\n' - << "Material effects switch: " << particleHypothesis << '\n' - << "Outlier removal switch: " << outlierRemoval); + ATH_MSG_VERBOSE( + "Trk::GaussianSumFilter::fit() - Fitting a set of MeasurementBase objects" + << '\n' + << "Material effects switch: " << particleHypothesis << '\n' + << "Outlier removal switch: " << outlierRemoval); ++m_FitMeasurementBase; // Protect against empty PrepRawDataSet object @@ -440,7 +497,8 @@ Trk::GaussianSumFitter::fit(const Trk::MeasurementSet& measurementSet, MeasurementSet::const_iterator itSetEnd = measurementSet.end(); for (; itSet != itSetEnd; ++itSet) { if (!(*itSet)) { - ATH_MSG_WARNING("There is an empty MeasurementBase object in the track! Skip this object.."); + ATH_MSG_WARNING("There is an empty MeasurementBase object in the track! " + "Skip this object.."); } else { ccot = nullptr; if ((*itSet)->type(Trk::MeasurementBaseType::CaloCluster_OnTrack)) { @@ -449,23 +507,31 @@ Trk::GaussianSumFitter::fit(const Trk::MeasurementSet& measurementSet, if (!ccot) { cleanedMeasurementSet.push_back(*itSet); } else { - ATH_MSG_DEBUG("The MeasurementBase object is a Trk::CaloCluster_OnTrack"); + ATH_MSG_DEBUG( + "The MeasurementBase object is a Trk::CaloCluster_OnTrack"); } } } - // A const stl container cannot be sorted. This will re-cast it so that it can. - Trk::MeasurementSet sortedMeasurementSet = MeasurementSet(cleanedMeasurementSet); + // A const stl container cannot be sorted. This will re-cast it so that it + // can. + Trk::MeasurementSet sortedMeasurementSet = + MeasurementSet(cleanedMeasurementSet); if (m_doHitSorting) { - Trk::MeasurementBaseComparisonFunction measurementBaseComparisonFunction(estimatedParametersNearOrigin.position(), - estimatedParametersNearOrigin.momentum()); - sort(sortedMeasurementSet.begin(), sortedMeasurementSet.end(), measurementBaseComparisonFunction); + Trk::MeasurementBaseComparisonFunction measurementBaseComparisonFunction( + estimatedParametersNearOrigin.position(), + estimatedParametersNearOrigin.momentum()); + sort(sortedMeasurementSet.begin(), + sortedMeasurementSet.end(), + measurementBaseComparisonFunction); } // Perform GSF forwards fit - new memory allocated in forwards fitter ForwardTrajectory* forwardTrajectory = - m_forwardGsfFitter->fitMeasurements(sortedMeasurementSet, estimatedParametersNearOrigin, particleHypothesis) + m_forwardGsfFitter + ->fitMeasurements( + sortedMeasurementSet, estimatedParametersNearOrigin, particleHypothesis) .release(); if (!forwardTrajectory) { @@ -484,7 +550,8 @@ Trk::GaussianSumFitter::fit(const Trk::MeasurementSet& measurementSet, ATH_MSG_VERBOSE("*** Forward GSF fit passed! ***"); // Perform GSF smoother operation - SmoothedTrajectory* smoothedTrajectory = m_gsfSmoother->fit(*forwardTrajectory, particleHypothesis, ccot); + SmoothedTrajectory* smoothedTrajectory = + m_gsfSmoother->fit(*forwardTrajectory, particleHypothesis, ccot); // Protect against failed smoother fit if (!smoothedTrajectory) { @@ -507,16 +574,18 @@ Trk::GaussianSumFitter::fit(const Trk::MeasurementSet& measurementSet, } if (outlierRemoval) { - ATH_MSG_DEBUG("Outlier removal not yet implemented for the Gaussian Sum Filter"); + ATH_MSG_DEBUG( + "Outlier removal not yet implemented for the Gaussian Sum Filter"); } if (m_makePerigee) { const Trk::MultiComponentStateOnSurface* perigeeMultiStateOnSurface = this->makePerigee(smoothedTrajectory, particleHypothesis); - ATH_MSG_DEBUG("perigeeMultiStateOnSurface :" << perigeeMultiStateOnSurface); + ATH_MSG_DEBUG( + "perigeeMultiStateOnSurface :" << perigeeMultiStateOnSurface); - if (perigeeMultiStateOnSurface) + if (perigeeMultiStateOnSurface) { smoothedTrajectory->push_back(perigeeMultiStateOnSurface); - else { + } else { ATH_MSG_DEBUG("Perigee asked to be created but failed.....Exiting"); ++m_PerigeeFailure; delete fitQuality; @@ -541,8 +610,10 @@ Trk::GaussianSumFitter::fit(const Trk::MeasurementSet& measurementSet, if (fittedTrack) { ATH_MSG_DEBUG("Fitting of a set of MeasurementBase objects is successful" << '\n' - << "Track fit chi squared... " << fitQuality->chiSquared() << '\n' - << "Track fit number of degrees of freedom... " << fitQuality->numberDoF()); + << "Track fit chi squared... " << fitQuality->chiSquared() + << '\n' + << "Track fit number of degrees of freedom... " + << fitQuality->numberDoF()); } else { ATH_MSG_DEBUG("Trk::GaussianSumFilter::fit() failed!"); } @@ -558,32 +629,38 @@ Trk::GaussianSumFitter::fit(const Track& intrk, ATH_MSG_VERBOSE("--> enter GaussianSumFitter::fit(Track,PrdSet,,)" << '\n' - << " with Track from author = " << intrk.info().dumpInfo()); + << " with Track from author = " + << intrk.info().dumpInfo()); // protection, if empty PrepRawDataSet if (addPrdColl.empty()) { - ATH_MSG_WARNING("client tries to add an empty PrepRawDataSet to the track fit."); + ATH_MSG_WARNING( + "client tries to add an empty PrepRawDataSet to the track fit."); return fit(intrk, runOutlier, matEffects); } /* determine the Track Parameter which is the start of the trajectory, i.e. closest to the reference point */ - ATH_MSG_DEBUG("get track parameters near origin " << (m_doHitSorting ? "via STL sort" : "from 1st state")); + ATH_MSG_DEBUG("get track parameters near origin " + << (m_doHitSorting ? "via STL sort" : "from 1st state")); const TrackParameters* estimatedStartParameters = - m_doHitSorting - ? *(std::min_element( - intrk.trackParameters()->begin(), intrk.trackParameters()->end(), *m_trkParametersComparisonFunction)) - : *intrk.trackParameters()->begin(); + m_doHitSorting ? *(std::min_element(intrk.trackParameters()->begin(), + intrk.trackParameters()->end(), + *m_trkParametersComparisonFunction)) + : *intrk.trackParameters()->begin(); // use external preparator class to prepare PRD set for fitter interface - Amg::Vector3D referencePosition(m_sortingReferencePoint[0], m_sortingReferencePoint[1], m_sortingReferencePoint[2]); + Amg::Vector3D referencePosition(m_sortingReferencePoint[0], + m_sortingReferencePoint[1], + m_sortingReferencePoint[2]); - TrackFitInputPreparator* inputPreparator = new TrackFitInputPreparator(referencePosition); + TrackFitInputPreparator* inputPreparator = + new TrackFitInputPreparator(referencePosition); - PrepRawDataSet orderedPRDColl = - inputPreparator->stripPrepRawData(intrk, addPrdColl, m_doHitSorting, true /* do not lose outliers! */); + PrepRawDataSet orderedPRDColl = inputPreparator->stripPrepRawData( + intrk, addPrdColl, m_doHitSorting, true /* do not lose outliers! */); delete inputPreparator; @@ -597,11 +674,13 @@ Trk::GaussianSumFitter::fit(const Track& inputTrack, const ParticleHypothesis matEffects) const { - ATH_MSG_VERBOSE("Trk::GaussianSumFilter::fit() - Refitting a track with a additional information "); + ATH_MSG_VERBOSE("Trk::GaussianSumFilter::fit() - Refitting a track with a " + "additional information "); // protection, if empty MeasurementSet if (measurementSet.empty()) { - ATH_MSG_WARNING("Client tries to add an empty MeasurementSet to the track fit."); + ATH_MSG_WARNING( + "Client tries to add an empty MeasurementSet to the track fit."); return fit(inputTrack, runOutlier, matEffects); } @@ -613,15 +692,19 @@ Trk::GaussianSumFitter::fit(const Track& inputTrack, // Check that the input track has associated MeasurementBase objects if (inputTrack.trackStateOnSurfaces()->empty()) { - ATH_MSG_FATAL("Attempting to fit track to empty MeasurementBase collection... Exiting!"); + ATH_MSG_FATAL("Attempting to fit track to empty MeasurementBase " + "collection... Exiting!"); return nullptr; } // Retrieve the set of track parameters closest to the reference point - const Trk::TrackParameters* parametersNearestReference = *(std::min_element( - inputTrack.trackParameters()->begin(), inputTrack.trackParameters()->end(), *m_trkParametersComparisonFunction)); + const Trk::TrackParameters* parametersNearestReference = + *(std::min_element(inputTrack.trackParameters()->begin(), + inputTrack.trackParameters()->end(), + *m_trkParametersComparisonFunction)); - MeasurementSet combinedMS = m_inputPreparator->stripMeasurements(inputTrack, measurementSet, true, false); + MeasurementSet combinedMS = m_inputPreparator->stripMeasurements( + inputTrack, measurementSet, true, false); // Apply GSF fit to MeasurementBase objects return fit(combinedMS, *parametersNearestReference, runOutlier, matEffects); @@ -635,21 +718,30 @@ Trk::GaussianSumFitter::fit(const Track& intrk1, { // Not a great implementation but simple... Just add the hits on track // protection against not having measurements on the input tracks - if (!intrk1.trackStateOnSurfaces() || !intrk2.trackStateOnSurfaces() || intrk1.trackStateOnSurfaces()->size() < 2) { - msg(MSG::WARNING) << "called to refit empty track or track with too little information, reject fit" << endmsg; + if (!intrk1.trackStateOnSurfaces() || !intrk2.trackStateOnSurfaces() || + intrk1.trackStateOnSurfaces()->size() < 2) { + msg(MSG::WARNING) << "called to refit empty track or track with too little " + "information, reject fit" + << endmsg; return nullptr; } if (!intrk1.trackParameters() || intrk1.trackParameters()->empty()) { - msg(MSG::WARNING) << "input #1 fails to provide track parameters for seeding the GXF, reject fit" << endmsg; + msg(MSG::WARNING) << "input #1 fails to provide track parameters for " + "seeding the GXF, reject fit" + << endmsg; return nullptr; } const TrackParameters* minPar = *intrk1.trackParameters()->begin(); - DataVector<const TrackStateOnSurface>::const_iterator itStates = intrk1.trackStateOnSurfaces()->begin(); - DataVector<const TrackStateOnSurface>::const_iterator endState = intrk1.trackStateOnSurfaces()->end(); - DataVector<const TrackStateOnSurface>::const_iterator itStates2 = intrk2.trackStateOnSurfaces()->begin(); - DataVector<const TrackStateOnSurface>::const_iterator endState2 = intrk2.trackStateOnSurfaces()->end(); + DataVector<const TrackStateOnSurface>::const_iterator itStates = + intrk1.trackStateOnSurfaces()->begin(); + DataVector<const TrackStateOnSurface>::const_iterator endState = + intrk1.trackStateOnSurfaces()->end(); + DataVector<const TrackStateOnSurface>::const_iterator itStates2 = + intrk2.trackStateOnSurfaces()->begin(); + DataVector<const TrackStateOnSurface>::const_iterator endState2 = + intrk2.trackStateOnSurfaces()->end(); Trk::MeasurementSet ms; @@ -659,7 +751,8 @@ Trk::GaussianSumFitter::fit(const Track& intrk1, continue; } - if ((*itStates)->measurementOnTrack()->type(Trk::MeasurementBaseType::PseudoMeasurementOnTrack)) { + if ((*itStates)->measurementOnTrack()->type( + Trk::MeasurementBaseType::PseudoMeasurementOnTrack)) { continue; } @@ -673,7 +766,9 @@ Trk::GaussianSumFitter::fit(const Track& intrk1, continue; } - if ((*itStates2)->measurementOnTrack()->type(Trk::MeasurementBaseType::PseudoMeasurementOnTrack)) { + if ((*itStates2) + ->measurementOnTrack() + ->type(Trk::MeasurementBaseType::PseudoMeasurementOnTrack)) { continue; } @@ -684,25 +779,31 @@ Trk::GaussianSumFitter::fit(const Track& intrk1, } const Trk::MultiComponentStateOnSurface* -Trk::GaussianSumFitter::makePerigee(const Trk::SmoothedTrajectory* smoothedTrajectory, - const Trk::ParticleHypothesis particleHypothesis) const +Trk::GaussianSumFitter::makePerigee( + const Trk::SmoothedTrajectory* smoothedTrajectory, + const Trk::ParticleHypothesis particleHypothesis) const { // Propagate track to perigee const Trk::PerigeeSurface perigeeSurface; - const Trk::TrackStateOnSurface* stateOnSurfaceNearestOrigin = smoothedTrajectory->back(); - const Trk::MultiComponentStateOnSurface* multiComponentStateOnSurfaceNearestOrigin = - dynamic_cast<const Trk::MultiComponentStateOnSurface*>(stateOnSurfaceNearestOrigin); + const Trk::TrackStateOnSurface* stateOnSurfaceNearestOrigin = + smoothedTrajectory->back(); + const Trk::MultiComponentStateOnSurface* + multiComponentStateOnSurfaceNearestOrigin = + dynamic_cast<const Trk::MultiComponentStateOnSurface*>( + stateOnSurfaceNearestOrigin); const Trk::MultiComponentState* multiComponentState = nullptr; if (!multiComponentStateOnSurfaceNearestOrigin) { // we need to make a dummy multicomponent surface - Trk::ComponentParameters dummyComponent(stateOnSurfaceNearestOrigin->trackParameters()->clone(), 1.); + Trk::ComponentParameters dummyComponent( + stateOnSurfaceNearestOrigin->trackParameters()->clone(), 1.); auto tmp_multiComponentState = std::make_unique<Trk::MultiComponentState>(); tmp_multiComponentState->push_back(std::move(dummyComponent)); multiComponentState = tmp_multiComponentState.release(); } else { - multiComponentState = multiComponentStateOnSurfaceNearestOrigin->components(); + multiComponentState = + multiComponentStateOnSurfaceNearestOrigin->components(); } // Extrapolate to perigee, taking material effects considerations into account Trk::MultiComponentState stateExtrapolatedToPerigee = @@ -728,38 +829,45 @@ Trk::GaussianSumFitter::makePerigee(const Trk::SmoothedTrajectory* smoothedTraje double modeQoverP = 0; if (modeQoverP) { - ATH_MSG_VERBOSE("Calculated mode is stored by default in the Perigee Parameters" - << "and is NO Longer Stored as a seperate Parameter"); + ATH_MSG_VERBOSE( + "Calculated mode is stored by default in the Perigee Parameters" + << "and is NO Longer Stored as a seperate Parameter"); } - // Determine the combined state as well to be passed to the MultiComponentStateOnSurface object + // Determine the combined state as well to be passed to the + // MultiComponentStateOnSurface object std::unique_ptr<Trk::TrackParameters> combinedPerigee = MultiComponentStateCombiner::combine(stateExtrapolatedToPerigee, true); // Perigee is given as an additional MultiComponentStateOnSurface - std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> pattern(0); + std::bitset<Trk::TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> + pattern(0); pattern.set(Trk::TrackStateOnSurface::Perigee); if (fabs(combinedPerigee->parameters()[Trk::qOverP]) > 1e8) { - // GC: protection against 0-momentum track .. this check should NEVER be needed. + // GC: protection against 0-momentum track .. this check should NEVER be + // needed. // actual cutoff is 0.01eV track - ATH_MSG_ERROR("makePerigee() about to return with 0 momentum!! Returning null instead"); + ATH_MSG_ERROR( + "makePerigee() about to return with 0 momentum!! Returning null instead"); return nullptr; } const Trk::MultiComponentStateOnSurface* perigeeMultiStateOnSurface = - new MultiComponentStateOnSurface(nullptr, - combinedPerigee.release(), - MultiComponentStateHelpers::clone(stateExtrapolatedToPerigee).release(), - nullptr, - nullptr, - pattern, - modeQoverP); + new MultiComponentStateOnSurface( + nullptr, + combinedPerigee.release(), + MultiComponentStateHelpers::clone(stateExtrapolatedToPerigee).release(), + nullptr, + nullptr, + pattern, + modeQoverP); ATH_MSG_DEBUG("makePerigee() returning sucessfully!"); return perigeeMultiStateOnSurface; } const Trk::FitQuality* -Trk::GaussianSumFitter::buildFitQuality(const Trk::SmoothedTrajectory& smoothedTrajectory) const +Trk::GaussianSumFitter::buildFitQuality( + const Trk::SmoothedTrajectory& smoothedTrajectory) const { ATH_MSG_VERBOSE("Gsf fitQuality"); @@ -767,21 +875,25 @@ Trk::GaussianSumFitter::buildFitQuality(const Trk::SmoothedTrajectory& smoothedT int numberDoF = -5; // Loop over all TrackStateOnSurface objects in trajectory - SmoothedTrajectory::const_iterator stateOnSurface = smoothedTrajectory.begin(); + SmoothedTrajectory::const_iterator stateOnSurface = + smoothedTrajectory.begin(); for (; stateOnSurface != smoothedTrajectory.end(); ++stateOnSurface) { - if (!(*stateOnSurface)->type(TrackStateOnSurface::Measurement)) + if (!(*stateOnSurface)->type(TrackStateOnSurface::Measurement)) { continue; - if ((*stateOnSurface)->fitQualityOnSurface() == nullptr) + } + if ((*stateOnSurface)->fitQualityOnSurface() == nullptr) { continue; + } chiSquared += (*stateOnSurface)->fitQualityOnSurface()->chiSquared(); numberDoF += (*stateOnSurface)->fitQualityOnSurface()->numberDoF(); } - if (std::isnan(chiSquared) || chiSquared <= 0.) + if (std::isnan(chiSquared) || chiSquared <= 0.) { return nullptr; + } const FitQuality* fitQuality = new FitQuality(chiSquared, numberDoF); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfBetheHeitlerEffects.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfBetheHeitlerEffects.cxx index 65cbd6386a1f0709c5d74f2c23e625c2156b5485..4770fb6d931e22d683ae6a957ae777eaa17badef 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfBetheHeitlerEffects.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfBetheHeitlerEffects.cxx @@ -8,8 +8,8 @@ begin : Sunday 20th February 2005 author : atkinson email : Tom.Atkinson@cern.ch -decription : Implementation code for the Bethe-Heitler material effects - in the GSF package +decription : Implementation code for the Bethe-Heitler material +effects in the GSF package *********************************************************************************/ #include "TrkGaussianSumFilter/GsfBetheHeitlerEffects.h" @@ -44,9 +44,12 @@ Trk::GsfBetheHeitlerEffects::GsfBetheHeitlerEffects(const std::string& type, { declareInterface<IMultiStateMaterialEffects>(this); - declareProperty("BetheHeitlerParameterisationFileName", m_parameterisationFileName); - declareProperty("BetheHeitlerParameterisationFileNameHighX0", m_parameterisationFileNameHighX0); - declareProperty("BetheHeitlerParameterisationCorrectionFlag", m_correctionFlag); + declareProperty("BetheHeitlerParameterisationFileName", + m_parameterisationFileName); + declareProperty("BetheHeitlerParameterisationFileNameHighX0", + m_parameterisationFileNameHighX0); + declareProperty("BetheHeitlerParameterisationCorrectionFlag", + m_correctionFlag); declareProperty("SingleGaussianRange", m_singleGaussianRange = 0.0001); declareProperty("LowerRange", m_lowerRange = 0.002); declareProperty("XoverRange", m_xOverRange = 0.10); @@ -59,14 +62,15 @@ StatusCode Trk::GsfBetheHeitlerEffects::initialize() { - if (m_correctionFlag == 1) + if (m_correctionFlag == 1) { ATH_MSG_INFO("1st moment of mixture will be corrected"); - else if (m_correctionFlag == 2) + } else if (m_correctionFlag == 2) { ATH_MSG_INFO("1st and 2nd moment of mixture will be corrected"); - else if (m_correctionFlag == 0) + } else if (m_correctionFlag == 0) { ATH_MSG_INFO("Moments of mixture will not be corrected"); - else { - ATH_MSG_INFO("Inappropriate setting for Bethe-Heitler mixture correction! ...Exiting!"); + } else { + ATH_MSG_INFO("Inappropriate setting for Bethe-Heitler mixture correction! " + "...Exiting!"); return StatusCode::FAILURE; } @@ -74,13 +78,10 @@ Trk::GsfBetheHeitlerEffects::initialize() ATH_MSG_INFO("Parameters successfully imported from file"); ATH_MSG_INFO("Initialisation of " << name() << " was successful"); return StatusCode::SUCCESS; - } - else { - ATH_MSG_ERROR("Parameters could NOT be successfully imported from file"); - return StatusCode::FAILURE; - } + ATH_MSG_ERROR("Parameters could NOT be successfully imported from file"); + return StatusCode::FAILURE; } StatusCode @@ -94,10 +95,11 @@ Trk::GsfBetheHeitlerEffects::finalize() bool Trk::GsfBetheHeitlerEffects::readParameters() { - std::string resolvedFileName = PathResolver::find_file(m_parameterisationFileName, "DATAPATH"); - if (!resolvedFileName.empty()) + std::string resolvedFileName = + PathResolver::find_file(m_parameterisationFileName, "DATAPATH"); + if (!resolvedFileName.empty()) { ATH_MSG_INFO("Parameterisation file found: " << resolvedFileName); - else { + } else { ATH_MSG_ERROR("Parameterisation file not found"); return false; } @@ -115,15 +117,18 @@ Trk::GsfBetheHeitlerEffects::readParameters() fin >> m_transformationCode; // if (not inRange(m_numberOfComponents, 0, 100)) { - ATH_MSG_ERROR("numberOfComponents Parameter out of range 0-100: " << m_numberOfComponents); + ATH_MSG_ERROR("numberOfComponents Parameter out of range 0-100: " + << m_numberOfComponents); return false; } if (not inRange(orderPolynomial, 0, 10)) { - ATH_MSG_ERROR("orderPolynomial Parameter out of range 0-10: " << orderPolynomial); + ATH_MSG_ERROR( + "orderPolynomial Parameter out of range 0-10: " << orderPolynomial); return false; } if (not inRange(m_transformationCode, 0, 10)) { - ATH_MSG_ERROR("transformationCode Parameter out of range 0-10: " << m_transformationCode); + ATH_MSG_ERROR("transformationCode Parameter out of range 0-10: " + << m_transformationCode); return false; } if (!fin) { @@ -139,10 +144,11 @@ Trk::GsfBetheHeitlerEffects::readParameters() } if (m_useHighX0) { - resolvedFileName = PathResolver::find_file(m_parameterisationFileNameHighX0, "DATAPATH"); - if (!resolvedFileName.empty()) + resolvedFileName = + PathResolver::find_file(m_parameterisationFileNameHighX0, "DATAPATH"); + if (!resolvedFileName.empty()) { ATH_MSG_INFO("Parameterisation file found: " << resolvedFileName); - else { + } else { ATH_MSG_ERROR("Parameterisation file not found"); return false; } @@ -161,15 +167,18 @@ Trk::GsfBetheHeitlerEffects::readParameters() fin >> m_transformationCodeHighX0; // if (not inRange(m_numberOfComponentsHighX0, 0, 100)) { - ATH_MSG_ERROR("numberOfComponents Parameter out of range 0-100: " << m_numberOfComponentsHighX0); + ATH_MSG_ERROR("numberOfComponents Parameter out of range 0-100: " + << m_numberOfComponentsHighX0); return false; } if (not inRange(orderPolynomial, 0, 10)) { - ATH_MSG_ERROR("orderPolynomial Parameter out of range 0-10: " << orderPolynomial); + ATH_MSG_ERROR( + "orderPolynomial Parameter out of range 0-10: " << orderPolynomial); return false; } if (not inRange(m_transformationCodeHighX0, 0, 10)) { - ATH_MSG_ERROR("transformationCode Parameter out of range 0-10: " << m_transformationCodeHighX0); + ATH_MSG_ERROR("transformationCode Parameter out of range 0-10: " + << m_transformationCodeHighX0); return false; } if (fin.bad()) { @@ -181,7 +190,8 @@ Trk::GsfBetheHeitlerEffects::readParameters() for (; componentIndex < m_numberOfComponentsHighX0; ++componentIndex) { m_polynomialWeightsHighX0.push_back(readPolynomial(fin, orderPolynomial)); m_polynomialMeansHighX0.push_back(readPolynomial(fin, orderPolynomial)); - m_polynomialVariancesHighX0.push_back(readPolynomial(fin, orderPolynomial)); + m_polynomialVariancesHighX0.push_back( + readPolynomial(fin, orderPolynomial)); } } return true; @@ -197,7 +207,8 @@ Trk::GsfBetheHeitlerEffects::readPolynomial(std::ifstream& fin, const int order) for (; orderIndex < (order + 1); ++orderIndex) { if (!fin) { - throw std::runtime_error("Reached end of stream but still expecting data."); + throw std::runtime_error( + "Reached end of stream but still expecting data."); } fin >> coefficients[orderIndex]; } @@ -206,12 +217,13 @@ Trk::GsfBetheHeitlerEffects::readPolynomial(std::ifstream& fin, const int order) } void -Trk::GsfBetheHeitlerEffects::compute(Cache& cache, - const Trk::ComponentParameters& componentParameters, - const Trk::MaterialProperties& materialProperties, - double pathLength, - Trk::PropDirection direction, - Trk::ParticleHypothesis) const +Trk::GsfBetheHeitlerEffects::compute( + Cache& cache, + const Trk::ComponentParameters& componentParameters, + const Trk::MaterialProperties& materialProperties, + double pathLength, + Trk::PropDirection direction, + Trk::ParticleHypothesis) const { // Clear cache cache.reset(); @@ -222,26 +234,28 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, double radiationLength = materialProperties.x0(); double pathlengthInX0 = pathLength / radiationLength; double momentum = globalMomentum.mag(); - + // Produce a multi-component State if (pathlengthInX0 > m_singleGaussianRange) { - // If the amount of material is between 0.0001 and 0.01 return the gaussian approximation to the - // Bethe-Heitler distribution + // If the amount of material is between 0.0001 and 0.01 return the gaussian + // approximation to the Bethe-Heitler distribution if (pathlengthInX0 < m_lowerRange) { - ATH_MSG_DEBUG("Amount of material less than" << m_lowerRange << "... Parameterising Bethe-Heitler as Gaussian"); + ATH_MSG_DEBUG("Amount of material less than" + << m_lowerRange + << "... Parameterising Bethe-Heitler as Gaussian"); const double meanZ = exp(-1. * pathlengthInX0); const double sign = (direction == Trk::oppositeMomentum) ? 1. : -1.; - const double varZ = exp(-1. * pathlengthInX0 * log(3.) / log(2.)) - exp(-2. * pathlengthInX0); + const double varZ = exp(-1. * pathlengthInX0 * log(3.) / log(2.)) - + exp(-2. * pathlengthInX0); double deltaP(0.); double varQoverP(0.); - if (direction == Trk::alongMomentum){ + if (direction == Trk::alongMomentum) { deltaP = sign * momentum * (1. - meanZ); varQoverP = 1. / (meanZ * meanZ * momentum * momentum) * varZ; - } - else{ + } else { deltaP = sign * momentum * (1. / meanZ - 1.); varQoverP = varZ / (momentum * momentum); } @@ -252,20 +266,20 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, cache.deltaPs.push_back(deltaP); cache.weights.push_back(1.); cache.deltaCovariances.push_back(std::move(newCovarianceMatrix)); - ATH_MSG_VERBOSE("Weight / deltaP / var (delta q/p) " << 1. << "\t" << deltaP << "\t" << varQoverP); + ATH_MSG_VERBOSE("Weight / deltaP / var (delta q/p) " + << 1. << "\t" << deltaP << "\t" << varQoverP); return; } - if (pathlengthInX0 > m_upperRange){ + if (pathlengthInX0 > m_upperRange) { pathlengthInX0 = m_upperRange; } MixtureParameters mixture; mixture.reserve(m_numberOfComponents); - if (m_useHighX0 && pathlengthInX0 > m_xOverRange){ + if (m_useHighX0 && pathlengthInX0 > m_xOverRange) { getMixtureParametersHighX0(pathlengthInX0, mixture); - } - else{ + } else { getMixtureParameters(pathlengthInX0, mixture); } correctWeights(mixture); @@ -283,10 +297,11 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, int componentWithHighestMean(0); for (; componentIndex < m_numberOfComponents; ++componentIndex) { - if (mixture[componentIndex].mean > mixture[componentWithHighestMean].mean){ + if (mixture[componentIndex].mean > + mixture[componentWithHighestMean].mean) { componentWithHighestMean = componentIndex; } - if (mixture[componentIndex].mean >= m_componentMeanCut){ + if (mixture[componentIndex].mean >= m_componentMeanCut) { continue; } weightToBeRemoved += mixture[componentIndex].weight; @@ -295,13 +310,13 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, for (; componentIndex < m_numberOfComponents; ++componentIndex) { double varianceInverseMomentum; // This is not mathematically correct but it does stabilize the GSF - if (mixture[componentIndex].mean < m_componentMeanCut){ + if (mixture[componentIndex].mean < m_componentMeanCut) { continue; } - if (componentIndex == componentWithHighestMean){ - cache.weights.push_back(mixture[componentIndex].weight + weightToBeRemoved); - } - else{ + if (componentIndex == componentWithHighestMean) { + cache.weights.push_back(mixture[componentIndex].weight + + weightToBeRemoved); + } else { cache.weights.push_back(mixture[componentIndex].weight); } @@ -317,7 +332,8 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, // For backwards propagation deltaP = momentum * (1. / mixture[componentIndex].mean - 1.); cache.deltaPs.push_back(deltaP); - varianceInverseMomentum = mixture[componentIndex].variance / (momentum * momentum); + varianceInverseMomentum = + mixture[componentIndex].variance / (momentum * momentum); } // end backwards propagation if clause AmgSymMatrix(5) newCovarianceMatrix; @@ -330,7 +346,9 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, } // end material limiting if clause else { - ATH_MSG_DEBUG("Trying to apply energy loss to " << pathlengthInX0 << " x/x0. No Bethe-Heitler effects applied"); + ATH_MSG_DEBUG("Trying to apply energy loss to " + << pathlengthInX0 + << " x/x0. No Bethe-Heitler effects applied"); cache.weights.push_back(1.); cache.deltaPs.push_back(0.); AmgSymMatrix(5) newCovarianceMatrix; @@ -340,85 +358,94 @@ Trk::GsfBetheHeitlerEffects::compute(Cache& cache, } void -Trk::GsfBetheHeitlerEffects::getMixtureParameters(const double pathlengthInX0, - Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const +Trk::GsfBetheHeitlerEffects::getMixtureParameters( + const double pathlengthInX0, + Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const { int componentIndex = 0; for (; componentIndex < m_numberOfComponents; ++componentIndex) { double updatedWeight = m_polynomialWeights[componentIndex](pathlengthInX0); double updatedMean = m_polynomialMeans[componentIndex](pathlengthInX0); - double updatedVariance = m_polynomialVariances[componentIndex](pathlengthInX0); - if (m_transformationCode){ + double updatedVariance = + m_polynomialVariances[componentIndex](pathlengthInX0); + if (m_transformationCode) { updatedWeight = logisticFunction(updatedWeight); updatedMean = logisticFunction(updatedMean); updatedVariance = exp(updatedVariance); - } - else{ + } else { updatedVariance = updatedVariance * updatedVariance; } - mixture.emplace_back(updatedWeight,updatedMean,updatedVariance); + mixture.emplace_back(updatedWeight, updatedMean, updatedVariance); } } void -Trk::GsfBetheHeitlerEffects::getMixtureParametersHighX0(const double pathlengthInX0, - Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const +Trk::GsfBetheHeitlerEffects::getMixtureParametersHighX0( + const double pathlengthInX0, + Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const { int componentIndex = 0; for (; componentIndex < m_numberOfComponentsHighX0; ++componentIndex) { - double updatedWeight = m_polynomialWeightsHighX0[componentIndex](pathlengthInX0); - double updatedMean = m_polynomialMeansHighX0[componentIndex](pathlengthInX0); - double updatedVariance = m_polynomialVariancesHighX0[componentIndex](pathlengthInX0); - if (m_transformationCodeHighX0){ + double updatedWeight = + m_polynomialWeightsHighX0[componentIndex](pathlengthInX0); + double updatedMean = + m_polynomialMeansHighX0[componentIndex](pathlengthInX0); + double updatedVariance = + m_polynomialVariancesHighX0[componentIndex](pathlengthInX0); + if (m_transformationCodeHighX0) { updatedWeight = logisticFunction(updatedWeight); updatedMean = logisticFunction(updatedMean); updatedVariance = exp(updatedVariance); - } - else{ + } else { updatedVariance = updatedVariance * updatedVariance; } - mixture.emplace_back(updatedWeight,updatedMean,updatedVariance); + mixture.emplace_back(updatedWeight, updatedMean, updatedVariance); } } void -Trk::GsfBetheHeitlerEffects::correctWeights(Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const +Trk::GsfBetheHeitlerEffects::correctWeights( + Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const { - if (mixture.empty()){ + if (mixture.empty()) { return; } // Obtain the sum of weights double weightSum(0.); - Trk::GsfBetheHeitlerEffects::MixtureParameters::const_iterator component = mixture.begin(); - for (; component != mixture.end(); ++component){ + Trk::GsfBetheHeitlerEffects::MixtureParameters::const_iterator component = + mixture.begin(); + for (; component != mixture.end(); ++component) { weightSum += (*component).weight; } // Rescale so that total weighting is 1 - Trk::GsfBetheHeitlerEffects::MixtureParameters::iterator modifiableComponent = mixture.begin(); + Trk::GsfBetheHeitlerEffects::MixtureParameters::iterator modifiableComponent = + mixture.begin(); - for (; modifiableComponent != mixture.end(); ++modifiableComponent){ + for (; modifiableComponent != mixture.end(); ++modifiableComponent) { (*modifiableComponent).weight /= weightSum; } } double -Trk::GsfBetheHeitlerEffects::correctedFirstMean(const double pathlengthInX0, - const Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const +Trk::GsfBetheHeitlerEffects::correctedFirstMean( + const double pathlengthInX0, + const Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const { - if (mixture.empty()){ + if (mixture.empty()) { return 0.; } // Obtain the difference between the true and weighted sum double meanBH = betheHeitlerMean(pathlengthInX0); - Trk::GsfBetheHeitlerEffects::MixtureParameters::const_iterator component = mixture.begin() + 1; - for (; component != mixture.end(); ++component){ + Trk::GsfBetheHeitlerEffects::MixtureParameters::const_iterator component = + mixture.begin() + 1; + for (; component != mixture.end(); ++component) { meanBH -= (*component).weight * (*component).mean; } // return the corrected mean for the first component @@ -426,22 +453,26 @@ Trk::GsfBetheHeitlerEffects::correctedFirstMean(const double pathlengthInX0, } double -Trk::GsfBetheHeitlerEffects::correctedFirstVariance(const double pathlengthInX0, - const Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const +Trk::GsfBetheHeitlerEffects::correctedFirstVariance( + const double pathlengthInX0, + const Trk::GsfBetheHeitlerEffects::MixtureParameters& mixture) const { - if (mixture.empty()){ + if (mixture.empty()) { return 0.; } // Obtain the difference between the true and weighed sum variances double varianceBH = - betheHeitlerVariance(pathlengthInX0) + (betheHeitlerMean(pathlengthInX0) * betheHeitlerMean(pathlengthInX0)); + betheHeitlerVariance(pathlengthInX0) + + (betheHeitlerMean(pathlengthInX0) * betheHeitlerMean(pathlengthInX0)); varianceBH -= mixture[0].weight * mixture[0].mean * mixture[0].mean; - Trk::GsfBetheHeitlerEffects::MixtureParameters::const_iterator component = mixture.begin() + 1; - for (; component != mixture.end(); ++component){ - varianceBH -= (*component).weight * ((*component).mean * (*component).mean + (*component).variance); + Trk::GsfBetheHeitlerEffects::MixtureParameters::const_iterator component = + mixture.begin() + 1; + for (; component != mixture.end(); ++component) { + varianceBH -= (*component).weight * ((*component).mean * (*component).mean + + (*component).variance); } return std::max(varianceBH / mixture[0].weight, 0.); } diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfCombinedMaterialEffects.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfCombinedMaterialEffects.cxx index 55bb5aaa72c9f1805cba3e05b33503a651779692..c5b2735ab7536d41f3b4db68959c1bbb94b2ade6 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfCombinedMaterialEffects.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfCombinedMaterialEffects.cxx @@ -13,19 +13,20 @@ decription : Implementation code for GsfCombinedMaterialEffects class #include "TrkGaussianSumFilter/GsfCombinedMaterialEffects.h" #include "GaudiKernel/ToolHandle.h" -#include "TrkSurfaces/Surface.h" +#include "TrkEventPrimitives/ParamDefs.h" #include "TrkGeometry/Layer.h" -#include "TrkParameters/TrackParameters.h" #include "TrkMaterialOnTrack/EnergyLoss.h" -#include "TrkEventPrimitives/ParamDefs.h" +#include "TrkParameters/TrackParameters.h" +#include "TrkSurfaces/Surface.h" namespace { const Trk::ParticleMasses s_particleMasses{}; } -Trk::GsfCombinedMaterialEffects::GsfCombinedMaterialEffects(const std::string& type, - const std::string& name, - const IInterface* parent) +Trk::GsfCombinedMaterialEffects::GsfCombinedMaterialEffects( + const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) { declareInterface<IMultiStateMaterialEffects>(this); @@ -36,11 +37,13 @@ Trk::GsfCombinedMaterialEffects::~GsfCombinedMaterialEffects() = default; StatusCode Trk::GsfCombinedMaterialEffects::initialize() { - // Retrieve and configure multiple scattering effects for multi-state operation + // Retrieve and configure multiple scattering effects for multi-state + // operation ATH_MSG_INFO("Configuring for multiple scattering"); ATH_CHECK(m_msUpdator.retrieve()); - // Retrieve and configure the std energy loss effects for multi-state operation + // Retrieve and configure the std energy loss effects for multi-state + // operation ATH_MSG_INFO("Configuring for normal energy loss"); ATH_CHECK(m_EnergyLossUpdator.retrieve()); @@ -104,10 +107,18 @@ Trk::GsfCombinedMaterialEffects::compute( IMultiStateMaterialEffects::Cache cache_energyLoss; if (particleHypothesis == electron) { - m_betheHeitlerEffects->compute(cache_energyLoss, componentParameters, materialProperties, pathLength, direction); + m_betheHeitlerEffects->compute(cache_energyLoss, + componentParameters, + materialProperties, + pathLength, + direction); } else if (particleHypothesis != nonInteracting) { - this->energyLoss( - cache_energyLoss, componentParameters, materialProperties, pathLength, direction, particleHypothesis); + this->energyLoss(cache_energyLoss, + componentParameters, + materialProperties, + pathLength, + direction, + particleHypothesis); } // Protect if there are no new components @@ -126,7 +137,8 @@ Trk::GsfCombinedMaterialEffects::compute( // Iterators over the multiple scattering components auto multipleScatter_weightsIterator = cache_multipleScatter.weights.begin(); auto multipleScatter_deltaPsIterator = cache_multipleScatter.deltaPs.begin(); - auto multipleScatter_deltaCovariancesIterator = cache_multipleScatter.deltaCovariances.begin(); + auto multipleScatter_deltaCovariancesIterator = + cache_multipleScatter.deltaCovariances.begin(); // Loop over multiple scattering components for (; multipleScatter_weightsIterator != cache_multipleScatter.weights.end(); @@ -137,22 +149,28 @@ Trk::GsfCombinedMaterialEffects::compute( // Iterators over the energy loss components auto energyLoss_weightsIterator = cache_energyLoss.weights.begin(); auto energyLoss_deltaPsIterator = cache_energyLoss.deltaPs.begin(); - auto energyLoss_deltaCovariancesIterator = cache_energyLoss.deltaCovariances.begin(); + auto energyLoss_deltaCovariancesIterator = + cache_energyLoss.deltaCovariances.begin(); // Loop over energy loss components for (; energyLoss_weightsIterator != cache_energyLoss.weights.end(); - ++energyLoss_weightsIterator, ++energyLoss_deltaPsIterator, ++energyLoss_deltaCovariancesIterator) { + ++energyLoss_weightsIterator, + ++energyLoss_deltaPsIterator, + ++energyLoss_deltaCovariancesIterator) { - double combinedWeight = (*multipleScatter_weightsIterator) * (*energyLoss_weightsIterator); - double combinedDeltaP = (*multipleScatter_deltaPsIterator) + (*energyLoss_deltaPsIterator); + double combinedWeight = + (*multipleScatter_weightsIterator) * (*energyLoss_weightsIterator); + double combinedDeltaP = + (*multipleScatter_deltaPsIterator) + (*energyLoss_deltaPsIterator); cache.weights.push_back(combinedWeight); cache.deltaPs.push_back(combinedDeltaP); if (measuredCov) { AmgSymMatrix(5) summedCovariance = - (*multipleScatter_deltaCovariancesIterator) + (*energyLoss_deltaCovariancesIterator); + (*multipleScatter_deltaCovariancesIterator) + + (*energyLoss_deltaCovariancesIterator); cache.deltaCovariances.push_back(std::move(summedCovariance)); } } // end for loop over energy loss components @@ -171,13 +189,14 @@ Trk::GsfCombinedMaterialEffects::scattering( { // Reset the cache cache.reset(); - + // Request track parameters from component parameters const Trk::TrackParameters* trackParameters = componentParameters.first.get(); const AmgSymMatrix(5)* measuredTrackCov = trackParameters->covariance(); if (!measuredTrackCov) { - ATH_MSG_DEBUG("No measurement associated with track parameters... returning original parameters"); + ATH_MSG_DEBUG("No measurement associated with track parameters... " + "returning original parameters"); return; } @@ -185,13 +204,17 @@ Trk::GsfCombinedMaterialEffects::scattering( double p = globalMomentum.mag(); double pathcorrection = 1.; - if (materialProperties.thickness() != 0) + if (materialProperties.thickness() != 0) { pathcorrection = pathLength / materialProperties.thickness(); + } - // Here we know the path length to be meff.thicknessX0, so we set pathcorrection = 1 - // and create a dummy materialProperties with the properties we are interested in - MaterialProperties mprop(materialProperties.thicknessInX0(), 1., 0., 0., 0., 0.); - const double angularVariation = m_msUpdator->sigmaSquare(mprop, p, pathcorrection, Trk::muon); + // Here we know the path length to be meff.thicknessX0, so we set + // pathcorrection = 1 and create a dummy materialProperties with the + // properties we are interested in + MaterialProperties mprop( + materialProperties.thicknessInX0(), 1., 0., 0., 0., 0.); + const double angularVariation = + m_msUpdator->sigmaSquare(mprop, p, pathcorrection, Trk::muon); AmgSymMatrix(5) deltaCov; deltaCov.setZero(); @@ -220,14 +243,19 @@ Trk::GsfCombinedMaterialEffects::energyLoss( const Trk::TrackParameters* trackParameters = componentParameters.first.get(); const AmgSymMatrix(5)* measuredCov = trackParameters->covariance(); if (!measuredCov) { - ATH_MSG_DEBUG("No measurement on track parameters... returning original track parameters"); + ATH_MSG_DEBUG("No measurement on track parameters... returning original " + "track parameters"); return; } double pathcorrection = pathLength / materialProperties.thickness(); const Amg::Vector3D& globalMomentum = trackParameters->momentum(); - EnergyLoss* energyLoss = m_EnergyLossUpdator->energyLoss( - materialProperties, globalMomentum.mag(), pathcorrection, direction, particleHypothesis, true); + EnergyLoss* energyLoss = m_EnergyLossUpdator->energyLoss(materialProperties, + globalMomentum.mag(), + pathcorrection, + direction, + particleHypothesis, + true); // update for mean energy loss const double deltaE = energyLoss ? energyLoss->deltaE() : 0; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfExtrapolator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfExtrapolator.cxx index b154379b17fc042f5c87ef0a38a7778df58bc673..80513e339cb2ab7739e1472944e4f88d9934fe4e 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfExtrapolator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfExtrapolator.cxx @@ -13,13 +13,13 @@ decription : Implementation code for GsfExtrapolator class #include "TrkGaussianSumFilter/GsfExtrapolator.h" -#include "TrkGaussianSumFilter/IMaterialMixtureConvolution.h" #include "TrkExInterfaces/IMultipleScatteringUpdator.h" +#include "TrkGaussianSumFilter/IMaterialMixtureConvolution.h" #include "TrkGeometry/Layer.h" +#include "TrkGeometry/MagneticFieldProperties.h" #include "TrkGeometry/MaterialProperties.h" #include "TrkGeometry/TrackingVolume.h" -#include "TrkGeometry/MagneticFieldProperties.h" #include "TrkExUtils/MaterialUpdateMode.h" @@ -38,7 +38,9 @@ namespace { const bool useBoundaryMaterialUpdate(true); } -Trk::GsfExtrapolator::GsfExtrapolator(const std::string& type, const std::string& name, const IInterface* parent) +Trk::GsfExtrapolator::GsfExtrapolator(const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) , m_propagatorStickyConfiguration(true) , m_surfaceBasedMaterialEffects(false) @@ -72,7 +74,7 @@ Trk::GsfExtrapolator::initialize() { // Request the Propagator AlgTools - unsigned int retrievedPropagators=0; + unsigned int retrievedPropagators = 0; if (!m_propagators.empty()) { ATH_CHECK(m_propagators.retrieve()); ATH_MSG_INFO("Retrieved tools " << m_propagators); @@ -86,35 +88,44 @@ Trk::GsfExtrapolator::initialize() return StatusCode::FAILURE; } - ATH_MSG_INFO("Propagator configuration level: " << m_propagatorConfigurationLevel); + ATH_MSG_INFO( + "Propagator configuration level: " << m_propagatorConfigurationLevel); - // Request the Navigation AlgTool - ATH_CHECK(m_navigator.retrieve()); + // Request the Navigation AlgTool + ATH_CHECK(m_navigator.retrieve()); - // Request the Material Effects Updator AlgTool - ATH_CHECK(m_materialUpdator.retrieve()); + // Request the Material Effects Updator AlgTool + ATH_CHECK(m_materialUpdator.retrieve()); - ATH_CHECK(m_elossupdators.retrieve()); + ATH_CHECK(m_elossupdators.retrieve()); - ATH_CHECK(m_msupdators.retrieve()); + ATH_CHECK(m_msupdators.retrieve()); - m_fieldProperties = m_fastField ? Trk::MagneticFieldProperties(Trk::FastField) - : Trk::MagneticFieldProperties(Trk::FullField); + m_fieldProperties = m_fastField + ? Trk::MagneticFieldProperties(Trk::FastField) + : Trk::MagneticFieldProperties(Trk::FullField); - ATH_MSG_INFO("Initialisation of " << name() << " was successful"); - return StatusCode::SUCCESS; + ATH_MSG_INFO("Initialisation of " << name() << " was successful"); + return StatusCode::SUCCESS; } StatusCode Trk::GsfExtrapolator::finalize() { - ATH_MSG_INFO("*** Extrapolator " << name() << " performance statistics ***********"); - ATH_MSG_INFO(" * - Number of extrapolate() calls: " << m_extrapolateCalls); - ATH_MSG_INFO(" * - Number of extrapolateDirectly() fallbacks: " << m_extrapolateDirectlyFallbacks); - ATH_MSG_INFO(" * - Number of navigation distance check breaks: " << m_navigationDistanceIncreaseBreaks); - ATH_MSG_INFO(" * - Number of volume boundary search failures: " << m_missedVolumeBoundary); - ATH_MSG_INFO(" * - Number of tracking volume oscillation breaks: " << m_oscillationBreaks); - ATH_MSG_INFO("***********************************************************************************)"); + ATH_MSG_INFO("*** Extrapolator " << name() + << " performance statistics ***********"); + ATH_MSG_INFO(" * - Number of extrapolate() calls: " + << m_extrapolateCalls); + ATH_MSG_INFO(" * - Number of extrapolateDirectly() fallbacks: " + << m_extrapolateDirectlyFallbacks); + ATH_MSG_INFO(" * - Number of navigation distance check breaks: " + << m_navigationDistanceIncreaseBreaks); + ATH_MSG_INFO(" * - Number of volume boundary search failures: " + << m_missedVolumeBoundary); + ATH_MSG_INFO(" * - Number of tracking volume oscillation breaks: " + << m_oscillationBreaks); + ATH_MSG_INFO("***************************************************************" + "********************)"); ATH_MSG_INFO("Finalisation of " << name() << " was successful"); return StatusCode::SUCCESS; } @@ -123,7 +134,8 @@ Trk::GsfExtrapolator::finalize() * This is the actual (non-direct) extrapolation method * The other one will end up calling this one passing the internal cache */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateImpl( const EventContext& ctx, Cache& cache, const Trk::IPropagator& propagator, @@ -135,8 +147,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( { auto buff_extrapolateCalls = m_extrapolateCalls.buffer(); - // If the extrapolation is to be without material effects simply revert to the extrapolateDirectly - // method + // If the extrapolation is to be without material effects simply revert to the + // extrapolateDirectly method if (particleHypothesis == Trk::nonInteracting) { return extrapolateDirectlyImpl(ctx, propagator, @@ -146,7 +158,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( boundaryCheck, particleHypothesis); } - // Surface based material effects (assumes all material is on active sensor elements) + // Surface based material effects (assumes all material is on active sensor + // elements) if (m_surfaceBasedMaterialEffects) { return extrapolateSurfaceBasedMaterialEffects(ctx, propagator, @@ -176,27 +189,31 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( direction); // Bail to direct extrapolation if the direction cannot be determined - if (direction == Trk::anyDirection) + if (direction == Trk::anyDirection) { return extrapolateDirectlyImpl(ctx, - propagator, - multiComponentState, - surface, - direction, - boundaryCheck, - particleHypothesis); + propagator, + multiComponentState, + surface, + direction, + boundaryCheck, + particleHypothesis); + } - const Trk::TrackParameters* combinedState = multiComponentState.begin()->first.get(); + const Trk::TrackParameters* combinedState = + multiComponentState.begin()->first.get(); const Trk::MultiComponentState* currentState = &multiComponentState; - /* Define the initial distance between destination and current position. Destination should be - determined from either + /* Define the initial distance between destination and current position. + Destination should be determined from either - reference parameters (prefered if they exist) or - destination surface */ - Amg::Vector3D globalSeparation = referenceParameters ? referenceParameters->position() - combinedState->position() - : surface.globalReferencePoint() - combinedState->position(); + Amg::Vector3D globalSeparation = + referenceParameters + ? referenceParameters->position() - combinedState->position() + : surface.globalReferencePoint() - combinedState->position(); double initialDistance = globalSeparation.mag(); // Clean up memory from combiner. It is no longer needed combinedState = nullptr; @@ -218,12 +235,15 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( const Trk::TrackingVolume* previousVolume = nullptr; auto buff_missedVolumeBoundary = m_missedVolumeBoundary.buffer(); auto buff_oscillationBreaks = m_oscillationBreaks.buffer(); - auto buff_navigationDistanceIncreaseBreaks = m_navigationDistanceIncreaseBreaks.buffer(); + auto buff_navigationDistanceIncreaseBreaks = + m_navigationDistanceIncreaseBreaks.buffer(); while (currentVolume && currentVolume != destinationVolume && currentState) { // Configure propagator based on the current tracking volume currentPropagator = - m_propagatorStickyConfiguration ? &propagator : &(*m_propagators[this->propagatorType(*currentVolume)]); + m_propagatorStickyConfiguration + ? &propagator + : &(*m_propagators[this->propagatorType(*currentVolume)]); // Extrapolate to volume boundary extrapolateToVolumeBoundary(ctx, @@ -235,11 +255,14 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( direction, particleHypothesis); - // New current state is the state extrapolated to the tracking volume boundary. + // New current state is the state extrapolated to the tracking volume + // boundary. currentState = cache.m_stateAtBoundarySurface.stateAtBoundary; - // The volume that the extrapolation is about to enter into is called the nextVolume - const Trk::TrackingVolume* nextVolume = cache.m_stateAtBoundarySurface.trackingVolume; + // The volume that the extrapolation is about to enter into is called the + // nextVolume + const Trk::TrackingVolume* nextVolume = + cache.m_stateAtBoundarySurface.trackingVolume; // Break the loop if the next tracking volume is the same as the current one if (!nextVolume || nextVolume == currentVolume) { @@ -249,7 +272,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( break; } - // New reference parameters are the navigation parameters at the boundary surface + // New reference parameters are the navigation parameters at the boundary + // surface referenceParameters = cache.m_stateAtBoundarySurface.navigationParameters; // Break the lop if an oscillation is detected @@ -264,12 +288,18 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( break; } - // Break the loop if the distance between the surface and the track parameters has increased + // Break the loop if the distance between the surface and the track + // parameters has increased combinedState = currentState->begin()->first.get(); const TrackParameters* parametersAtDestination = - currentPropagator->propagateParameters( - ctx, *combinedState, surface, direction, false, m_fieldProperties, Trk::electron); + currentPropagator->propagateParameters(ctx, + *combinedState, + surface, + direction, + false, + m_fieldProperties, + Trk::electron); Amg::Vector3D newDestination; if (parametersAtDestination) { newDestination = parametersAtDestination->position(); @@ -279,24 +309,29 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( newDestination = surface.center(); } - double revisedDistance = (referenceParameters->position() - newDestination).mag(); + double revisedDistance = + (referenceParameters->position() - newDestination).mag(); double distanceChange = fabs(revisedDistance - initialDistance); if (revisedDistance > initialDistance && distanceChange > 0.01) { - ATH_MSG_DEBUG("Navigation break. Initial separation: " << initialDistance - << " Current Sepatation: " << revisedDistance); - ATH_MSG_DEBUG(".... Volume " << nextVolume->volumeName() << " from " << currentVolume->volumeName()); + ATH_MSG_DEBUG("Navigation break. Initial separation: " + << initialDistance + << " Current Sepatation: " << revisedDistance); + ATH_MSG_DEBUG(".... Volume " << nextVolume->volumeName() << " from " + << currentVolume->volumeName()); foundFinalBoundary = false; ++buff_navigationDistanceIncreaseBreaks; break; } combinedState = nullptr; - ATH_MSG_DEBUG("Switching tracking volume look for Material: " << nextVolume->volumeName()); + ATH_MSG_DEBUG("Switching tracking volume look for Material: " + << nextVolume->volumeName()); // Initialise the oscillation checker previousVolume = currentVolume; - // As the extrapolation is moving into the next volume, the next volume -> current volume + // As the extrapolation is moving into the next volume, the next volume -> + // current volume currentVolume = nextVolume; // Associated layer now needs to be reset // if(!entryLayerFound) @@ -305,27 +340,31 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( // Look to catch failures now if (!currentState) { - ATH_MSG_DEBUG("No current state at boundary... Falling back to original state"); + ATH_MSG_DEBUG( + "No current state at boundary... Falling back to original state"); currentState = &multiComponentState; foundFinalBoundary = false; } if (currentVolume != destinationVolume) { - ATH_MSG_DEBUG("Trk::GsfExtrapolator::extrapolate failed to reach destination volume... "); + ATH_MSG_DEBUG("Trk::GsfExtrapolator::extrapolate failed to reach " + "destination volume... "); currentState = &multiComponentState; foundFinalBoundary = false; } if (!foundFinalBoundary) { - ATH_MSG_DEBUG("Could not find final boundary switch to direct EXTRAPOLATION"); - - Trk::MultiComponentState bailOutState = multiStatePropagate(ctx, - propagator, - *currentState, - surface, - Trk::anyDirection, - boundaryCheck, - particleHypothesis); + ATH_MSG_DEBUG( + "Could not find final boundary switch to direct EXTRAPOLATION"); + + Trk::MultiComponentState bailOutState = + multiStatePropagate(ctx, + propagator, + *currentState, + surface, + Trk::anyDirection, + boundaryCheck, + particleHypothesis); if (bailOutState.empty()) { ATH_MSG_DEBUG("Fallback to propagation failed... Returning 0"); @@ -341,34 +380,41 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateImpl( // Configure propagator based on the current tracking volume currentPropagator = - m_propagatorStickyConfiguration ? &propagator : &(*m_propagators[this->propagatorType(*currentVolume)]); + m_propagatorStickyConfiguration + ? &propagator + : &(*m_propagators[this->propagatorType(*currentVolume)]); // extrapolate inside destination volume - Trk::MultiComponentState destinationState = extrapolateInsideVolume(ctx, - cache, - *currentPropagator, - *currentState, - surface, - associatedLayer, - *currentVolume, - direction, - boundaryCheck, - particleHypothesis); - - // FALLBACK POINT: Crisis if extrapolation fails here... As per extrapolation to volume boundary, - // in emergency revert to extrapolateDirectly + Trk::MultiComponentState destinationState = + extrapolateInsideVolume(ctx, + cache, + *currentPropagator, + *currentState, + surface, + associatedLayer, + *currentVolume, + direction, + boundaryCheck, + particleHypothesis); + + // FALLBACK POINT: Crisis if extrapolation fails here... As per extrapolation + // to volume boundary, in emergency revert to extrapolateDirectly // or we failed to reach the target - if (!destinationState.empty() && &((*(destinationState.begin())).first->associatedSurface()) != &surface) { - ATH_MSG_DEBUG("Failed to reach destination surface ... reached some other surface"); + if (!destinationState.empty() && + &((*(destinationState.begin())).first->associatedSurface()) != &surface) { + ATH_MSG_DEBUG( + "Failed to reach destination surface ... reached some other surface"); destinationState.clear(); } // Gaudi counter buffer - auto buff_extrapolateDirectlyFallbacks = m_extrapolateDirectlyFallbacks.buffer(); + auto buff_extrapolateDirectlyFallbacks = + m_extrapolateDirectlyFallbacks.buffer(); if (destinationState.empty()) { - ATH_MSG_DEBUG("extrapolateInsideVolume() failed... falling back to direct propagation"); + ATH_MSG_DEBUG( + "extrapolateInsideVolume() failed... falling back to direct propagation"); destinationState = multiStatePropagate(ctx, propagator, *currentState, @@ -410,7 +456,6 @@ Trk::GsfExtrapolator::extrapolateDirectlyImpl( particleHypothesis); } - /************************************************************/ /* * Done with the internal actual implementation methods here @@ -421,7 +466,8 @@ Trk::GsfExtrapolator::extrapolateDirectlyImpl( /* * Extrapolate Interface */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolate( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolate( const EventContext& ctx, const Trk::MultiComponentState& multiComponentState, const Trk::Surface& surface, @@ -436,7 +482,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolate( } // Set the propagator to that one corresponding to the configuration level - const Trk::IPropagator* currentPropagator = &(*m_propagators[m_propagatorConfigurationLevel]); + const Trk::IPropagator* currentPropagator = + &(*m_propagators[m_propagatorConfigurationLevel]); return extrapolateImpl(ctx, cache, *currentPropagator, @@ -450,7 +497,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolate( /* * Extrapolate Directly method. Does not use a cache */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateDirectly( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateDirectly( const EventContext& ctx, const Trk::MultiComponentState& multiComponentState, const Trk::Surface& surface, @@ -463,14 +511,16 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateDirectly( return {}; } // Set the propagator to that one corresponding to the configuration level - const Trk::IPropagator* currentPropagator = &(*m_propagators[m_propagatorConfigurationLevel]); - + const Trk::IPropagator* currentPropagator = + &(*m_propagators[m_propagatorConfigurationLevel]); + auto buff_extrapolateDirectlyCalls = m_extrapolateDirectlyCalls.buffer(); // statistics ++buff_extrapolateDirectlyCalls; const Trk::TrackingVolume* currentVolume = m_navigator->highestVolume(); if (!currentVolume) { - ATH_MSG_WARNING("Current tracking volume could not be determined... returning 0"); + ATH_MSG_WARNING( + "Current tracking volume could not be determined... returning 0"); return {}; } return extrapolateDirectlyImpl(ctx, @@ -486,38 +536,41 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateDirectly( * Extrapolate M */ std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> -Trk::GsfExtrapolator::extrapolateM(const EventContext& ctx, - const Trk::MultiComponentState& mcsparameters, - const Surface& sf, - PropDirection dir, - const BoundaryCheck& bcheck, - ParticleHypothesis particle) const +Trk::GsfExtrapolator::extrapolateM( + const EventContext& ctx, + const Trk::MultiComponentState& mcsparameters, + const Surface& sf, + PropDirection dir, + const BoundaryCheck& bcheck, + ParticleHypothesis particle) const { // create a new vector for the material to be collected - //Look for current volume + // Look for current volume Cache cache{}; cache.m_matstates.reset(); // collect the material - // Set the propagator to that one corresponding to the configuration level - const Trk::IPropagator* currentPropagator = &(*m_propagators[m_propagatorConfigurationLevel]); - MultiComponentState parameterAtDestination = extrapolateImpl( - ctx, cache, *currentPropagator, mcsparameters, sf, dir, bcheck, particle); - // there are no parameters - if (parameterAtDestination.empty()) { - // loop over and clean up - for (const Trk::TrackStateOnSurface* ptr : *cache.m_matstates) { - delete ptr; - } - emptyGarbageBins(cache); - return nullptr; + // Set the propagator to that one corresponding to the configuration level + const Trk::IPropagator* currentPropagator = + &(*m_propagators[m_propagatorConfigurationLevel]); + MultiComponentState parameterAtDestination = extrapolateImpl( + ctx, cache, *currentPropagator, mcsparameters, sf, dir, bcheck, particle); + // there are no parameters + if (parameterAtDestination.empty()) { + // loop over and clean up + for (const Trk::TrackStateOnSurface* ptr : *cache.m_matstates) { + delete ptr; + } + emptyGarbageBins(cache); + return nullptr; } - cache.m_matstates->push_back( - new TrackStateOnSurface(nullptr, parameterAtDestination.begin()->first->clone(), nullptr, nullptr)); + cache.m_matstates->push_back(new TrackStateOnSurface( + nullptr, parameterAtDestination.begin()->first->clone(), nullptr, nullptr)); // assign the temporary states - std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> tmpMatStates = std::move(cache.m_matstates); + std::unique_ptr<std::vector<const Trk::TrackStateOnSurface*>> tmpMatStates = + std::move(cache.m_matstates); emptyGarbageBins(cache); // return the material states return tmpMatStates; @@ -533,14 +586,15 @@ Trk::GsfExtrapolator::extrapolateM(const EventContext& ctx, * Extrapolate to Volume Boundary! */ void -Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, - Cache& cache, - const Trk::IPropagator& propagator, - const Trk::MultiComponentState& multiComponentState, - const Trk::Layer* layer, - const Trk::TrackingVolume& trackingVolume, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfExtrapolator::extrapolateToVolumeBoundary( + const EventContext& ctx, + Cache& cache, + const Trk::IPropagator& propagator, + const Trk::MultiComponentState& multiComponentState, + const Trk::Layer* layer, + const Trk::TrackingVolume& trackingVolume, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { // MultiComponentState propagation and material effects @@ -549,31 +603,39 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, // Determine the current layer - the state combiner is required if (!currentState) { - ATH_MSG_WARNING("extrapolateToVolumeBoundary: Trying to extrapolate nothing?? - return"); + ATH_MSG_WARNING( + "extrapolateToVolumeBoundary: Trying to extrapolate nothing?? - return"); return; } - const Trk::TrackParameters* combinedState = currentState->begin()->first.get(); + const Trk::TrackParameters* combinedState = + currentState->begin()->first.get(); const Trk::Layer* associatedLayer = layer; if (!associatedLayer) { ATH_MSG_DEBUG("No associated layer passed with volume.... lets get one"); - // Get entry layer but do not use it as it should have already be hit if it was desired + // Get entry layer but do not use it as it should have already be hit if it + // was desired associatedLayer = trackingVolume.associatedLayer(combinedState->position()); - associatedLayer = associatedLayer ? associatedLayer - : trackingVolume.nextLayer(combinedState->position(), - direction * combinedState->momentum().unit(), - associatedLayer); + associatedLayer = + associatedLayer + ? associatedLayer + : trackingVolume.nextLayer(combinedState->position(), + direction * combinedState->momentum().unit(), + associatedLayer); ATH_MSG_DEBUG("Found layer in Volume " << layerRZoutput(associatedLayer)); } // Only loop over layers if they can be found within the tracking volume - else if (trackingVolume.confinedLayers() && associatedLayer->layerMaterialProperties()) { - Trk::MultiComponentState updatedState = - m_materialUpdator->postUpdate(*currentState, *layer, direction, particleHypothesis); + else if (trackingVolume.confinedLayers() && + associatedLayer->layerMaterialProperties()) { + Trk::MultiComponentState updatedState = m_materialUpdator->postUpdate( + *currentState, *layer, direction, particleHypothesis); if (!updatedState.empty()) { addMaterialtoVector(cache, layer, currentState->begin()->first.get()); - currentState = std::make_unique<Trk::MultiComponentState>(std::move(updatedState)).release(); + currentState = + std::make_unique<Trk::MultiComponentState>(std::move(updatedState)) + .release(); } } @@ -581,8 +643,9 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, combinedState = nullptr; Trk::MultiComponentState nextState{}; - // If an associated surface can be found, extrapolation within the tracking volume is mandatory - // This will take extrapolate to the last layer in the volume + // If an associated surface can be found, extrapolation within the tracking + // volume is mandatory This will take extrapolate to the last layer in the + // volume if (associatedLayer) { nextState = extrapolateFromLayerToLayer(ctx, cache, @@ -595,12 +658,15 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, particleHypothesis); // if we have a next State update the currentState if (!nextState.empty()) { - // We can delete the currentState as long as it does not point to the input + // We can delete the currentState as long as it does not point to the + // input if (currentState != &multiComponentState) { delete currentState; } // currentState now owns the ptr - currentState = std::make_unique<Trk::MultiComponentState>(std::move(nextState)).release(); + currentState = + std::make_unique<Trk::MultiComponentState>(std::move(nextState)) + .release(); } } @@ -613,33 +679,38 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, combinedState = currentState->begin()->first->clone(); const Trk::TrackingVolume* nextVolume = nullptr; - const Trk::TrackParameters* navigationParameters = cache.m_stateAtBoundarySurface.navigationParameters - ? cache.m_stateAtBoundarySurface.navigationParameters - : combinedState; + const Trk::TrackParameters* navigationParameters = + cache.m_stateAtBoundarySurface.navigationParameters + ? cache.m_stateAtBoundarySurface.navigationParameters + : combinedState; unsigned int navigationPropagatorIndex = 0; while (navigationPropagatorIndex <= m_propagatorConfigurationLevel) { - const Trk::IPropagator* navigationPropagator = &(*m_propagators[navigationPropagatorIndex]); + const Trk::IPropagator* navigationPropagator = + &(*m_propagators[navigationPropagatorIndex]); if (!navigationPropagator) { - ATH_MSG_WARNING("Navigation propagator cannot be retrieved... Continuing"); + ATH_MSG_WARNING( + "Navigation propagator cannot be retrieved... Continuing"); continue; } nextNavigationCell = m_navigator->nextTrackingVolume( *navigationPropagator, *navigationParameters, direction, trackingVolume); nextVolume = nextNavigationCell.nextVolume; - if (navigationPropagatorIndex >= 1) + if (navigationPropagatorIndex >= 1) { delete navigationParameters; + } navigationParameters = nextNavigationCell.parametersOnBoundary; ++navigationPropagatorIndex; // If the next tracking volume is found then no need to continue looping - if (nextVolume) + if (nextVolume) { break; + } } // Clean up memory allocated by the combiner if (navigationParameters != combinedState) { @@ -647,7 +718,9 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, } if (!nextVolume) { - ATH_MSG_DEBUG("Cannot find next TrackingVolume from initial tracking volume: " << trackingVolume.volumeName()); + ATH_MSG_DEBUG( + "Cannot find next TrackingVolume from initial tracking volume: " + << trackingVolume.volumeName()); // Reset the layer recall resetRecallInformation(cache); } @@ -661,9 +734,12 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, // If so, apply material effects update. // Get layer associated with boundary surface. - const Trk::TrackParameters* paramsAtBoundary = nextNavigationCell.parametersOnBoundary; + const Trk::TrackParameters* paramsAtBoundary = + nextNavigationCell.parametersOnBoundary; const Trk::Layer* layerAtBoundary = - (paramsAtBoundary) ? (paramsAtBoundary->associatedSurface()).materialLayer() : nullptr; + (paramsAtBoundary) + ? (paramsAtBoundary->associatedSurface()).materialLayer() + : nullptr; const Trk::TrackParameters* matUpdatedParameters = nullptr; Trk::MultiComponentState matUpdatedState{}; @@ -671,16 +747,20 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, if (layerAtBoundary->layerMaterialProperties()) { ATH_MSG_DEBUG("Boundary surface has material - updating properties"); assert(currentState); - matUpdatedState = m_materialUpdator->postUpdate(*currentState, *layerAtBoundary, direction, particleHypothesis); + matUpdatedState = m_materialUpdator->postUpdate( + *currentState, *layerAtBoundary, direction, particleHypothesis); } } - // If state has changed due to boundary material, modify state, parameters accordingly. + // If state has changed due to boundary material, modify state, parameters + // accordingly. if (!matUpdatedState.empty()) { ATH_MSG_DEBUG("Performing state update"); // Clean out memory, update state. delete currentState; - currentState = std::make_unique<Trk::MultiComponentState>(std::move(matUpdatedState)).release(); + currentState = + std::make_unique<Trk::MultiComponentState>(std::move(matUpdatedState)) + .release(); // Update navigation parameters (?). matUpdatedParameters = currentState->begin()->first->clone(); if (matUpdatedParameters != navigationParameters) { @@ -688,12 +768,14 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, navigationParameters = matUpdatedParameters; } // Add to material vector. - addMaterialtoVector(cache, layerAtBoundary, currentState->begin()->first.get()); + addMaterialtoVector( + cache, layerAtBoundary, currentState->begin()->first.get()); } } // Update the boundary information in the cache - cache.m_stateAtBoundarySurface.updateBoundaryInformation(currentState, navigationParameters, nextVolume); + cache.m_stateAtBoundarySurface.updateBoundaryInformation( + currentState, navigationParameters, nextVolume); // Make sure navigation parameters // and currentstate (if is not the same as input) @@ -708,7 +790,8 @@ Trk::GsfExtrapolator::extrapolateToVolumeBoundary(const EventContext& ctx, * Extrapolate inside volume to destination surface! */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateInsideVolume( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateInsideVolume( const EventContext& ctx, Cache& cache, const Trk::IPropagator& propagator, @@ -721,50 +804,59 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateInsideVolume( Trk::ParticleHypothesis particleHypothesis) const { - ATH_MSG_DEBUG("GSF extrapolateInsideVolume() in tracking volume: " << trackingVolume.volumeName()); + ATH_MSG_DEBUG("GSF extrapolateInsideVolume() in tracking volume: " + << trackingVolume.volumeName()); /* * We use current State to track where we are */ const Trk::MultiComponentState* currentState = &multiComponentState; - //Retrieve the destination layer + // Retrieve the destination layer // 1. Association const Trk::Layer* destinationLayer = surface.associatedLayer(); // 2. Recall and Global Search if (!destinationLayer) { ATH_MSG_DEBUG("No associated later to surface"); - destinationLayer = (&surface == cache.m_recallSurface) - ? cache.m_recallLayer - : trackingVolume.associatedLayer(surface.globalReferencePoint()); + destinationLayer = + (&surface == cache.m_recallSurface) + ? cache.m_recallLayer + : trackingVolume.associatedLayer(surface.globalReferencePoint()); } - //Retrieve the current layer + // Retrieve the current layer // Produce a combined state - const Trk::TrackParameters* combinedState = currentState->begin()->first.get(); + const Trk::TrackParameters* combinedState = + currentState->begin()->first.get(); const Trk::Layer* associatedLayer = layer; Trk::MultiComponentState updatedState{}; if (!associatedLayer) { ATH_MSG_DEBUG("No assoicated layer passed with volume.... lets get one"); - // Get entry layer but do not use it as it should have already be hit if it was desired + // Get entry layer but do not use it as it should have already be hit if it + // was desired associatedLayer = trackingVolume.associatedLayer(combinedState->position()); - associatedLayer = associatedLayer ? associatedLayer - : trackingVolume.nextLayer(combinedState->position(), - direction * combinedState->momentum().unit(), - associatedLayer); + associatedLayer = + associatedLayer + ? associatedLayer + : trackingVolume.nextLayer(combinedState->position(), + direction * combinedState->momentum().unit(), + associatedLayer); ATH_MSG_DEBUG("Found layer in Volume " << layerRZoutput(associatedLayer)); } - else if (associatedLayer != destinationLayer && trackingVolume.confinedLayers() && + else if (associatedLayer != destinationLayer && + trackingVolume.confinedLayers() && associatedLayer->layerMaterialProperties()) { - updatedState = m_materialUpdator->postUpdate(*currentState, *associatedLayer, direction, particleHypothesis); + updatedState = m_materialUpdator->postUpdate( + *currentState, *associatedLayer, direction, particleHypothesis); if (!updatedState.empty()) { - addMaterialtoVector(cache, associatedLayer, currentState->begin()->first.get()); + addMaterialtoVector( + cache, associatedLayer, currentState->begin()->first.get()); // Refresh the current state pointer currentState = &updatedState; } @@ -774,7 +866,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateInsideVolume( combinedState = nullptr; Trk::MultiComponentState nextState{}; if (destinationLayer) { - // If there are intermediate layers then additional extrapolations need to be done + // If there are intermediate layers then additional extrapolations need to + // be done if (associatedLayer && associatedLayer != destinationLayer) { nextState = extrapolateFromLayerToLayer(ctx, cache, @@ -793,35 +886,40 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateInsideVolume( } } // Final extrapolation to destination surface - Trk::MultiComponentState returnState = extrapolateToDestinationLayer(ctx, - cache, - propagator, - *currentState, - surface, - *destinationLayer, - // trackingVolume, - associatedLayer, - direction, - boundaryCheck, - particleHypothesis); + Trk::MultiComponentState returnState = + extrapolateToDestinationLayer(ctx, + cache, + propagator, + *currentState, + surface, + *destinationLayer, + // trackingVolume, + associatedLayer, + direction, + boundaryCheck, + particleHypothesis); // Set the information for the current layer, surface, tracking volume setRecallInformation(cache, surface, *destinationLayer, trackingVolume); return returnState; } - // FALLBACK POINT: If no destination layer is found fall-back and extrapolate directly - ATH_MSG_DEBUG("extrapolateInsideVolume() could not find the destination layer... propagating " + // FALLBACK POINT: If no destination layer is found fall-back and extrapolate + // directly + ATH_MSG_DEBUG("extrapolateInsideVolume() could not find the destination " + "layer... propagating " "directly to surface"); - Trk::MultiComponentState returnState = multiStatePropagate(ctx, - propagator, - *currentState, - surface, - direction, - boundaryCheck, - particleHypothesis); - - // No destination layer exists so layer recall method cannot be used and should be reset + Trk::MultiComponentState returnState = + multiStatePropagate(ctx, + propagator, + *currentState, + surface, + direction, + boundaryCheck, + particleHypothesis); + + // No destination layer exists so layer recall method cannot be used and + // should be reset resetRecallInformation(cache); return returnState; @@ -830,7 +928,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateInsideVolume( /* * Extrapolate from Layer to Layer */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateFromLayerToLayer( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateFromLayerToLayer( const EventContext& ctx, Cache& cache, const IPropagator& propagator, @@ -845,12 +944,14 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateFromLayerToLayer( const Trk::Layer* currentLayer = startLayer; Trk::MultiComponentState currentState{}; - const Trk::TrackParameters* combinedState = multiComponentState.begin()->first.get(); + const Trk::TrackParameters* combinedState = + multiComponentState.begin()->first.get(); Amg::Vector3D currentPosition = combinedState->position(); Amg::Vector3D currentDirection = direction * combinedState->momentum().unit(); // No need to extrapolate to start layer, find the next one - const Trk::Layer* nextLayer = currentLayer->nextLayer(currentPosition, currentDirection); + const Trk::Layer* nextLayer = + currentLayer->nextLayer(currentPosition, currentDirection); std::set<const Trk::Layer*> layersHit; layersHit.insert(currentLayer); @@ -858,8 +959,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateFromLayerToLayer( // Begin while loop over all intermediate layers while (nextLayer && nextLayer != destinationLayer) { layersHit.insert(nextLayer); - // Only extrapolate to an intermediate layer if it requires material update... otherwise step - // over it + // Only extrapolate to an intermediate layer if it requires material + // update... otherwise step over it if (nextLayer && nextLayer->layerMaterialProperties()) { if (!currentState.empty()) { @@ -898,8 +999,10 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateFromLayerToLayer( } } - if (destinationLayer && nextLayer != destinationLayer && !currentState.empty()) { - ATH_MSG_DEBUG("extrapolateFromLayerToLayer failed to reach destination layer.. return nullptr"); + if (destinationLayer && nextLayer != destinationLayer && + !currentState.empty()) { + ATH_MSG_DEBUG("extrapolateFromLayerToLayer failed to reach destination " + "layer.. return nullptr"); ATH_MSG_DEBUG("Current layer " << layerRZoutput(currentLayer)); ATH_MSG_DEBUG("NextLayer layer " << layerRZoutput(nextLayer)); ATH_MSG_DEBUG("Destination layer " << layerRZoutput(destinationLayer)); @@ -913,7 +1016,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateFromLayerToLayer( * Extrapolate to Intermediate Layer */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateToIntermediateLayer( const EventContext& ctx, Cache& cache, const Trk::IPropagator& propagator, @@ -924,7 +1028,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( Trk::ParticleHypothesis particleHypothesis, bool doPerpCheck) const { - const Trk::Surface* startSurface = &(multiComponentState.begin()->first->associatedSurface()); + const Trk::Surface* startSurface = + &(multiComponentState.begin()->first->associatedSurface()); if (startSurface) { const Trk::Layer* startLayer = startSurface->associatedLayer(); ATH_MSG_DEBUG("Starting Layer: " << layerRZoutput(startLayer)); @@ -936,13 +1041,14 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( const Trk::MultiComponentState* initialState = &multiComponentState; // Propagate over all components - Trk::MultiComponentState destinationState = multiStatePropagate(ctx, - propagator, - *initialState, - layer.surfaceRepresentation(), - direction, - true, - particleHypothesis); + Trk::MultiComponentState destinationState = + multiStatePropagate(ctx, + propagator, + *initialState, + layer.surfaceRepresentation(), + direction, + true, + particleHypothesis); if (destinationState.empty()) { ATH_MSG_DEBUG("Multi-state propagation failed... Returning 0!"); @@ -950,13 +1056,16 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( } // the layer has been intersected - // ------------------------------------------------------------------------ check for radial - // direction change --------------------------------------------------------------------- + // ------------------------------------------------------------------------ + // check for radial direction change + // --------------------------------------------------------------------- int rDirection = radialDirection(multiComponentState, direction); int newrDirection = radialDirection(destinationState, direction); if (newrDirection != rDirection && doPerpCheck) { - // it is unfortunate that the cancelling could invalidate the material collection - ATH_MSG_DEBUG(" [!] Perpendicular direction of track has changed -- checking"); + // it is unfortunate that the cancelling could invalidate the material + // collection + ATH_MSG_DEBUG( + " [!] Perpendicular direction of track has changed -- checking"); // reset the nextParameters if the radial change is not allowed // resetting is ok - since the parameters are in the garbage bin already if (!radialDirectionCheck(ctx, @@ -966,7 +1075,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( trackingVolume, direction, particleHypothesis)) { - ATH_MSG_DEBUG(" [+] Perpendicular direction check cancelled this layer intersection."); + ATH_MSG_DEBUG(" [+] Perpendicular direction check cancelled this layer " + "intersection."); return {}; } } @@ -975,14 +1085,18 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( Material effects ------------------------------------- */ - Trk::MultiComponentState updatedState = - m_materialUpdator->update(destinationState, layer, direction, particleHypothesis); + Trk::MultiComponentState updatedState = m_materialUpdator->update( + destinationState, layer, direction, particleHypothesis); if (updatedState.empty()) { return destinationState; } - addMaterialtoVector(cache, &layer, updatedState.begin()->first.get(), direction, particleHypothesis); + addMaterialtoVector(cache, + &layer, + updatedState.begin()->first.get(), + direction, + particleHypothesis); return updatedState; } @@ -990,7 +1104,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToIntermediateLayer( /* Extrapolate to Destination Layer */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToDestinationLayer( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateToDestinationLayer( const EventContext& ctx, Cache& cache, const Trk::IPropagator& propagator, @@ -1008,20 +1123,22 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToDestinationLayer( const Trk::TrackParameters* combinedState = nullptr; // Propagate over all components - Trk::MultiComponentState destinationState = multiStatePropagate(ctx, - propagator, - multiComponentState, - surface, - direction, - boundaryCheck, - particleHypothesis); - - // Require a fall-back if the initial state is close to the destination surface then a fall-back - // solution is required + Trk::MultiComponentState destinationState = + multiStatePropagate(ctx, + propagator, + multiComponentState, + surface, + direction, + boundaryCheck, + particleHypothesis); + + // Require a fall-back if the initial state is close to the destination + // surface then a fall-back solution is required if (destinationState.empty()) { combinedState = initialState->begin()->first.get(); - if (surface.isOnSurface(combinedState->position(), true, 0.5 * layer.thickness())) { + if (surface.isOnSurface( + combinedState->position(), true, 0.5 * layer.thickness())) { ATH_MSG_DEBUG("Initiating fall-back from failed propagation"); destinationState = multiStatePropagate(ctx, propagator, @@ -1044,21 +1161,27 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateToDestinationLayer( Trk::MultiComponentState updatedState{}; if (startLayer != &layer) { - updatedState = m_materialUpdator->preUpdate(destinationState, layer, direction, particleHypothesis); + updatedState = m_materialUpdator->preUpdate( + destinationState, layer, direction, particleHypothesis); } - if (updatedState.empty()){ + if (updatedState.empty()) { return destinationState; } - - addMaterialtoVector(cache, &layer, updatedState.begin()->first.get(), direction, particleHypothesis); + + addMaterialtoVector(cache, + &layer, + updatedState.begin()->first.get(), + direction, + particleHypothesis); return updatedState; } /* * Extrapolate based on material on active surfaces */ -Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateSurfaceBasedMaterialEffects( +Trk::MultiComponentState +Trk::GsfExtrapolator::extrapolateSurfaceBasedMaterialEffects( const EventContext& ctx, const IPropagator& propagator, const MultiComponentState& multiComponentState, @@ -1074,7 +1197,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateSurfaceBasedMaterialEf // Check the multi-component state is populated if (multiComponentState.empty()) { - ATH_MSG_WARNING("Multi component state passed to extrapolateInsideVolume is not populated... returning 0"); + ATH_MSG_WARNING("Multi component state passed to extrapolateInsideVolume " + "is not populated... returning 0"); return {}; } @@ -1098,7 +1222,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateSurfaceBasedMaterialEf ---------------------------------------- */ Trk::MultiComponentState finalState = - m_materialUpdator->simplifiedMaterialUpdate(lastState, direction, particleHypothesis); + m_materialUpdator->simplifiedMaterialUpdate( + lastState, direction, particleHypothesis); if (finalState.empty()) { ATH_MSG_DEBUG("Simple material effects updator failed"); return lastState; @@ -1110,7 +1235,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::extrapolateSurfaceBasedMaterialEf * Multi-component state propagate */ -Trk::MultiComponentState Trk::GsfExtrapolator::multiStatePropagate( +Trk::MultiComponentState +Trk::GsfExtrapolator::multiStatePropagate( const EventContext& ctx, const IPropagator& propagator, const Trk::MultiComponentState& multiComponentState, @@ -1120,30 +1246,34 @@ Trk::MultiComponentState Trk::GsfExtrapolator::multiStatePropagate( ParticleHypothesis particleHypothesis) const { - ATH_MSG_DEBUG("GSF multiStatePropagate() propagating " << multiComponentState.size() << " components\n" - << "\t\t\t\t\t...Propagating to surface [r,z] [" - << surface.center().perp() << ",\t" << surface.center().z() - << ']'); + ATH_MSG_DEBUG("GSF multiStatePropagate() propagating " + << multiComponentState.size() << " components\n" + << "\t\t\t\t\t...Propagating to surface [r,z] [" + << surface.center().perp() << ",\t" << surface.center().z() + << ']'); const Trk::Layer* layer = surface.associatedLayer(); ATH_MSG_DEBUG("...associated layer to surface " << layerRZoutput(layer)); Trk::MultiComponentState propagatedState{}; propagatedState.reserve(multiComponentState.size()); - Trk::MultiComponentState::const_iterator component = multiComponentState.begin(); + Trk::MultiComponentState::const_iterator component = + multiComponentState.begin(); double sumw(0); // HACK variable to avoid propagation errors for (; component != multiComponentState.end(); ++component) { const Trk::TrackParameters* currentParameters = component->first.get(); if (!currentParameters) { - ATH_MSG_DEBUG("Component parameters not defined... component will not be propagated... continuing"); + ATH_MSG_DEBUG("Component parameters not defined... component will not be " + "propagated... continuing"); continue; } - Trk::TrackParameters* propagatedParameters = propagator.propagate(ctx, - *currentParameters, - surface, - direction, - boundaryCheck, - m_fieldProperties, - particleHypothesis); + Trk::TrackParameters* propagatedParameters = + propagator.propagate(ctx, + *currentParameters, + surface, + direction, + boundaryCheck, + m_fieldProperties, + particleHypothesis); if (!propagatedParameters) { ATH_MSG_DEBUG("Propagation of component failed... continuing"); continue; @@ -1153,7 +1283,8 @@ Trk::MultiComponentState Trk::GsfExtrapolator::multiStatePropagate( propagatedState.emplace_back(propagatedParameters, component->second); } - ATH_MSG_DEBUG("GSF multiStatePropagate() propagated " << propagatedState.size() << "components"); + ATH_MSG_DEBUG("GSF multiStatePropagate() propagated " + << propagatedState.size() << "components"); // Protect against empty propagation if (propagatedState.empty() || sumw < 0.1) { ATH_MSG_DEBUG("multiStatePropagate failed... "); @@ -1166,29 +1297,36 @@ Trk::MultiComponentState Trk::GsfExtrapolator::multiStatePropagate( * PropagatorType */ unsigned int -Trk::GsfExtrapolator::propagatorType(const Trk::TrackingVolume& trackingVolume) const +Trk::GsfExtrapolator::propagatorType( + const Trk::TrackingVolume& trackingVolume) const { if (m_propagatorStickyConfiguration) { - if (m_propagators.size() > m_propagatorConfigurationLevel) + if (m_propagators.size() > m_propagatorConfigurationLevel) { return m_propagatorConfigurationLevel; - ATH_MSG_WARNING("Misconfigured propagator type, set to " << m_propagatorConfigurationLevel << "->0"); + } + ATH_MSG_WARNING("Misconfigured propagator type, set to " + << m_propagatorConfigurationLevel << "->0"); return 0; } // Determine what sort of magnetic field is present unsigned int magneticFieldMode = m_fieldProperties.magneticFieldMode(); - // Chose between runge-kutta and step propagators depending on field magnetic field and material - // properties ST : the following check may fail as the dEdX is often dummy for dense volumes - - // switch to rho or zOverAtimesRho ? - unsigned int propagatorMode = (magneticFieldMode > 1 && fabs(trackingVolume.dEdX) < 10e-2) ? 2 : 3; + // Chose between runge-kutta and step propagators depending on field magnetic + // field and material properties ST : the following check may fail as the dEdX + // is often dummy for dense volumes - switch to rho or zOverAtimesRho ? + unsigned int propagatorMode = + (magneticFieldMode > 1 && fabs(trackingVolume.dEdX) < 10e-2) ? 2 : 3; - unsigned int returnType = - (propagatorMode > m_propagatorConfigurationLevel) ? m_propagatorConfigurationLevel : propagatorMode; + unsigned int returnType = (propagatorMode > m_propagatorConfigurationLevel) + ? m_propagatorConfigurationLevel + : propagatorMode; - if (m_propagators.size() > returnType) + if (m_propagators.size() > returnType) { return returnType; - ATH_MSG_WARNING("Misconfigured propagator type, set to " << returnType << "->0"); + } + ATH_MSG_WARNING("Misconfigured propagator type, set to " << returnType + << "->0"); return 0; } @@ -1197,31 +1335,37 @@ Trk::GsfExtrapolator::propagatorType(const Trk::TrackingVolume& trackingVolume) */ void -Trk::GsfExtrapolator::initialiseNavigation(const EventContext& ctx, - Cache& cache, - const Trk::IPropagator& propagator, - const Trk::MultiComponentState& multiComponentState, - const Trk::Surface& surface, - const Trk::Layer*& currentLayer, - const Trk::TrackingVolume*& currentVolume, - const Trk::TrackingVolume*& destinationVolume, - const Trk::TrackParameters*& referenceParameters, - Trk::PropDirection direction) const +Trk::GsfExtrapolator::initialiseNavigation( + const EventContext& ctx, + Cache& cache, + const Trk::IPropagator& propagator, + const Trk::MultiComponentState& multiComponentState, + const Trk::Surface& surface, + const Trk::Layer*& currentLayer, + const Trk::TrackingVolume*& currentVolume, + const Trk::TrackingVolume*& destinationVolume, + const Trk::TrackParameters*& referenceParameters, + Trk::PropDirection direction) const { ATH_MSG_DEBUG("initialiseNavigation !!!"); // Empty the garbage bin - ATH_MSG_DEBUG("Destination to surface [r,z] [" << surface.center().perp() << ",\t" << surface.center().z() << ']'); + ATH_MSG_DEBUG("Destination to surface [r,z] [" + << surface.center().perp() << ",\t" << surface.center().z() + << ']'); emptyGarbageBins(cache); - const Trk::TrackParameters* combinedState = multiComponentState.begin()->first.get(); + const Trk::TrackParameters* combinedState = + multiComponentState.begin()->first.get(); /* ============================================= Look for current volume ============================================= */ // 1. See if the current layer is associated with a tracking volume const Trk::Surface* associatedSurface = &(combinedState->associatedSurface()); - currentLayer = associatedSurface ? associatedSurface->associatedLayer() : currentLayer; - currentVolume = currentLayer ? currentLayer->enclosingTrackingVolume() : currentVolume; + currentLayer = + associatedSurface ? associatedSurface->associatedLayer() : currentLayer; + currentVolume = + currentLayer ? currentLayer->enclosingTrackingVolume() : currentVolume; // If the association method failed then try the recall method @@ -1235,7 +1379,9 @@ Trk::GsfExtrapolator::initialiseNavigation(const EventContext& ctx, // If the recall method fails then the cashed information needs to be reset resetRecallInformation(cache); currentVolume = m_navigator->volume(combinedState->position()); - currentLayer = (currentVolume) ? currentVolume->associatedLayer(combinedState->position()) : nullptr; + currentLayer = (currentVolume) + ? currentVolume->associatedLayer(combinedState->position()) + : nullptr; } /* ============================================= Determine the resolved direction @@ -1247,14 +1393,19 @@ Trk::GsfExtrapolator::initialiseNavigation(const EventContext& ctx, ATH_MSG_DEBUG("Any direction initialisation"); } referenceParameters = - currentVolume ? propagator.propagateParameters( - ctx, *combinedState, surface, direction, false, m_fieldProperties) - : nullptr; - // These parameters will need to be deleted later. Add to list of garbage to be collected + currentVolume + ? propagator.propagateParameters( + ctx, *combinedState, surface, direction, false, m_fieldProperties) + : nullptr; + // These parameters will need to be deleted later. Add to list of garbage to + // be collected throwIntoGarbageBin(cache, referenceParameters); if (referenceParameters) { - Amg::Vector3D surfaceDirection(referenceParameters->position() - combinedState->position()); - direction = (surfaceDirection.dot(combinedState->momentum()) > 0.) ? Trk::alongMomentum : Trk::oppositeMomentum; + Amg::Vector3D surfaceDirection(referenceParameters->position() - + combinedState->position()); + direction = (surfaceDirection.dot(combinedState->momentum()) > 0.) + ? Trk::alongMomentum + : Trk::oppositeMomentum; } } @@ -1263,9 +1414,12 @@ Trk::GsfExtrapolator::initialiseNavigation(const EventContext& ctx, ============================================= */ // 1. See if the destination layer is associated with a tracking volume - destinationVolume = surface.associatedLayer() ? surface.associatedLayer()->enclosingTrackingVolume() : nullptr; - if (!surface.associatedLayer()) + destinationVolume = surface.associatedLayer() + ? surface.associatedLayer()->enclosingTrackingVolume() + : nullptr; + if (!surface.associatedLayer()) { ATH_MSG_DEBUG("No layer associated to the surface"); + } // 2. See if there is a cashed recall surface if (!destinationVolume && &surface == cache.m_recallSurface) { @@ -1277,7 +1431,8 @@ Trk::GsfExtrapolator::initialiseNavigation(const EventContext& ctx, ? propagator.propagateParameters( ctx, *combinedState, surface, direction, false, m_fieldProperties) : nullptr; - // These parameters will need to be deleted later. Add to list of garbage to be collected + // These parameters will need to be deleted later. Add to list of garbage + // to be collected throwIntoGarbageBin(cache, referenceParameters); } @@ -1290,14 +1445,16 @@ Trk::GsfExtrapolator::initialiseNavigation(const EventContext& ctx, ? propagator.propagateParameters( ctx, *combinedState, surface, direction, false, m_fieldProperties) : nullptr; - // These parameters will need to be deleted later. Add to list of garbage to be collected + // These parameters will need to be deleted later. Add to list of garbage + // to be collected throwIntoGarbageBin(cache, referenceParameters); } // Global search of tracking geometry to find the destination volume if (referenceParameters) { destinationVolume = m_navigator->volume(referenceParameters->position()); } - // If destination volume is still not found then global search based on surface position + // If destination volume is still not found then global search based on + // surface position else { destinationVolume = m_navigator->volume(surface.globalReferencePoint()); } @@ -1329,22 +1486,30 @@ Trk::GsfExtrapolator::addMaterialtoVector(Cache& cache, // Get the surface associated with the parameters const Trk::Surface* surface = &(nextPar->associatedSurface()); - // Only utilise the reference material if an associated detector element exists + // Only utilise the reference material if an associated detector element + // exists if (surface && surface->associatedDetectorElement()) { // Get the layer material properties - const Trk::LayerMaterialProperties* layerMaterial = nextLayer->layerMaterialProperties(); + const Trk::LayerMaterialProperties* layerMaterial = + nextLayer->layerMaterialProperties(); // Assign the material properties - materialProperties = layerMaterial ? layerMaterial->fullMaterial(nextPar->position()) : nullptr; + materialProperties = layerMaterial + ? layerMaterial->fullMaterial(nextPar->position()) + : nullptr; // Determine the pathCorrection if the material properties exist - pathcorr = materialProperties ? 1. / fabs(surface->normal().dot(nextPar->momentum().unit())) : 0.; + pathcorr = materialProperties + ? 1. / fabs(surface->normal().dot(nextPar->momentum().unit())) + : 0.; } - // Check that the material properties have been defined - if not define them from the layer - // information - materialProperties = materialProperties ? materialProperties : nextLayer->fullUpdateMaterialProperties(*nextPar); + // Check that the material properties have been defined - if not define them + // from the layer information + materialProperties = materialProperties + ? materialProperties + : nextLayer->fullUpdateMaterialProperties(*nextPar); if (!materialProperties) { ATH_MSG_DEBUG("addMaterialVector: layer has no MaterialProperties!! "); @@ -1354,25 +1519,29 @@ Trk::GsfExtrapolator::addMaterialtoVector(Cache& cache, if (cache.m_matstates) { pathcorr = pathcorr > 0. ? pathcorr - : nextLayer->surfaceRepresentation().pathCorrection(nextPar->position(), nextPar->momentum()); + : nextLayer->surfaceRepresentation().pathCorrection( + nextPar->position(), nextPar->momentum()); double thick = pathcorr * materialProperties->thickness(); double dInX0 = thick / materialProperties->x0(); double absP = 1 / fabs(nextPar->parameters()[Trk::qOverP]); - double scatsigma = sqrt(m_msupdators->sigmaSquare(*materialProperties, absP, pathcorr, particle)); - Trk::ScatteringAngles* newsa = - new Trk::ScatteringAngles(0, 0, scatsigma / sin(nextPar->parameters()[Trk::theta]), scatsigma); + double scatsigma = sqrt( + m_msupdators->sigmaSquare(*materialProperties, absP, pathcorr, particle)); + Trk::ScatteringAngles* newsa = new Trk::ScatteringAngles( + 0, 0, scatsigma / sin(nextPar->parameters()[Trk::theta]), scatsigma); // energy loss - Trk::EnergyLoss* eloss = - m_elossupdators->energyLoss(*materialProperties, absP, pathcorr, dir, particle, Trk::addNoise); + Trk::EnergyLoss* eloss = m_elossupdators->energyLoss( + *materialProperties, absP, pathcorr, dir, particle, Trk::addNoise); // use curvilinear TPs to simplify retrieval by fitters - Trk::CurvilinearParameters* cvlTP = - new Trk::CurvilinearParameters(nextPar->position(), nextPar->momentum(), nextPar->charge()); - Trk::MaterialEffectsOnTrack* mefot = - new Trk::MaterialEffectsOnTrack(dInX0, newsa, eloss, cvlTP->associatedSurface()); - cache.m_matstates->push_back(new TrackStateOnSurface(nullptr, cvlTP, nullptr, mefot)); - ATH_MSG_DEBUG("addMaterialVector: from layer:" << layerRZoutput(nextLayer) << ". Size is now " - << cache.m_matstates->size()); + Trk::CurvilinearParameters* cvlTP = new Trk::CurvilinearParameters( + nextPar->position(), nextPar->momentum(), nextPar->charge()); + Trk::MaterialEffectsOnTrack* mefot = new Trk::MaterialEffectsOnTrack( + dInX0, newsa, eloss, cvlTP->associatedSurface()); + cache.m_matstates->push_back( + new TrackStateOnSurface(nullptr, cvlTP, nullptr, mefot)); + ATH_MSG_DEBUG("addMaterialVector: from layer:" + << layerRZoutput(nextLayer) << ". Size is now " + << cache.m_matstates->size()); } } @@ -1380,10 +1549,13 @@ std::string Trk::GsfExtrapolator::layerRZoutput(const Trk::Layer* lay) const { std::string result("NULL"); - if (not lay) + if (not lay) { return result; - result = "[r,z] = [ " + std::to_string(lay->surfaceRepresentation().bounds().r()) + ", " + - std::to_string(lay->surfaceRepresentation().center().z()) + " ] - Index "; + } + result = "[r,z] = [ " + + std::to_string(lay->surfaceRepresentation().bounds().r()) + ", " + + std::to_string(lay->surfaceRepresentation().center().z()) + + " ] - Index "; result += std::to_string(lay->layerIndex().value()); return result; } @@ -1392,29 +1564,34 @@ std::string Trk::GsfExtrapolator::positionOutput(const Amg::Vector3D& pos) const { std::stringstream outStream; - outStream << "[r,phi,z] = [ " << pos.perp() << ", " << pos.phi() << ", " << pos.z() << " ]"; + outStream << "[r,phi,z] = [ " << pos.perp() << ", " << pos.phi() << ", " + << pos.z() << " ]"; return outStream.str(); } int -Trk::GsfExtrapolator::radialDirection(const Trk::MultiComponentState& pars, PropDirection dir) const +Trk::GsfExtrapolator::radialDirection(const Trk::MultiComponentState& pars, + PropDirection dir) const { // safe inbound/outbound estimation double prePositionR = pars.begin()->first->position().perp(); return (prePositionR > - (pars.begin()->first->position() + dir * 0.5 * prePositionR * pars.begin()->first->momentum().unit()).perp()) + (pars.begin()->first->position() + + dir * 0.5 * prePositionR * pars.begin()->first->momentum().unit()) + .perp()) ? -1 : 1; } bool -Trk::GsfExtrapolator::radialDirectionCheck(const EventContext& ctx, - const IPropagator& prop, - const MultiComponentState& startParm, - const MultiComponentState& parsOnLayer, - const TrackingVolume& tvol, - PropDirection dir, - ParticleHypothesis particle) const +Trk::GsfExtrapolator::radialDirectionCheck( + const EventContext& ctx, + const IPropagator& prop, + const MultiComponentState& startParm, + const MultiComponentState& parsOnLayer, + const TrackingVolume& tvol, + PropDirection dir, + ParticleHypothesis particle) const { const Amg::Vector3D& startPosition = startParm.begin()->first->position(); const Amg::Vector3D& onLayerPosition = parsOnLayer.begin()->first->position(); @@ -1422,12 +1599,15 @@ Trk::GsfExtrapolator::radialDirectionCheck(const EventContext& ctx, // the 3D distance to the layer intersection double distToLayer = (startPosition - onLayerPosition).mag(); // get the innermost contained surface for crosscheck - const std::vector<SharedObject<const BoundarySurface<TrackingVolume>>>& boundarySurfaces = tvol.boundarySurfaces(); + const std::vector<SharedObject<const BoundarySurface<TrackingVolume>>>& + boundarySurfaces = tvol.boundarySurfaces(); // only for tubes the crossing makes sense to check for validity if (boundarySurfaces.size() == 4) { // propagate to the inside surface and compare the distance: - // it can be either the next layer from the initial point, or the inner tube boundary surface - const Trk::Surface& insideSurface = (boundarySurfaces[Trk::tubeInnerCover].get())->surfaceRepresentation(); + // it can be either the next layer from the initial point, or the inner tube + // boundary surface + const Trk::Surface& insideSurface = + (boundarySurfaces[Trk::tubeInnerCover].get())->surfaceRepresentation(); const Trk::TrackParameters* parsOnInsideSurface = prop.propagateParameters(ctx, *(startParm.begin()->first), @@ -1437,18 +1617,25 @@ Trk::GsfExtrapolator::radialDirectionCheck(const EventContext& ctx, m_fieldProperties, particle); double distToInsideSurface = - parsOnInsideSurface ? (startPosition - (parsOnInsideSurface->position())).mag() : 10e10; - - ATH_MSG_DEBUG(" Radial direction check start - at " << positionOutput(startPosition)); - ATH_MSG_DEBUG(" Radial direction check layer - at " << positionOutput(onLayerPosition)); - if (parsOnInsideSurface) - ATH_MSG_DEBUG(" Radial direction check inner - at " << positionOutput(parsOnInsideSurface->position())); + parsOnInsideSurface + ? (startPosition - (parsOnInsideSurface->position())).mag() + : 10e10; + + ATH_MSG_DEBUG(" Radial direction check start - at " + << positionOutput(startPosition)); + ATH_MSG_DEBUG(" Radial direction check layer - at " + << positionOutput(onLayerPosition)); + if (parsOnInsideSurface) { + ATH_MSG_DEBUG(" Radial direction check inner - at " + << positionOutput(parsOnInsideSurface->position())); + } // memory cleanup (no garbage bin, this is faster) delete parsOnInsideSurface; - ATH_MSG_DEBUG(" Check radial direction: distance layer / boundary = " << distToLayer << " / " - << distToInsideSurface); - // the intersection with the original layer is valid if it is before the inside surface + ATH_MSG_DEBUG(" Check radial direction: distance layer / boundary = " + << distToLayer << " / " << distToInsideSurface); + // the intersection with the original layer is valid if it is before the + // inside surface return distToLayer < distToInsideSurface; } return true; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialEffectsUpdator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialEffectsUpdator.cxx index 50017bd0f155d3e7702d15d3d56c1ebd93b4bed1..9657a682b8513f15c507950d39186a9ba9f1e9f8 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialEffectsUpdator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialEffectsUpdator.cxx @@ -7,7 +7,8 @@ --------------------------------------------- begin : Wednesday 9th January 2005 author : atkinson,morley,anastopoulos -decription : Implementation code for the class GsfMaterialEffectsUpdator +decription : Implementation code for the class +GsfMaterialEffectsUpdator ***********************************************************************************/ #include "TrkGaussianSumFilter/GsfMaterialEffectsUpdator.h" @@ -21,9 +22,10 @@ decription : Implementation code for the class GsfMaterialEffectsUpdat #include "TrkGeometry/Layer.h" #include "TrkGeometry/MaterialProperties.h" -Trk::GsfMaterialEffectsUpdator::GsfMaterialEffectsUpdator(const std::string& type, - const std::string& name, - const IInterface* parent) +Trk::GsfMaterialEffectsUpdator::GsfMaterialEffectsUpdator( + const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) , m_useReferenceMaterial(false) , m_momentumCut(250. * Gaudi::Units::MeV) @@ -53,13 +55,15 @@ Trk::GsfMaterialEffectsUpdator::finalize() /* ============================================================================ Full update based on layer information - ============================================================================ */ + ============================================================================ + */ Trk::MultiComponentState -Trk::GsfMaterialEffectsUpdator::updateState(const Trk::ComponentParameters& componentParameters, - const Trk::Layer& layer, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialEffectsUpdator::updateState( + const Trk::ComponentParameters& componentParameters, + const Trk::Layer& layer, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { const Trk::TrackParameters* trackParameters = componentParameters.first.get(); @@ -78,23 +82,32 @@ Trk::GsfMaterialEffectsUpdator::updateState(const Trk::ComponentParameters& comp // Get the surface associated with the parameters const Trk::Surface* surface = &(trackParameters->associatedSurface()); - // Only utilise the reference material if an associated detector element exists + // Only utilise the reference material if an associated detector element + // exists if (surface && surface->associatedDetectorElement()) { // Get the layer material properties - const Trk::LayerMaterialProperties* layerMaterial = layer.layerMaterialProperties(); + const Trk::LayerMaterialProperties* layerMaterial = + layer.layerMaterialProperties(); // Assign the material properties - materialProperties = layerMaterial ? layerMaterial->fullMaterial(trackParameters->position()) : nullptr; + materialProperties = + layerMaterial ? layerMaterial->fullMaterial(trackParameters->position()) + : nullptr; // Determine the pathCorrection if the material properties exist - pathCorrection = materialProperties ? 1. / fabs(surface->normal().dot(trackParameters->momentum().unit())) : 0.; + pathCorrection = + materialProperties + ? 1. / fabs(surface->normal().dot(trackParameters->momentum().unit())) + : 0.; } } - // Check that the material properties have been defined - if not define them from the layer - // information - materialProperties = materialProperties ? materialProperties : layer.fullUpdateMaterialProperties(*trackParameters); + // Check that the material properties have been defined - if not define them + // from the layer information + materialProperties = materialProperties + ? materialProperties + : layer.fullUpdateMaterialProperties(*trackParameters); // Bail out if still no material properties can be found if (!materialProperties) { @@ -104,55 +117,73 @@ Trk::GsfMaterialEffectsUpdator::updateState(const Trk::ComponentParameters& comp } // Define the path correction - pathCorrection = pathCorrection > 0. ? pathCorrection - : layer.surfaceRepresentation().pathCorrection(trackParameters->position(), - trackParameters->momentum()); - - // The pathlength ( in mm ) is the path correction * the thickness of the material + pathCorrection = + pathCorrection > 0. + ? pathCorrection + : layer.surfaceRepresentation().pathCorrection( + trackParameters->position(), trackParameters->momentum()); + + // The pathlength ( in mm ) is the path correction * the thickness of the + // material double pathLength = pathCorrection * materialProperties->thickness(); - auto updatedState = compute(componentParameters, *materialProperties, pathLength, direction, particleHypothesis); + auto updatedState = compute(componentParameters, + *materialProperties, + pathLength, + direction, + particleHypothesis); return updatedState; } /* ============================================================================ Full update based on path-length & material properties information - ============================================================================ */ + ============================================================================ + */ Trk::MultiComponentState -Trk::GsfMaterialEffectsUpdator::updateState(const Trk::ComponentParameters& componentParameters, - const Trk::MaterialProperties& materialProperties, - double pathLength, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialEffectsUpdator::updateState( + const Trk::ComponentParameters& componentParameters, + const Trk::MaterialProperties& materialProperties, + double pathLength, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { - auto updatedState = compute(componentParameters, materialProperties, pathLength, direction, particleHypothesis); + auto updatedState = compute(componentParameters, + materialProperties, + pathLength, + direction, + particleHypothesis); return updatedState; } /* ============================================================================ Pre-update based on layer information - ============================================================================ */ + ============================================================================ + */ Trk::MultiComponentState -Trk::GsfMaterialEffectsUpdator::preUpdateState(const Trk::ComponentParameters& componentParameters, - const Trk::Layer& layer, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialEffectsUpdator::preUpdateState( + const Trk::ComponentParameters& componentParameters, + const Trk::Layer& layer, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { - ATH_MSG_DEBUG("Material effects update prior to propagation using layer information and particle hypothesis: " + ATH_MSG_DEBUG("Material effects update prior to propagation using layer " + "information and particle hypothesis: " << particleHypothesis); const Trk::TrackParameters* trackParameters = componentParameters.first.get(); if (!trackParameters) { - ATH_MSG_ERROR("Trying to update component without trackParameters... returing 0!"); + ATH_MSG_ERROR( + "Trying to update component without trackParameters... returing 0!"); return {}; } // Get the pre-update factor - double preUpdateFactor = layer.preUpdateMaterialFactor(*trackParameters, direction); + double preUpdateFactor = + layer.preUpdateMaterialFactor(*trackParameters, direction); // Bail if the pre-update factor is small if (preUpdateFactor < 0.01) { @@ -169,70 +200,92 @@ Trk::GsfMaterialEffectsUpdator::preUpdateState(const Trk::ComponentParameters& c // Get the surface associated with the parameters const Trk::Surface* surface = &(trackParameters->associatedSurface()); - // Only utilise the reference material if an associated detector element exists + // Only utilise the reference material if an associated detector element + // exists if (surface && surface->associatedDetectorElement()) { // Get the layer material properties - const Trk::LayerMaterialProperties* layerMaterial = layer.layerMaterialProperties(); + const Trk::LayerMaterialProperties* layerMaterial = + layer.layerMaterialProperties(); // Assign the material properties - materialProperties = layerMaterial ? layerMaterial->fullMaterial(trackParameters->position()) : nullptr; + materialProperties = + layerMaterial ? layerMaterial->fullMaterial(trackParameters->position()) + : nullptr; // Determine the pathCorrection if the material properties exist - pathCorrection = materialProperties ? 1. / fabs(surface->normal().dot(trackParameters->momentum().unit())) : 0.; + pathCorrection = + materialProperties + ? 1. / fabs(surface->normal().dot(trackParameters->momentum().unit())) + : 0.; } } - // Check that the material properties have been defined - if not define them from the layer - // information - materialProperties = materialProperties ? materialProperties : layer.fullUpdateMaterialProperties(*trackParameters); + // Check that the material properties have been defined - if not define them + // from the layer information + materialProperties = materialProperties + ? materialProperties + : layer.fullUpdateMaterialProperties(*trackParameters); // Bail out if still no material properties can be found if (!materialProperties) { Trk::MultiComponentState clonedMultiComponentState{}; - clonedMultiComponentState.emplace_back(componentParameters.first->clone(), componentParameters.second); + clonedMultiComponentState.emplace_back(componentParameters.first->clone(), + componentParameters.second); return clonedMultiComponentState; } // Define the path correction - pathCorrection = pathCorrection > 0. ? pathCorrection - : layer.surfaceRepresentation().pathCorrection(trackParameters->position(), - trackParameters->momentum()); + pathCorrection = + pathCorrection > 0. + ? pathCorrection + : layer.surfaceRepresentation().pathCorrection( + trackParameters->position(), trackParameters->momentum()); // Scale the correction by the pre-update factor pathCorrection *= preUpdateFactor; - // The pathlength ( in mm ) is the path correction * the thickness of the material + // The pathlength ( in mm ) is the path correction * the thickness of the + // material double pathLength = pathCorrection * materialProperties->thickness(); - auto updatedState = compute(componentParameters, *materialProperties, pathLength, direction, particleHypothesis); + auto updatedState = compute(componentParameters, + *materialProperties, + pathLength, + direction, + particleHypothesis); return updatedState; } /* ============================================================================ Post-update based on layer information - ============================================================================ */ + ============================================================================ + */ Trk::MultiComponentState -Trk::GsfMaterialEffectsUpdator::postUpdateState(const Trk::ComponentParameters& componentParameters, - const Layer& layer, - PropDirection direction, - ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialEffectsUpdator::postUpdateState( + const Trk::ComponentParameters& componentParameters, + const Layer& layer, + PropDirection direction, + ParticleHypothesis particleHypothesis) const { - ATH_MSG_DEBUG("Material effects update after propagation using layer information and particle hypothesis: " + ATH_MSG_DEBUG("Material effects update after propagation using layer " + "information and particle hypothesis: " << particleHypothesis); Trk::TrackParameters* trackParameters = componentParameters.first.get(); if (!trackParameters) { - ATH_MSG_ERROR("Trying to update component without trackParameters... returing component!"); + ATH_MSG_ERROR("Trying to update component without trackParameters... " + "returing component!"); return {}; } // Get the post-update factor - double postUpdateFactor = layer.postUpdateMaterialFactor(*trackParameters, direction); + double postUpdateFactor = + layer.postUpdateMaterialFactor(*trackParameters, direction); // Bail if the postUpdateFactor is small if (postUpdateFactor < 0.01) { @@ -247,55 +300,73 @@ Trk::GsfMaterialEffectsUpdator::postUpdateState(const Trk::ComponentParameters& // Get the surface associated with the parameters const Trk::Surface* surface = &(trackParameters->associatedSurface()); - // Only utilise the reference material if an associated detector element exists + // Only utilise the reference material if an associated detector element + // exists if (surface && surface->associatedDetectorElement()) { // Get the layer material properties - const Trk::LayerMaterialProperties* layerMaterial = layer.layerMaterialProperties(); + const Trk::LayerMaterialProperties* layerMaterial = + layer.layerMaterialProperties(); // Assign the material properties - materialProperties = layerMaterial ? layerMaterial->fullMaterial(trackParameters->position()) : nullptr; + materialProperties = + layerMaterial ? layerMaterial->fullMaterial(trackParameters->position()) + : nullptr; // Determine the pathCorrection if the material properties exist - pathCorrection = materialProperties ? 1. / fabs(surface->normal().dot(trackParameters->momentum().unit())) : 0.; + pathCorrection = + materialProperties + ? 1. / fabs(surface->normal().dot(trackParameters->momentum().unit())) + : 0.; } } - // Check that the material properties have been defined - if not define them from the layer - // information - materialProperties = materialProperties ? materialProperties : layer.fullUpdateMaterialProperties(*trackParameters); + // Check that the material properties have been defined - if not define them + // from the layer information + materialProperties = materialProperties + ? materialProperties + : layer.fullUpdateMaterialProperties(*trackParameters); // Bail out if still no material properties can be found if (!materialProperties) { Trk::MultiComponentState clonedMultiComponentState{}; - clonedMultiComponentState.emplace_back(componentParameters.first->clone(), componentParameters.second); + clonedMultiComponentState.emplace_back(componentParameters.first->clone(), + componentParameters.second); return clonedMultiComponentState; } // Define the path correction - pathCorrection = pathCorrection > 0. ? pathCorrection - : layer.surfaceRepresentation().pathCorrection(trackParameters->position(), - trackParameters->momentum()); + pathCorrection = + pathCorrection > 0. + ? pathCorrection + : layer.surfaceRepresentation().pathCorrection( + trackParameters->position(), trackParameters->momentum()); // Scale the correction by the pre-update factor pathCorrection *= postUpdateFactor; - // The pathlength ( in mm ) is the path correction * the thickness of the material + // The pathlength ( in mm ) is the path correction * the thickness of the + // material double pathLength = pathCorrection * materialProperties->thickness(); - return compute(componentParameters, *materialProperties, pathLength, direction, particleHypothesis); - + return compute(componentParameters, + *materialProperties, + pathLength, + direction, + particleHypothesis); } /* ============================================================================ Compute method - ============================================================================ */ + ============================================================================ + */ Trk::MultiComponentState -Trk::GsfMaterialEffectsUpdator::compute(const Trk::ComponentParameters& componentParameters, - const Trk::MaterialProperties& materialProperties, - double pathLength, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialEffectsUpdator::compute( + const Trk::ComponentParameters& componentParameters, + const Trk::MaterialProperties& materialProperties, + double pathLength, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { double momentum = componentParameters.first->momentum().mag(); @@ -303,7 +374,8 @@ Trk::GsfMaterialEffectsUpdator::compute(const Trk::ComponentParameters& componen if (momentum <= m_momentumCut) { ATH_MSG_DEBUG("Ignoring material effects... Momentum too low"); Trk::MultiComponentState clonedMultiComponentState{}; - clonedMultiComponentState.emplace_back(componentParameters.first->clone(), componentParameters.second); + clonedMultiComponentState.emplace_back(componentParameters.first->clone(), + componentParameters.second); return clonedMultiComponentState; } @@ -316,11 +388,17 @@ Trk::GsfMaterialEffectsUpdator::compute(const Trk::ComponentParameters& componen const AmgSymMatrix(5)* measuredCov = trackParameters->covariance(); Trk::IMultiStateMaterialEffects::Cache cache; - m_materialEffects->compute(cache, componentParameters, materialProperties, pathLength, direction, particleHypothesis); + m_materialEffects->compute(cache, + componentParameters, + materialProperties, + pathLength, + direction, + particleHypothesis); // check all vectors have the same size if (cache.weights.size() != cache.deltaPs.size()) { - ATH_MSG_ERROR("Inconsistent number of components in the updator!!! return nullptr"); + ATH_MSG_ERROR( + "Inconsistent number of components in the updator!!! return nullptr"); return {}; } @@ -332,25 +410,28 @@ Trk::GsfMaterialEffectsUpdator::compute(const Trk::ComponentParameters& componen for (; componentIndex < cache.weights.size(); ++componentIndex) { AmgVector(5) updatedStateVector = trackParameters->parameters(); - // Adjust the momentum of the component's parameters vector here. Check to make sure update is - // good. + // Adjust the momentum of the component's parameters vector here. Check to + // make sure update is good. if (!updateP(updatedStateVector, cache.deltaPs[componentIndex])) { ATH_MSG_ERROR("Cannot update state vector momentum!!! return nullptr"); return {}; } AmgSymMatrix(5)* updatedCovariance = nullptr; - if (measuredCov && cache.deltaCovariances.size()>componentIndex) { - updatedCovariance = new AmgSymMatrix(5)(cache.deltaCovariances[componentIndex] + *measuredCov); + if (measuredCov && cache.deltaCovariances.size() > componentIndex) { + updatedCovariance = new AmgSymMatrix(5)( + cache.deltaCovariances[componentIndex] + *measuredCov); } Trk::TrackParameters* updatedTrackParameters = - trackParameters->associatedSurface().createTrackParameters(updatedStateVector[Trk::loc1], - updatedStateVector[Trk::loc2], - updatedStateVector[Trk::phi], - updatedStateVector[Trk::theta], - updatedStateVector[Trk::qOverP], - updatedCovariance); - double updatedWeight = componentParameters.second * cache.weights[componentIndex]; + trackParameters->associatedSurface().createTrackParameters( + updatedStateVector[Trk::loc1], + updatedStateVector[Trk::loc2], + updatedStateVector[Trk::phi], + updatedStateVector[Trk::theta], + updatedStateVector[Trk::qOverP], + updatedCovariance); + double updatedWeight = + componentParameters.second * cache.weights[componentIndex]; computedState.emplace_back(updatedTrackParameters, updatedWeight); } return computedState; @@ -358,10 +439,12 @@ Trk::GsfMaterialEffectsUpdator::compute(const Trk::ComponentParameters& componen /* ============================================================================ updateP method - ============================================================================ */ + ============================================================================ + */ bool -Trk::GsfMaterialEffectsUpdator::updateP(AmgVector(5) & stateVector, double deltaP) const +Trk::GsfMaterialEffectsUpdator::updateP(AmgVector(5) & stateVector, + double deltaP) const { double p = 1. / fabs(stateVector[Trk::qOverP]); p += deltaP; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx index 2b42448fff656124c70d3085ca7ca76a9bd63f21..438bb317b845b090869ba45e02fbd2a9f18af03d 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMaterialMixtureConvolution.cxx @@ -22,9 +22,10 @@ decription : Implementation code for GSF material mixture convolution #include "TrkMultiComponentStateOnSurface/MultiComponentState.h" #include "TrkSurfaces/PerigeeSurface.h" -Trk::GsfMaterialMixtureConvolution::GsfMaterialMixtureConvolution(const std::string& type, - const std::string& name, - const IInterface* parent) +Trk::GsfMaterialMixtureConvolution::GsfMaterialMixtureConvolution( + const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) { declareInterface<IMaterialMixtureConvolution>(this); @@ -37,12 +38,11 @@ Trk::GsfMaterialMixtureConvolution::initialize() { if (m_updator.retrieve().isFailure()) { - ATH_MSG_ERROR("Could not retrieve the material effects updator instance " << m_updator.typeAndName() - << "... Exiting"); + ATH_MSG_ERROR("Could not retrieve the material effects updator instance " + << m_updator.typeAndName() << "... Exiting"); return StatusCode::FAILURE; } - return StatusCode::SUCCESS; } @@ -57,10 +57,11 @@ Trk::GsfMaterialMixtureConvolution::finalize() ========================================== */ Trk::MultiComponentState -Trk::GsfMaterialMixtureConvolution::update(const Trk::MultiComponentState& multiComponentState, - const Trk::Layer& layer, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialMixtureConvolution::update( + const Trk::MultiComponentState& multiComponentState, + const Trk::Layer& layer, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { const Trk::MaterialProperties* materialProperties = @@ -81,34 +82,39 @@ Trk::GsfMaterialMixtureConvolution::update(const Trk::MultiComponentState& multi // Check the multi-component state is populated if (multiComponentState.empty()) { - ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is not populated... returning 0"); + ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is " + "not populated... returning 0"); return {}; } // Loop over all components and perform material effects update separately - Trk::MultiComponentState::const_iterator component = multiComponentState.begin(); + Trk::MultiComponentState::const_iterator component = + multiComponentState.begin(); for (; component != multiComponentState.end(); ++component) { Trk::MultiComponentState updatedState = m_updator->updateState(*component, layer, direction, particleHypothesis); - if (updatedState.empty()){ + if (updatedState.empty()) { continue; } - bool componentAdded = MultiComponentStateAssembler::addMultiState(cache, std::move(updatedState)); + bool componentAdded = MultiComponentStateAssembler::addMultiState( + cache, std::move(updatedState)); if (!componentAdded) { - ATH_MSG_WARNING("Component could not be added to the state in the assembler"); + ATH_MSG_WARNING( + "Component could not be added to the state in the assembler"); } } - Trk::MultiComponentState mergedState = QuickCloseComponentsMultiStateMerger::merge( - std::move(cache.multiComponentState), m_maximumNumberOfComponents); + Trk::MultiComponentState mergedState = + QuickCloseComponentsMultiStateMerger::merge( + std::move(cache.multiComponentState), m_maximumNumberOfComponents); if (mergedState.empty()) { - return {}; + return {}; } // Renormalise state MultiComponentStateHelpers::renormaliseState(mergedState); @@ -121,10 +127,11 @@ Trk::GsfMaterialMixtureConvolution::update(const Trk::MultiComponentState& multi ========================================== */ Trk::MultiComponentState -Trk::GsfMaterialMixtureConvolution::preUpdate(const Trk::MultiComponentState& multiComponentState, - const Trk::Layer& layer, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialMixtureConvolution::preUpdate( + const Trk::MultiComponentState& multiComponentState, + const Trk::Layer& layer, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { const Trk::MaterialProperties* materialProperties = layer.fullUpdateMaterialProperties(*(multiComponentState.begin()->first)); @@ -139,30 +146,36 @@ Trk::GsfMaterialMixtureConvolution::preUpdate(const Trk::MultiComponentState& mu // Check the multi-component state is populated if (multiComponentState.empty()) { - ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is not populated... returning 0"); + ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is " + "not populated... returning 0"); return {}; } // Loop over all components and perform material effects update separately - Trk::MultiComponentState::const_iterator component = multiComponentState.begin(); + Trk::MultiComponentState::const_iterator component = + multiComponentState.begin(); for (; component != multiComponentState.end(); ++component) { - Trk::MultiComponentState updatedState = - m_updator->preUpdateState(*component, layer, direction, particleHypothesis); + Trk::MultiComponentState updatedState = m_updator->preUpdateState( + *component, layer, direction, particleHypothesis); - if (updatedState.empty()){ + if (updatedState.empty()) { continue; } - bool componentAdded = MultiComponentStateAssembler::addMultiState(cache, std::move(updatedState)); + bool componentAdded = MultiComponentStateAssembler::addMultiState( + cache, std::move(updatedState)); - if (!componentAdded) - ATH_MSG_WARNING("Component could not be added to the state in the assembler"); + if (!componentAdded) { + ATH_MSG_WARNING( + "Component could not be added to the state in the assembler"); + } } - Trk::MultiComponentState mergedState = QuickCloseComponentsMultiStateMerger::merge( - std::move(cache.multiComponentState), m_maximumNumberOfComponents); + Trk::MultiComponentState mergedState = + QuickCloseComponentsMultiStateMerger::merge( + std::move(cache.multiComponentState), m_maximumNumberOfComponents); if (mergedState.empty()) { return {}; @@ -178,10 +191,11 @@ Trk::GsfMaterialMixtureConvolution::preUpdate(const Trk::MultiComponentState& mu ========================================== */ Trk::MultiComponentState -Trk::GsfMaterialMixtureConvolution::postUpdate(const Trk::MultiComponentState& multiComponentState, - const Trk::Layer& layer, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialMixtureConvolution::postUpdate( + const Trk::MultiComponentState& multiComponentState, + const Trk::Layer& layer, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { const Trk::MaterialProperties* materialProperties = @@ -198,31 +212,36 @@ Trk::GsfMaterialMixtureConvolution::postUpdate(const Trk::MultiComponentState& m // Check the multi-component state is populated if (multiComponentState.empty()) { - ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is not populated... returning 0"); + ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is " + "not populated... returning 0"); return {}; } // Loop over all components and perform material effects update separately - Trk::MultiComponentState::const_iterator component = multiComponentState.begin(); + Trk::MultiComponentState::const_iterator component = + multiComponentState.begin(); for (; component != multiComponentState.end(); ++component) { - Trk::MultiComponentState updatedState = - m_updator->postUpdateState(*component, layer, direction, particleHypothesis); + Trk::MultiComponentState updatedState = m_updator->postUpdateState( + *component, layer, direction, particleHypothesis); - if (updatedState.empty()){ + if (updatedState.empty()) { continue; } - bool componentAdded = MultiComponentStateAssembler::addMultiState(cache, std::move(updatedState)); + bool componentAdded = MultiComponentStateAssembler::addMultiState( + cache, std::move(updatedState)); if (!componentAdded) { - ATH_MSG_WARNING("Component could not be added to the state in the assembler"); + ATH_MSG_WARNING( + "Component could not be added to the state in the assembler"); } } - Trk::MultiComponentState mergedState = QuickCloseComponentsMultiStateMerger::merge( - std::move(cache.multiComponentState), m_maximumNumberOfComponents); + Trk::MultiComponentState mergedState = + QuickCloseComponentsMultiStateMerger::merge( + std::move(cache.multiComponentState), m_maximumNumberOfComponents); if (mergedState.empty()) { return {}; @@ -238,9 +257,10 @@ Trk::GsfMaterialMixtureConvolution::postUpdate(const Trk::MultiComponentState& m ========================================== */ Trk::MultiComponentState -Trk::GsfMaterialMixtureConvolution::simplifiedMaterialUpdate(const Trk::MultiComponentState& multiComponentState, - Trk::PropDirection direction, - Trk::ParticleHypothesis particleHypothesis) const +Trk::GsfMaterialMixtureConvolution::simplifiedMaterialUpdate( + const Trk::MultiComponentState& multiComponentState, + Trk::PropDirection direction, + Trk::ParticleHypothesis particleHypothesis) const { /* ------------------------------------- Preliminary checks @@ -250,24 +270,29 @@ Trk::GsfMaterialMixtureConvolution::simplifiedMaterialUpdate(const Trk::MultiCom // Check the multi-component state is populated if (multiComponentState.empty()) { - ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is not populated... returning 0"); + ATH_MSG_DEBUG("Multi component state passed to extrapolateInsideVolume is " + "not populated... returning 0"); return {}; } // Hardwired material effects based on approximate material distribution - std::unique_ptr<Trk::TrackParameters> combinedState = MultiComponentStateCombiner::combine(multiComponentState); + std::unique_ptr<Trk::TrackParameters> combinedState = + MultiComponentStateCombiner::combine(multiComponentState); const Amg::Vector3D& globalPosition = combinedState->position(); const Trk::MaterialProperties* materialProperties = nullptr; // Material properties 2.5% X0 - pixels if (globalPosition.x() >= 180. && globalPosition.x() < 350.) { - materialProperties = new Trk::MaterialProperties(2.34, 93.6, 0.3879, 28.0855, 14, 0.00233); + materialProperties = + new Trk::MaterialProperties(2.34, 93.6, 0.3879, 28.0855, 14, 0.00233); } - // Material properties 0.75% X0 - SCT ( total for a module = 1.5% - 2 measurement surfaces ) + // Material properties 0.75% X0 - SCT ( total for a module = 1.5% - 2 + // measurement surfaces ) else if (globalPosition.x() >= 350. && globalPosition.x() < 1200.) { - materialProperties = new Trk::MaterialProperties(0.702, 93.6, 0.3879, 28.0855, 14, 0.00233); + materialProperties = + new Trk::MaterialProperties(0.702, 93.6, 0.3879, 28.0855, 14, 0.00233); } if (!materialProperties) { @@ -285,29 +310,39 @@ Trk::GsfMaterialMixtureConvolution::simplifiedMaterialUpdate(const Trk::MultiCom return std::move(*MultiComponentStateHelpers::clone(multiComponentState)); } - // Assume tracks normal to detector surface. Approximation resonable for the CTB + // Assume tracks normal to detector surface. Approximation resonable for the + // CTB double pathLength = materialProperties->thickness(); // Loop over all components and perform material effects update separately - Trk::MultiComponentState::const_iterator component = multiComponentState.begin(); + Trk::MultiComponentState::const_iterator component = + multiComponentState.begin(); for (; component != multiComponentState.end(); ++component) { - Trk::MultiComponentState updatedState = - m_updator->updateState(*component, *materialProperties, pathLength, direction, particleHypothesis); + Trk::MultiComponentState updatedState = + m_updator->updateState(*component, + *materialProperties, + pathLength, + direction, + particleHypothesis); - if (updatedState.empty()) + if (updatedState.empty()) { continue; + } - bool componentAdded = MultiComponentStateAssembler::addMultiState(cache, std::move(updatedState)); + bool componentAdded = MultiComponentStateAssembler::addMultiState( + cache, std::move(updatedState)); if (!componentAdded) { - ATH_MSG_WARNING("Component could not be added to the state in the assembler"); + ATH_MSG_WARNING( + "Component could not be added to the state in the assembler"); } } // end loop over components - Trk::MultiComponentState mergedState = QuickCloseComponentsMultiStateMerger::merge( - std::move(cache.multiComponentState), m_maximumNumberOfComponents); + Trk::MultiComponentState mergedState = + QuickCloseComponentsMultiStateMerger::merge( + std::move(cache.multiComponentState), m_maximumNumberOfComponents); if (mergedState.empty()) { return {}; diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx index 77871ebdd75c94137fde37127ace47dc4893b14d..40148d8932a38d58810d4d78070e41e436043d53 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfMeasurementUpdator.cxx @@ -34,7 +34,8 @@ Trk::GsfMeasurementUpdator::initialize() { // Retrieve the updator tool if (m_updator.retrieve().isFailure()) { - ATH_MSG_FATAL("Could not retrieve measurement updator AlgTool ... Exiting!"); + ATH_MSG_FATAL( + "Could not retrieve measurement updator AlgTool ... Exiting!"); return StatusCode::FAILURE; } @@ -50,44 +51,51 @@ Trk::GsfMeasurementUpdator::finalize() } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement) const +Trk::GsfMeasurementUpdator::update( + Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement) const { - MultiComponentState updatedState{}; - // Point to the correct member function of the linear fitter measurement updator for fitting in - // the direction of momentum + MultiComponentState updatedState{}; + // Point to the correct member function of the linear fitter measurement + // updator for fitting in the direction of momentum Updator updator = &Trk::IUpdator::addToState; // 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 + // 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()); + rebuildStateWithErrors = + rebuildStateWithErrors || invalidComponent(component->first.get()); } if (rebuildStateWithErrors) { - Trk::MultiComponentState stateWithInsertedErrors = rebuildState(std::move(stateBeforeUpdate)); + Trk::MultiComponentState stateWithInsertedErrors = + rebuildState(std::move(stateBeforeUpdate)); // Perform the measurement update with the modified state - updatedState = calculateFilterStep(std::move(stateWithInsertedErrors), measurement, updator); + updatedState = calculateFilterStep( + std::move(stateWithInsertedErrors), measurement, updator); return updatedState; } // Perform the measurement update - updatedState = calculateFilterStep(std::move(stateBeforeUpdate), measurement, updator); + updatedState = + calculateFilterStep(std::move(stateBeforeUpdate), measurement, updator); return updatedState; } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::getUnbiasedTrackParameters(Trk::MultiComponentState&& stateBeforeUpdate, - const MeasurementBase& measurement) const +Trk::GsfMeasurementUpdator::getUnbiasedTrackParameters( + Trk::MultiComponentState&& stateBeforeUpdate, + const MeasurementBase& measurement) const { // Point to the correct member function of the linear fitter measurement // updator for fitting in the direction opposite to momentum (smoothing) Updator updator = &Trk::IUpdator::removeFromState; // Calculate the weight of each state after the measurement - return calculateFilterStep(std::move(stateBeforeUpdate), measurement, updator); + return calculateFilterStep( + std::move(stateBeforeUpdate), measurement, updator); } const Trk::FitQualityOnSurface* @@ -95,11 +103,12 @@ Trk::GsfMeasurementUpdator::fitQuality(const MultiComponentState& updatedState, const MeasurementBase& measurement) const { - // Fit quality assumes that a state that has been updated by the measurement updator has been - // supplied to it + // Fit quality assumes that a state that has been updated by the measurement + // updator has been supplied to it if (updatedState.empty()) { - ATH_MSG_WARNING("Attempting to calculate chi2 of a hit with respect to an empty multiple-component state"); + ATH_MSG_WARNING("Attempting to calculate chi2 of a hit with respect to an " + "empty multiple-component state"); return nullptr; } @@ -110,19 +119,24 @@ Trk::GsfMeasurementUpdator::fitQuality(const MultiComponentState& updatedState, for (; component != updatedState.end(); ++component) { const Trk::TrackParameters* trackParameters = component->first.get(); - // IUpdator interface change (27/09/2005) to allow for fit quality calculations depending on if - // the track parameters incorporate the information contained in the measurement. I ALWAYS do - // this - hence the fullStateFitQuality method is used + // IUpdator interface change (27/09/2005) to allow for fit quality + // calculations depending on if the track parameters incorporate the + // information contained in the measurement. I ALWAYS do this - hence the + // fullStateFitQuality method is used const Trk::FitQualityOnSurface* componentFitQuality = - m_updator->fullStateFitQuality(*trackParameters, measurement.localParameters(), measurement.localCovariance()); + m_updator->fullStateFitQuality(*trackParameters, + measurement.localParameters(), + measurement.localCovariance()); double componentChi2 = componentFitQuality->chiSquared(); chi2 += component->second * componentChi2; - // The same measurement is included in each update so it is the same for each component - if (component == updatedState.begin()) + // The same measurement is included in each update so it is the same for + // each component + if (component == updatedState.begin()) { degreesOfFreedom = componentFitQuality->numberDoF(); + } delete componentFitQuality; } @@ -132,15 +146,17 @@ Trk::GsfMeasurementUpdator::fitQuality(const MultiComponentState& updatedState, return nullptr; } - const Trk::FitQualityOnSurface* fitQualityOnSurface = new FitQualityOnSurface(chi2, degreesOfFreedom); + const Trk::FitQualityOnSurface* fitQualityOnSurface = + new FitQualityOnSurface(chi2, degreesOfFreedom); return fitQualityOnSurface; } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement, - const Updator updator) const +Trk::GsfMeasurementUpdator::calculateFilterStep( + Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement, + const Updator updator) const { // state Assembler cache MultiComponentStateAssembler::Cache cache; @@ -152,27 +168,34 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state // Calculate the weight of each component after the measurement PosteriorWeightsCalculator pwc; - std::vector<Trk::ComponentParameters> stateWithNewWeights = pwc.weights(std::move(stateBeforeUpdate), measurement); + std::vector<Trk::ComponentParameters> stateWithNewWeights = + pwc.weights(std::move(stateBeforeUpdate), measurement); if (stateWithNewWeights.empty()) { ATH_MSG_DEBUG("Cacluation of state posterior weights failed... Exiting!"); return {}; } // Update each component using the specified updator - Trk::MultiComponentState::const_iterator component = stateWithNewWeights.begin(); + Trk::MultiComponentState::const_iterator component = + stateWithNewWeights.begin(); for (; component != stateWithNewWeights.end(); ++component) { Trk::FitQualityOnSurface* fitQuality = nullptr; // Track updates using a pointer to the member function - std::unique_ptr<Trk::TrackParameters> updatedTrackParameters(((&(*m_updator))->*updator)( - *(*component).first, measurement.localParameters(), measurement.localCovariance(), fitQuality)); + std::unique_ptr<Trk::TrackParameters> updatedTrackParameters( + ((&(*m_updator))->*updator)(*(*component).first, + measurement.localParameters(), + measurement.localCovariance(), + fitQuality)); if (!updatedTrackParameters) { - ATH_MSG_DEBUG("Update of state with Measurement has failed 1... Exiting!"); - if (fitQuality) + ATH_MSG_DEBUG( + "Update of state with Measurement has failed 1... Exiting!"); + if (fitQuality) { delete fitQuality; + } continue; } if (fitQuality && fitQuality->chiSquared() <= 0.) { @@ -185,16 +208,21 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state delete fitQuality; // Updator does not change the weighting - ComponentParameters updatedComponentParameters(std::move(updatedTrackParameters), component->second); - // Add component to state being prepared for assembly and check that it is valid - bool componentAdded = MultiComponentStateAssembler::addComponent(cache, std::move(updatedComponentParameters)); + ComponentParameters updatedComponentParameters( + std::move(updatedTrackParameters), component->second); + // Add component to state being prepared for assembly and check that it is + // valid + bool componentAdded = MultiComponentStateAssembler::addComponent( + cache, std::move(updatedComponentParameters)); if (!componentAdded) { - ATH_MSG_DEBUG("Component could not be added to the state in the assembler"); + ATH_MSG_DEBUG( + "Component could not be added to the state in the assembler"); } } - Trk::MultiComponentState assembledUpdatedState = MultiComponentStateAssembler::assembledState(cache); + Trk::MultiComponentState assembledUpdatedState = + MultiComponentStateAssembler::assembledState(cache); if (assembledUpdatedState.empty()) { return {}; @@ -205,9 +233,10 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement, - std::unique_ptr<FitQualityOnSurface>& fitQoS) const +Trk::GsfMeasurementUpdator::update( + Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement, + std::unique_ptr<FitQualityOnSurface>& fitQoS) const { Trk::MultiComponentState updatedState{}; @@ -217,16 +246,19 @@ Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, bool rebuildStateWithErrors = false; - // Perform initial check of state awaiting update. If all states have associated error matricies - // then no need to perform the rebuild + // 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()); + rebuildStateWithErrors = + rebuildStateWithErrors || invalidComponent(component->first.get()); } if (rebuildStateWithErrors) { - Trk::MultiComponentState stateWithInsertedErrors = rebuildState(std::move(stateBeforeUpdate)); + Trk::MultiComponentState stateWithInsertedErrors = + rebuildState(std::move(stateBeforeUpdate)); // Perform the measurement update with the modified state - updatedState = calculateFilterStep(std::move(stateWithInsertedErrors), measurement, fitQoS); + updatedState = calculateFilterStep( + std::move(stateWithInsertedErrors), measurement, fitQoS); if (updatedState.empty()) { ATH_MSG_DEBUG("Updated state could not be calculated... Returning 0"); fitQoS.reset(); @@ -236,7 +268,8 @@ Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, } // Perform the measurement update - updatedState = calculateFilterStep(std::move(stateBeforeUpdate), measurement, fitQoS); + updatedState = + calculateFilterStep(std::move(stateBeforeUpdate), measurement, fitQoS); if (updatedState.empty()) { ATH_MSG_DEBUG("Updated state could not be calculated... Returning 0"); @@ -247,9 +280,10 @@ Trk::GsfMeasurementUpdator::update(Trk::MultiComponentState&& stateBeforeUpdate, } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& stateBeforeUpdate, - const Trk::MeasurementBase& measurement, - std::unique_ptr<FitQualityOnSurface>& fitQoS) const +Trk::GsfMeasurementUpdator::calculateFilterStep( + Trk::MultiComponentState&& stateBeforeUpdate, + const Trk::MeasurementBase& measurement, + std::unique_ptr<FitQualityOnSurface>& fitQoS) const { // state Assembler cache MultiComponentStateAssembler::Cache cache; @@ -269,7 +303,8 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state } // Update each component using the specified updator - Trk::MultiComponentState::const_iterator component = stateWithNewWeights.begin(); + Trk::MultiComponentState::const_iterator component = + stateWithNewWeights.begin(); double chiSquared = 0; int degreesOfFreedom = 0; @@ -277,16 +312,21 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state for (; component != stateWithNewWeights.end(); ++component) { if (fabs((*component).first->parameters()[Trk::qOverP]) > 0.033333) { - ATH_MSG_DEBUG("About to update component with p<30MeV...skipping component! (2)"); + ATH_MSG_DEBUG( + "About to update component with p<30MeV...skipping component! (2)"); continue; } Trk::FitQualityOnSurface* componentFitQuality = nullptr; // Track update alternates between update and getUnbiasedTrackParams - std::unique_ptr<Trk::TrackParameters> updatedTrackParameters(m_updator->addToState( - *(*component).first, measurement.localParameters(), measurement.localCovariance(), componentFitQuality)); + std::unique_ptr<Trk::TrackParameters> updatedTrackParameters( + m_updator->addToState(*(*component).first, + measurement.localParameters(), + measurement.localCovariance(), + componentFitQuality)); if (!updatedTrackParameters) { - ATH_MSG_DEBUG("Update of state with Measurement has failed 2... Exiting!"); + ATH_MSG_DEBUG( + "Update of state with Measurement has failed 2... Exiting!"); if (componentFitQuality) { delete componentFitQuality; } @@ -296,10 +336,12 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state if (invalidComponent(updatedTrackParameters.get())) { ATH_MSG_DEBUG("Invalid cov matrix after update... Exiting!"); if ((*component).first->covariance()) { - ATH_MSG_DEBUG("Original has a COV\n " << *(*component).first->covariance()); + ATH_MSG_DEBUG("Original has a COV\n " + << *(*component).first->covariance()); } if (updatedTrackParameters->covariance()) { - ATH_MSG_DEBUG("Result has a COV\n" << *updatedTrackParameters->covariance()); + ATH_MSG_DEBUG("Result has a COV\n" + << *updatedTrackParameters->covariance()); } updatedTrackParameters.reset(); delete componentFitQuality; @@ -316,7 +358,8 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state double componentChi2 = componentFitQuality->chiSquared(); chiSquared += component->second * componentChi2; - // The same measurement is included in each update so it is the same for each component + // The same measurement is included in each update so it is the same for + // each component if (component == stateWithNewWeights.begin()) { degreesOfFreedom = componentFitQuality->numberDoF(); } @@ -324,16 +367,21 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state delete componentFitQuality; // Updator does not change the weighting - ComponentParameters updatedComponentParameters(std::move(updatedTrackParameters), component->second); - // Add component to state being prepared for assembly and check that it is valid - bool componentAdded = MultiComponentStateAssembler::addComponent(cache, std::move(updatedComponentParameters)); + ComponentParameters updatedComponentParameters( + std::move(updatedTrackParameters), component->second); + // Add component to state being prepared for assembly and check that it is + // valid + bool componentAdded = MultiComponentStateAssembler::addComponent( + cache, std::move(updatedComponentParameters)); if (!componentAdded) { - ATH_MSG_DEBUG("Component could not be added to the state in the assembler"); + ATH_MSG_DEBUG( + "Component could not be added to the state in the assembler"); } } - Trk::MultiComponentState assembledUpdatedState = MultiComponentStateAssembler::assembledState(cache); + Trk::MultiComponentState assembledUpdatedState = + MultiComponentStateAssembler::assembledState(cache); if (assembledUpdatedState.empty()) { return {}; @@ -346,7 +394,8 @@ Trk::GsfMeasurementUpdator::calculateFilterStep(Trk::MultiComponentState&& state } bool -Trk::GsfMeasurementUpdator::invalidComponent(const Trk::TrackParameters* trackParameters) const +Trk::GsfMeasurementUpdator::invalidComponent( + const Trk::TrackParameters* trackParameters) const { auto measuredCov = trackParameters->covariance(); bool rebuildCov = false; @@ -354,15 +403,17 @@ Trk::GsfMeasurementUpdator::invalidComponent(const Trk::TrackParameters* trackPa rebuildCov = true; } else { for (int i(0); i < 5; ++i) { - if ((*measuredCov)(i, i) <= 0.) + if ((*measuredCov)(i, i) <= 0.) { rebuildCov = true; + } } } return rebuildCov; } Trk::MultiComponentState -Trk::GsfMeasurementUpdator::rebuildState(Trk::MultiComponentState&& stateBeforeUpdate) const +Trk::GsfMeasurementUpdator::rebuildState( + Trk::MultiComponentState&& stateBeforeUpdate) const { Trk::MultiComponentState stateWithInsertedErrors{}; @@ -383,8 +434,14 @@ Trk::GsfMeasurementUpdator::rebuildState(Trk::MultiComponentState&& stateBeforeU (*bigNewCovarianceMatrix)(4, 4) = 0.001 * 0.001; AmgVector(5) par = trackParameters->parameters(); - Trk::TrackParameters* trackParametersWithError = trackParameters->associatedSurface().createTrackParameters( - par[Trk::loc1], par[Trk::loc2], par[Trk::phi], par[Trk::theta], par[Trk::qOverP], bigNewCovarianceMatrix); + Trk::TrackParameters* trackParametersWithError = + trackParameters->associatedSurface().createTrackParameters( + par[Trk::loc1], + par[Trk::loc2], + par[Trk::phi], + par[Trk::theta], + par[Trk::qOverP], + bigNewCovarianceMatrix); stateWithInsertedErrors.emplace_back(trackParametersWithError, weight); } else { stateWithInsertedErrors.push_back(std::move(*component)); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfSmoother.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfSmoother.cxx index 863e82d32e7f345b49f96b8027b04a5f5df33923..af2de668dc091b6c29eea1524c9ebbd093f853b8 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfSmoother.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/GsfSmoother.cxx @@ -9,7 +9,8 @@ begin : Wednesday 9th March 2005 author : atkinson email : Tom.Atkinson@cern.ch decription : Implementation code for the class GsfSmoother -********************************************************************************** */ +********************************************************************************** +*/ #include "TrkGaussianSumFilter/GsfSmoother.h" @@ -22,13 +23,15 @@ decription : Implementation code for the class GsfSmoother #include "TrkPseudoMeasurementOnTrack/PseudoMeasurementOnTrack.h" #include "TrkSurfaces/Surface.h" -#include "TrkMultiComponentStateOnSurface/MultiComponentStateOnSurface.h" -#include "TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h" #include "TrkGaussianSumFilter/IMultiStateExtrapolator.h" #include "TrkGaussianSumFilter/IMultiStateMeasurementUpdator.h" #include "TrkGaussianSumFilter/MultiComponentStateCombiner.h" +#include "TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h" +#include "TrkMultiComponentStateOnSurface/MultiComponentStateOnSurface.h" -Trk::GsfSmoother::GsfSmoother(const std::string& type, const std::string& name, const IInterface* parent) +Trk::GsfSmoother::GsfSmoother(const std::string& type, + const std::string& name, + const IInterface* parent) : AthAlgTool(type, name, parent) , m_combineWithFitter(false) { @@ -50,8 +53,9 @@ Trk::GsfSmoother::finalize() } StatusCode -Trk::GsfSmoother::configureTools(const ToolHandle<IMultiStateExtrapolator>& extrapolator, - const ToolHandle<IMultiStateMeasurementUpdator>& measurementUpdator) +Trk::GsfSmoother::configureTools( + const ToolHandle<IMultiStateExtrapolator>& extrapolator, + const ToolHandle<IMultiStateMeasurementUpdator>& measurementUpdator) { m_extrapolator = extrapolator; m_updator = measurementUpdator; @@ -75,14 +79,15 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, } // Check that the forward trajectory is filled if (forwardTrajectory.empty()) { - ATH_MSG_ERROR("Attempting to smooth an empty forward trajectory... Exiting!"); + ATH_MSG_ERROR( + "Attempting to smooth an empty forward trajectory... Exiting!"); return nullptr; } - /* Instansiate the return trajectory. This is a vectory of TrackStateOnSurface object - In the GSF Smoother these TrackStateOnSurface objects are the base class for the - MultiComponentStateOnSurface. This memory should be freed by the fitter / smoother master - method */ + /* Instansiate the return trajectory. This is a vectory of TrackStateOnSurface + object In the GSF Smoother these TrackStateOnSurface objects are the base + class for the MultiComponentStateOnSurface. This memory should be freed by + the fitter / smoother master method */ /* * In general for things we want to control their lifetime locally @@ -93,34 +98,41 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, * We control the lifetime of these so unique_ptr */ auto smoothedTrajectory = std::make_unique<Trk::SmoothedTrajectory>(); - auto smootherPredictionMultiState = std::make_unique<Trk::MultiComponentState>(); + auto smootherPredictionMultiState = + std::make_unique<Trk::MultiComponentState>(); /* - * Get the initial smoother prediction. It is the last prediction in the forwards trajectory + * Get the initial smoother prediction. It is the last prediction in the + * forwards trajectory */ /* these can be owned by the input so const ptr*/ - const Trk::TrackStateOnSurface* smootherPredictionStateOnSurface = forwardTrajectory.back(); + const Trk::TrackStateOnSurface* smootherPredictionStateOnSurface = + forwardTrajectory.back(); /* * We can have single or Multi components here, so we choose what to clone */ - const Trk::MultiComponentStateOnSurface* smootherPredictionMultiStateOnSurface = - dynamic_cast<const Trk::MultiComponentStateOnSurface*>(smootherPredictionStateOnSurface); + const Trk::MultiComponentStateOnSurface* + smootherPredictionMultiStateOnSurface = + dynamic_cast<const Trk::MultiComponentStateOnSurface*>( + smootherPredictionStateOnSurface); if (!smootherPredictionMultiStateOnSurface) { - ATH_MSG_DEBUG("GSF smoother has a single component state as starting point"); + ATH_MSG_DEBUG( + "GSF smoother has a single component state as starting point"); auto dummyMultiState = std::make_unique<Trk::MultiComponentState>(); - Trk::ComponentParameters dummyParams(smootherPredictionStateOnSurface->trackParameters()->clone(), 1.0); + Trk::ComponentParameters dummyParams( + smootherPredictionStateOnSurface->trackParameters()->clone(), 1.0); dummyMultiState->push_back(std::move(dummyParams)); smootherPredictionMultiState = std::move(dummyMultiState); } else { - smootherPredictionMultiState = - MultiComponentStateHelpers::clone(*(smootherPredictionMultiStateOnSurface->components())); + smootherPredictionMultiState = MultiComponentStateHelpers::clone( + *(smootherPredictionMultiStateOnSurface->components())); } /* * Perform the measurement update - * The first smoother prediction state is equivalent to the last forwards prediction - * updated with the last measurement - * Retrieve the first MeasurementBase object for the smoother + * The first smoother prediction state is equivalent to the last forwards + * prediction updated with the last measurement Retrieve the first + * MeasurementBase object for the smoother */ std::unique_ptr<Trk::FitQualityOnSurface> fitQuality; @@ -134,12 +146,15 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, const Trk::MeasurementBase* firstSmootherMeasurementOnTrack = smootherPredictionStateOnSurface->measurementOnTrack()->clone(); if (!firstSmootherMeasurementOnTrack) { - ATH_MSG_WARNING("Initial state on surface in smoother does not have an associated " - "MeasurementBase object... returning 0"); + ATH_MSG_WARNING( + "Initial state on surface in smoother does not have an associated " + "MeasurementBase object... returning 0"); return nullptr; } Trk::MultiComponentState firstSmoothedState = - m_updator->update(std::move(*smootherPredictionMultiState), *firstSmootherMeasurementOnTrack, fitQuality); + m_updator->update(std::move(*smootherPredictionMultiState), + *firstSmootherMeasurementOnTrack, + fitQuality); if (firstSmoothedState.empty()) { ATH_MSG_DEBUG("First GSF smoothing update failed... Exiting!"); @@ -151,11 +166,12 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, std::unique_ptr<Trk::TrackParameters> combinedFirstSmoothedState = MultiComponentStateCombiner::combine(firstSmoothedState, true); /*owned be the tragectory*/ - const Trk::MultiComponentStateOnSurface* updatedStateOnSurface = new MultiComponentStateOnSurface( - firstSmootherMeasurementOnTrack, - combinedFirstSmoothedState.release(), - MultiComponentStateHelpers::clone(firstSmoothedState).release(), - fitQuality.release()); + const Trk::MultiComponentStateOnSurface* updatedStateOnSurface = + new MultiComponentStateOnSurface( + firstSmootherMeasurementOnTrack, + combinedFirstSmoothedState.release(), + MultiComponentStateHelpers::clone(firstSmoothedState).release(), + fitQuality.release()); smoothedTrajectory->push_back(updatedStateOnSurface); /* * Reset ptr @@ -170,24 +186,29 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, smootherPredictionMultiState.reset(); if (!MultiComponentStateHelpers::isMeasured(firstSmoothedState)) { - ATH_MSG_WARNING("Updated state is not measured. Rejecting smoothed state... returning 0"); + ATH_MSG_WARNING( + "Updated state is not measured. Rejecting smoothed state... returning 0"); return nullptr; } /* - * Generate prediction by scaling the covariance of all components in the initial state + * Generate prediction by scaling the covariance of all components in the + * initial state * - * Generate a large prediction for extrapolation. This way there is no dependance on error of - * prediction NB local Y and theta are not blown out too much to help in the TRT + * Generate a large prediction for extrapolation. This way there is no + * dependance on error of prediction NB local Y and theta are not blown out + * too much to help in the TRT */ std::unique_ptr<Trk::MultiComponentState> smoothedStateWithScaledError = - MultiComponentStateHelpers::cloneWithScaledError(firstSmoothedState, 15., 5., 15., 5., 15.); + MultiComponentStateHelpers::cloneWithScaledError( + firstSmoothedState, 15., 5., 15., 5., 15.); // Perform a measurement update on this new state - Trk::MultiComponentState updatedState = - m_updator->update(std::move(*smoothedStateWithScaledError), *firstSmootherMeasurementOnTrack); + Trk::MultiComponentState updatedState = m_updator->update( + std::move(*smoothedStateWithScaledError), *firstSmootherMeasurementOnTrack); if (updatedState.empty()) { - ATH_MSG_WARNING("Smoother prediction could not be determined... returning 0"); + ATH_MSG_WARNING( + "Smoother prediction could not be determined... returning 0"); return nullptr; } @@ -195,20 +216,27 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, firstSmootherMeasurementOnTrack = nullptr; // ============================================================================= - // Loop over all remaining TrackStateOnSurface objects in the forward trajectory + // Loop over all remaining TrackStateOnSurface objects in the forward + // trajectory // ============================================================================= - Trk::ForwardTrajectory::const_reverse_iterator trackStateOnSurface = forwardTrajectory.rbegin() + 1; - Trk::ForwardTrajectory::const_reverse_iterator lasttrackStateOnSurface = forwardTrajectory.rend() - 1; - // TSOS that the cluster measuremenet will added on after .. can’t be teh last as the impact - // parameters will be compromised - Trk::ForwardTrajectory::const_reverse_iterator secondLastTrackStateOnSurface = forwardTrajectory.rend() - 2; - - for (; trackStateOnSurface != forwardTrajectory.rend(); ++trackStateOnSurface) { + Trk::ForwardTrajectory::const_reverse_iterator trackStateOnSurface = + forwardTrajectory.rbegin() + 1; + Trk::ForwardTrajectory::const_reverse_iterator lasttrackStateOnSurface = + forwardTrajectory.rend() - 1; + // TSOS that the cluster measuremenet will added on after .. can’t be teh last + // as the impact parameters will be compromised + Trk::ForwardTrajectory::const_reverse_iterator secondLastTrackStateOnSurface = + forwardTrajectory.rend() - 2; + + for (; trackStateOnSurface != forwardTrajectory.rend(); + ++trackStateOnSurface) { // Retrieve the MeasurementBase object from the TrackStateOnSurface object - const Trk::MeasurementBase* measurement_in = (*trackStateOnSurface)->measurementOnTrack(); + const Trk::MeasurementBase* measurement_in = + (*trackStateOnSurface)->measurementOnTrack(); if (!measurement_in) { - ATH_MSG_WARNING("MeasurementBase object could not be extracted from a measurement... continuing"); + ATH_MSG_WARNING("MeasurementBase object could not be extracted from a " + "measurement... continuing"); continue; } // Clone the MeasurementBase object @@ -227,7 +255,8 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, particleHypothesis); if (extrapolatedState.empty()) { - ATH_MSG_DEBUG("Extrapolation to measurement surface failed... rejecting track!"); + ATH_MSG_DEBUG( + "Extrapolation to measurement surface failed... rejecting track!"); return nullptr; } @@ -235,23 +264,27 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, if (!(*trackStateOnSurface)->type(TrackStateOnSurface::Measurement)) { updatedState = std::move(extrapolatedState); - std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> type(0); + std::bitset<TrackStateOnSurface::NumberOfTrackStateOnSurfaceTypes> type( + 0); type.set(TrackStateOnSurface::Outlier); Trk::MultiComponentStateOnSurface* updatedStateOnSurface = - new Trk::MultiComponentStateOnSurface(measurement.release(), - MultiComponentStateHelpers::clone(updatedState).release(), - new FitQuality(1, 1), - nullptr, - type); + new Trk::MultiComponentStateOnSurface( + measurement.release(), + MultiComponentStateHelpers::clone(updatedState).release(), + new FitQuality(1, 1), + nullptr, + type); smoothedTrajectory->push_back(updatedStateOnSurface); continue; } // Update newly extrapolated state with MeasurementBase measurement - updatedState = m_updator->update(std::move(extrapolatedState), *measurement, fitQuality); + updatedState = + m_updator->update(std::move(extrapolatedState), *measurement, fitQuality); if (updatedState.empty()) { - ATH_MSG_WARNING("Could not update the multi-component state... rejecting track!"); + ATH_MSG_WARNING( + "Could not update the multi-component state... rejecting track!"); return nullptr; } @@ -265,29 +298,39 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, std::unique_ptr<Trk::MultiComponentState> forwardsMultiStateOwn; const Trk::MultiComponentStateOnSurface* forwardsMultiStateOnSurface = - dynamic_cast<const Trk::MultiComponentStateOnSurface*>(*trackStateOnSurface); + dynamic_cast<const Trk::MultiComponentStateOnSurface*>( + *trackStateOnSurface); if (!forwardsMultiStateOnSurface) { // Create new multiComponentState from single state - Trk::ComponentParameters componentParameters((*trackStateOnSurface)->trackParameters()->clone(), 1.); + Trk::ComponentParameters componentParameters( + (*trackStateOnSurface)->trackParameters()->clone(), 1.); forwardsMultiStateOwn = std::make_unique<Trk::MultiComponentState>(); forwardsMultiStateOwn->push_back(std::move(componentParameters)); forwardsMultiState = forwardsMultiStateOwn.get(); } else { forwardsMultiState = forwardsMultiStateOnSurface->components(); } - Trk::MultiComponentState combinedState2 = combine(*forwardsMultiState, updatedState); + Trk::MultiComponentState combinedState2 = + combine(*forwardsMultiState, updatedState); if (combinedState2.empty()) { - ATH_MSG_WARNING("Could not combine state from forward fit with smoother state... rejecting track!"); + ATH_MSG_WARNING("Could not combine state from forward fit with " + "smoother state... rejecting track!"); return nullptr; } - const Trk::FitQualityOnSurface* combinedFitQuality = m_updator->fitQuality(combinedState2, *measurement); - // In the case of combination with forwards state - push back the combined state - const Trk::MultiComponentStateOnSurface* combinedStateOnSurface = new MultiComponentStateOnSurface( - measurement.release(), MultiComponentStateHelpers::clone(combinedState2).release(), combinedFitQuality); + const Trk::FitQualityOnSurface* combinedFitQuality = + m_updator->fitQuality(combinedState2, *measurement); + // In the case of combination with forwards state - push back the combined + // state + const Trk::MultiComponentStateOnSurface* combinedStateOnSurface = + new MultiComponentStateOnSurface( + measurement.release(), + MultiComponentStateHelpers::clone(combinedState2).release(), + combinedFitQuality); smoothedTrajectory->push_back(combinedStateOnSurface); } else { - // If combination with forwards state is not done - push back updated state + // If combination with forwards state is not done - push back updated + // state const Trk::MultiComponentStateOnSurface* updatedStateOnSurface = nullptr; if (trackStateOnSurface == lasttrackStateOnSurface) { @@ -295,18 +338,22 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, MultiComponentStateCombiner::combine(updatedState, true); if (combinedLastState) { - updatedStateOnSurface = - new Trk::MultiComponentStateOnSurface(measurement.release(), - combinedLastState.release(), - MultiComponentStateHelpers::clone(updatedState).release(), - fitQuality.release()); + updatedStateOnSurface = new Trk::MultiComponentStateOnSurface( + measurement.release(), + combinedLastState.release(), + MultiComponentStateHelpers::clone(updatedState).release(), + fitQuality.release()); } else { updatedStateOnSurface = new Trk::MultiComponentStateOnSurface( - measurement.release(), MultiComponentStateHelpers::clone(updatedState).release(), fitQuality.release()); + measurement.release(), + MultiComponentStateHelpers::clone(updatedState).release(), + fitQuality.release()); } } else { updatedStateOnSurface = new Trk::MultiComponentStateOnSurface( - measurement.release(), MultiComponentStateHelpers::clone(updatedState).release(), fitQuality.release()); + measurement.release(), + MultiComponentStateHelpers::clone(updatedState).release(), + fitQuality.release()); } smoothedTrajectory->push_back(updatedStateOnSurface); @@ -317,7 +364,8 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, if (ccot && trackStateOnSurface == secondLastTrackStateOnSurface) { - Trk::MultiComponentState ccotState = addCCOT(updatedStateOnSurface, ccot, smoothedTrajectory.get()); + Trk::MultiComponentState ccotState = + addCCOT(updatedStateOnSurface, ccot, smoothedTrajectory.get()); if (!ccotState.empty()) { updatedState = std::move(ccotState); } @@ -328,18 +376,21 @@ Trk::GsfSmoother::fit(const ForwardTrajectory& forwardTrajectory, } Trk::MultiComponentState -Trk::GsfSmoother::combine(const Trk::MultiComponentState& forwardsMultiState, - const Trk::MultiComponentState& smootherMultiState) const +Trk::GsfSmoother::combine( + const Trk::MultiComponentState& forwardsMultiState, + const Trk::MultiComponentState& smootherMultiState) const { - std::unique_ptr<Trk::MultiComponentState> combinedMultiState = std::make_unique<MultiComponentState>(); + std::unique_ptr<Trk::MultiComponentState> combinedMultiState = + std::make_unique<MultiComponentState>(); /* ================================================ Loop over all components in forwards multi-state ================================================ */ for (auto& forwardsComponent : forwardsMultiState) { // Need to check that all components have associated weight matricies - const AmgSymMatrix(5)* forwardMeasuredCov = forwardsComponent.first->covariance(); + const AmgSymMatrix(5)* forwardMeasuredCov = + forwardsComponent.first->covariance(); /* ==================================================== Loop over all components in the smoother multi-state @@ -347,58 +398,74 @@ Trk::GsfSmoother::combine(const Trk::MultiComponentState& forwardsMultiState, for (auto& smootherComponent : smootherMultiState) { // Need to check that all components have associated weight matricies - const AmgSymMatrix(5)* smootherMeasuredCov = smootherComponent.first->covariance(); + const AmgSymMatrix(5)* smootherMeasuredCov = + smootherComponent.first->covariance(); if (!smootherMeasuredCov && !forwardMeasuredCov) { - ATH_MSG_WARNING("Cannot combine two components both without associated errors... returning 0"); + ATH_MSG_WARNING("Cannot combine two components both without associated " + "errors... returning 0"); return {}; } if (!forwardMeasuredCov) { - Trk::ComponentParameters smootherComponentOnly(smootherComponent.first->clone(), smootherComponent.second); + Trk::ComponentParameters smootherComponentOnly( + smootherComponent.first->clone(), smootherComponent.second); combinedMultiState->push_back(std::move(smootherComponentOnly)); continue; } if (!smootherMeasuredCov) { - Trk::ComponentParameters forwardComponentOnly(forwardsComponent.first->clone(), forwardsComponent.second); + Trk::ComponentParameters forwardComponentOnly( + forwardsComponent.first->clone(), forwardsComponent.second); combinedMultiState->push_back(std::move(forwardComponentOnly)); continue; } - const AmgSymMatrix(5) summedCovariance = *forwardMeasuredCov + *smootherMeasuredCov; - const AmgSymMatrix(5) K = *forwardMeasuredCov * summedCovariance.inverse(); + const AmgSymMatrix(5) summedCovariance = + *forwardMeasuredCov + *smootherMeasuredCov; + const AmgSymMatrix(5) K = + *forwardMeasuredCov * summedCovariance.inverse(); const Amg::VectorX newParameters = forwardsComponent.first->parameters() + - K * (smootherComponent.first->parameters() - forwardsComponent.first->parameters()); - const Amg::VectorX parametersDiff = forwardsComponent.first->parameters() - smootherComponent.first->parameters(); - - AmgSymMatrix(5)* covarianceOfNewParameters = new AmgSymMatrix(5)(K * *smootherMeasuredCov); - - Trk::TrackParameters* combinedTrackParameters = (forwardsComponent.first) - ->associatedSurface() - .createTrackParameters(newParameters[Trk::loc1], - newParameters[Trk::loc2], - newParameters[Trk::phi], - newParameters[Trk::theta], - newParameters[Trk::qOverP], - covarianceOfNewParameters); - // Covariance matrix object now owned by TrackParameters object. Reset pointer to prevent - // delete + K * (smootherComponent.first->parameters() - + forwardsComponent.first->parameters()); + const Amg::VectorX parametersDiff = + forwardsComponent.first->parameters() - + smootherComponent.first->parameters(); + + AmgSymMatrix(5)* covarianceOfNewParameters = + new AmgSymMatrix(5)(K * *smootherMeasuredCov); + + Trk::TrackParameters* combinedTrackParameters = + (forwardsComponent.first) + ->associatedSurface() + .createTrackParameters(newParameters[Trk::loc1], + newParameters[Trk::loc2], + newParameters[Trk::phi], + newParameters[Trk::theta], + newParameters[Trk::qOverP], + covarianceOfNewParameters); + // Covariance matrix object now owned by TrackParameters object. Reset + // pointer to prevent delete covarianceOfNewParameters = nullptr; - const AmgSymMatrix(5) invertedSummedCovariance = summedCovariance.inverse(); - // Determine the scaling factor for the new weighting. Determined from the PDF of the - // many-dimensional gaussian - double exponent = parametersDiff.transpose() * invertedSummedCovariance * parametersDiff; + const AmgSymMatrix(5) invertedSummedCovariance = + summedCovariance.inverse(); + // Determine the scaling factor for the new weighting. Determined from the + // PDF of the many-dimensional gaussian + double exponent = + parametersDiff.transpose() * invertedSummedCovariance * parametersDiff; double weightScalingFactor = exp(-0.5 * exponent); - double combinedWeight = smootherComponent.second * forwardsComponent.second * weightScalingFactor; - Trk::ComponentParameters combinedComponent(combinedTrackParameters, combinedWeight); + double combinedWeight = smootherComponent.second * + forwardsComponent.second * weightScalingFactor; + Trk::ComponentParameters combinedComponent(combinedTrackParameters, + combinedWeight); combinedMultiState->push_back(std::move(combinedComponent)); } } // Component reduction on the combined state - Trk::MultiComponentState mergedState = QuickCloseComponentsMultiStateMerger::merge( - std::move(*combinedMultiState), m_maximumNumberOfComponents); + Trk::MultiComponentState mergedState = + QuickCloseComponentsMultiStateMerger::merge(std::move(*combinedMultiState), + m_maximumNumberOfComponents); // Before return the weights of the states need to be renormalised to one. MultiComponentStateHelpers::renormaliseState(mergedState); @@ -417,7 +484,8 @@ Trk::GsfSmoother::addCCOT(const Trk::TrackStateOnSurface* currentState, return {}; } - const Trk::MultiComponentState* currentMultiComponentState = currentMultiStateOS->components(); + const Trk::MultiComponentState* currentMultiComponentState = + currentMultiStateOS->components(); const Trk::MeasurementBase* measurement = currentState->measurementOnTrack(); const Trk::Surface* currentSurface(nullptr); @@ -427,49 +495,59 @@ Trk::GsfSmoother::addCCOT(const Trk::TrackStateOnSurface* currentState, Trk::MultiComponentState extrapolatedState{}; // Extrapolate to the Calo if (currentSurface) { - extrapolatedState = m_extrapolator->extrapolateDirectly(Gaudi::Hive::currentContext(), - *currentMultiComponentState, - ccot->associatedSurface(), - Trk::alongMomentum, - false, - Trk::nonInteracting); + extrapolatedState = + m_extrapolator->extrapolateDirectly(Gaudi::Hive::currentContext(), + *currentMultiComponentState, + ccot->associatedSurface(), + Trk::alongMomentum, + false, + Trk::nonInteracting); } // Extrapolation Failed continue if (extrapolatedState.empty()) { - ATH_MSG_DEBUG("Extrapolation to the CCOT failed .. now not being taken in account"); + ATH_MSG_DEBUG( + "Extrapolation to the CCOT failed .. now not being taken in account"); return {}; } // Update newly extrapolated state with MeasurementBase measurement std::unique_ptr<Trk::FitQualityOnSurface> fitQuality; - Trk::MultiComponentState updatedState = m_updator->update(std::move(extrapolatedState), *ccot, fitQuality); + Trk::MultiComponentState updatedState = + m_updator->update(std::move(extrapolatedState), *ccot, fitQuality); if (updatedState.empty()) { - ATH_MSG_DEBUG("Update of extrapolated state with CCOT failed .. now not being taken in account"); + ATH_MSG_DEBUG("Update of extrapolated state with CCOT failed .. now not " + "being taken in account"); return {}; } // Build TSOS with CCOT at the surface of the surface of calo - Trk::MultiComponentStateOnSurface* updatedMCSOS = new Trk::MultiComponentStateOnSurface( - ccot->clone(), MultiComponentStateHelpers::clone(updatedState).release(), fitQuality.release()); + Trk::MultiComponentStateOnSurface* updatedMCSOS = + new Trk::MultiComponentStateOnSurface( + ccot->clone(), + MultiComponentStateHelpers::clone(updatedState).release(), + fitQuality.release()); // Extrapolate back to the surface nearest the origin - extrapolatedState = m_extrapolator->extrapolateDirectly(Gaudi::Hive::currentContext(), - updatedState, - *currentSurface, - Trk::oppositeMomentum, - false, - Trk::nonInteracting); + extrapolatedState = + m_extrapolator->extrapolateDirectly(Gaudi::Hive::currentContext(), + updatedState, + *currentSurface, + Trk::oppositeMomentum, + false, + Trk::nonInteracting); if (extrapolatedState.empty()) { - ATH_MSG_DEBUG("Extrapolation from CCOT to 1st measurement failed .. now not being taken in account"); + ATH_MSG_DEBUG("Extrapolation from CCOT to 1st measurement failed .. now " + "not being taken in account"); delete updatedMCSOS; return {}; } - // Now build a dummy measurement .... we dont want to a double count the measurement but - // we need to extrapolate back to origin to allow for the perigee parameters to be estimated - // Note this only important if the track is refit otherwise it has no influence. + // Now build a dummy measurement .... we dont want to a double count the + // measurement but we need to extrapolate back to origin to allow for the + // perigee parameters to be estimated Note this only important if the track is + // refit otherwise it has no influence. AmgSymMatrix(5) covMatrix; covMatrix.setZero(); covMatrix(0, 0) = 1e6; @@ -479,19 +557,23 @@ Trk::GsfSmoother::addCCOT(const Trk::TrackStateOnSurface* currentState, defPar.push_back(locX); Trk::LocalParameters locpars(defPar); - Trk::PseudoMeasurementOnTrack* pseudoMeasurement = new PseudoMeasurementOnTrack(locpars, covMatrix, *currentSurface); + Trk::PseudoMeasurementOnTrack* pseudoMeasurement = + new PseudoMeasurementOnTrack(locpars, covMatrix, *currentSurface); // Combine the state using and find the mode of the distribution - std::unique_ptr<Trk::TrackParameters> combinedState = MultiComponentStateCombiner::combine(extrapolatedState, true); + std::unique_ptr<Trk::TrackParameters> combinedState = + MultiComponentStateCombiner::combine(extrapolatedState, true); - const Trk::FitQualityOnSurface* combinedFitQuality = m_updator->fitQuality(extrapolatedState, *ccot); + const Trk::FitQualityOnSurface* combinedFitQuality = + m_updator->fitQuality(extrapolatedState, *ccot); // Build a TSOS using the dummy measurement and combined state Trk::MultiComponentStateOnSurface* finalSOS = - new Trk::MultiComponentStateOnSurface(pseudoMeasurement, - combinedState.release(), - MultiComponentStateHelpers::clone(extrapolatedState).release(), - combinedFitQuality); + new Trk::MultiComponentStateOnSurface( + pseudoMeasurement, + combinedState.release(), + MultiComponentStateHelpers::clone(extrapolatedState).release(), + combinedFitQuality); smoothedTrajectory->push_back(updatedMCSOS); smoothedTrajectory->push_back(finalSOS); ATH_MSG_DEBUG("Successfully added CCOT "); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/KLGaussianMixtureReduction.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/KLGaussianMixtureReduction.cxx index 47e78775b2304e9171f4ff2b473351fb255b3c5e..471707c49baf44e4509d9367d0214768845cef83 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/KLGaussianMixtureReduction.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/KLGaussianMixtureReduction.cxx @@ -2,9 +2,9 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "TrkGaussianSumFilter/KLGaussianMixtureReduction.h" -#include "TrkGaussianSumFilter/AlignedDynArray.h" #include "CxxUtils/features.h" #include "CxxUtils/vectorize.h" +#include "TrkGaussianSumFilter/AlignedDynArray.h" #include <limits> #if !defined(__GNUC__) #define __builtin_assume_aligned(X, N) X @@ -16,25 +16,23 @@ #endif #endif -//This enables -ftree-vectorize in gcc (we compile with O2) +// This enables -ftree-vectorize in gcc (we compile with O2) ATH_ENABLE_VECTORIZATION; -namespace{ +namespace { /** - * Component Merging helper methods + * Component Merging helper methods */ using namespace GSFUtils; /** * Based on - * https://www.sciencedirect.com/science/article/pii/089812218990103X - * equation (16) + * https://www.sciencedirect.com/science/article/pii/089812218990103X + * equation (16) * but not accounting for weights - * covI * invCovJ + covJ * invCovI + (mean1-mean2) (invcov+invcov) (mean1-mean2) - */ -[[maybe_unused]] -float -symmetricKL(const Component1D& componentI, - const Component1D& componentJ) + * covI * invCovJ + covJ * invCovI + (mean1-mean2) (invcov+invcov) (mean1-mean2) + */ +[[maybe_unused]] float +symmetricKL(const Component1D& componentI, const Component1D& componentJ) { const double meanDifference = componentI.mean - componentJ.mean; const double inverCovSum = componentI.invCov + componentJ.invCov; @@ -44,11 +42,10 @@ symmetricKL(const Component1D& componentI, } /** * https://arxiv.org/pdf/2001.00727.pdf - * equation (10) + * equation (10) * Same as above but accounting for weights - */ -[[maybe_unused]] -float + */ +[[maybe_unused]] float weightedSymmetricKL(const Component1D& componentI, const Component1D& componentJ) { @@ -64,13 +61,12 @@ weightedSymmetricKL(const Component1D& componentI, /* * Moment-preserving merge of two 1D components * for example see - * Runnalls, Andrew R.(2007) + * Runnalls, Andrew R.(2007) * Kullback-Leibler approach to Gaussian mixture reduction * equations (2),(3),(4) */ void -combine(GSFUtils::Component1D& updated, - GSFUtils::Component1D& removed) +combine(GSFUtils::Component1D& updated, GSFUtils::Component1D& removed) { const double sumWeight = updated.weight + removed.weight; @@ -91,8 +87,8 @@ combine(GSFUtils::Component1D& updated, updated.invCov = 1. / sumVariance; updated.weight = sumWeight; - //large numbers to enter the multiplications/sums - //make distance large + // large numbers to enter the multiplications/sums + // make distance large removed.mean = 1e10; removed.cov = 1e10; removed.invCov = 1e10; @@ -100,7 +96,7 @@ combine(GSFUtils::Component1D& updated, } /** - * Recalculate the distances given a merged input + * Recalculate the distances given a merged input * and return the minimum index/distance wrt to this * new component */ @@ -110,28 +106,29 @@ recalculateDistances(const componentPtrRestrict componentsIn, const int32_t mini, const int32_t n) { - const Component1D* components = - static_cast<const Component1D*>(__builtin_assume_aligned(componentsIn, alignment)); - float* distances = static_cast<float*>(__builtin_assume_aligned(distancesIn, alignment)); + const Component1D* components = static_cast<const Component1D*>( + __builtin_assume_aligned(componentsIn, alignment)); + float* distances = + static_cast<float*>(__builtin_assume_aligned(distancesIn, alignment)); const int32_t j = mini; const int32_t indexConst = (j - 1) * j / 2; - //Rows + // Rows const Component1D componentJ = components[j]; for (int32_t i = 0; i < j; ++i) { const Component1D componentI = components[i]; const int32_t index = indexConst + i; distances[index] = symmetricKL(componentI, componentJ); } - //Columns + // Columns for (int32_t i = j + 1; i < n; ++i) { const int32_t index = (i - 1) * i / 2 + j; const Component1D componentI = components[i]; - distances[index] = symmetricKL(componentI,componentJ); + distances[index] = symmetricKL(componentI, componentJ); } } -/** +/** * Calculate the distances for all component pairs */ void @@ -140,15 +137,16 @@ calculateAllDistances(const componentPtrRestrict componentsIn, const int32_t n) { - const Component1D* components = - static_cast<const Component1D*>(__builtin_assume_aligned(componentsIn, alignment)); - float* distances = static_cast<float*>(__builtin_assume_aligned(distancesIn, alignment)); + const Component1D* components = static_cast<const Component1D*>( + __builtin_assume_aligned(componentsIn, alignment)); + float* distances = + static_cast<float*>(__builtin_assume_aligned(distancesIn, alignment)); for (int32_t i = 1; i < n; ++i) { - const int32_t indexConst = (i-1) * i / 2; + const int32_t indexConst = (i - 1) * i / 2; const Component1D componentI = components[i]; for (int32_t j = 0; j < i; ++j) { const Component1D componentJ = components[j]; - distances[indexConst + j] = symmetricKL(componentI,componentJ); + distances[indexConst + j] = symmetricKL(componentI, componentJ); } } } @@ -164,13 +162,13 @@ resetDistances(floatPtrRestrict distancesIn, float* distances = (float*)__builtin_assume_aligned(distancesIn, alignment); const int32_t j = minj; const int32_t indexConst = (j - 1) * j / 2; - //Rows + // Rows for (int32_t i = 0; i < j; ++i) { distances[indexConst + i] = std::numeric_limits<float>::max(); } - //Columns - for (int32_t i = j+1; i < n; ++i) { - const int32_t index = (i-1)*i/2 + j; + // Columns + for (int32_t i = j + 1; i < n; ++i) { + const int32_t index = (i - 1) * i / 2 + j; distances[index] = std::numeric_limits<float>::max(); } } @@ -179,7 +177,7 @@ resetDistances(floatPtrRestrict distancesIn, namespace GSFUtils { /* - * Merge the componentsIn and return + * Merge the componentsIn and return * which componets got merged */ std::vector<std::pair<int32_t, int32_t>> @@ -187,42 +185,41 @@ findMerges(componentPtrRestrict componentsIn, const int32_t inputSize, const int32_t reducedSize) { - Component1D* components = - static_cast<Component1D*>(__builtin_assume_aligned(componentsIn, alignment)); - //Based on the inputSize allocate enough space for the pairwise distances + Component1D* components = static_cast<Component1D*>( + __builtin_assume_aligned(componentsIn, alignment)); + // Based on the inputSize allocate enough space for the pairwise distances const int32_t n = inputSize; - const int32_t nn = n * (n-1)/2; + const int32_t nn = n * (n - 1) / 2; // Create a trianular mapping for the pairwise distances std::vector<triangularToIJ> convert; convert.reserve(nn); - for (int32_t i = 1; i<n; ++i) { - const int indexConst = (i-1) * i / 2; - for (int32_t j = 0; j<i; ++j) { + for (int32_t i = 1; i < n; ++i) { + const int indexConst = (i - 1) * i / 2; + for (int32_t j = 0; j < i; ++j) { int32_t index = indexConst + j; - convert[index]={i,j}; + convert[index] = { i, j }; } } - //We need to work with multiple of 8, in principle this is a requirement - //of aligned_alloc (although not in POSIX ) i.e allocation should be multiple - //of the requested size. - const int32_t nn2 = - (nn & 7) == 0 ? nn - : nn + (8 - (nn & 7)); - AlignedDynArray<float, alignment> distances(nn2, std::numeric_limits<float>::max()); - + // We need to work with multiple of 8, in principle this is a requirement + // of aligned_alloc (although not in POSIX ) i.e allocation should be multiple + // of the requested size. + const int32_t nn2 = (nn & 7) == 0 ? nn : nn + (8 - (nn & 7)); + AlignedDynArray<float, alignment> distances( + nn2, std::numeric_limits<float>::max()); + // vector to be returned std::vector<std::pair<int32_t, int32_t>> merges; merges.reserve(inputSize - reducedSize); // initial distance calculation calculateAllDistances(components, distances, n); - + // merge loop int32_t numberOfComponentsLeft = n; while (numberOfComponentsLeft > reducedSize) { // see if we have the next already const std::pair<int32_t, float> minDis = findMinimumIndex(distances, nn2); const int32_t minIndex = minDis.first; - const triangularToIJ conversion= convert[minIndex]; + const triangularToIJ conversion = convert[minIndex]; const int32_t mini = conversion.I; const int32_t minj = conversion.J; // Combine the 2 components @@ -232,7 +229,7 @@ findMerges(componentPtrRestrict componentsIn, // Reset old weights wrt the minj position resetDistances(distances, minj, n); // keep track and decrement - merges.emplace_back(mini,minj); + merges.emplace_back(mini, minj); --numberOfComponentsLeft; } // end of merge while return merges; @@ -255,7 +252,7 @@ findMerges(componentPtrRestrict componentsIn, * AVX2 intrinsics used : * * _mm256_set1_epi32 - * Broadcast 32-bit integer a to all elements of dst. + * Broadcast 32-bit integer a to all elements of dst. * * _mm256_setr_epi32 * Set packed 32-bit integers in dst with the supplied values in reverse order. @@ -281,8 +278,7 @@ findMerges(componentPtrRestrict componentsIn, * Blend packed 8-bit integers from a and b using mask, and store the results * in dst. */ -__attribute__((target("avx2"))) -std::pair<int32_t,float> +__attribute__((target("avx2"))) std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int n) { float* array = (float*)__builtin_assume_aligned(distancesIn, alignment); @@ -296,12 +292,13 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) // increment the indices indicesIn = _mm256_add_epi32(indicesIn, increment); // Get a mask indicating when an element is less than the ones we have - __m256i lt = _mm256_castps_si256(_mm256_cmp_ps(values, minvalues, _CMP_LT_OS)); + __m256i lt = + _mm256_castps_si256(_mm256_cmp_ps(values, minvalues, _CMP_LT_OS)); // b lend select the indices to update minindices = _mm256_blendv_epi8(minindices, indicesIn, lt); minvalues = _mm256_min_ps(values, minvalues); } - //Do the final calculation scalar way + // Do the final calculation scalar way alignas(alignment) float distances[8]; alignas(alignment) int32_t indices[8]; _mm256_store_ps(distances, minvalues); @@ -314,7 +311,7 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) minDistance = distances[i]; } } - return {minIndex,minDistance}; + return { minIndex, minDistance }; } /* * SSE intrinsics used @@ -344,12 +341,11 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) * for compilation and does not generate any instructions, thus it has zero * latency. */ -__attribute__((target("sse4.1"))) -std::pair<int32_t,float> +__attribute__((target("sse4.1"))) std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int n) { float* array = (float*)__builtin_assume_aligned(distancesIn, alignment); - //Do 2 vectors of 4 elements , so 8 at time + // Do 2 vectors of 4 elements , so 8 at time const __m128i increment = _mm_set1_epi32(8); __m128i indices1 = _mm_setr_epi32(0, 1, 2, 3); __m128i indices2 = _mm_setr_epi32(4, 5, 6, 7); @@ -373,7 +369,7 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) minindices2 = _mm_blendv_epi8(minindices2, indices2, lt2); minvalues2 = _mm_min_ps(values2, minvalues2); } - //Do the final calculation scalar way + // Do the final calculation scalar way alignas(alignment) float distances[8]; alignas(alignment) int32_t indices[8]; _mm_store_ps(distances, minvalues1); @@ -389,7 +385,7 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) minDistance = distances[i]; } } - return {minIndex,minDistance}; + return { minIndex, minDistance }; } /* * SSE2 does not have a blend/select instruction. @@ -404,12 +400,11 @@ SSE2_mm_blendv_epi8(__m128i a, __m128i b, __m128i mask) { return _mm_or_si128(_mm_andnot_si128(mask, a), _mm_and_si128(mask, b)); } -__attribute__((target("sse2"))) -std::pair<int32_t,float> +__attribute__((target("sse2"))) std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int n) { float* array = (float*)__builtin_assume_aligned(distancesIn, alignment); - //Do 2 vectors of 4 elements, so 8 at a time + // Do 2 vectors of 4 elements, so 8 at a time const __m128i increment = _mm_set1_epi32(8); __m128i indices1 = _mm_setr_epi32(0, 1, 2, 3); __m128i indices2 = _mm_setr_epi32(4, 5, 6, 7); @@ -433,7 +428,7 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) minindices2 = SSE2_mm_blendv_epi8(minindices2, indices2, lt2); minvalues2 = _mm_min_ps(values2, minvalues2); } - //Do the final calculation scalar way + // Do the final calculation scalar way alignas(alignment) float distances[8]; alignas(alignment) int32_t indices[8]; _mm_store_ps(distances, minvalues1); @@ -449,13 +444,13 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) minDistance = distances[i]; } } - return {minIndex,minDistance}; + return { minIndex, minDistance }; } #endif // end of x86_64 versions /* Always fall back to a simple default version with no intrinsics */ __attribute__((target("default"))) #endif // HAVE_FUNCTION_MULTIVERSIONING -std::pair<int32_t,float> +std::pair<int32_t, float> findMinimumIndex(const floatPtrRestrict distancesIn, const int n) { float* array = (float*)__builtin_assume_aligned(distancesIn, alignment); @@ -468,6 +463,6 @@ findMinimumIndex(const floatPtrRestrict distancesIn, const int n) minDistance = value; } } - return {minIndex,minDistance}; + return { minIndex, minDistance }; } } // end namespace GSFUtils diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx index 01b4f7d61f5109b724ffc67413c5e390f5d40047..500870bdc653481e64fa67433001043705cf4326 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateAssembler.cxx @@ -40,18 +40,23 @@ Trk::MultiComponentStateAssembler::reset(Cache& cache) } bool -Trk::MultiComponentStateAssembler::addComponent(Cache& cache, ComponentParameters&& componentParameters) +Trk::MultiComponentStateAssembler::addComponent( + Cache& cache, + ComponentParameters&& componentParameters) { if (cache.assemblyDone) { return false; } cache.validWeightSum += componentParameters.second; - cache.multiComponentState.emplace_back(componentParameters.first.release(), componentParameters.second); + cache.multiComponentState.emplace_back(componentParameters.first.release(), + componentParameters.second); return true; } bool -Trk::MultiComponentStateAssembler::addMultiState(Cache& cache, Trk::MultiComponentState&& multiComponentState) +Trk::MultiComponentStateAssembler::addMultiState( + Cache& cache, + Trk::MultiComponentState&& multiComponentState) { if (cache.assemblyDone) { return false; @@ -59,7 +64,8 @@ Trk::MultiComponentStateAssembler::addMultiState(Cache& cache, Trk::MultiCompone double sumW(0.); for (auto& component : multiComponentState) { sumW += component.second; - cache.multiComponentState.emplace_back(component.first.release(), component.second); + cache.multiComponentState.emplace_back(component.first.release(), + component.second); } multiComponentState.clear(); cache.validWeightSum += sumW; @@ -67,7 +73,9 @@ Trk::MultiComponentStateAssembler::addMultiState(Cache& cache, Trk::MultiCompone } bool -Trk::MultiComponentStateAssembler::addInvalidComponentWeight(Cache& cache, const double invalidComponentWeight) +Trk::MultiComponentStateAssembler::addInvalidComponentWeight( + Cache& cache, + const double invalidComponentWeight) { cache.invalidWeightSum += invalidComponentWeight; return true; @@ -78,13 +86,14 @@ Trk::MultiComponentStateAssembler::prepareStateForAssembly(Cache& cache) { // Protect against empty state if (!isStateValid(cache)) { - return false; + return false; } // 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 @@ -95,7 +104,9 @@ Trk::MultiComponentStateAssembler::prepareStateForAssembly(Cache& cache) /* * 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.) { @@ -105,7 +116,8 @@ Trk::MultiComponentStateAssembler::prepareStateForAssembly(Cache& cache) * are before the value (i.e ordered descending). * return the 1st element where (element<value) */ - ComponentParameters dummySmallestWeight(nullptr, cache.minimumFractionalWeight * totalWeight); + ComponentParameters dummySmallestWeight( + nullptr, cache.minimumFractionalWeight * totalWeight); auto lower_than = std::upper_bound(cache.multiComponentState.begin(), cache.multiComponentState.end(), dummySmallestWeight, @@ -114,7 +126,9 @@ Trk::MultiComponentStateAssembler::prepareStateForAssembly(Cache& cache) * reverse iterate , so as to delete removing the last */ auto lower_than_reverse = std::make_reverse_iterator(lower_than); - for (auto itr = cache.multiComponentState.rbegin(); itr != lower_than_reverse; ++itr) { + for (auto itr = cache.multiComponentState.rbegin(); + itr != lower_than_reverse; + ++itr) { cache.multiComponentState.erase(itr.base() - 1); } } @@ -141,7 +155,8 @@ Trk::MultiComponentStateAssembler::assembledState(Cache& cache) } Trk::MultiComponentState -Trk::MultiComponentStateAssembler::assembledState(Cache& cache, const double newWeight) +Trk::MultiComponentStateAssembler::assembledState(Cache& cache, + const double newWeight) { if (!prepareStateForAssembly(cache)) { return {}; @@ -150,16 +165,17 @@ Trk::MultiComponentStateAssembler::assembledState(Cache& cache, const double new } Trk::MultiComponentState -Trk::MultiComponentStateAssembler::doStateAssembly(Cache& cache, const double newWeight) +Trk::MultiComponentStateAssembler::doStateAssembly(Cache& cache, + const double newWeight) { if (!isStateValid(cache)) { return {}; } - const size_t cacheSize=cache.multiComponentState.size(); + const size_t cacheSize = cache.multiComponentState.size(); if (cache.validWeightSum <= 0.) { if (!cache.multiComponentState.empty()) { - const double fixedWeights = 1. /static_cast<double>(cacheSize); + const double fixedWeights = 1. / static_cast<double>(cacheSize); for (auto& component : cache.multiComponentState) { component.second = fixedWeights; } @@ -175,9 +191,11 @@ Trk::MultiComponentStateAssembler::doStateAssembly(Cache& cache, const double ne } Trk::MultiComponentState assembledState; assembledState.reserve(cacheSize); - const double scalingFactor = cache.validWeightSum > 0. ? newWeight / cache.validWeightSum : 1.; + const double scalingFactor = + cache.validWeightSum > 0. ? newWeight / cache.validWeightSum : 1.; for (auto& component : cache.multiComponentState) { - assembledState.emplace_back(component.first.release(), component.second * scalingFactor); + assembledState.emplace_back(component.first.release(), + component.second * scalingFactor); } // Reset the cache before leaving reset(cache); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx index 4b8742f9714cd8098a57c80cafe1f437170fe851..e41a362475af2046c1632e42372be1784335c0dd 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateCombiner.cxx @@ -7,7 +7,8 @@ ----------------------------------------------- begin : Monday 20th December 2004 author : atkinson,morley,anastopoulos -description : Implementation code for MultiComponentStateCombiner helpers +description : Implementation code for MultiComponentStateCombiner +helpers *********************************************************************************/ #include "TrkGaussianSumFilter/MultiComponentStateCombiner.h" @@ -16,26 +17,30 @@ description : Implementation code for MultiComponentStateCombiner helpe #include "TrkSurfaces/Surface.h" std::unique_ptr<Trk::TrackParameters> -Trk::MultiComponentStateCombiner::combine(const Trk::MultiComponentState& uncombinedState, - const bool useMode, - const double fractionPDFused) +Trk::MultiComponentStateCombiner::combine( + const Trk::MultiComponentState& uncombinedState, + const bool useMode, + const double fractionPDFused) { - std::unique_ptr<Trk::ComponentParameters> combinedComponent = compute(&uncombinedState, useMode, fractionPDFused); + std::unique_ptr<Trk::ComponentParameters> combinedComponent = + compute(&uncombinedState, useMode, fractionPDFused); return std::move(combinedComponent->first); } std::unique_ptr<Trk::ComponentParameters> -Trk::MultiComponentStateCombiner::combineWithWeight(const Trk::MultiComponentState& uncombinedState, - const bool useMode, - const double fractionPDFused) +Trk::MultiComponentStateCombiner::combineWithWeight( + const Trk::MultiComponentState& uncombinedState, + const bool useMode, + const double fractionPDFused) { return compute(&uncombinedState, useMode, fractionPDFused); } void -Trk::MultiComponentStateCombiner::combineWithWeight(Trk::ComponentParameters& mergeTo, - const Trk::ComponentParameters& addThis) +Trk::MultiComponentStateCombiner::combineWithWeight( + Trk::ComponentParameters& mergeTo, + const Trk::ComponentParameters& addThis) { const Trk::TrackParameters* firstParameters = mergeTo.first.get(); @@ -64,7 +69,8 @@ Trk::MultiComponentStateCombiner::combineWithWeight(Trk::ComponentParameters& me parameters[2] -= 2 * M_PI; } - mean = firstWeight * firstParameters->parameters() + secondWeight * parameters; + mean = + firstWeight * firstParameters->parameters() + secondWeight * parameters; mean /= totalWeight; // Ensure that phi is between -pi and pi @@ -75,8 +81,8 @@ Trk::MultiComponentStateCombiner::combineWithWeight(Trk::ComponentParameters& me mean[2] += 2 * M_PI; } - // Extract local error matrix: Must make sure track parameters are measured, ie have an associated - // error matrix. + // Extract local error matrix: Must make sure track parameters are measured, + // ie have an associated error matrix. if (firstMeasuredCov && secondMeasuredCov) { AmgSymMatrix(5) covariance; AmgSymMatrix(5) covariancePart1; @@ -84,8 +90,10 @@ Trk::MultiComponentStateCombiner::combineWithWeight(Trk::ComponentParameters& me AmgSymMatrix(5) covariancePart2; covariancePart2.setZero(); - covariancePart1 = firstWeight * (*firstMeasuredCov) + secondWeight * (*secondMeasuredCov); - AmgVector(5) parameterDifference = firstParameters->parameters() - parameters; + covariancePart1 = + firstWeight * (*firstMeasuredCov) + secondWeight * (*secondMeasuredCov); + AmgVector(5) parameterDifference = + firstParameters->parameters() - parameters; if (parameterDifference[2] > M_PI) { parameterDifference[2] -= 2 * M_PI; @@ -93,8 +101,10 @@ Trk::MultiComponentStateCombiner::combineWithWeight(Trk::ComponentParameters& me parameterDifference[2] += 2 * M_PI; } - covariancePart2 = firstWeight * secondWeight * parameterDifference * parameterDifference.transpose(); - covariance = covariancePart1 / totalWeight + covariancePart2 / (totalWeight * totalWeight); + covariancePart2 = firstWeight * secondWeight * parameterDifference * + parameterDifference.transpose(); + covariance = covariancePart1 / totalWeight + + covariancePart2 / (totalWeight * totalWeight); mergeTo.first->updateParameters(mean, covariance); mergeTo.second = totalWeight; @@ -105,22 +115,25 @@ Trk::MultiComponentStateCombiner::combineWithWeight(Trk::ComponentParameters& me } std::unique_ptr<Trk::ComponentParameters> -Trk::MultiComponentStateCombiner::compute(const Trk::MultiComponentState* uncombinedState, - const bool useMode, - const double fractionPDFused) +Trk::MultiComponentStateCombiner::compute( + const Trk::MultiComponentState* uncombinedState, + const bool useMode, + const double fractionPDFused) { if (uncombinedState->empty()) { return nullptr; } - const Trk::TrackParameters* firstParameters = uncombinedState->front().first.get(); + const Trk::TrackParameters* firstParameters = + uncombinedState->front().first.get(); // Check to see if first track parameters are measured or not const AmgSymMatrix(5)* firstMeasuredCov = firstParameters->covariance(); - if (uncombinedState->size() == 1) - return std::make_unique<Trk::ComponentParameters>(uncombinedState->front().first->clone(), - uncombinedState->front().second); + if (uncombinedState->size() == 1) { + return std::make_unique<Trk::ComponentParameters>( + uncombinedState->front().first->clone(), uncombinedState->front().second); + } double sumW(0.); const int dimension = (uncombinedState->front()).first->parameters().rows(); @@ -154,7 +167,8 @@ Trk::MultiComponentStateCombiner::compute(const Trk::MultiComponentState* uncomb // Ensure that we don't have any problems with the cyclical nature of phi // Use first state as reference poin - double deltaPhi = (*uncombinedState->begin()).first->parameters()[2] - parameters[2]; + double deltaPhi = + (*uncombinedState->begin()).first->parameters()[2] - parameters[2]; if (deltaPhi > M_PI) { parameters[2] += 2 * M_PI; @@ -165,11 +179,11 @@ Trk::MultiComponentStateCombiner::compute(const Trk::MultiComponentState* uncomb sumW += weight; mean += weight * parameters; - // Extract local error matrix: Must make sure track parameters are measured, ie have an - // associated error matrix. + // Extract local error matrix: Must make sure track parameters are measured, + // ie have an associated error matrix. const AmgSymMatrix(5)* measuredCov = trackParameters->covariance(); - // Calculate the combined covariance matrix + // Calculate the combined covariance matrix // \sigma = \Sum_{m=1}^{M} w_{m}(\sigma_m + (\mu_m-\mu)(\mu_m-\mu)^{T}) if (measuredCov) { // Changed from errorMatrixInMeasurementFrame @@ -177,27 +191,37 @@ Trk::MultiComponentStateCombiner::compute(const Trk::MultiComponentState* uncomb covariancePart1 += weight * (*measuredCov); /* ============================================================================ - Loop over all remaining components to find the second part of the covariance - ============================================================================ */ + Loop over all remaining components to find the second part of the + covariance + ============================================================================ + */ - Trk::MultiComponentState::const_iterator remainingComponentIterator = component; + Trk::MultiComponentState::const_iterator remainingComponentIterator = + component; - for (; remainingComponentIterator != uncombinedState->end(); ++remainingComponentIterator) { + for (; remainingComponentIterator != uncombinedState->end(); + ++remainingComponentIterator) { - if (remainingComponentIterator == component) + if (remainingComponentIterator == component) { continue; + } - AmgVector(5) parameterDifference = parameters - ((*remainingComponentIterator).first)->parameters(); + AmgVector(5) parameterDifference = + parameters - ((*remainingComponentIterator).first)->parameters(); - double remainingComponentIteratorWeight = (*remainingComponentIterator).second; + double remainingComponentIteratorWeight = + (*remainingComponentIterator).second; - covariancePart2 += weight * remainingComponentIteratorWeight * parameterDifference * parameterDifference.transpose(); + covariancePart2 += weight * remainingComponentIteratorWeight * + parameterDifference * + parameterDifference.transpose(); } // end loop over remaining components } // end clause if errors are involved - if (weight / totalWeight > fractionPDFused) + if (weight / totalWeight > fractionPDFused) { break; + } } // end loop over all components mean /= sumW; @@ -215,7 +239,8 @@ Trk::MultiComponentStateCombiner::compute(const Trk::MultiComponentState* uncomb if (useMode && dimension == 5) { // Calculate the mode of the q/p distribution - std::array<double, 10> modes = Trk::MultiComponentStateModeCalculator::calculateMode(*uncombinedState); + std::array<double, 10> modes = + Trk::MultiComponentStateModeCalculator::calculateMode(*uncombinedState); // Replace mean with mode if qOverP mode is not 0 if (modes[4] != 0) { @@ -280,14 +305,17 @@ Trk::MultiComponentStateCombiner::compute(const Trk::MultiComponentState* uncomb double phi = mean[Trk::phi]; double theta = mean[Trk::theta]; double qoverp = mean[Trk::qOverP]; - if (firstMeasuredCov) + if (firstMeasuredCov) { combinedTrackParameters.reset( - firstParameters->associatedSurface().createTrackParameters(loc1, loc2, phi, theta, qoverp, covariance)); - else { + firstParameters->associatedSurface().createTrackParameters( + loc1, loc2, phi, theta, qoverp, covariance)); + } else { combinedTrackParameters.reset( - firstParameters->associatedSurface().createTrackParameters(loc1, loc2, phi, theta, qoverp, nullptr)); + firstParameters->associatedSurface().createTrackParameters( + loc1, loc2, phi, theta, qoverp, nullptr)); delete covariance; } - return std::make_unique<ComponentParameters>(std::move(combinedTrackParameters), totalWeight); + return std::make_unique<ComponentParameters>( + std::move(combinedTrackParameters), totalWeight); } diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateModeCalculator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateModeCalculator.cxx index 20f0115c47bc54634ff54314c9a69e306ef15d02..1f109fe8bbf407aa77087a9733778a041d76e6f7 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateModeCalculator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/MultiComponentStateModeCalculator.cxx @@ -8,7 +8,8 @@ begin : Thursday 6th July 2006 author : atkinson , amorley , anastopoulos email : amorley@cern.ch -description : Implementation code for MultiComponentStateModeCalculator class +description : Implementation code for MultiComponentStateModeCalculator +class ****************************************************************************************/ #include "TrkGaussianSumFilter/MultiComponentStateModeCalculator.h" @@ -20,7 +21,8 @@ const double invsqrt2PI = 1. / sqrt(2. * M_PI); } std::array<double, 10> -Trk::MultiComponentStateModeCalculator::calculateMode(const Trk::MultiComponentState& multiComponentState) +Trk::MultiComponentStateModeCalculator::calculateMode( + const Trk::MultiComponentState& multiComponentState) { std::array<double, 10> modes{}; // Check to see if the multi-component state is measured @@ -52,8 +54,8 @@ Trk::MultiComponentStateModeCalculator::calculateMode(const Trk::MultiComponentS } } modes[i] = findMode(largerMeanComponent, i, mixture); - // Calculate the FWHM and return this back so that it can be used to correct the covariance - // matrix + // Calculate the FWHM and return this back so that it can be used to correct + // the covariance matrix if (largerMeanComponent != modes[i]) { // mode calculation was successful now calulate FWHM double currentWidth = width(i, mixture); @@ -72,7 +74,8 @@ Trk::MultiComponentStateModeCalculator::calculateMode(const Trk::MultiComponentS } } - bool highXFound = findRoot(highX, modes[i], upperbound, pdfVal * 0.5, i, mixture); + bool highXFound = + findRoot(highX, modes[i], upperbound, pdfVal * 0.5, i, mixture); double lowerbound = modes[i] - 1.5 * currentWidth; while (true) { @@ -82,7 +85,8 @@ Trk::MultiComponentStateModeCalculator::calculateMode(const Trk::MultiComponentS break; } } - bool lowXFound = findRoot(lowX, lowerbound, modes[i], pdfVal * 0.5, i, mixture); + bool lowXFound = + findRoot(lowX, lowerbound, modes[i], pdfVal * 0.5, i, mixture); if (highXFound && lowXFound) { double FWHM = highX - lowX; modes[i + 5] = FWHM / 2.35482; // 2 * sqrt( 2* log(2)) @@ -101,8 +105,9 @@ Trk::MultiComponentStateModeCalculator::calculateMode(const Trk::MultiComponentS } void -Trk::MultiComponentStateModeCalculator::fillMixture(const Trk::MultiComponentState& multiComponentState, - std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::fillMixture( + const Trk::MultiComponentState& multiComponentState, + std::array<std::vector<Component>, 5>& mixture) { for (int i = 0; i < 5; i++) { @@ -110,28 +115,33 @@ Trk::MultiComponentStateModeCalculator::fillMixture(const Trk::MultiComponentSta } // Loop over all the components in the multi-component state - Trk::MultiComponentState::const_iterator component = multiComponentState.begin(); - Trk::ParamDefs parameter[5] = { Trk::d0, Trk::z0, Trk::phi, Trk::theta, Trk::qOverP }; + Trk::MultiComponentState::const_iterator component = + multiComponentState.begin(); + Trk::ParamDefs parameter[5] = { + Trk::d0, Trk::z0, Trk::phi, Trk::theta, Trk::qOverP + }; for (; component != multiComponentState.end(); ++component) { for (int i = 0; i < 5; ++i) { const Trk::TrackParameters* componentParameters = component->first.get(); const AmgSymMatrix(5)* measuredCov = componentParameters->covariance(); - if (!measuredCov) + if (!measuredCov) { return; + } // Enums for Perigee // // d0=0, z0=1, phi0=2, theta=3, qOverP=4, double weight = component->second; double mean = componentParameters->parameters()[parameter[i]]; - // FIXME ATLASRECTS-598 this fabs() should not be necessary... for some reason - // cov(qOverP,qOverP) can be negative + // FIXME ATLASRECTS-598 this fabs() should not be necessary... for some + // reason cov(qOverP,qOverP) can be negative double sigma = sqrt(fabs((*measuredCov)(parameter[i], parameter[i]))); // Ensure that we don't have any problems with the cyclical nature of phi // Use first state as reference point if (i == 2) { // phi - double deltaPhi = multiComponentState.begin()->first->parameters()[2] - mean; + double deltaPhi = + multiComponentState.begin()->first->parameters()[2] - mean; if (deltaPhi > M_PI) { mean += 2 * M_PI; } else if (deltaPhi < -M_PI) { @@ -145,9 +155,10 @@ Trk::MultiComponentStateModeCalculator::fillMixture(const Trk::MultiComponentSta } double -Trk::MultiComponentStateModeCalculator::findMode(double xStart, - int i, - const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::findMode( + double xStart, + int i, + const std::array<std::vector<Component>, 5>& mixture) { int iteration(0); @@ -187,9 +198,10 @@ Trk::MultiComponentStateModeCalculator::findMode(double xStart, } double -Trk::MultiComponentStateModeCalculator::findModeGlobal(double mean, - int i, - const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::findModeGlobal( + double mean, + int i, + const std::array<std::vector<Component>, 5>& mixture) { double start(-1); @@ -217,21 +229,28 @@ Trk::MultiComponentStateModeCalculator::findModeGlobal(double mean, } double -Trk::MultiComponentStateModeCalculator::pdf(double x, int i, const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::pdf( + double x, + int i, + const std::array<std::vector<Component>, 5>& mixture) { double pdf(0.); auto component = mixture[i].begin(); - for (; component != mixture[i].end(); ++component) + for (; component != mixture[i].end(); ++component) { pdf += component->weight * gaus(x, component->mean, component->sigma); + } return pdf; } double -Trk::MultiComponentStateModeCalculator::d1pdf(double x, int i, const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::d1pdf( + double x, + int i, + const std::array<std::vector<Component>, 5>& mixture) { double result(0.); @@ -242,14 +261,18 @@ Trk::MultiComponentStateModeCalculator::d1pdf(double x, int i, const std::array< double z = (x - component->mean) / component->sigma; - result += -1. * component->weight * z * gaus(x, component->mean, component->sigma) / component->sigma; + result += -1. * component->weight * z * + gaus(x, component->mean, component->sigma) / component->sigma; } return result; } double -Trk::MultiComponentStateModeCalculator::d2pdf(double x, int i, const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::d2pdf( + double x, + int i, + const std::array<std::vector<Component>, 5>& mixture) { double result(0.); @@ -260,21 +283,23 @@ Trk::MultiComponentStateModeCalculator::d2pdf(double x, int i, const std::array< double z = (x - component->mean) / component->sigma; - result += component->weight / (component->sigma * component->sigma) * (z * z - 1.) * - gaus(x, component->mean, component->sigma); + result += component->weight / (component->sigma * component->sigma) * + (z * z - 1.) * gaus(x, component->mean, component->sigma); } return result; } double -Trk::MultiComponentStateModeCalculator::gaus(double x, double mean, double sigma) +Trk::MultiComponentStateModeCalculator::gaus(double x, + double mean, + double sigma) { /* * gauss = 1/(sigma * sqrt(2*pi)) * exp ( -0.5 * ((x-mean)/sigma)^2 ) - * =(1/sqrt(2*pi))* (1/sigma) * exp (-0.5 * ((x-mean)*(1/sigma)) * ((x-mean)*(1/sigma)) ) - * = invsqrt2PI * invertsigma * exp (-0.5 *z * z) + * =(1/sqrt(2*pi))* (1/sigma) * exp (-0.5 * ((x-mean)*(1/sigma)) * + * ((x-mean)*(1/sigma)) ) = invsqrt2PI * invertsigma * exp (-0.5 *z * z) */ double invertsigma = 1. / sigma; double z = (x - mean) * invertsigma; @@ -283,31 +308,35 @@ Trk::MultiComponentStateModeCalculator::gaus(double x, double mean, double sigma } double -Trk::MultiComponentStateModeCalculator::width(int i, const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::width( + int i, + const std::array<std::vector<Component>, 5>& mixture) { double pdf(0.); auto component = mixture[i].begin(); - for (; component != mixture[i].end(); ++component) + for (; component != mixture[i].end(); ++component) { pdf += component->weight * component->sigma; + } return pdf; } double -Trk::MultiComponentStateModeCalculator::findRoot(double& result, - double xlo, - double xhi, - double value, - double i, - const std::array<std::vector<Component>, 5>& mixture) +Trk::MultiComponentStateModeCalculator::findRoot( + double& result, + double xlo, + double xhi, + double value, + double i, + const std::array<std::vector<Component>, 5>& mixture) { - // Do the root finding using the Brent-Decker method. Returns a boolean status and - // loads 'result' with our best guess at the root if true. - // Prints a warning if the initial interval does not bracket a single - // root or if the root is not found after a fixed number of iterations. + // Do the root finding using the Brent-Decker method. Returns a boolean status + // and loads 'result' with our best guess at the root if true. Prints a + // warning if the initial interval does not bracket a single root or if the + // root is not found after a fixed number of iterations. double a(xlo); double b(xhi); diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/PosteriorWeightsCalculator.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/PosteriorWeightsCalculator.cxx index 24e2300ee099f42f25694013ccbb2c283936bd48..23fc5777c24b1a964ef07b8fa9fe60eba5737163 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/PosteriorWeightsCalculator.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/PosteriorWeightsCalculator.cxx @@ -18,7 +18,9 @@ description : Implementation code for PosteriorWeightsCalculator class #include "TrkParameters/TrackParameters.h" std::vector<Trk::ComponentParameters> -Trk::PosteriorWeightsCalculator::weights(MultiComponentState&& predictedState, const MeasurementBase& measurement) const +Trk::PosteriorWeightsCalculator::weights( + MultiComponentState&& predictedState, + const MeasurementBase& measurement) const { const size_t predictedStateSize = predictedState.size(); @@ -40,19 +42,22 @@ Trk::PosteriorWeightsCalculator::weights(MultiComponentState&& predictedState, c for (; component != predictedState.end(); ++component) { - const Trk::TrackParameters* componentTrackParameters = (*component).first.get(); + const Trk::TrackParameters* componentTrackParameters = + (*component).first.get(); if (!componentTrackParameters) { continue; } - const AmgSymMatrix(5)* predictedCov = componentTrackParameters->covariance(); + const AmgSymMatrix(5)* predictedCov = + componentTrackParameters->covariance(); if (!predictedCov) { continue; } - const Trk::LocalParameters& measurementLocalParameters = measurement.localParameters(); + const Trk::LocalParameters& measurementLocalParameters = + measurement.localParameters(); std::pair<double, double> result(0, 0); int nLocCoord = measurement.localParameters().dimension(); if (nLocCoord == 1) { @@ -63,35 +68,40 @@ Trk::PosteriorWeightsCalculator::weights(MultiComponentState&& predictedState, c measurementLocalParameters.parameterKey()); } else if (nLocCoord == 2) { if (measurementLocalParameters.parameterKey() == 3) { - result = calculateWeight_2D_3(componentTrackParameters, - predictedCov, - measurementLocalParameters.block<2, 1>(0, 0), - measurement.localCovariance().block<2, 2>(0, 0)); + result = + calculateWeight_2D_3(componentTrackParameters, + predictedCov, + measurementLocalParameters.block<2, 1>(0, 0), + measurement.localCovariance().block<2, 2>(0, 0)); } else { - result = calculateWeight_T<2>(componentTrackParameters, - predictedCov, - measurementLocalParameters.block<2, 1>(0, 0), - measurement.localCovariance().block<2, 2>(0, 0), - measurementLocalParameters.parameterKey()); + result = + calculateWeight_T<2>(componentTrackParameters, + predictedCov, + measurementLocalParameters.block<2, 1>(0, 0), + measurement.localCovariance().block<2, 2>(0, 0), + measurementLocalParameters.parameterKey()); } } else if (nLocCoord == 3) { - result = calculateWeight_T<3>(componentTrackParameters, - predictedCov, - measurementLocalParameters.block<3, 1>(0, 0), - measurement.localCovariance().block<3, 3>(0, 0), - measurementLocalParameters.parameterKey()); + result = + calculateWeight_T<3>(componentTrackParameters, + predictedCov, + measurementLocalParameters.block<3, 1>(0, 0), + measurement.localCovariance().block<3, 3>(0, 0), + measurementLocalParameters.parameterKey()); } else if (nLocCoord == 4) { - result = calculateWeight_T<4>(componentTrackParameters, - predictedCov, - measurementLocalParameters.block<4, 1>(0, 0), - measurement.localCovariance().block<4, 4>(0, 0), - measurementLocalParameters.parameterKey()); + result = + calculateWeight_T<4>(componentTrackParameters, + predictedCov, + measurementLocalParameters.block<4, 1>(0, 0), + measurement.localCovariance().block<4, 4>(0, 0), + measurementLocalParameters.parameterKey()); } else if (nLocCoord == 5) { - result = calculateWeight_T<5>(componentTrackParameters, - predictedCov, - measurementLocalParameters.block<5, 1>(0, 0), - measurement.localCovariance().block<5, 5>(0, 0), - measurementLocalParameters.parameterKey()); + result = + calculateWeight_T<5>(componentTrackParameters, + predictedCov, + measurementLocalParameters.block<5, 1>(0, 0), + measurement.localCovariance().block<5, 5>(0, 0), + measurementLocalParameters.parameterKey()); } else { break; } @@ -103,12 +113,14 @@ Trk::PosteriorWeightsCalculator::weights(MultiComponentState&& predictedState, c componentDeterminantR.push_back(result.first); componentChi2.push_back(result.second); - if (result.second < minimumChi2) + if (result.second < minimumChi2) { minimumChi2 = result.second; + } } // end loop over components - if (componentDeterminantR.size() != predictedState.size() || componentChi2.size() != predictedState.size()) { + if (componentDeterminantR.size() != predictedState.size() || + componentChi2.size() != predictedState.size()) { returnMultiComponentState.clear(); return {}; } @@ -128,26 +140,31 @@ Trk::PosteriorWeightsCalculator::weights(MultiComponentState&& predictedState, c double chi2 = componentChi2[index] - minimumChi2; double updatedWeight(0.); - // Determinant can not be belowe 1e-19 in CLHEP .... rather ugly but protect against 0 - // determinants Normally occur when the component is a poor fit + // Determinant can not be belowe 1e-19 in CLHEP .... rather ugly but protect + // against 0 determinants Normally occur when the component is a poor fit if (componentDeterminantR[index] > 1e-20) { - updatedWeight = priorWeight * sqrt(1. / componentDeterminantR[index]) * exp(-0.5 * chi2); + updatedWeight = priorWeight * sqrt(1. / componentDeterminantR[index]) * + exp(-0.5 * chi2); } else { updatedWeight = 1e-10; } - returnMultiComponentState.emplace_back(component->first.release(), updatedWeight); + returnMultiComponentState.emplace_back(component->first.release(), + updatedWeight); sumWeights += updatedWeight; } // Renormalise the state to total weight = 1 - Trk::MultiComponentState::iterator returnComponent = returnMultiComponentState.begin(); + Trk::MultiComponentState::iterator returnComponent = + returnMultiComponentState.begin(); component = predictedState.begin(); if (sumWeights > 0.) { - for (; returnComponent != returnMultiComponentState.end(); ++returnComponent, ++component) { + for (; returnComponent != returnMultiComponentState.end(); + ++returnComponent, ++component) { (*returnComponent).second /= sumWeights; } } else { - for (; returnComponent != returnMultiComponentState.end(); ++returnComponent, ++component) { + for (; returnComponent != returnMultiComponentState.end(); + ++returnComponent, ++component) { (*returnComponent).second = component->second; } } @@ -156,26 +173,29 @@ Trk::PosteriorWeightsCalculator::weights(MultiComponentState&& predictedState, c } std::pair<double, double> -Trk::PosteriorWeightsCalculator::calculateWeight_1D(const TrackParameters* componentTrackParameters, - const AmgSymMatrix(5) * predictedCov, - const double measPar, - const double measCov, - int paramKey) const +Trk::PosteriorWeightsCalculator::calculateWeight_1D( + const TrackParameters* componentTrackParameters, + const AmgSymMatrix(5) * predictedCov, + const double measPar, + const double measCov, + int paramKey) const { // use measuring coordinate (variable "mk") instead of reduction matrix int mk = 0; - if (paramKey != 1) - for (int i = 0; i < 5; ++i) + if (paramKey != 1) { + for (int i = 0; i < 5; ++i) { if (paramKey & (1 << i)) { mk = i; break; } + } + } // Calculate the residual const double r = measPar - (componentTrackParameters->parameters())(mk); - // Residual covariance. Posterior weights is calculated used predicted state and measurement. - // Therefore add covariances + // Residual covariance. Posterior weights is calculated used predicted state + // and measurement. Therefore add covariances const double R = measCov + (*predictedCov)(mk, mk); if (R == 0) { @@ -186,22 +206,26 @@ Trk::PosteriorWeightsCalculator::calculateWeight_1D(const TrackParameters* compo } std::pair<double, double> -Trk::PosteriorWeightsCalculator::calculateWeight_2D_3(const TrackParameters* componentTrackParameters, - const AmgSymMatrix(5) * predictedCov, - const AmgVector(2) & measPar, - const AmgSymMatrix(2) & measCov) const +Trk::PosteriorWeightsCalculator::calculateWeight_2D_3( + const TrackParameters* componentTrackParameters, + const AmgSymMatrix(5) * predictedCov, + const AmgVector(2) & measPar, + const AmgSymMatrix(2) & measCov) const { // Calculate the residual - AmgVector(2) r = measPar - componentTrackParameters->parameters().block<2, 1>(0, 0); - // Residual covariance. Posterior weights is calculated used predicted state and measurement. - // Therefore add covariances + AmgVector(2) r = + measPar - componentTrackParameters->parameters().block<2, 1>(0, 0); + // Residual covariance. Posterior weights is calculated used predicted state + // and measurement. Therefore add covariances AmgSymMatrix(2) R(measCov + predictedCov->block<2, 2>(0, 0)); // compute determinant of residual const double det = R.determinant(); if (det == 0) { - // ATH_MSG_WARNING( "Determinant is 0, cannot invert matrix... Ignoring component" ); + // ATH_MSG_WARNING( "Determinant is 0, cannot invert matrix... Ignoring + // component" ); return std::pair<double, double>(0, 0); } // Compute Chi2 - return std::pair<double, double>(det, 0.5 * ((r.transpose() * R.inverse() * r)(0, 0))); + return std::pair<double, double>( + det, 0.5 * ((r.transpose() * R.inverse() * r)(0, 0))); } diff --git a/Tracking/TrkFitter/TrkGaussianSumFilter/src/QuickCloseComponentsMultiStateMerger.cxx b/Tracking/TrkFitter/TrkGaussianSumFilter/src/QuickCloseComponentsMultiStateMerger.cxx index ee5ace1928cb9eb7b0ddca1ddb4b2a14035925a2..5f91cc28d8746dfabf34ffb6eff4b58c9d7a88f2 100644 --- a/Tracking/TrkFitter/TrkGaussianSumFilter/src/QuickCloseComponentsMultiStateMerger.cxx +++ b/Tracking/TrkFitter/TrkGaussianSumFilter/src/QuickCloseComponentsMultiStateMerger.cxx @@ -8,8 +8,8 @@ begin : Wednesday 3rd September 2008 author : amorley email : Anthony.Morley@cern.ch -decription : Implementation code for QuickCloseComponentsMultiStateMerger - class +decription : Implementation code for +QuickCloseComponentsMultiStateMerger class *********************************************************************************/ #include "TrkGaussianSumFilter/QuickCloseComponentsMultiStateMerger.h" @@ -23,13 +23,15 @@ decription : Implementation code for QuickCloseComponentsMultiStateMer using namespace GSFUtils; Trk::MultiComponentState -Trk::QuickCloseComponentsMultiStateMerger::merge(Trk::MultiComponentState&& statesToMerge, - const unsigned int maximumNumberOfComponents) +Trk::QuickCloseComponentsMultiStateMerger::merge( + Trk::MultiComponentState&& statesToMerge, + const unsigned int maximumNumberOfComponents) { // Assembler Cache MultiComponentStateAssembler::Cache cache; if (statesToMerge.size() <= maximumNumberOfComponents) { - MultiComponentStateAssembler::addMultiState(cache, std::move(statesToMerge)); + MultiComponentStateAssembler::addMultiState(cache, + std::move(statesToMerge)); return MultiComponentStateAssembler::assembledState(cache); } @@ -52,13 +54,14 @@ Trk::QuickCloseComponentsMultiStateMerger::merge(Trk::MultiComponentState&& stat return x.second > y.second; }); - Trk::ComponentParameters dummyCompParams(statesToMerge.begin()->first->clone(), 1.); + Trk::ComponentParameters dummyCompParams( + statesToMerge.begin()->first->clone(), 1.); Trk::MultiComponentState returnMultiState; returnMultiState.push_back(std::move(dummyCompParams)); return returnMultiState; } - return mergeFullDistArray(cache, statesToMerge,maximumNumberOfComponents); + return mergeFullDistArray(cache, statesToMerge, maximumNumberOfComponents); } Trk::MultiComponentState @@ -73,7 +76,8 @@ Trk::QuickCloseComponentsMultiStateMerger::mergeFullDistArray( const AmgSymMatrix(5)* measuredCov = statesToMerge[i].first->covariance(); const AmgVector(5)& parameters = statesToMerge[i].first->parameters(); // Fill in infomation - const double cov = measuredCov ? (*measuredCov)(Trk::qOverP, Trk::qOverP) : -1.; + const double cov = + measuredCov ? (*measuredCov)(Trk::qOverP, Trk::qOverP) : -1.; components[i].mean = parameters[Trk::qOverP]; components[i].cov = cov; components[i].invCov = cov > 0 ? 1. / cov : 1e10; @@ -88,7 +92,8 @@ Trk::QuickCloseComponentsMultiStateMerger::mergeFullDistArray( for (const auto& mergePair : merges) { const int32_t mini = mergePair.first; const int32_t minj = mergePair.second; - MultiComponentStateCombiner::combineWithWeight(statesToMerge[mini], statesToMerge[minj]); + MultiComponentStateCombiner::combineWithWeight(statesToMerge[mini], + statesToMerge[minj]); statesToMerge[minj].first.reset(); statesToMerge[minj].second = 0.; } @@ -98,10 +103,12 @@ Trk::QuickCloseComponentsMultiStateMerger::mergeFullDistArray( if (!state.first) { continue; } - cache.multiComponentState.push_back(ComponentParameters(state.first.release(), state.second)); + cache.multiComponentState.push_back( + ComponentParameters(state.first.release(), state.second)); cache.validWeightSum += state.second; } - Trk::MultiComponentState mergedState = MultiComponentStateAssembler::assembledState(cache); + Trk::MultiComponentState mergedState = + MultiComponentStateAssembler::assembledState(cache); // Clear the state vector statesToMerge.clear(); return mergedState;