Skip to content
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
26 changes: 24 additions & 2 deletions Core/include/Acts/Utilities/Axis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <vector>

namespace Acts {
Expand Down Expand Up @@ -42,7 +43,19 @@ class Axis<AxisType::Equidistant, bdt> : public IAxis {
m_min(xmin),
m_max(xmax),
m_width((xmax - xmin) / nBins),
m_bins(nBins) {}
m_bins(nBins) {
if (m_min >= m_max) {
std::string msg = "Axis: Invalid axis range'";
msg += "', min edge (" + std::to_string(m_min) + ") ";
msg += " needs to be smaller than max edge (";
msg += std::to_string(m_max) + ").";
throw std::invalid_argument(msg);
}
if (m_bins < 1u) {
throw std::invalid_argument(
"Axis: Invalid binning, at least one bin is needed.");
}
}

/// Divide the range \f$[\text{xmin},\text{xmax})\f$ into \f$\text{nBins}\f$
/// equidistant bins.
Expand Down Expand Up @@ -325,7 +338,16 @@ class Axis<AxisType::Variable, bdt> : public IAxis {
/// @pre @c binEdges must contain at least two entries.
explicit Axis(std::vector<double> binEdges,
std::optional<AxisDirection> direction = std::nullopt)
: IAxis(direction), m_binEdges(std::move(binEdges)) {}
: IAxis(direction), m_binEdges(std::move(binEdges)) {
if (m_binEdges.size() < 2) {
throw std::invalid_argument(
"Axis: Invalid binning, at least two bin edges are needed.");
}
if (!std::ranges::is_sorted(m_binEdges)) {
throw std::invalid_argument(
"Axis: Invalid binning, bin edges are not sorted.");
}
}

/// Create a binning structure with @c nBins variable-sized bins from the
/// given bin boundaries. @c nBins is given by the number of bin edges
Expand Down
23 changes: 0 additions & 23 deletions Core/src/Utilities/IAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ std::unique_ptr<IAxis> IAxis::createEquidistant(
using enum AxisType;
using enum AxisBoundaryType;

if (min >= max) {
std::string msg = "IAxis: Invalid axis range'";
msg += "', min edge (" + std::to_string(min) + ") ";
msg += " needs to be smaller than max edge (";
msg += std::to_string(max) + ").";
throw std::invalid_argument(msg);
}
if (nbins < 1u) {
throw std::invalid_argument(
"IAxis: Invalid binning, at least one bin is needed.");
}

switch (aBoundaryType) {
case Open:
return std::make_unique<Axis<Equidistant, Open>>(min, max, nbins,
Expand All @@ -54,17 +42,6 @@ std::unique_ptr<IAxis> IAxis::createVariable(
using enum AxisType;
using enum AxisBoundaryType;

// Not enough edges
if (edges.size() < 2) {
throw std::invalid_argument(
"IAxis: Invalid binning, at least two bin edges are needed.");
}

// Not sorted
if (!std::ranges::is_sorted(edges)) {
throw std::invalid_argument(
"IAxis: Invalid binning, bin edges are not sorted.");
}
switch (aBoundaryType) {
case Open:
return std::make_unique<Axis<Variable, Open>>(edges, direction);
Expand Down
Loading