Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:33:56

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Utilities/IAxis.hpp"
0010 
0011 #include "Acts/Utilities/Axis.hpp"
0012 
0013 #include <algorithm>
0014 #include <stdexcept>
0015 
0016 std::unique_ptr<Acts::IAxis> Acts::IAxis::createEquidistant(
0017     AxisBoundaryType aBoundaryType, double min, double max, std::size_t nbins) {
0018   using enum AxisType;
0019   using enum AxisBoundaryType;
0020 
0021   if (min >= max) {
0022     std::string msg = "IAxis: Invalid axis range'";
0023     msg += "', min edge (" + std::to_string(min) + ") ";
0024     msg += " needs to be smaller than max edge (";
0025     msg += std::to_string(max) + ").";
0026     throw std::invalid_argument(msg);
0027   }
0028   if (nbins < 1u) {
0029     throw std::invalid_argument(
0030         "IAxis: Invalid binning, at least one bin is needed.");
0031   }
0032 
0033   switch (aBoundaryType) {
0034     case Open:
0035       return std::make_unique<Axis<Equidistant, Open>>(min, max, nbins);
0036     case Bound:
0037       return std::make_unique<Axis<Equidistant, Bound>>(min, max, nbins);
0038     case Closed:
0039       return std::make_unique<Axis<Equidistant, Closed>>(min, max, nbins);
0040     default:  // should never happen
0041       throw std::logic_error("Unknown axis boundary type");
0042   }
0043 }
0044 
0045 std::unique_ptr<Acts::IAxis> Acts::IAxis::createVariable(
0046     AxisBoundaryType aBoundaryType, const std::vector<double>& edges) {
0047   using enum AxisType;
0048   using enum AxisBoundaryType;
0049 
0050   // Not enough edges
0051   if (edges.size() < 2) {
0052     throw std::invalid_argument(
0053         "IAxis: Invalid binning, at least two bin edges are needed.");
0054   }
0055 
0056   // Not sorted
0057   if (!std::ranges::is_sorted(edges)) {
0058     throw std::invalid_argument(
0059         "IAxis: Invalid binning, bin edges are not sorted.");
0060   }
0061   switch (aBoundaryType) {
0062     case Open:
0063       return std::make_unique<Axis<Variable, Open>>(edges);
0064     case Bound:
0065       return std::make_unique<Axis<Variable, Bound>>(edges);
0066     case Closed:
0067       return std::make_unique<Axis<Variable, Closed>>(edges);
0068     default:  // should never happen
0069       throw std::logic_error("Unknown axis boundary type");
0070   }
0071 }