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

fix: resurrect ActsScalar with float #3754

Closed
wants to merge 15 commits into from
56 changes: 56 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,62 @@ jobs:
- name: Downstream run
run: ./build-downstream/bin/ShowActsVersion

linux_float:
# This job tests the correct usage of the type ActsScalar by testing it with float instead of double
runs-on: ubuntu-latest
container: ghcr.io/acts-project/ubuntu2404:58
env:
INSTALL_DIR: ${{ github.workspace }}/install
ACTS_LOG_FAILURE_THRESHOLD: WARNING
steps:
- name: Install git lfs
run: apt-get update && apt-get install -y git-lfs

- uses: actions/checkout@v4
with:
submodules: true
lfs: true

- name: Restore ccache
uses: actions/cache/restore@v4
id: ccache-restore
with:
path: ${{ github.workspace }}/ccache
key: ${{ runner.os }}-ccache-linux_float_${{ env.CCACHE_KEY_SUFFIX }}_${{ github.sha }}
restore-keys: |
${{ runner.os }}-ccache-linux_float_${{ env.CCACHE_KEY_SUFFIX }}_

- name: Configure
# setting CMAKE_CXX_STANDARD=20 is a workaround for a bug in the
# dd4hep CMake configuration that gets triggered on recent CMake
# versions
# Need to set git user & email for patching to work (GeoModel plugin)
run: >
git config --global user.name 'CI' &&
git config --global user.email '<>' &&
ccache -z &&
cmake -B build -S .
-DCMAKE_CXX_FLAGS="-Wno-narrowing"
-DACTS_CUSTOM_SCALARTYPE=float

- name: Build
run: cmake --build build

- name: ccache stats
run: ccache -s

- name: Save ccache
uses: actions/cache/save@v4
if: always()
with:
path: ${{ github.workspace }}/ccache
key: ${{ steps.ccache-restore.outputs.cache-primary-key }}

- uses: actions/upload-artifact@v4
with:
name: acts-linux-ubuntu
path: build.tar.gz

macos:
runs-on: macos-14
env:
Expand Down
10 changes: 10 additions & 0 deletions Core/include/Acts/Definitions/Algebra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <string>

// for GNU: ignore this specific warning, otherwise just include Eigen/Dense
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
#pragma GCC diagnostic push
Expand Down Expand Up @@ -102,4 +104,12 @@ using Transform3 = Eigen::Transform<ActsScalar, 3, Eigen::Affine>;

constexpr ActsScalar s_transformEquivalentTolerance = 1e-9;

// User-defined literals for creating ActsScalar. Use as 3_scalar
constexpr ActsScalar operator""_scalar(long double n) {
return static_cast<ActsScalar>(n);
}
constexpr ActsScalar operator""_scalar(unsigned long long n) {
return static_cast<ActsScalar>(n);
}

} // namespace Acts
8 changes: 4 additions & 4 deletions Core/include/Acts/EventData/ChargeConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
namespace Acts {

template <typename C>
concept ChargeConcept = requires(C c, C c2, float f, double d) {
concept ChargeConcept = requires(C c, C c2, float f, ActsScalar a) {
{ C{f} };

{ c == c2 } -> std::same_as<bool>;
{ c != c2 } -> std::same_as<bool>;

{ c.absQ() } -> std::same_as<float>;
{ c.extractCharge(d) } -> std::same_as<float>;
{ c.extractMomentum(d) } -> std::same_as<double>;
{ c.qOverP(d, d) } -> std::same_as<double>;
{ c.extractCharge(a) } -> std::same_as<float>;
{ c.extractMomentum(a) } -> std::same_as<ActsScalar>;
{ c.qOverP(a, f) } -> std::same_as<ActsScalar>;
};

} // namespace Acts
6 changes: 4 additions & 2 deletions Core/include/Acts/EventData/TrackParameterHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Utilities/detail/periodic.hpp"

#include <numbers>

namespace Acts {

/// Normalize the bound parameter angles
Expand All @@ -36,8 +38,8 @@ inline BoundVector normalizeBoundParameters(const BoundVector& boundParams) {
inline BoundVector subtractBoundParameters(const BoundVector& lhs,
const BoundVector& rhs) {
BoundVector result = lhs - rhs;
result[eBoundPhi] =
detail::difference_periodic(lhs[eBoundPhi], rhs[eBoundPhi], 2 * M_PI);
result[eBoundPhi] = detail::difference_periodic(
lhs[eBoundPhi], rhs[eBoundPhi], ActsScalar{2 * std::numbers::pi});
return result;
}

Expand Down
18 changes: 9 additions & 9 deletions Core/include/Acts/Geometry/CutoutCylinderVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class CutoutCylinderVolumeBounds : public VolumeBounds {
/// @param rmax The outer radius of the overall shape
/// @param hlZ The longer halflength of the shape
/// @param hlZc The cutout halflength of the shape
CutoutCylinderVolumeBounds(double rmin, double rmed, double rmax, double hlZ,
double hlZc) noexcept(false)
CutoutCylinderVolumeBounds(ActsScalar rmin, ActsScalar rmed, ActsScalar rmax,
ActsScalar hlZ, ActsScalar hlZc) noexcept(false)
: m_values({rmin, rmed, rmax, hlZ, hlZc}) {
checkConsistency();
buildSurfaceBounds();
Expand All @@ -66,8 +66,8 @@ class CutoutCylinderVolumeBounds : public VolumeBounds {
/// Constructor - from a fixed size array
///
/// @param values The bound values
CutoutCylinderVolumeBounds(const std::array<double, eSize>& values) noexcept(
false)
CutoutCylinderVolumeBounds(
const std::array<ActsScalar, eSize>& values) noexcept(false)
: m_values(values) {
checkConsistency();
buildSurfaceBounds();
Expand All @@ -82,14 +82,14 @@ class CutoutCylinderVolumeBounds : public VolumeBounds {
/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;
std::vector<ActsScalar> values() const final;

/// Inside method to test whether a point is inside the shape
///
/// @param gpos The point to test
/// @param tol The tolerance to test with
/// @return Whether the point is inside or not.
bool inside(const Vector3& gpos, double tol = 0) const override;
bool inside(const Vector3& gpos, ActsScalar tol = 0) const override;

/// Oriented surfaces, i.e. the decomposed boundary surfaces and the
/// according navigation direction into the volume given the normal
Expand Down Expand Up @@ -134,7 +134,7 @@ class CutoutCylinderVolumeBounds : public VolumeBounds {
double get(BoundValues bValue) const { return m_values[bValue]; }

private:
std::array<double, eSize> m_values;
std::array<ActsScalar, eSize> m_values;

// The surface bound objects
std::shared_ptr<const CylinderBounds> m_innerCylinderBounds{nullptr};
Expand All @@ -151,8 +151,8 @@ class CutoutCylinderVolumeBounds : public VolumeBounds {
void checkConsistency() noexcept(false);
};

inline std::vector<double> CutoutCylinderVolumeBounds::values() const {
std::vector<double> valvector;
inline std::vector<ActsScalar> CutoutCylinderVolumeBounds::values() const {
std::vector<ActsScalar> valvector;
valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
return valvector;
}
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Geometry/GenericCuboidVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class GenericCuboidVolumeBounds : public VolumeBounds {
///
/// @param values The input values
GenericCuboidVolumeBounds(
const std::array<double, BoundValues::eSize>& values) noexcept(false);
const std::array<ActsScalar, BoundValues::eSize>& values) noexcept(false);

~GenericCuboidVolumeBounds() override = default;

Expand All @@ -57,15 +57,15 @@ class GenericCuboidVolumeBounds : public VolumeBounds {
/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;
std::vector<ActsScalar> values() const final;

/// Checking if position given in volume frame is inside
///
/// @param gpos is the global position to be checked
/// @param tol is the tolerance applied for the inside check
///
/// @return boolean indicating if the position is inside
bool inside(const Vector3& gpos, double tol = 0.) const override;
bool inside(const Vector3& gpos, ActsScalar tol = 0.) const override;

/// Oriented surfaces, i.e. the decomposed boundary surfaces and the
/// according navigation direction into the volume given the normal
Expand Down
10 changes: 5 additions & 5 deletions Core/include/Acts/Geometry/VolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ class VolumeBounds {
/// vector containing the parameters needed to describe these bounds
///
/// @return of the stored values for this SurfaceBounds object
virtual std::vector<double> values() const = 0;
virtual std::vector<ActsScalar> values() const = 0;

/// Checking if position given in volume frame is inside
///
/// @param gpos is the global position to be checked
/// @param tol is the tolerance applied for the inside check
///
/// @return boolean indicating if the position is inside
virtual bool inside(const Vector3& gpos, double tol = 0.) const = 0;
virtual bool inside(const Vector3& gpos, ActsScalar tol = 0.) const = 0;

/// Oriented surfaces, i.e. the decomposed boundary surfaces and the
/// according navigation direction into the volume given the normal
Expand Down Expand Up @@ -143,7 +143,7 @@ class VolumeBounds {
/// @param bValue is the binning schema used
///
/// @return float offset to be used for the binning
virtual double binningBorder(BinningValue bValue) const;
virtual ActsScalar binningBorder(BinningValue bValue) const;

/// Output Method for std::ostream, to be overloaded by child classes
///
Expand All @@ -157,8 +157,8 @@ inline Vector3 VolumeBounds::binningOffset(
return Vector3(0., 0., 0.);
}

inline double VolumeBounds::binningBorder(BinningValue /*bValue*/) const {
return 0.;
inline ActsScalar VolumeBounds::binningBorder(BinningValue /*bValue*/) const {
return 0_scalar;
}

/// Overload of << operator for std::ostream for debug output
Expand Down
20 changes: 10 additions & 10 deletions Core/include/Acts/MagneticField/InterpolatedBFieldMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class InterpolatedMagneticField : public MagneticFieldProvider {
/// @brief get the minimum value of all axes of the field map
///
/// @return vector returning the minima of all field map axes
virtual std::vector<double> getMin() const = 0;
virtual std::vector<ActsScalar> getMin() const = 0;

/// @brief get the maximum value of all axes of the field map
///
/// @return vector returning the maxima of all field map axes
virtual std::vector<double> getMax() const = 0;
virtual std::vector<ActsScalar> getMax() const = 0;

/// @brief check whether given 3D position is inside look-up domain
///
Expand Down Expand Up @@ -98,8 +98,8 @@ class InterpolatedBFieldMap : public InterpolatedMagneticField {
/// each Dimension)
/// @param [in] fieldValues field values at the hyper box corners sorted in
/// the canonical order defined in Acts::interpolate
FieldCell(std::array<double, DIM_POS> lowerLeft,
std::array<double, DIM_POS> upperRight,
FieldCell(std::array<ActsScalar, DIM_POS> lowerLeft,
std::array<ActsScalar, DIM_POS> upperRight,
std::array<Vector3, N> fieldValues)
: m_lowerLeft(std::move(lowerLeft)),
m_upperRight(std::move(upperRight)),
Expand Down Expand Up @@ -132,10 +132,10 @@ class InterpolatedBFieldMap : public InterpolatedMagneticField {

private:
/// generalized lower-left corner of the confining hyper-box
std::array<double, DIM_POS> m_lowerLeft;
std::array<ActsScalar, DIM_POS> m_lowerLeft;

/// generalized upper-right corner of the confining hyper-box
std::array<double, DIM_POS> m_upperRight;
std::array<ActsScalar, DIM_POS> m_upperRight;

/// @brief magnetic field vectors at the hyper-box corners
///
Expand Down Expand Up @@ -225,15 +225,15 @@ class InterpolatedBFieldMap : public InterpolatedMagneticField {
/// @brief get the minimum value of all axes of the field map
///
/// @return vector returning the minima of all field map axes
std::vector<double> getMin() const final {
return std::vector<double>(m_lowerLeft.begin(), m_lowerLeft.end());
std::vector<ActsScalar> getMin() const final {
return std::vector<ActsScalar>(m_lowerLeft.begin(), m_lowerLeft.end());
}

/// @brief get the maximum value of all axes of the field map
///
/// @return vector returning the maxima of all field map axes
std::vector<double> getMax() const final {
return std::vector<double>(m_upperRight.begin(), m_upperRight.end());
std::vector<ActsScalar> getMax() const final {
return std::vector<ActsScalar>(m_upperRight.begin(), m_upperRight.end());
}

/// @brief check whether given 3D position is inside look-up domain
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Surfaces/AnnulusBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AnnulusBounds : public DiscBounds {
/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;
std::vector<ActsScalar> values() const final;

/// Inside check for the bounds object driven by the boundary check directive
/// Each Bounds has a method inside, which checks if a LocalPosition is inside
Expand Down Expand Up @@ -248,8 +248,8 @@ inline double AnnulusBounds::binningValuePhi() const {
return get(eAveragePhi);
}

inline std::vector<double> AnnulusBounds::values() const {
std::vector<double> valvector;
inline std::vector<ActsScalar> AnnulusBounds::values() const {
std::vector<ActsScalar> valvector;
valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
return valvector;
}
Expand Down
6 changes: 3 additions & 3 deletions Core/include/Acts/Surfaces/ConeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ConeBounds : public SurfaceBounds {
/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;
std::vector<ActsScalar> values() const final;

/// inside method for local position
///
Expand Down Expand Up @@ -134,8 +134,8 @@ inline double ConeBounds::tanAlpha() const {
return m_tanAlpha;
}

inline std::vector<double> ConeBounds::values() const {
std::vector<double> valvector;
inline std::vector<ActsScalar> ConeBounds::values() const {
std::vector<ActsScalar> valvector;
valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
return valvector;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/ConeSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ConeSurface : public RegularSurface {
const Vector3& direction,
const BoundaryTolerance& boundaryTolerance =
BoundaryTolerance::Infinite(),
double tolerance = s_onSurfaceTolerance) const final;
ActsScalar tolerance = s_onSurfaceTolerance) const final;

/// The pathCorrection for derived classes with thickness
///
Expand Down
2 changes: 1 addition & 1 deletion Core/include/Acts/Surfaces/ConvexPolygonBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ConvexPolygonBoundsBase : public PlanarBounds {
/// Return the bound values as dynamically sized vector
///
/// @return this returns a copy of the internal values
std::vector<double> values() const final;
std::vector<ActsScalar> values() const final;

protected:
/// Return a rectangle bounds instance that encloses a set of vertices.
Expand Down
Loading
Loading