Skip to content

Commit

Permalink
Merge branch 'main' into header-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger authored Dec 2, 2024
2 parents 7665395 + c4c5f95 commit 2316226
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ repos:
- id: leftover_conflict_markers
name: Leftover conflict markers
language: system
entry: git diff --staged --check
entry: git --no-pager diff --staged --check

- repo: local
hooks:
Expand Down
15 changes: 8 additions & 7 deletions Core/include/Acts/MagneticField/BFieldMapUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fieldMapRZ(const std::function<std::size_t(std::array<std::size_t, 2> binsRZ,
std::array<std::size_t, 2> nBinsRZ)>&
localToGlobalBin,
std::vector<double> rPos, std::vector<double> zPos,
std::vector<Acts::Vector2> bField,
const std::vector<Acts::Vector2>& bField,
double lengthUnit = UnitConstants::mm,
double BFieldUnit = UnitConstants::T, bool firstQuadrant = false);

Expand Down Expand Up @@ -137,25 +137,26 @@ fieldMapXYZ(
std::array<std::size_t, 3> nBinsXYZ)>&
localToGlobalBin,
std::vector<double> xPos, std::vector<double> yPos,
std::vector<double> zPos, std::vector<Acts::Vector3> bField,
std::vector<double> zPos, const std::vector<Acts::Vector3>& bField,
double lengthUnit = UnitConstants::mm, double BFieldUnit = UnitConstants::T,
bool firstOctant = false);

/// Function which takes an existing SolenoidBField instance and
/// creates a field mapper by sampling grid points from the analytical
/// solenoid field.
///
/// @param rlim pair of r bounds
/// @param zlim pair of z bounds
/// @param nbins pair of bin counts
/// @param rLim pair of r bounds
/// @param zLim pair of z bounds
/// @param nBins pair of bin counts
/// @param field the solenoid field instance
///
/// @return A field map instance for use in interpolation.
Acts::InterpolatedBFieldMap<
Acts::Grid<Acts::Vector2, Acts::Axis<Acts::AxisType::Equidistant>,
Acts::Axis<Acts::AxisType::Equidistant>>>
solenoidFieldMap(std::pair<double, double> rlim, std::pair<double, double> zlim,
std::pair<std::size_t, std::size_t> nbins,
solenoidFieldMap(const std::pair<double, double>& rLim,
const std::pair<double, double>& zLim,
const std::pair<std::size_t, std::size_t>& nBins,
const SolenoidBField& field);

} // namespace Acts
45 changes: 45 additions & 0 deletions Core/include/Acts/Utilities/Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,49 @@ struct overloaded : Ts... {
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

namespace detail {

/// Computes the minimum, maximum, and bin count for a given vector of values.
///
/// This function processes a vector of doubles to compute:
/// - The minimum value (@c xMin)
/// - The maximum value (@c xMax), adjusted to include an additional bin
/// - The bin count (@c xBinCount) based on the number of unique values
///
/// The computation is performed as follows:
/// 1. Sorts the input vector using @c std::ranges::sort to prepare for uniqueness.
/// 2. Determines the number of unique values using @c std::unique and calculates the bin count.
/// 3. Calculates the minimum and maximum using @c std::ranges::minmax.
/// 4. Adjusts the maximum to include an additional bin by adding the bin step
/// size.
///
/// @param xPos A reference to a vector of doubles.
/// @return A tuple containing:
/// - The minimum value (double)
/// - The adjusted maximum value (double)
/// - The bin count (std::size_t)
///
/// @note The vector xPos will be modified during the call.
inline auto getMinMaxAndBinCount(std::vector<double>& xPos) {
// sort the values for unique()
std::ranges::sort(xPos);

// get the number of bins over unique values
auto it = std::unique(xPos.begin(), xPos.end());
const std::size_t xBinCount = std::distance(xPos.begin(), it);

// get the minimum and maximum
auto [xMin, xMax] = std::ranges::minmax(xPos);

// calculate maxima (add one last bin, because bin value always corresponds to
// left boundary)
const double stepX = (xMax - xMin) / static_cast<double>(xBinCount - 1);
xMax += stepX;

// Return all values as a tuple
return std::make_tuple(xMin, xMax, xBinCount);
}

} // namespace detail

} // namespace Acts
Loading

0 comments on commit 2316226

Please sign in to comment.