Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:11

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 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Utilities/AxisDefinitions.hpp"
0013 
0014 #include <iosfwd>
0015 #include <vector>
0016 
0017 namespace Acts {
0018 
0019 /// Common base class for all Axis instance. This allows generice handling
0020 /// such as for inspection.
0021 class IAxis {
0022  public:
0023   /// @brief returns whether the axis is equidistant
0024   ///
0025   /// @return bool is equidistant
0026   virtual bool isEquidistant() const = 0;
0027 
0028   /// @brief returns whether the axis is variable
0029   ///
0030   /// @return bool is variable
0031   virtual bool isVariable() const = 0;
0032 
0033   /// @brief returns the type of the axis
0034   /// @return @c AxisType of this axis
0035   virtual AxisType getType() const = 0;
0036 
0037   /// @brief returns the boundary type set in the template param
0038   ///
0039   /// @return @c AxisBoundaryType of this axis
0040   virtual AxisBoundaryType getBoundaryType() const = 0;
0041 
0042   /// @brief Return a vector of bin edges
0043   /// @return Vector which contains the bin edges
0044   virtual std::vector<double> getBinEdges() const = 0;
0045 
0046   /// @brief get minimum of binning range
0047   ///
0048   /// @return minimum of binning range
0049   virtual double getMin() const = 0;
0050 
0051   /// @brief get maximum of binning range
0052   ///
0053   /// @return maximum of binning range
0054   virtual double getMax() const = 0;
0055 
0056   /// @brief get total number of bins
0057   ///
0058   /// @return total number of bins (excluding under-/overflow bins)
0059   virtual std::size_t getNBins() const = 0;
0060 
0061   /// Helper function that dispatches from the @c IAxis base class
0062   /// to a concrete axis type. It will call the provided @p callable
0063   /// with a const reference to the concrete axis type.
0064   /// @tparam callable_t the callable type
0065   /// @param callable the callable object
0066   /// @return the value returned by the callable
0067   template <typename callable_t>
0068   decltype(auto) visit(const callable_t& callable) const {
0069     auto switchOnType =
0070         [this, &callable]<AxisBoundaryType bdt>(AxisBoundaryTypeTag<bdt>) {
0071           switch (getType()) {
0072             using enum AxisType;
0073             case Equidistant:
0074               return callable(
0075                   dynamic_cast<const Axis<AxisType::Equidistant, bdt>&>(*this));
0076             case Variable:
0077               return callable(
0078                   dynamic_cast<const Axis<AxisType::Variable, bdt>&>(*this));
0079             default:
0080               throw std::logic_error("Unknown axis type");
0081           }
0082         };
0083 
0084     switch (getBoundaryType()) {
0085       using enum AxisBoundaryType;
0086       case Open:
0087         return switchOnType(AxisOpen);
0088       case Bound:
0089         return switchOnType(AxisBound);
0090       case Closed:
0091         return switchOnType(AxisClosed);
0092       default:
0093         throw std::logic_error("Unknown axis type");
0094     }
0095   }
0096 
0097   /// Check if two axes are equal
0098   /// @param lhs first axis
0099   /// @param rhs second axis
0100   /// @return true if the axes are equal
0101   friend bool operator==(const IAxis& lhs, const IAxis& rhs) {
0102     return lhs.getType() == rhs.getType() &&
0103            lhs.getBoundaryType() == rhs.getBoundaryType() &&
0104            lhs.getMin() == rhs.getMin() && lhs.getMax() == rhs.getMax() &&
0105            lhs.getNBins() == rhs.getNBins() &&
0106            lhs.getBinEdges() == rhs.getBinEdges();
0107   }
0108 
0109   /// Output stream operator
0110   /// @param os output stream
0111   /// @param axis the axis to be printed
0112   /// @return the output stream
0113   friend std::ostream& operator<<(std::ostream& os, const IAxis& axis) {
0114     axis.toStream(os);
0115     return os;
0116   }
0117 
0118  protected:
0119   /// Dispatch to the correct stream operator
0120   /// @param os output stream
0121   virtual void toStream(std::ostream& os) const = 0;
0122 };
0123 
0124 template <typename T>
0125 concept AxisConcept = std::derived_from<T, IAxis>;
0126 
0127 }  // namespace Acts