From 5ccabfd1645cd917dc5a2b1687855d10a2708512 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Wed, 3 Apr 2024 22:11:55 +0200 Subject: [PATCH] refactor!: Replace `Surface` `FreeVector` input with position and direction (#2933) We do not depend on free parameters for `Surface` so this should not be part of the interface. I consistently replace this by position and direction vectors here. blocked by - https://github.com/acts-project/acts/pull/2932 - https://github.com/acts-project/acts/pull/2811 --- .../Kernel/detail/AlignmentEngine.hpp | 6 +- Core/include/Acts/Propagator/EigenStepper.hpp | 8 ++- Core/include/Acts/Propagator/EigenStepper.ipp | 8 ++- .../Acts/Propagator/StraightLineStepper.hpp | 8 ++- Core/include/Acts/Surfaces/ConeSurface.hpp | 6 +- .../include/Acts/Surfaces/CylinderSurface.hpp | 6 +- Core/include/Acts/Surfaces/DiscSurface.hpp | 16 +++-- Core/include/Acts/Surfaces/LineSurface.hpp | 22 ++++--- Core/include/Acts/Surfaces/Surface.hpp | 43 ++++++++----- Core/include/Acts/Surfaces/SurfaceConcept.hpp | 10 +-- .../Acts/TrackFitting/detail/GsfActor.hpp | 6 +- Core/src/Propagator/StraightLineStepper.cpp | 8 ++- .../Propagator/detail/CovarianceEngine.cpp | 3 +- Core/src/Propagator/detail/JacobianEngine.cpp | 15 +++-- Core/src/Surfaces/ConeSurface.cpp | 8 +-- Core/src/Surfaces/CylinderSurface.cpp | 8 +-- Core/src/Surfaces/DiscSurface.cpp | 20 +++--- Core/src/Surfaces/LineSurface.cpp | 30 +++------ Core/src/Surfaces/Surface.cpp | 62 ++++++------------- .../CorrectedTransformFreeToBoundTests.cpp | 2 +- .../BoundToCurvilinearConversionTests.cpp | 5 +- .../Core/Propagator/JacobianEngineTests.cpp | 30 ++------- .../Core/Surfaces/DiscSurfaceTests.cpp | 7 +-- .../Core/Surfaces/LineSurfaceTests.cpp | 6 +- .../Core/Surfaces/PlaneSurfaceTests.cpp | 12 ++-- 25 files changed, 160 insertions(+), 195 deletions(-) diff --git a/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp b/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp index 0e9a724ca47..225357c0486 100644 --- a/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp +++ b/Alignment/include/ActsAlignment/Kernel/detail/AlignmentEngine.hpp @@ -225,6 +225,8 @@ TrackAlignmentState trackAlignmentState( // The free parameters transformed from the smoothed parameters const FreeVector freeParams = Acts::MultiTrajectoryHelpers::freeSmoothed(gctx, state); + // The position + const Vector3 position = freeParams.segment<3>(eFreePos0); // The direction const Vector3 direction = freeParams.segment<3>(eFreeDir0); // The derivative of free parameters w.r.t. path length. @note Here, we @@ -234,8 +236,8 @@ TrackAlignmentState trackAlignmentState( FreeVector pathDerivative = FreeVector::Zero(); pathDerivative.head<3>() = direction; // Get the derivative of bound parameters w.r.t. alignment parameters - AlignmentToBoundMatrix alignToBound = - surface->alignmentToBoundDerivative(gctx, freeParams, pathDerivative); + AlignmentToBoundMatrix alignToBound = surface->alignmentToBoundDerivative( + gctx, position, direction, pathDerivative); // Set the degree of freedom per surface. // @Todo: don't allocate memory for fixed degree of freedom and consider surface/layer/volume wise align mask (instead of using global mask as now) resetAlignmentDerivative(alignToBound, alignMask); diff --git a/Core/include/Acts/Propagator/EigenStepper.hpp b/Core/include/Acts/Propagator/EigenStepper.hpp index dfa7300d381..b12962ca1f3 100644 --- a/Core/include/Acts/Propagator/EigenStepper.hpp +++ b/Core/include/Acts/Propagator/EigenStepper.hpp @@ -80,8 +80,10 @@ class EigenStepper { stepSize(ssize), fieldCache(std::move(fieldCacheIn)), geoContext(gctx) { - pars.template segment<3>(eFreePos0) = par.position(gctx); - pars.template segment<3>(eFreeDir0) = par.direction(); + Vector3 position = par.position(gctx); + Vector3 direction = par.direction(); + pars.template segment<3>(eFreePos0) = position; + pars.template segment<3>(eFreeDir0) = direction; pars[eFreeTime] = par.time(); pars[eFreeQOverP] = par.parameters()[eBoundQOverP]; @@ -92,7 +94,7 @@ class EigenStepper { // set the covariance transport flag to true and copy covTransport = true; cov = BoundSquareMatrix(*par.covariance()); - jacToGlobal = surface.boundToFreeJacobian(gctx, pars); + jacToGlobal = surface.boundToFreeJacobian(gctx, position, direction); } } diff --git a/Core/include/Acts/Propagator/EigenStepper.ipp b/Core/include/Acts/Propagator/EigenStepper.ipp index 8f366266e71..1ad6cbfffe0 100644 --- a/Core/include/Acts/Propagator/EigenStepper.ipp +++ b/Core/include/Acts/Propagator/EigenStepper.ipp @@ -39,7 +39,9 @@ void Acts::EigenStepper::resetState(State& state, state.pathAccumulated = 0.; // Reinitialize the stepping jacobian - state.jacToGlobal = surface.boundToFreeJacobian(state.geoContext, freeParams); + state.jacToGlobal = surface.boundToFreeJacobian( + state.geoContext, freeParams.template segment<3>(eFreePos0), + freeParams.template segment<3>(eFreeDir0)); state.jacobian = BoundMatrix::Identity(); state.jacTransport = FreeMatrix::Identity(); state.derivative = FreeVector::Zero(); @@ -112,7 +114,9 @@ void Acts::EigenStepper::update(State& state, const Surface& surface) const { state.pars = freeParams; state.cov = covariance; - state.jacToGlobal = surface.boundToFreeJacobian(state.geoContext, freeParams); + state.jacToGlobal = surface.boundToFreeJacobian( + state.geoContext, freeParams.template segment<3>(eFreePos0), + freeParams.template segment<3>(eFreeDir0)); } template diff --git a/Core/include/Acts/Propagator/StraightLineStepper.hpp b/Core/include/Acts/Propagator/StraightLineStepper.hpp index 30e2b4aa2cc..05fa59d54c6 100644 --- a/Core/include/Acts/Propagator/StraightLineStepper.hpp +++ b/Core/include/Acts/Propagator/StraightLineStepper.hpp @@ -76,8 +76,10 @@ class StraightLineStepper { tolerance(stolerance), geoContext(gctx) { (void)mctx; - pars.template segment<3>(eFreePos0) = par.position(gctx); - pars.template segment<3>(eFreeDir0) = par.direction(); + Vector3 position = par.position(gctx); + Vector3 direction = par.direction(); + pars.template segment<3>(eFreePos0) = position; + pars.template segment<3>(eFreeDir0) = direction; pars[eFreeTime] = par.time(); pars[eFreeQOverP] = par.parameters()[eBoundQOverP]; if (par.covariance()) { @@ -86,7 +88,7 @@ class StraightLineStepper { // set the covariance transport flag to true and copy covTransport = true; cov = BoundSquareMatrix(*par.covariance()); - jacToGlobal = surface.boundToFreeJacobian(gctx, pars); + jacToGlobal = surface.boundToFreeJacobian(gctx, position, direction); } } diff --git a/Core/include/Acts/Surfaces/ConeSurface.hpp b/Core/include/Acts/Surfaces/ConeSurface.hpp index 3701bc7b5f7..a2bcd496747 100644 --- a/Core/include/Acts/Surfaces/ConeSurface.hpp +++ b/Core/include/Acts/Surfaces/ConeSurface.hpp @@ -219,11 +219,13 @@ class ConeSurface : public RegularSurface { /// represented with extrinsic Euler angles) /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of path length w.r.t. the alignment parameters AlignmentToPathMatrix alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const final; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const final; /// Calculate the derivative of bound track parameters local position w.r.t. /// position in local 3D Cartesian coordinates diff --git a/Core/include/Acts/Surfaces/CylinderSurface.hpp b/Core/include/Acts/Surfaces/CylinderSurface.hpp index 717b55514c8..7986263859d 100644 --- a/Core/include/Acts/Surfaces/CylinderSurface.hpp +++ b/Core/include/Acts/Surfaces/CylinderSurface.hpp @@ -228,11 +228,13 @@ class CylinderSurface : public RegularSurface { /// represented with extrinsic Euler angles) /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of path length w.r.t. the alignment parameters AlignmentToPathMatrix alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const final; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const final; /// Calculate the derivative of bound track parameters local position w.r.t. /// position in local 3D Cartesian coordinates diff --git a/Core/include/Acts/Surfaces/DiscSurface.hpp b/Core/include/Acts/Surfaces/DiscSurface.hpp index 242da300367..fb5846af363 100644 --- a/Core/include/Acts/Surfaces/DiscSurface.hpp +++ b/Core/include/Acts/Surfaces/DiscSurface.hpp @@ -234,21 +234,25 @@ class DiscSurface : public RegularSurface { /// hence the calculation is done here. /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters vector + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Jacobian from local to global - BoundToFreeMatrix boundToFreeJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const final; + BoundToFreeMatrix boundToFreeJacobian(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const final; /// Calculate the jacobian from global to local which the surface knows best, /// hence the calculation is done here. /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters vector + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Jacobian from global to local - FreeToBoundMatrix freeToBoundJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const final; + FreeToBoundMatrix freeToBoundJacobian(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const final; /// Path correction due to incident of the track /// diff --git a/Core/include/Acts/Surfaces/LineSurface.hpp b/Core/include/Acts/Surfaces/LineSurface.hpp index 422a6b8d349..33db81ac505 100644 --- a/Core/include/Acts/Surfaces/LineSurface.hpp +++ b/Core/include/Acts/Surfaces/LineSurface.hpp @@ -121,21 +121,25 @@ class LineSurface : public Surface { /// hence the calculation is done here. /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters vector + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Jacobian from local to global - BoundToFreeMatrix boundToFreeJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const final; + BoundToFreeMatrix boundToFreeJacobian(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const final; /// Calculate the derivative of path length at the geometry constraint or /// point-of-closest-approach w.r.t. free parameters /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters vector + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of path length w.r.t. free parameters - FreeToPathMatrix freeToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const final; + FreeToPathMatrix freeToPathDerivative(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const final; /// Local to global transformation /// @@ -265,11 +269,13 @@ class LineSurface : public Surface { /// represented with extrinsic Euler angles) /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of path length w.r.t. the alignment parameters AlignmentToPathMatrix alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const final; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const final; /// Calculate the derivative of bound track parameters local position w.r.t. /// position in local 3D Cartesian coordinates diff --git a/Core/include/Acts/Surfaces/Surface.hpp b/Core/include/Acts/Surfaces/Surface.hpp index bc31ebe66f9..cf5ef39de38 100644 --- a/Core/include/Acts/Surfaces/Surface.hpp +++ b/Core/include/Acts/Surfaces/Surface.hpp @@ -326,11 +326,13 @@ class Surface : public virtual GeometryObject, /// "Acts/EventData/detail/coordinate_transformations.hpp" /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters vector + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Jacobian from local to global - virtual BoundToFreeMatrix boundToFreeJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const; + virtual BoundToFreeMatrix boundToFreeJacobian(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const; /// Calculate the jacobian from global to local which the surface knows best, /// hence the calculation is done here. @@ -343,11 +345,13 @@ class Surface : public virtual GeometryObject, /// "Acts/EventData/detail/coordinate_transformations.hpp" /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters vector + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Jacobian from global to local - virtual FreeToBoundMatrix freeToBoundJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const; + virtual FreeToBoundMatrix freeToBoundJacobian(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const; /// Calculate the derivative of path length at the geometry constraint or /// point-of-closest-approach w.r.t. free parameters. The calculation is @@ -359,11 +363,13 @@ class Surface : public virtual GeometryObject, /// "Acts/EventData/detail/coordinate_transformations.hpp" /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of path length w.r.t. free parameters - virtual FreeToPathMatrix freeToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const; + virtual FreeToPathMatrix freeToPathDerivative(const GeometryContext& gctx, + const Vector3& position, + const Vector3& direction) const; /// Calucation of the path correction for incident /// @@ -430,15 +436,16 @@ class Surface : public virtual GeometryObject, /// /// @param gctx The current geometry context object, e.g. alignment /// change of alignment parameters - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// @param pathDerivative is the derivative of free parameters w.r.t. path /// length /// /// @return Derivative of bound track parameters w.r.t. local frame /// alignment parameters AlignmentToBoundMatrix alignmentToBoundDerivative( - const GeometryContext& gctx, const FreeVector& parameters, - const FreeVector& pathDerivative) const; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction, const FreeVector& pathDerivative) const; /// Calculate the derivative of path length at the geometry constraint or /// point-of-closest-approach w.r.t. alignment parameters of the surface (i.e. @@ -450,11 +457,13 @@ class Surface : public virtual GeometryObject, /// ConeSurface /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of path length w.r.t. the alignment parameters virtual AlignmentToPathMatrix alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const; /// Calculate the derivative of bound track parameters local position w.r.t. /// position in local 3D Cartesian coordinates @@ -496,12 +505,14 @@ class Surface : public virtual GeometryObject, /// derivative to get the full alignment to bound derivatives /// /// @param gctx The current geometry context object, e.g. alignment - /// @param parameters is the free parameters + /// @param position global 3D position + /// @param direction global 3D momentum direction /// /// @return Derivative of bound track parameters w.r.t. local frame alignment /// parameters without path correction AlignmentToBoundMatrix alignmentToBoundDerivativeWithoutCorrection( - const GeometryContext& gctx, const FreeVector& parameters) const; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const; }; /// Print surface information to the provided stream. Internally invokes the diff --git a/Core/include/Acts/Surfaces/SurfaceConcept.hpp b/Core/include/Acts/Surfaces/SurfaceConcept.hpp index 9aea7ad5d1d..46d01b0fbb3 100644 --- a/Core/include/Acts/Surfaces/SurfaceConcept.hpp +++ b/Core/include/Acts/Surfaces/SurfaceConcept.hpp @@ -68,15 +68,15 @@ concept SurfaceConcept = requires(S s, const S cs, S s2, const S cs2, } -> std::same_as; { - cs.boundToFreeJacobian(gctx, FreeVector{}) + cs.boundToFreeJacobian(gctx, Vector3{}, Vector3{}) } -> std::same_as; { - cs.freeToBoundJacobian(gctx, FreeVector{}) + cs.freeToBoundJacobian(gctx, Vector3{}, Vector3{}) } -> std::same_as; { - cs.freeToPathDerivative(gctx, FreeVector{}) + cs.freeToPathDerivative(gctx, Vector3{}, Vector3{}) } -> std::same_as; { cs.pathCorrection(gctx, Vector3{}, Vector3{}) } -> std::same_as; @@ -99,11 +99,11 @@ concept SurfaceConcept = requires(S s, const S cs, S s2, const S cs2, } -> std::same_as; { - cs.alignmentToBoundDerivative(gctx, FreeVector{}, FreeVector{}) + cs.alignmentToBoundDerivative(gctx, Vector3{}, Vector3{}, FreeVector{}) } -> std::same_as; { - cs.alignmentToPathDerivative(gctx, FreeVector{}) + cs.alignmentToPathDerivative(gctx, Vector3{}, Vector3{}) } -> std::same_as; { diff --git a/Core/include/Acts/TrackFitting/detail/GsfActor.hpp b/Core/include/Acts/TrackFitting/detail/GsfActor.hpp index fe4f0244a58..187c8853a8e 100644 --- a/Core/include/Acts/TrackFitting/detail/GsfActor.hpp +++ b/Core/include/Acts/TrackFitting/detail/GsfActor.hpp @@ -529,8 +529,10 @@ struct GsfActor { } auto& cmp = *res; - cmp.jacToGlobal() = - surface.boundToFreeJacobian(state.geoContext, cmp.pars()); + auto freeParams = cmp.pars(); + cmp.jacToGlobal() = surface.boundToFreeJacobian( + state.geoContext, freeParams.template segment<3>(eFreePos0), + freeParams.template segment<3>(eFreeDir0)); cmp.pathAccumulated() = state.stepping.pathAccumulated; cmp.jacobian() = Acts::BoundMatrix::Identity(); cmp.derivative() = Acts::FreeVector::Zero(); diff --git a/Core/src/Propagator/StraightLineStepper.cpp b/Core/src/Propagator/StraightLineStepper.cpp index 0b8049ef100..58661100cc7 100644 --- a/Core/src/Propagator/StraightLineStepper.cpp +++ b/Core/src/Propagator/StraightLineStepper.cpp @@ -38,7 +38,9 @@ void StraightLineStepper::update(State& state, const FreeVector& freeParams, const Surface& surface) const { state.pars = freeParams; state.cov = covariance; - state.jacToGlobal = surface.boundToFreeJacobian(state.geoContext, freeParams); + state.jacToGlobal = surface.boundToFreeJacobian( + state.geoContext, freeParams.template segment<3>(eFreePos0), + freeParams.template segment<3>(eFreeDir0)); } void StraightLineStepper::update(State& state, const Vector3& uposition, @@ -79,7 +81,9 @@ void StraightLineStepper::resetState(State& state, state.pathAccumulated = 0.; // Reinitialize the stepping jacobian - state.jacToGlobal = surface.boundToFreeJacobian(state.geoContext, freeParams); + state.jacToGlobal = surface.boundToFreeJacobian( + state.geoContext, freeParams.template segment<3>(eFreePos0), + freeParams.template segment<3>(eFreeDir0)); state.jacobian = BoundMatrix::Identity(); state.jacTransport = FreeMatrix::Identity(); state.derivative = FreeVector::Zero(); diff --git a/Core/src/Propagator/detail/CovarianceEngine.cpp b/Core/src/Propagator/detail/CovarianceEngine.cpp index 8668a1e60b6..206f37c4957 100644 --- a/Core/src/Propagator/detail/CovarianceEngine.cpp +++ b/Core/src/Propagator/detail/CovarianceEngine.cpp @@ -209,7 +209,8 @@ Acts::Result detail::boundToBoundConversion( if (boundParameters.covariance().has_value()) { Acts::BoundToFreeMatrix boundToFreeJacobian = - sourceSurface.boundToFreeJacobian(gctx, freePars); + sourceSurface.boundToFreeJacobian(gctx, freePars.segment<3>(eFreePos0), + freePars.segment<3>(eFreeDir0)); Acts::FreeMatrix freeTransportJacobian = FreeMatrix::Identity(); diff --git a/Core/src/Propagator/detail/JacobianEngine.cpp b/Core/src/Propagator/detail/JacobianEngine.cpp index a9483200fba..1b31aebb26e 100644 --- a/Core/src/Propagator/detail/JacobianEngine.cpp +++ b/Core/src/Propagator/detail/JacobianEngine.cpp @@ -94,13 +94,15 @@ void detail::boundToBoundTransportJacobian( const FreeMatrix& freeTransportJacobian, const FreeVector& freeToPathDerivatives, BoundMatrix& fullTransportJacobian) { + const Vector3 position = freeParameters.segment<3>(eFreePos0); + const Vector3 direction = freeParameters.segment<3>(eFreeDir0); // Calculate the derivative of path length at the final surface or the // point-of-closest approach w.r.t. free parameters const FreeToPathMatrix freeToPath = - surface.freeToPathDerivative(geoContext, freeParameters); + surface.freeToPathDerivative(geoContext, position, direction); // Calculate the jacobian from free to bound at the final surface FreeToBoundMatrix freeToBoundJacobian = - surface.freeToBoundJacobian(geoContext, freeParameters); + surface.freeToBoundJacobian(geoContext, position, direction); // https://acts.readthedocs.io/en/latest/white_papers/correction-for-transport-jacobian.html // Calculate the full jacobian from the local/bound parameters at the start // surface to local/bound parameters at the final surface @@ -160,11 +162,13 @@ void detail::freeToBoundTransportJacobian( const FreeVector& freeParameters, const FreeMatrix& freeTransportJacobian, const FreeVector& freeToPathDerivatives, FreeToBoundMatrix& fullTransportJacobian) { + const Vector3 position = freeParameters.segment<3>(eFreePos0); + const Vector3 direction = freeParameters.segment<3>(eFreeDir0); // Calculate the jacobian from free to bound at the final surface FreeToBoundMatrix freeToBoundJacobian = - surface.freeToBoundJacobian(geoContext, freeParameters); + surface.freeToBoundJacobian(geoContext, position, direction); FreeToPathMatrix sVec = - surface.freeToPathDerivative(geoContext, freeParameters); + surface.freeToPathDerivative(geoContext, position, direction); // Return the jacobian to local fullTransportJacobian = freeToBoundJacobian * (freeTransportJacobian + freeToPathDerivatives * sVec * @@ -199,7 +203,8 @@ Result detail::reinitializeJacobians( return lpResult.error(); } // Reset the jacobian from local to global - boundToFreeJacobian = surface.boundToFreeJacobian(geoContext, freeParameters); + boundToFreeJacobian = + surface.boundToFreeJacobian(geoContext, position, direction); return Result::success(); } diff --git a/Core/src/Surfaces/ConeSurface.cpp b/Core/src/Surfaces/ConeSurface.cpp index 9d8a0856a83..71a94aff0eb 100644 --- a/Core/src/Surfaces/ConeSurface.cpp +++ b/Core/src/Surfaces/ConeSurface.cpp @@ -331,12 +331,8 @@ Acts::SurfaceMultiIntersection Acts::ConeSurface::intersect( } Acts::AlignmentToPathMatrix Acts::ConeSurface::alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global position - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The vector between position and center diff --git a/Core/src/Surfaces/CylinderSurface.cpp b/Core/src/Surfaces/CylinderSurface.cpp index 1a34e71cea3..269ee900252 100644 --- a/Core/src/Surfaces/CylinderSurface.cpp +++ b/Core/src/Surfaces/CylinderSurface.cpp @@ -286,12 +286,8 @@ Acts::SurfaceMultiIntersection Acts::CylinderSurface::intersect( } Acts::AlignmentToPathMatrix Acts::CylinderSurface::alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global position - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The vector between position and center diff --git a/Core/src/Surfaces/DiscSurface.cpp b/Core/src/Surfaces/DiscSurface.cpp index 38219f5b2a7..d8f882f9871 100644 --- a/Core/src/Surfaces/DiscSurface.cpp +++ b/Core/src/Surfaces/DiscSurface.cpp @@ -11,6 +11,7 @@ #include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData/detail/TransformationBoundToFree.hpp" #include "Acts/Geometry/GeometryObject.hpp" +#include "Acts/Surfaces/BoundaryCheck.hpp" #include "Acts/Surfaces/DiscBounds.hpp" #include "Acts/Surfaces/DiscTrapezoidBounds.hpp" #include "Acts/Surfaces/InfiniteBounds.hpp" @@ -209,17 +210,14 @@ Acts::Vector2 Acts::DiscSurface::localCartesianToPolar( } Acts::BoundToFreeMatrix Acts::DiscSurface::boundToFreeJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global position - const Vector3 position = parameters.segment<3>(eFreePos0); - // The direction - const Vector3 direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The measurement frame of the surface RotationMatrix3 rframeT = referenceFrame(gctx, position, direction).transpose(); + // calculate the transformation to local coordinates const Vector3 posLoc = transform(gctx).inverse() * position; const double lr = perp(posLoc); @@ -245,17 +243,17 @@ Acts::BoundToFreeMatrix Acts::DiscSurface::boundToFreeJacobian( } Acts::FreeToBoundMatrix Acts::DiscSurface::freeToBoundJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const { + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { using VectorHelpers::perp; using VectorHelpers::phi; - // The global position - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); + assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); + // The measurement frame of the surface RotationMatrix3 rframeT = referenceFrame(gctx, position, direction).transpose(); + // calculate the transformation to local coordinates const Vector3 posLoc = transform(gctx).inverse() * position; const double lr = perp(posLoc); diff --git a/Core/src/Surfaces/LineSurface.cpp b/Core/src/Surfaces/LineSurface.cpp index 58cb9d524ff..23e07aa03f4 100644 --- a/Core/src/Surfaces/LineSurface.cpp +++ b/Core/src/Surfaces/LineSurface.cpp @@ -197,12 +197,8 @@ Acts::SurfaceMultiIntersection Acts::LineSurface::intersect( } Acts::BoundToFreeMatrix Acts::LineSurface::boundToFreeJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global position - Vector3 position = parameters.segment<3>(eFreePos0); - // The direction - Vector3 direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // retrieve the reference frame @@ -211,13 +207,13 @@ Acts::BoundToFreeMatrix Acts::LineSurface::boundToFreeJacobian( Vector2 local = *globalToLocal(gctx, position, direction, std::numeric_limits::max()); - BoundToFreeMatrix jacToGlobal = - Surface::boundToFreeJacobian(gctx, parameters); - // For the derivative of global position with bound angles, refer the // following white paper: // https://acts.readthedocs.io/en/latest/white_papers/line-surface-jacobian.html + BoundToFreeMatrix jacToGlobal = + Surface::boundToFreeJacobian(gctx, position, direction); + // the projection of direction onto ref frame normal double ipdn = 1. / direction.dot(rframe.col(2)); // build the cross product of d(D)/d(eBoundPhi) components with y axis @@ -238,12 +234,8 @@ Acts::BoundToFreeMatrix Acts::LineSurface::boundToFreeJacobian( } Acts::FreeToPathMatrix Acts::LineSurface::freeToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global posiiton - Vector3 position = parameters.segment<3>(eFreePos0); - // The direction - Vector3 direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The vector between position and center @@ -271,12 +263,8 @@ Acts::FreeToPathMatrix Acts::LineSurface::freeToPathDerivative( } Acts::AlignmentToPathMatrix Acts::LineSurface::alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global posiiton - Vector3 position = parameters.segment<3>(eFreePos0); - // The direction - Vector3 direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The vector between position and center diff --git a/Core/src/Surfaces/Surface.cpp b/Core/src/Surfaces/Surface.cpp index 7846200b616..598da8aa284 100644 --- a/Core/src/Surfaces/Surface.cpp +++ b/Core/src/Surfaces/Surface.cpp @@ -57,25 +57,18 @@ bool Acts::Surface::isOnSurface(const GeometryContext& gctx, } Acts::AlignmentToBoundMatrix Acts::Surface::alignmentToBoundDerivative( - const GeometryContext& gctx, const FreeVector& parameters, - const FreeVector& pathDerivative) const { - // The global posiiton - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); - - (void)position; - (void)direction; + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction, const FreeVector& pathDerivative) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // 1) Calculate the derivative of bound parameter local position w.r.t. // alignment parameters without path length correction const auto alignToBoundWithoutCorrection = - alignmentToBoundDerivativeWithoutCorrection(gctx, parameters); + alignmentToBoundDerivativeWithoutCorrection(gctx, position, direction); // 2) Calculate the derivative of path length w.r.t. alignment parameters - const auto alignToPath = alignmentToPathDerivative(gctx, parameters); + const auto alignToPath = alignmentToPathDerivative(gctx, position, direction); // 3) Calculate the jacobian from free parameters to bound parameters - FreeToBoundMatrix jacToLocal = freeToBoundJacobian(gctx, parameters); + FreeToBoundMatrix jacToLocal = freeToBoundJacobian(gctx, position, direction); // 4) The derivative of bound parameters w.r.t. alignment // parameters is alignToBoundWithoutCorrection + // jacToLocal*pathDerivative*alignToPath @@ -87,12 +80,8 @@ Acts::AlignmentToBoundMatrix Acts::Surface::alignmentToBoundDerivative( Acts::AlignmentToBoundMatrix Acts::Surface::alignmentToBoundDerivativeWithoutCorrection( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global posiiton - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { (void)direction; assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); @@ -132,12 +121,8 @@ Acts::Surface::alignmentToBoundDerivativeWithoutCorrection( } Acts::AlignmentToPathMatrix Acts::Surface::alignmentToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global posiiton - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The vector between position and center @@ -272,15 +257,13 @@ Acts::RotationMatrix3 Acts::Surface::referenceFrame( } Acts::BoundToFreeMatrix Acts::Surface::boundToFreeJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const { - const Vector3 position = parameters.segment<3>(eFreePos0); - // The direction - const Vector3 direction = parameters.segment<3>(eFreeDir0); + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { + assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); + // retrieve the reference frame const auto rframe = referenceFrame(gctx, position, direction); - assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); - // Initialize the jacobian from local to global BoundToFreeMatrix jacToGlobal = BoundToFreeMatrix::Zero(); // the local error components - given by reference frame @@ -295,17 +278,14 @@ Acts::BoundToFreeMatrix Acts::Surface::boundToFreeJacobian( } Acts::FreeToBoundMatrix Acts::Surface::freeToBoundJacobian( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global position - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { + assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); + // The measurement frame of the surface RotationMatrix3 rframeT = referenceFrame(gctx, position, direction).transpose(); - assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); - // Initialize the jacobian from global to local FreeToBoundMatrix jacToLocal = FreeToBoundMatrix::Zero(); // Local position component given by the reference frame @@ -320,12 +300,8 @@ Acts::FreeToBoundMatrix Acts::Surface::freeToBoundJacobian( } Acts::FreeToPathMatrix Acts::Surface::freeToPathDerivative( - const GeometryContext& gctx, const FreeVector& parameters) const { - // The global position - const auto position = parameters.segment<3>(eFreePos0); - // The direction - const auto direction = parameters.segment<3>(eFreeDir0); - + const GeometryContext& gctx, const Vector3& position, + const Vector3& direction) const { assert(isOnSurface(gctx, position, direction, BoundaryCheck(false))); // The measurement frame of the surface diff --git a/Tests/UnitTests/Core/EventData/CorrectedTransformFreeToBoundTests.cpp b/Tests/UnitTests/Core/EventData/CorrectedTransformFreeToBoundTests.cpp index 06047847bad..0991bcf3219 100644 --- a/Tests/UnitTests/Core/EventData/CorrectedTransformFreeToBoundTests.cpp +++ b/Tests/UnitTests/Core/EventData/CorrectedTransformFreeToBoundTests.cpp @@ -91,7 +91,7 @@ BOOST_AUTO_TEST_CASE(CorrectedFreeToBoundTrackParameters) { // the jacobian from local to global at the starting position BoundToFreeMatrix boundToFreeJac = - eSurface->boundToFreeJacobian(geoCtx, eFreeParams); + eSurface->boundToFreeJacobian(geoCtx, tpos, dir); // the transport jacobian without B field FreeMatrix transportJac = FreeMatrix::Identity(); diff --git a/Tests/UnitTests/Core/Propagator/BoundToCurvilinearConversionTests.cpp b/Tests/UnitTests/Core/Propagator/BoundToCurvilinearConversionTests.cpp index 3ce13f94ab8..851202bc375 100644 --- a/Tests/UnitTests/Core/Propagator/BoundToCurvilinearConversionTests.cpp +++ b/Tests/UnitTests/Core/Propagator/BoundToCurvilinearConversionTests.cpp @@ -197,9 +197,6 @@ void test_bound_to_curvilinear(const std::vector &test_data_list, } } - FreeVector free_param_vec = Acts::detail::transformBoundToFreeParameters( - *surface, geoCtx, param_vec); - Vector3 direction{cos(param_vec[2]) * sin(param_vec[3]), sin(param_vec[2]) * sin(param_vec[3]), cos(param_vec[3])}; Vector3 position(surface->localToGlobal( @@ -225,7 +222,7 @@ void test_bound_to_curvilinear(const std::vector &test_data_list, // compute Jacobian for bound to curvilinear covariance transformation Acts::BoundMatrix b2c; Acts::detail::boundToCurvilinearTransportJacobian( - direction, surface->boundToFreeJacobian(geoCtx, free_param_vec), + direction, surface->boundToFreeJacobian(geoCtx, position, direction), Acts::FreeMatrix::Identity(), computeFreeToPathDerivatives( direction, params.parameters()[eBoundQOverP], diff --git a/Tests/UnitTests/Core/Propagator/JacobianEngineTests.cpp b/Tests/UnitTests/Core/Propagator/JacobianEngineTests.cpp index 2561b83e564..cd5715287e3 100644 --- a/Tests/UnitTests/Core/Propagator/JacobianEngineTests.cpp +++ b/Tests/UnitTests/Core/Propagator/JacobianEngineTests.cpp @@ -130,9 +130,9 @@ BOOST_AUTO_TEST_CASE(jacobian_engine_to_bound) { FreeMatrix realTransportJacobian = 2 * FreeMatrix::Identity(); FreeToPathMatrix freeToPathDerivatives = - pSurface->freeToPathDerivative(tgContext, freeParameters); + pSurface->freeToPathDerivative(tgContext, position, direction); BoundToFreeMatrix boundToFreeJacobian = - pSurface->boundToFreeJacobian(tgContext, freeParameters); + pSurface->boundToFreeJacobian(tgContext, position, direction); // (1) curvilinear/bound to bound transport jacobian // a) test without actual transport into the same surface @@ -179,22 +179,11 @@ BOOST_AUTO_TEST_CASE(jacobian_engine_to_curvilinear) { // Build a start vector Vector3 position{1., 2., 3.}; - double time = 4.; Vector3 direction = Vector3(5., 2., 7.).normalized(); - double qop = 0.125; // Build a surface, starting surface for curvilinear auto pSurface = Surface::makeShared(position, direction); - // The free parameter vector - FreeVector freeParameters; - freeParameters << position[0], position[1], position[2], time, direction[0], - direction[1], direction[2], qop; - // And its associated bound vector - BoundVector boundParameters; - boundParameters << 0., 0., VectorHelpers::phi(direction), - VectorHelpers::theta(direction), qop, time; - // Build covariance matrices for bound and free case BoundSquareMatrix boundCovariance = 0.025 * BoundSquareMatrix::Identity(); FreeSquareMatrix freeCovariance = 0.025 * FreeSquareMatrix::Identity(); @@ -202,7 +191,7 @@ BOOST_AUTO_TEST_CASE(jacobian_engine_to_curvilinear) { FreeMatrix noTransportJacobian = FreeMatrix::Identity(); FreeToPathMatrix freeToPathDerivatives = - pSurface->freeToPathDerivative(tgContext, freeParameters); + pSurface->freeToPathDerivative(tgContext, position, direction); BoundToFreeMatrix boundToFreeJacobian = detail::curvilinearToFreeJacobian(direction); @@ -242,22 +231,11 @@ BOOST_AUTO_TEST_CASE(jacobian_engine_to_free) { // Build a start vector Vector3 position{1., 2., 3.}; - double time = 4.; Vector3 direction = Vector3(5., 2., 7.).normalized(); - double qop = 0.125; // Build a surface, starting surface for curvilinear auto pSurface = Surface::makeShared(position, direction); - // The free parameter vector - FreeVector freeParameters; - freeParameters << position[0], position[1], position[2], time, direction[0], - direction[1], direction[2], qop; - // And its associated bound vector - BoundVector boundParameters; - boundParameters << 0., 0., VectorHelpers::phi(direction), - VectorHelpers::theta(direction), qop, time; - // Build covariance matrices for bound and free case BoundSquareMatrix boundCovariance = 0.025 * BoundSquareMatrix::Identity(); FreeSquareMatrix freeCovariance = 0.025 * FreeSquareMatrix::Identity(); @@ -265,7 +243,7 @@ BOOST_AUTO_TEST_CASE(jacobian_engine_to_free) { FreeMatrix noTransportJacobian = FreeMatrix::Identity(); BoundToFreeMatrix boundToFreeJacobian = - pSurface->boundToFreeJacobian(tgContext, freeParameters); + pSurface->boundToFreeJacobian(tgContext, position, direction); // (1) bound to free BoundToFreeMatrix b2fTransportJacobian = detail::boundToFreeTransportJacobian( diff --git a/Tests/UnitTests/Core/Surfaces/DiscSurfaceTests.cpp b/Tests/UnitTests/Core/Surfaces/DiscSurfaceTests.cpp index b935c1498de..a2068eeea67 100644 --- a/Tests/UnitTests/Core/Surfaces/DiscSurfaceTests.cpp +++ b/Tests/UnitTests/Core/Surfaces/DiscSurfaceTests.cpp @@ -283,14 +283,11 @@ BOOST_AUTO_TEST_CASE(DiscSurfaceAlignment) { Vector3 globalPosition{0, 4, 2}; Vector3 momentum{0, 0, 1}; Vector3 direction = momentum.normalized(); - // Construct a free parameters - FreeVector parameters = FreeVector::Zero(); - parameters.head<3>() = globalPosition; - parameters.segment<3>(eFreeDir0) = direction; // (a) Test the derivative of path length w.r.t. alignment parameters const AlignmentToPathMatrix& alignToPath = - discSurfaceObject->alignmentToPathDerivative(tgContext, parameters); + discSurfaceObject->alignmentToPathDerivative(tgContext, globalPosition, + direction); // The expected results AlignmentToPathMatrix expAlignToPath = AlignmentToPathMatrix::Zero(); expAlignToPath << 0, 0, 1, 3, 0, 0; diff --git a/Tests/UnitTests/Core/Surfaces/LineSurfaceTests.cpp b/Tests/UnitTests/Core/Surfaces/LineSurfaceTests.cpp index 818d4ed5158..9f91d0a6284 100644 --- a/Tests/UnitTests/Core/Surfaces/LineSurfaceTests.cpp +++ b/Tests/UnitTests/Core/Surfaces/LineSurfaceTests.cpp @@ -223,14 +223,10 @@ BOOST_AUTO_TEST_CASE(LineSurfaceAlignment) { Vector3 globalPosition{1, 2, 4}; Vector3 momentum{-1, 1, 1}; Vector3 direction = momentum.normalized(); - // Construct a free parameters - FreeVector parameters = FreeVector::Zero(); - parameters.head<3>() = globalPosition; - parameters.segment<3>(eFreeDir0) = direction; // (a) Test the derivative of path length w.r.t. alignment parameters const AlignmentToPathMatrix& alignToPath = - line.alignmentToPathDerivative(tgContext, parameters); + line.alignmentToPathDerivative(tgContext, globalPosition, direction); // The expected results AlignmentToPathMatrix expAlignToPath = AlignmentToPathMatrix::Zero(); const double value = std::sqrt(3) / 2; diff --git a/Tests/UnitTests/Core/Surfaces/PlaneSurfaceTests.cpp b/Tests/UnitTests/Core/Surfaces/PlaneSurfaceTests.cpp index ed968d5ec2e..e365d4325b4 100644 --- a/Tests/UnitTests/Core/Surfaces/PlaneSurfaceTests.cpp +++ b/Tests/UnitTests/Core/Surfaces/PlaneSurfaceTests.cpp @@ -319,14 +319,10 @@ BOOST_AUTO_TEST_CASE(PlaneSurfaceAlignment) { Vector3 globalPosition = planeSurfaceObject->localToGlobal(tgContext, localPosition, momentum); - // Construct a free parameters - FreeVector parameters = FreeVector::Zero(); - parameters.head<3>() = globalPosition; - parameters.segment<3>(eFreeDir0) = direction; - // (a) Test the derivative of path length w.r.t. alignment parameters const AlignmentToPathMatrix& alignToPath = - planeSurfaceObject->alignmentToPathDerivative(tgContext, parameters); + planeSurfaceObject->alignmentToPathDerivative(tgContext, globalPosition, + direction); // The expected results AlignmentToPathMatrix expAlignToPath = AlignmentToPathMatrix::Zero(); expAlignToPath << 1, 0, 0, 2, -1, -2; @@ -347,8 +343,8 @@ BOOST_AUTO_TEST_CASE(PlaneSurfaceAlignment) { FreeVector derivatives = FreeVector::Zero(); derivatives.head<3>() = direction; const AlignmentToBoundMatrix& alignToBound = - planeSurfaceObject->alignmentToBoundDerivative(tgContext, parameters, - derivatives); + planeSurfaceObject->alignmentToBoundDerivative(tgContext, globalPosition, + direction, derivatives); const AlignmentToPathMatrix alignToloc0 = alignToBound.block<1, 6>(eBoundLoc0, eAlignmentCenter0); const AlignmentToPathMatrix alignToloc1 =