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/ProtoAxis.hpp"
0010 
0011 #include <sstream>
0012 
0013 namespace {
0014 void checkConsistency(Acts::AxisDirection aDir, Acts::AxisBoundaryType abType) {
0015   if (abType == Acts::AxisBoundaryType::Closed &&
0016       aDir != Acts::AxisDirection::AxisPhi &&
0017       aDir != Acts::AxisDirection::AxisRPhi) {
0018     std::string msg =
0019         "ProtoAxis: Invalid axis boundary type 'Closed' for direction '";
0020     msg += axisDirectionName(aDir) +
0021            "'. Closed boundary type is only valid for "
0022            "AxisPhi and AxisRPhi directions.";
0023     throw std::invalid_argument(msg);
0024   }
0025 }
0026 }  // namespace
0027 
0028 Acts::ProtoAxis::ProtoAxis(AxisDirection aDir, Acts::AxisBoundaryType abType,
0029                            const std::vector<double>& edges)
0030     : m_axisDir(aDir), m_axis(IAxis::createVariable(abType, edges)) {
0031   checkConsistency(aDir, abType);
0032 }
0033 
0034 Acts::ProtoAxis::ProtoAxis(AxisDirection aDir, AxisBoundaryType abType,
0035                            double minE, double maxE, std::size_t nbins)
0036     : m_axisDir(aDir),
0037       m_axis(IAxis::createEquidistant(abType, minE, maxE, nbins)) {
0038   checkConsistency(aDir, abType);
0039 }
0040 
0041 Acts::ProtoAxis::ProtoAxis(AxisDirection aDir, AxisBoundaryType abType,
0042                            std::size_t nbins)
0043     : m_axisDir(aDir),
0044       m_axis(IAxis::createEquidistant(abType, 0., 1., nbins)),
0045       m_autorange(true) {
0046   checkConsistency(aDir, abType);
0047 }
0048 
0049 Acts::AxisDirection Acts::ProtoAxis::getAxisDirection() const {
0050   return m_axisDir;
0051 }
0052 
0053 const Acts::IAxis& Acts::ProtoAxis::getAxis() const {
0054   return *m_axis;
0055 }
0056 
0057 void Acts::ProtoAxis::setRange(double minE, double maxE) {
0058   if (!m_autorange) {
0059     throw std::invalid_argument("ProtoAxis::setRange: Range is already set.");
0060   }
0061   if (m_axis->getType() != AxisType::Equidistant) {
0062     throw std::invalid_argument(
0063         "ProtoAxis::setRange: Range can only be set for equidistant binning.");
0064   }
0065   m_axis = IAxis::createEquidistant(m_axis->getBoundaryType(), minE, maxE,
0066                                     m_axis->getNBins());
0067   m_autorange = false;
0068 }
0069 
0070 bool Acts::ProtoAxis::isAutorange() const {
0071   return m_autorange;
0072 }
0073 
0074 void Acts::ProtoAxis::toStream(std::ostream& os) const {
0075   os << toString();
0076 }
0077 
0078 std::string Acts::ProtoAxis::toString() const {
0079   std::stringstream ss;
0080   const auto& axis = getAxis();
0081   ss << "ProtoAxis: " << axis.getNBins() << " bins in "
0082      << axisDirectionName(getAxisDirection());
0083   ss << (axis.getType() == AxisType::Variable ? ", variable "
0084                                               : ", equidistant ");
0085   if (!m_autorange) {
0086     const auto& edges = axis.getBinEdges();
0087     ss << "within [" << edges.front() << ", " << edges.back() << "]";
0088   } else {
0089     ss << "within automatic range";
0090   }
0091   return ss.str();
0092 }