Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-14 08:19:57

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/ProtoAxis.hpp"
0010 
0011 #include "Acts/Utilities/Diagnostics.hpp"
0012 
0013 #include <sstream>
0014 
0015 namespace Acts {
0016 
0017 // Definitions do not repeat the deprecation attributes of their declarations,
0018 // so the deprecated types they name are diagnosed here
0019 ACTS_PUSH_IGNORE_DEPRECATED()
0020 
0021 ProtoAxis::ProtoAxis(AxisBoundaryType abType, const std::vector<double>& edges)
0022     : m_axis(IAxis::createVariable(abType, edges)) {}
0023 
0024 ProtoAxis::ProtoAxis(AxisBoundaryType abType, double minE, double maxE,
0025                      std::size_t nbins)
0026     : m_axis(IAxis::createEquidistant(abType, minE, maxE, nbins)) {}
0027 
0028 ProtoAxis::ProtoAxis(AxisBoundaryType abType, std::size_t nbins)
0029     : m_axis(IAxis::createEquidistant(abType, 0., 1., nbins)),
0030       m_autorange(true) {}
0031 
0032 ProtoAxis::ProtoAxis(const ProtoAxis& other) : m_autorange(other.m_autorange) {
0033   const auto& axis = other.getAxis();
0034   if (!m_autorange) {
0035     const auto& edges = axis.getBinEdges();
0036     if (axis.getType() == AxisType::Variable) {
0037       m_axis = IAxis::createVariable(axis.getBoundaryType(), edges);
0038     } else {
0039       m_axis = IAxis::createEquidistant(axis.getBoundaryType(), edges.front(),
0040                                         edges.back(), axis.getNBins());
0041     }
0042   } else {
0043     m_axis = IAxis::createEquidistant(axis.getBoundaryType(), 0., 1.,
0044                                       axis.getNBins());
0045   }
0046 }
0047 
0048 ProtoAxis& ProtoAxis::operator=(const ProtoAxis& other) {
0049   if (this != &other) {
0050     m_autorange = other.m_autorange;
0051     const auto& axis = other.getAxis();
0052     if (!m_autorange) {
0053       const auto& edges = axis.getBinEdges();
0054       if (axis.getType() == AxisType::Variable) {
0055         m_axis = IAxis::createVariable(axis.getBoundaryType(), edges);
0056       } else {
0057         m_axis = IAxis::createEquidistant(axis.getBoundaryType(), edges.front(),
0058                                           edges.back(), axis.getNBins());
0059       }
0060     } else {
0061       m_axis = IAxis::createEquidistant(axis.getBoundaryType(), 0., 1.,
0062                                         axis.getNBins());
0063     }
0064   }
0065   return *this;
0066 }
0067 
0068 const IAxis& ProtoAxis::getAxis() const {
0069   return *m_axis;
0070 }
0071 
0072 void ProtoAxis::setRange(double minE, double maxE) {
0073   if (minE > maxE) {
0074     throw std::invalid_argument(
0075         "ProtoAxis::setRange: minE > maxE is not allowed.");
0076   }
0077 
0078   if (m_axis->getType() == AxisType::Equidistant) {
0079     m_axis = IAxis::createEquidistant(m_axis->getBoundaryType(), minE, maxE,
0080                                       m_axis->getNBins());
0081   } else {
0082     std::vector<double> edges = m_axis->getBinEdges();
0083     // Clip it to min/max
0084     std::erase_if(edges,
0085                   [minE, maxE](double e) { return (e < minE || e > maxE); });
0086     // Add the min and max
0087     edges.emplace_back(minE);
0088     edges.emplace_back(maxE);
0089     std::ranges::sort(edges);
0090     m_axis = IAxis::createVariable(m_axis->getBoundaryType(), edges);
0091   }
0092 
0093   // Force autorange to be false
0094   m_autorange = false;
0095 }
0096 
0097 bool ProtoAxis::isAutorange() const {
0098   return m_autorange;
0099 }
0100 
0101 void ProtoAxis::toStream(std::ostream& os) const {
0102   os << toString();
0103 }
0104 
0105 std::string ProtoAxis::toString() const {
0106   std::stringstream ss;
0107   const auto& axis = getAxis();
0108   ss << "ProtoAxis: " << axis.getNBins() << " bins";
0109   ss << (axis.getType() == AxisType::Variable ? ", variable "
0110                                               : ", equidistant ");
0111   if (!m_autorange) {
0112     const auto& edges = axis.getBinEdges();
0113     ss << "within [" << edges.front() << ", " << edges.back() << "]";
0114   } else {
0115     ss << "within automatic range";
0116   }
0117   return ss.str();
0118 }
0119 
0120 // Ostream operator implementation
0121 std::ostream& operator<<(std::ostream& os, const std::vector<ProtoAxis>& as) {
0122   for (const auto& a : as) {
0123     os << a.toString() << '\n';
0124   }
0125   return os;
0126 }
0127 
0128 DirectedProtoAxis::DirectedProtoAxis(AxisDirection axisDir,
0129                                      AxisBoundaryType abType,
0130                                      const std::vector<double>& edges)
0131     : ProtoAxis(abType, edges), m_direction(axisDir) {}
0132 
0133 DirectedProtoAxis::DirectedProtoAxis(AxisDirection axisDir,
0134                                      AxisBoundaryType abType, double minE,
0135                                      double maxE, std::size_t nbins)
0136     : ProtoAxis(abType, minE, maxE, nbins), m_direction(axisDir) {}
0137 
0138 DirectedProtoAxis::DirectedProtoAxis(AxisDirection axisDir,
0139                                      AxisBoundaryType abType, std::size_t nbins)
0140     : ProtoAxis(abType, nbins), m_direction(axisDir) {}
0141 
0142 AxisDirection DirectedProtoAxis::getAxisDirection() const {
0143   return m_direction;
0144 }
0145 
0146 void DirectedProtoAxis::toStream(std::ostream& os) const {
0147   os << toString();
0148 }
0149 
0150 std::string DirectedProtoAxis::toString() const {
0151   std::stringstream ss;
0152   const auto& axis = getAxis();
0153   ss << "DirectedProtoAxis: " << axis.getNBins() << " bins in "
0154      << axisDirectionName(m_direction);
0155   ss << (axis.getType() == AxisType::Variable ? ", variable "
0156                                               : ", equidistant ");
0157   if (!m_autorange) {
0158     const auto& edges = axis.getBinEdges();
0159     ss << "within [" << edges.front() << ", " << edges.back() << "]";
0160   } else {
0161     ss << "within automatic range";
0162   }
0163   return ss.str();
0164 }
0165 
0166 // Ostream operator implementation vector of directed proto axes
0167 std::ostream& operator<<(std::ostream& os,
0168                          const std::vector<DirectedProtoAxis>& as) {
0169   for (const auto& a : as) {
0170     os << a << '\n';
0171   }
0172   return os;
0173 }
0174 
0175 ACTS_POP_IGNORE_DEPRECATED()
0176 
0177 }  // namespace Acts