Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Remove MagneticFieldProvider::getFieldGradient #3983

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Core/include/Acts/MagneticField/ConstantBField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ class ConstantBField final : public MagneticFieldProvider {
return Result<Vector3>::success(m_BField);
}

/// @copydoc MagneticFieldProvider::getFieldGradient(const Vector3&,SquareMatrix3&,MagneticFieldProvider::Cache&) const
///
/// @note The @p position is ignored and only kept as argument to provide
/// a consistent interface with other magnetic field services.
/// @note currently the derivative is not calculated
/// @todo return derivative
Result<Vector3> getFieldGradient(
const Vector3& position, SquareMatrix3& derivative,
MagneticFieldProvider::Cache& cache) const override {
(void)position;
(void)derivative;
(void)cache;
return Result<Vector3>::success(m_BField);
}

/// @copydoc MagneticFieldProvider::makeCache(const MagneticFieldContext&) const
Acts::MagneticFieldProvider::Cache makeCache(
const Acts::MagneticFieldContext& mctx) const override {
Expand Down
12 changes: 0 additions & 12 deletions Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,6 @@ class InterpolatedBFieldMap : public InterpolatedMagneticField {
return Result<Vector3>::success((*lcache.fieldCell).getField(gridPosition));
}

/// @copydoc MagneticFieldProvider::getFieldGradient(const Vector3&,SquareMatrix3&,MagneticFieldProvider::Cache&) const
///
/// @note currently the derivative is not calculated
/// @note Cache is not used currently
/// @todo return derivative
Result<Vector3> getFieldGradient(
const Vector3& position, SquareMatrix3& derivative,
MagneticFieldProvider::Cache& cache) const final {
(void)derivative;
return getField(position, cache);
}

private:
Config m_cfg;

Expand Down
15 changes: 1 addition & 14 deletions Core/include/Acts/MagneticField/MagneticFieldProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,7 @@ class MagneticFieldProvider {
virtual Result<Vector3> getField(const Vector3& position,
Cache& cache) const = 0;

/// Retrieve magnetic field value its its gradient. Requires a cache object
/// created through makeCache().
///
/// @param [in] position global 3D position
/// @param [out] derivative gradient of magnetic field vector as (3x3) matrix
/// @param [in,out] cache Field provider specific cache object
/// @return magnetic field vector
virtual Result<Vector3> getFieldGradient(const Vector3& position,
SquareMatrix3& derivative,
Cache& cache) const = 0;

virtual ~MagneticFieldProvider();
virtual ~MagneticFieldProvider() = default;
};

inline MagneticFieldProvider::~MagneticFieldProvider() = default;

} // namespace Acts
9 changes: 1 addition & 8 deletions Core/include/Acts/MagneticField/MultiRangeBField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/MagneticField/MagneticFieldContext.hpp"
#include "Acts/MagneticField/MagneticFieldError.hpp"
#include "Acts/MagneticField/MagneticFieldProvider.hpp"
#include "Acts/Utilities/RangeXD.hpp"

Expand Down Expand Up @@ -57,12 +56,6 @@ class MultiRangeBField final : public MagneticFieldProvider {
/// otherwise.
Result<Vector3> getField(const Vector3& position,
MagneticFieldProvider::Cache& cache) const override;

/// @brief Get the field gradient at a given position.
///
/// @warning This is not currently implemented.
Result<Vector3> getFieldGradient(
const Vector3& position, SquareMatrix3& /*unused*/,
MagneticFieldProvider::Cache& cache) const override;
};

} // namespace Acts
22 changes: 2 additions & 20 deletions Core/include/Acts/MagneticField/NullBField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ class NullBField final : public MagneticFieldProvider {
MagneticFieldProvider::Cache& cache) const override {
(void)position;
(void)cache;
return Result<Vector3>::success(m_BField);
}

/// @copydoc MagneticFieldProvider::getFieldGradient(const Vector3&,SquareMatrix3&,MagneticFieldProvider::Cache&) const
///
/// @note The @p position is ignored and only kept as argument to provide
/// a consistent interface with other magnetic field services.
/// @note currently the derivative is not calculated
/// @todo return derivative
Result<Vector3> getFieldGradient(
const Vector3& position, SquareMatrix3& derivative,
MagneticFieldProvider::Cache& cache) const override {
(void)position;
(void)derivative;
(void)cache;
return Result<Vector3>::success(m_BField);
return Result<Vector3>::success(Vector3::Zero());
}

/// @copydoc MagneticFieldProvider::makeCache(const MagneticFieldContext&) const
Expand All @@ -64,9 +49,6 @@ class NullBField final : public MagneticFieldProvider {
/// otherwise @c false
/// @note The method will always return true for the null B-Field
bool isInside(const Vector3& /*position*/) const { return true; }

private:
/// magnetic field vector
const Vector3 m_BField = Vector3::Zero();
};

} // namespace Acts
9 changes: 0 additions & 9 deletions Core/include/Acts/MagneticField/SolenoidBField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "Acts/Utilities/Result.hpp"

#include <cstddef>
#include <functional>

namespace Acts {

Expand Down Expand Up @@ -111,14 +110,6 @@ class SolenoidBField final : public MagneticFieldProvider {
Result<Vector3> getField(const Vector3& position,
MagneticFieldProvider::Cache& cache) const override;

/// @copydoc MagneticFieldProvider::getFieldGradient(const Vector3&,SquareMatrix3&,MagneticFieldProvider::Cache&) const
///
/// @note currently the derivative is not calculated
/// @todo return derivative
Result<Vector3> getFieldGradient(
const Vector3& position, SquareMatrix3& derivative,
MagneticFieldProvider::Cache& cache) const override;

private:
Config m_cfg;
double m_scale;
Expand Down
7 changes: 2 additions & 5 deletions Core/src/MagneticField/MultiRangeBField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "Acts/MagneticField/MultiRangeBField.hpp"

#include "Acts/MagneticField/MagneticFieldError.hpp"

namespace Acts {

MultiRangeBField::Cache::Cache(const MagneticFieldContext& /*unused*/) {}
Expand Down Expand Up @@ -70,9 +72,4 @@ Result<Vector3> MultiRangeBField::getField(
}
}

Result<Vector3> MultiRangeBField::getFieldGradient(
const Vector3& position, SquareMatrix3& /*unused*/,
MagneticFieldProvider::Cache& cache) const {
return getField(position, cache);
}
} // namespace Acts
7 changes: 1 addition & 6 deletions Core/src/MagneticField/SolenoidBField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "Acts/MagneticField/SolenoidBField.hpp"

#include "Acts/MagneticField/MagneticFieldError.hpp"
#include "Acts/Utilities/VectorHelpers.hpp"

#include <cmath>
Expand Down Expand Up @@ -57,12 +58,6 @@ Acts::Vector2 Acts::SolenoidBField::getField(const Vector2& position) const {
return multiCoilField(position, m_scale);
}

Acts::Result<Acts::Vector3> Acts::SolenoidBField::getFieldGradient(
const Vector3& position, SquareMatrix3& /*derivative*/,
MagneticFieldProvider::Cache& /*cache*/) const {
return Result<Vector3>::success(getField(position));
}

Acts::Vector2 Acts::SolenoidBField::multiCoilField(const Vector2& pos,
double scale) const {
// iterate over all coils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,6 @@ class ScalableBField final : public Acts::MagneticFieldProvider {
return Acts::Result<Acts::Vector3>::success(m_BField * cache.scalor);
}

/// @brief retrieve magnetic field value & its gradient
///
/// @param [in] position global position
/// @param [out] derivative gradient of magnetic field vector as (3x3)
/// matrix
/// @param [in] cache Cache object (is ignored)
/// @return magnetic field vector
///
/// @note The @p position is ignored and only kept as argument to provide
/// a consistent interface with other magnetic field services.
/// @note currently the derivative is not calculated
/// @todo return derivative
Acts::Result<Acts::Vector3> getFieldGradient(
const Acts::Vector3& /*position*/, Acts::SquareMatrix3& /*derivative*/,
MagneticFieldProvider::Cache& gCache) const override {
Cache& cache = gCache.as<Cache>();
return Acts::Result<Acts::Vector3>::success(m_BField * cache.scalor);
}

Acts::MagneticFieldProvider::Cache makeCache(
const Acts::MagneticFieldContext& mctx) const override {
return Acts::MagneticFieldProvider::Cache(std::in_place_type<Cache>, mctx);
Expand Down Expand Up @@ -106,6 +87,6 @@ class ScalableBField final : public Acts::MagneticFieldProvider {
private:
/// magnetic field vector
Acts::Vector3 m_BField;
}; // namespace BField
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/MagneticField/MagneticFieldProvider.hpp"

#include <memory>
Expand All @@ -30,10 +31,6 @@ class DD4hepFieldAdapter : public Acts::MagneticFieldProvider {
Result<Vector3> getField(const Vector3& position,
MagneticFieldProvider::Cache& cache) const override;

Result<Vector3> getFieldGradient(
const Vector3& position, SquareMatrix3& derivative,
MagneticFieldProvider::Cache& cache) const override;

private:
double m_fieldConversionFactor;
double m_lengthConversionFactor;
Expand Down
6 changes: 0 additions & 6 deletions Plugins/DD4hep/src/DD4hepFieldAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,4 @@ Result<Vector3> DD4hepFieldAdapter::getField(
return Result<Vector3>::success(result);
}

Result<Vector3> DD4hepFieldAdapter::getFieldGradient(
const Vector3& /*position*/, SquareMatrix3& /*derivative*/,
MagneticFieldProvider::Cache& /*cache*/) const {
return Result<Vector3>::failure(MagneticFieldError::NotImplemented);
}

} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ BOOST_AUTO_TEST_CASE(InterpolatedBFieldMap_rz) {
pos << 1, 1, -5.5; // this position is outside the grid
BOOST_CHECK(!b.isInside(pos));
BOOST_CHECK(!b.getField(pos, bCacheAny).ok());
BOOST_CHECK(!b.getFieldGradient(pos, deriv, bCacheAny).ok());

pos << 1, 6, -1.7; // this position is outside the grid
BOOST_CHECK(!b.isInside(pos));
BOOST_CHECK(!b.getField(pos, bCacheAny).ok());
BOOST_CHECK(!b.getFieldGradient(pos, deriv, bCacheAny).ok());

pos << 0, 1.5, -2.5;
BOOST_CHECK(b.isInside(pos));
Expand Down
Loading