Skip to content

Commit

Permalink
core last
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger committed Oct 24, 2024
1 parent c425f06 commit 83f964d
Show file tree
Hide file tree
Showing 30 changed files with 161 additions and 109 deletions.
23 changes: 12 additions & 11 deletions Core/include/Acts/TrackFitting/detail/GsfComponentMerging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Acts/Utilities/detail/periodic.hpp"

#include <cmath>
#include <numbers>
#include <optional>
#include <tuple>

Expand Down Expand Up @@ -90,10 +91,10 @@ auto gaussianMixtureCov(const components_t components,

// Apply corrections for cyclic coordinates
auto handleCyclicCov = [&l = pars_l, &m = mean, &diff = diff](auto desc) {
diff[desc.idx] =
difference_periodic(l[desc.idx] / desc.constant,
m[desc.idx] / desc.constant, 2 * M_PI) *
desc.constant;
diff[desc.idx] = difference_periodic(l[desc.idx] / desc.constant,
m[desc.idx] / desc.constant,
2 * std::numbers::pi) *
desc.constant;
};

std::apply([&](auto... dsc) { (handleCyclicCov(dsc), ...); }, angleDesc);
Expand Down Expand Up @@ -174,10 +175,10 @@ auto gaussianMixtureMeanCov(const components_t components,
&weight = weight_l, &mean = mean](auto desc) {
const auto delta = (ref[desc.idx] - pars[desc.idx]) / desc.constant;

if (delta > M_PI) {
mean[desc.idx] += (2 * M_PI) * weight * desc.constant;
} else if (delta < -M_PI) {
mean[desc.idx] -= (2 * M_PI) * weight * desc.constant;
if (delta > std::numbers::pi) {
mean[desc.idx] += 2. * std::numbers::pi * weight * desc.constant;
} else if (delta < -std::numbers::pi) {
mean[desc.idx] -= 2. * std::numbers::pi * weight * desc.constant;
}
};

Expand All @@ -187,9 +188,9 @@ auto gaussianMixtureMeanCov(const components_t components,
mean /= sumOfWeights;

auto wrap = [&](auto desc) {
mean[desc.idx] =
wrap_periodic(mean[desc.idx] / desc.constant, -M_PI, 2 * M_PI) *
desc.constant;
mean[desc.idx] = wrap_periodic(mean[desc.idx] / desc.constant,
-std::numbers::pi, 2 * std::numbers::pi) *
desc.constant;
};

std::apply([&](auto... dsc) { (wrap(dsc), ...); }, angleDesc);
Expand Down
5 changes: 3 additions & 2 deletions Core/include/Acts/Utilities/BinAdjustmentVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Acts/Geometry/Volume.hpp"
#include "Acts/Utilities/BinUtility.hpp"

#include <numbers>
#include <stdexcept>

namespace Acts {
Expand Down Expand Up @@ -94,8 +95,8 @@ BinUtility adjustBinUtility(const BinUtility& bu,
// The parameters from the cutout cylinder bounds
double minR = cBounds.get(CutoutCylinderVolumeBounds::eMinR);
double maxR = cBounds.get(CutoutCylinderVolumeBounds::eMaxR);
double minPhi = -M_PI;
double maxPhi = M_PI;
double minPhi = -std::numbers::pi;
double maxPhi = std::numbers::pi;
double minZ = -cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
double maxZ = cBounds.get(CutoutCylinderVolumeBounds::eHalfLengthZ);
// Retrieve the binning data
Expand Down
10 changes: 6 additions & 4 deletions Core/include/Acts/Utilities/Frustum.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "Acts/Utilities/VectorHelpers.hpp"

#include <numbers>

template <typename value_t, std::size_t DIM, std::size_t SIDES>
Acts::Frustum<value_t, DIM, SIDES>::Frustum(const VertexType& origin,
const VertexType& dir,
Expand All @@ -17,13 +19,13 @@ Acts::Frustum<value_t, DIM, SIDES>::Frustum(const VertexType& origin,
using rotation_t = Eigen::Rotation2D<value_type>;

static_assert(SIDES == 2, "2D frustum can only have 2 sides");
assert(opening_angle < M_PI);
assert(opening_angle < std::numbers::pi_v<value_type>);

translation_t translation(origin);
value_type angle = VectorHelpers::phi(dir);
Eigen::Rotation2D<value_type> rot(angle);

value_type normal_angle = 0.5 * M_PI - 0.5 * opening_angle;
value_type normal_angle = 0.5 * std::numbers::pi - 0.5 * opening_angle;
VertexType normal1 = rotation_t(normal_angle) * VertexType::UnitX();
VertexType normal2 = rotation_t(-normal_angle) * VertexType::UnitX();

Expand All @@ -37,7 +39,7 @@ Acts::Frustum<value_t, DIM, SIDES>::Frustum(const VertexType& origin,
requires(DIM == 3)
: m_origin(origin) {
static_assert(SIDES > 2, "3D frustum must have 3 or more sides");
assert(opening_angle < M_PI);
assert(opening_angle < std::numbers::pi_v<value_type>);
using angle_axis_t = Eigen::AngleAxis<value_type>;

const VertexType ldir = VertexType::UnitZ();
Expand All @@ -48,7 +50,7 @@ Acts::Frustum<value_t, DIM, SIDES>::Frustum(const VertexType& origin,

m_normals[0] = ldir;

const value_type phi_sep = 2 * M_PI / sides;
const value_type phi_sep = 2 * std::numbers::pi / sides;
transform_type rot;
rot = angle_axis_t(phi_sep, ldir);

Expand Down
11 changes: 6 additions & 5 deletions Core/include/Acts/Utilities/detail/periodic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <cmath>
#include <numbers>

namespace Acts::detail {

Expand Down Expand Up @@ -49,13 +50,13 @@ inline T difference_periodic(T lhs, T rhs, T range) {
/// Calculate the equivalent angle in the [0, 2*pi) range.
template <typename T>
inline T radian_pos(T x) {
return wrap_periodic<T>(x, T{0}, T{2 * M_PI});
return wrap_periodic<T>(x, T{0}, T{2 * std::numbers::pi});
}

/// Calculate the equivalent angle in the [-pi, pi) range.
template <typename T>
inline T radian_sym(T x) {
return wrap_periodic<T>(x, T{-M_PI}, T{2 * M_PI});
return wrap_periodic<T>(x, -std::numbers::pi_v<T>, T{2 * std::numbers::pi});
}

/// Ensure both phi and theta direction angles are within the allowed range.
Expand All @@ -81,11 +82,11 @@ inline std::pair<T, T> normalizePhiTheta(T phi, T theta) {
// moving it first to the periodic range simplifies further steps as the
// possible range of theta becomes fixed.
theta = radian_pos(theta);
if (M_PI < theta) {
if (std::numbers::pi < theta) {
// theta is in the second half of the great circle and outside its nominal
// range. need to change both phi and theta to be within range.
phi += M_PI;
theta = 2 * M_PI - theta;
phi += std::numbers::pi_v<T>;
theta = T{2 * std::numbers::pi} - theta;
}
return {radian_sym(phi), theta};
}
Expand Down
21 changes: 11 additions & 10 deletions Core/include/Acts/Vertexing/SingleSeedVertexFinder.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <algorithm>
#include <cmath>
#include <numbers>
#include <system_error>

#include <Eigen/Eigenvalues>
Expand Down Expand Up @@ -85,8 +86,8 @@ Acts::SingleSeedVertexFinder<spacepoint_t>::sortSpacepoints(
for (const auto& sp : spacepoints) {
// phi will be saved for later
Acts::ActsScalar phi = detail::radian_pos(std::atan2(sp.y(), sp.x()));
std::uint32_t phislice =
static_cast<std::uint32_t>(phi / (2 * M_PI) * m_cfg.numPhiSlices);
std::uint32_t phislice = static_cast<std::uint32_t>(
phi / (2 * std::numbers::pi) * m_cfg.numPhiSlices);
if (phislice >= m_cfg.numPhiSlices) {
phislice = 0;
}
Expand Down Expand Up @@ -134,7 +135,7 @@ Acts::SingleSeedVertexFinder<spacepoint_t>::findTriplets(

std::uint32_t phiStep =
static_cast<std::uint32_t>(m_cfg.maxPhideviation /
(2 * M_PI / m_cfg.numPhiSlices)) +
(2 * std::numbers::pi / m_cfg.numPhiSlices)) +
1;

// calculate limits for middle spacepoints
Expand Down Expand Up @@ -194,7 +195,7 @@ Acts::SingleSeedVertexFinder<spacepoint_t>::findTriplets(
Acts::ActsScalar angleZfrom =
std::atan2(rMiddle[isLessFrom], deltaZfrom) + m_cfg.maxXYZdeviation;
std::uint32_t nearZFrom = 0;
if (angleZfrom < M_PI) {
if (angleZfrom < std::numbers::pi) {
Acts::ActsScalar new_deltaZfrom =
rMiddle[isLessFrom] / std::tan(angleZfrom) / zBinLength;
nearZFrom = static_cast<std::uint32_t>(std::max(
Expand Down Expand Up @@ -226,7 +227,7 @@ Acts::SingleSeedVertexFinder<spacepoint_t>::findTriplets(
std::atan2(rFarDelta[isMiddleLess], delta2Zfrom) +
m_cfg.maxXYZdeviation;
std::uint32_t farZFrom = 0;
if (angle2Zfrom < M_PI) {
if (angle2Zfrom < std::numbers::pi) {
farZFrom = static_cast<std::uint32_t>(std::max(
(rFarDelta[isMiddleLess] / std::tan(angle2Zfrom) / zBinLength) +
middleZ,
Expand Down Expand Up @@ -287,8 +288,8 @@ Acts::SingleSeedVertexFinder<spacepoint_t>::findTriplets(
for (const auto& middleSP :
sortedSpacepoints.getSP(1, middlePhi, middleZ)) {
Acts::ActsScalar phiB = middleSP.second;
Acts::ActsScalar deltaPhiAB =
detail::difference_periodic(phiA, phiB, 2 * M_PI);
Acts::ActsScalar deltaPhiAB = detail::difference_periodic(
phiA, phiB, 2 * std::numbers::pi);
if (std::abs(deltaPhiAB) > m_cfg.maxPhideviation) {
continue;
}
Expand All @@ -297,8 +298,8 @@ Acts::SingleSeedVertexFinder<spacepoint_t>::findTriplets(
for (const auto& farSP :
sortedSpacepoints.getSP(2, farPhi, farZ)) {
Acts::ActsScalar phiC = farSP.second;
Acts::ActsScalar deltaPhiBC =
detail::difference_periodic(phiB, phiC, 2 * M_PI);
Acts::ActsScalar deltaPhiBC = detail::difference_periodic(
phiB, phiC, 2 * std::numbers::pi);
if (std::abs(deltaPhiBC) > m_cfg.maxPhideviation) {
continue;
}
Expand Down Expand Up @@ -333,7 +334,7 @@ bool Acts::SingleSeedVertexFinder<spacepoint_t>::tripletValidationAndUpdate(
std::atan2(triplet.b.y() - triplet.c.y(), triplet.b.x() - triplet.c.x());
// these two slopes shouldn't be too different
Acts::ActsScalar deltaAlpha =
detail::difference_periodic(alpha1, alpha2, 2 * M_PI);
detail::difference_periodic(alpha1, alpha2, 2 * std::numbers::pi);
if (std::abs(deltaAlpha) > m_cfg.maxXYdeviation) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions Core/include/Acts/Visualization/EventDataView3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <array>
#include <cmath>
#include <cstddef>
#include <numbers>
#include <optional>
#include <vector>

Expand Down Expand Up @@ -81,9 +82,9 @@ struct EventDataView3D {
// Now generate the ellipse points
std::vector<Vector3> ellipse;
ellipse.reserve(lseg);
double thetaStep = 2 * M_PI / lseg;
double thetaStep = 2 * std::numbers::pi / lseg;
for (std::size_t it = 0; it < lseg; ++it) {
double phi = -M_PI + it * thetaStep;
double phi = -std::numbers::pi + it * thetaStep;
double cphi = std::cos(phi);
double sphi = std::sin(phi);
double x = lposition.x() + (l1sq * ctheta * cphi - l2sq * stheta * sphi);
Expand Down
4 changes: 3 additions & 1 deletion Core/src/Detector/VolumeStructureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "Acts/Utilities/Helpers.hpp"
#include "Acts/Utilities/StringHelpers.hpp"

#include <numbers>

Acts::Experimental::VolumeStructureBuilder::VolumeStructureBuilder(
const Acts::Experimental::VolumeStructureBuilder::Config& cfg,
std::unique_ptr<const Acts::Logger> mlogger)
Expand Down Expand Up @@ -142,7 +144,7 @@ Acts::Experimental::VolumeStructureBuilder::construct(
}
// Check if phi has been constraint, otherwise fill it with full coverage
if (boundValues.size() == 3u) {
boundValues.push_back(M_PI);
boundValues.push_back(std::numbers::pi_v<ActsScalar>);
boundValues.push_back(0.);
}
ACTS_VERBOSE(" - cylindrical shape with [iR, oR, hZ, sPhi, mPhi] = "
Expand Down
9 changes: 6 additions & 3 deletions Core/src/Detector/detail/CylindricalDetectorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <cstddef>
#include <iterator>
#include <map>
#include <numbers>
#include <ostream>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -404,7 +405,8 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInR(
}
} else {
ACTS_VERBOSE(
"No sector planes present, full 2 * M_PI cylindrical geometry.");
"No sector planes present, full 2 * std::numbers::pi cylindrical "
"geometry.");
}

// Attach the new volume multi links
Expand Down Expand Up @@ -604,7 +606,8 @@ Acts::Experimental::detail::CylindricalDetectorHelper::connectInZ(
}
} else {
ACTS_VERBOSE(
"No sector planes present, full 2 * M_PI cylindrical geometry.");
"No sector planes present, full 2 * std::numbers::pi cylindrical "
"geometry.");
}

// Attach the new volume multi links
Expand Down Expand Up @@ -823,7 +826,7 @@ Acts::Experimental::detail::CylindricalDetectorHelper::wrapInZR(
std::vector<PortalReplacement> pReplacements;
pReplacements.push_back(createCylinderReplacement(
volumes[0u]->transform(gctx), innerR, {-HlZ, -hlZ, hlZ, HlZ},
{-M_PI, M_PI}, 3u, Direction::Forward));
{-std::numbers::pi, std::numbers::pi}, 3u, Direction::Forward));
std::vector<std::shared_ptr<DetectorVolume>> zVolumes = {
volumes[1u], volumes[0u], volumes[1u]};
// Attach the new volume multi links
Expand Down
11 changes: 6 additions & 5 deletions Core/src/Detector/detail/SupportSurfacesHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <algorithm>
#include <cmath>
#include <numbers>
#include <stdexcept>
#include <utility>

Expand All @@ -39,7 +40,7 @@ operator()(const Extent& lExtent) const {
ActsScalar maxZ = lExtent.max(BinningValue::binZ) - std::abs(zClearance[1u]);

// Phi sector
ActsScalar hPhiSector = M_PI;
ActsScalar hPhiSector = std::numbers::pi_v<ActsScalar>;
ActsScalar avgPhi = 0.;
if (lExtent.constrains(BinningValue::binPhi)) {
// Min / Max phi with clearances adapted
Expand Down Expand Up @@ -83,7 +84,7 @@ Acts::Experimental::detail::SupportSurfacesHelper::DiscSupport::operator()(
ActsScalar maxR = lExtent.max(BinningValue::binR) - std::abs(rClearance[1u]);

// Phi sector
ActsScalar hPhiSector = M_PI;
ActsScalar hPhiSector = std::numbers::pi_v<ActsScalar>;
ActsScalar avgPhi = 0.;
if (lExtent.constrains(BinningValue::binPhi)) {
// Min / Max phi with clearances adapted
Expand Down Expand Up @@ -192,7 +193,7 @@ Acts::Experimental::detail::SupportSurfacesHelper::cylindricalSupport(
// Now create the Trapezoids
for (unsigned int iphi = 0; iphi < splits; ++iphi) {
// Get the moduleTransform
ActsScalar phi = -M_PI + (iphi + 0.5) * 2 * dHalfPhi;
ActsScalar phi = -std::numbers::pi + (iphi + 0.5) * 2 * dHalfPhi;
ActsScalar cosPhi = std::cos(phi);
ActsScalar sinPhi = std::sin(phi);
ActsScalar planeX = planeR * cosPhi;
Expand Down Expand Up @@ -271,10 +272,10 @@ Acts::Experimental::detail::SupportSurfacesHelper::discSupport(
// Now create the Trapezoids
for (unsigned int iphi = 0; iphi < splits; ++iphi) {
// Create the split module transform
ActsScalar phi = -M_PI + (iphi + 0.5) * 2 * dHalfPhi;
ActsScalar phi = -std::numbers::pi + (iphi + 0.5) * 2 * dHalfPhi;
auto sTransform = Transform3(
Translation3(hR * std::cos(phi), hR * std::sin(phi), zPosition) *
AngleAxis3(phi - 0.5 * M_PI, zAxis));
AngleAxis3(phi - std::numbers::pi / 2., zAxis));
// Place it
dSupport.push_back(
Surface::makeShared<PlaneSurface>(sTransform, sTrapezoid));
Expand Down
7 changes: 4 additions & 3 deletions Core/src/Geometry/ConeVolumeBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <algorithm>
#include <cmath>
#include <numbers>
#include <stdexcept>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -179,7 +180,7 @@ void ConeVolumeBounds::checkConsistency() noexcept(false) {
throw std::invalid_argument(
"ConeVolumeBounds: invalid longitudinal input.");
}
if (get(eHalfPhiSector) < 0. || get(eHalfPhiSector) > M_PI) {
if (get(eHalfPhiSector) < 0. || get(eHalfPhiSector) > std::numbers::pi) {
throw std::invalid_argument("ConeVolumeBounds: invalid phi sector setup.");
}
if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
Expand All @@ -200,7 +201,7 @@ bool ConeVolumeBounds::inside(const Vector3& pos, ActsScalar tol) const {
return false;
}
ActsScalar r = VectorHelpers::perp(pos);
if (std::abs(get(eHalfPhiSector) - M_PI) > s_onSurfaceTolerance) {
if (std::abs(get(eHalfPhiSector) - std::numbers::pi) > s_onSurfaceTolerance) {
// need to check the phi sector - approximate phi tolerance
ActsScalar phitol = tol / r;
ActsScalar phi = VectorHelpers::phi(pos);
Expand Down Expand Up @@ -280,7 +281,7 @@ void ConeVolumeBounds::buildSurfaceBounds() {
m_innerRmax, m_outerRmax, get(eHalfPhiSector), get(eAveragePhi));

// Create the sector bounds
if (std::abs(get(eHalfPhiSector) - M_PI) > s_epsilon) {
if (std::abs(get(eHalfPhiSector) - std::numbers::pi) > s_epsilon) {
// The 4 points building the sector
std::vector<Vector2> polyVertices = {{-get(eHalfLengthZ), m_innerRmin},
{get(eHalfLengthZ), m_innerRmax},
Expand Down
Loading

0 comments on commit 83f964d

Please sign in to comment.