Skip to content

Commit

Permalink
refactor!: Replace Surface FreeVector input with position and dir…
Browse files Browse the repository at this point in the history
…ection (acts-project#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
- acts-project#2932
- acts-project#2811
  • Loading branch information
andiwand authored and Ragansu committed Apr 19, 2024
1 parent f725096 commit 86c5809
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions Core/include/Acts/Propagator/EigenStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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);
}
}

Expand Down
8 changes: 6 additions & 2 deletions Core/include/Acts/Propagator/EigenStepper.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ void Acts::EigenStepper<E, A>::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();
Expand Down Expand Up @@ -112,7 +114,9 @@ void Acts::EigenStepper<E, A>::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 <typename E, typename A>
Expand Down
8 changes: 5 additions & 3 deletions Core/include/Acts/Propagator/StraightLineStepper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
}

Expand Down
6 changes: 4 additions & 2 deletions Core/include/Acts/Surfaces/ConeSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Core/include/Acts/Surfaces/CylinderSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions Core/include/Acts/Surfaces/DiscSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
22 changes: 14 additions & 8 deletions Core/include/Acts/Surfaces/LineSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -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
Expand Down
43 changes: 27 additions & 16 deletions Core/include/Acts/Surfaces/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
///
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Core/include/Acts/Surfaces/SurfaceConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ concept SurfaceConcept = requires(S s, const S cs, S s2, const S cs2,
} -> std::same_as<RotationMatrix3>;

{
cs.boundToFreeJacobian(gctx, FreeVector{})
cs.boundToFreeJacobian(gctx, Vector3{}, Vector3{})
} -> std::same_as<BoundToFreeMatrix>;

{
cs.freeToBoundJacobian(gctx, FreeVector{})
cs.freeToBoundJacobian(gctx, Vector3{}, Vector3{})
} -> std::same_as<FreeToBoundMatrix>;

{
cs.freeToPathDerivative(gctx, FreeVector{})
cs.freeToPathDerivative(gctx, Vector3{}, Vector3{})
} -> std::same_as<FreeToPathMatrix>;

{ cs.pathCorrection(gctx, Vector3{}, Vector3{}) } -> std::same_as<double>;
Expand All @@ -99,11 +99,11 @@ concept SurfaceConcept = requires(S s, const S cs, S s2, const S cs2,
} -> std::same_as<Polyhedron>;

{
cs.alignmentToBoundDerivative(gctx, FreeVector{}, FreeVector{})
cs.alignmentToBoundDerivative(gctx, Vector3{}, Vector3{}, FreeVector{})
} -> std::same_as<AlignmentToBoundMatrix>;

{
cs.alignmentToPathDerivative(gctx, FreeVector{})
cs.alignmentToPathDerivative(gctx, Vector3{}, Vector3{})
} -> std::same_as<AlignmentToPathMatrix>;

{
Expand Down
6 changes: 4 additions & 2 deletions Core/include/Acts/TrackFitting/detail/GsfActor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions Core/src/Propagator/StraightLineStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion Core/src/Propagator/detail/CovarianceEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ Acts::Result<Acts::BoundTrackParameters> 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();

Expand Down
Loading

0 comments on commit 86c5809

Please sign in to comment.