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: modernise map utils #3615

Merged
merged 23 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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: 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
39 changes: 39 additions & 0 deletions Core/include/Acts/Utilities/Helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,43 @@ struct overloaded : Ts... {
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

/// 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)
inline auto getMinMaxAndBinCount(std::vector<double>& xPos) {
// sort the values for unique()
std::ranges::sort(xPos);
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved

// 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);
}
AJPfleger marked this conversation as resolved.
Show resolved Hide resolved

} // namespace Acts
Loading
Loading