Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-24 08:19:38

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/Utilities/Axis.hpp"
0012 #include "Acts/Utilities/AxisDefinitions.hpp"
0013 #include "Acts/Utilities/Diagnostics.hpp"
0014 #include "Acts/Utilities/Grid.hpp"
0015 #include "Acts/Utilities/IAxis.hpp"
0016 
0017 #include <memory>
0018 #include <vector>
0019 
0020 namespace Acts {
0021 /// This class is a pure run-time placeholder for the axis definition
0022 ///
0023 /// The IAxis allows via the visitor pattern to access the actual axis type
0024 /// which helps to create grid creation code by the compiler as done
0025 /// in the makeGrid helper functions.
0026 ///
0027 /// In addition to a simple axis definitions, it holds also a description
0028 /// of the axis direction.
0029 ///
0030 /// @deprecated Use AxisSpec instead
0031 class [[deprecated("Use AxisSpec instead")]] ProtoAxis {
0032  public:
0033   /// Convenience constructors - for variable binning
0034   ///
0035   /// @param abType the axis boundary type
0036   /// @param edges the bin edges (variable binning)
0037   ProtoAxis(Acts::AxisBoundaryType abType, const std::vector<double>& edges);
0038 
0039   /// Convenience constructors - for equidistant binning
0040   ///
0041   /// @param abType the axis boundary type
0042   /// @param minE the lowest edge of the binning
0043   /// @param maxE the highest edge of the binning
0044   /// @param nbins the number of bins
0045   ProtoAxis(AxisBoundaryType abType, double minE, double maxE,
0046             std::size_t nbins);
0047 
0048   /// Placeholder constructor for auto-range binning
0049   ///
0050   /// @param abType the axis boundary type
0051   /// @param nbins the number of bins
0052   ///
0053   /// @note that auto-range is only supported for equidistant binning
0054   ProtoAxis(AxisBoundaryType abType, std::size_t nbins);
0055 
0056   /// Custom copy constructor
0057   /// @param other is the right hand side ProtoAxis
0058   ProtoAxis(const ProtoAxis& other);
0059 
0060   /// Custom assignment operator
0061   /// @param other is the right hand side ProtoAxis
0062   /// @return Reference to this ProtoAxis for assignment chaining
0063   ProtoAxis& operator=(const ProtoAxis& other);
0064 
0065   /// Move constructor
0066   ProtoAxis(ProtoAxis&&) = default;
0067   /// Move assignment operator
0068   /// @return Reference to this ProtoAxis for assignment chaining
0069   ProtoAxis& operator=(ProtoAxis&&) = default;
0070 
0071   ~ProtoAxis() = default;
0072 
0073   /// @brief Return the IAxis representation
0074   ///
0075   /// @return @c AxisType of this axis
0076   const IAxis& getAxis() const;
0077 
0078   /// Set the range, in case of autorange, this
0079   /// will toggle the autorange flag to false
0080   ///
0081   /// @throws an exception if minE > maxE
0082   ///
0083   /// @note In case of variable binning, it will clip the bins outside
0084   /// the new range off, i.e. it will potentially change the number
0085   /// of bins.
0086   ///
0087   /// @note In case of equidistant binning, it will adapt the bin size,
0088   /// and NOT change the number of bins.
0089   ///
0090   /// @param minE the lowest edge of the binning
0091   /// @param maxE the highest edge of the binning
0092   void setRange(double minE, double maxE);
0093 
0094   /// @brief check if this is an auto-range binning
0095   /// @return True if this axis uses auto-ranging
0096   bool isAutorange() const;
0097 
0098   /// Dump into a string
0099   /// @return the string representation
0100   std::string toString() const;
0101 
0102  private:
0103   /// @brief Hidden friend ostream operator
0104   /// @param os the output stream
0105   /// @param a the proto axis
0106   /// @return the streamed into operator
0107   friend std::ostream& operator<<(std::ostream& os, const ProtoAxis& a) {
0108     os << a.toString();
0109     return os;
0110   }
0111 
0112   /// Dispatch to the correct stream operator
0113   /// @param os output stream
0114   void toStream(std::ostream& os) const;
0115 
0116  protected:
0117   /// The axis representation
0118   std::unique_ptr<IAxis> m_axis = nullptr;
0119 
0120   /// Indicate if this is a place holder auto-range binning
0121   bool m_autorange = false;
0122 };
0123 
0124 /// @brief Helper method to create a 1D grid from a single proto axis
0125 ///
0126 /// @tparam payload_t the grid payloat type
0127 ///
0128 /// @param a the proto axis
0129 ///
0130 /// @return an IGrid unique ptr and hence transfers ownership
0131 /// @deprecated Use makeGrid(const IAxis&) instead
0132 template <typename payload_t>
0133 [[deprecated("Use makeGrid(const IAxis&) instead")]] std::unique_ptr<IGrid>
0134 makeGrid(const ProtoAxis& a) {
0135   if (a.isAutorange()) {
0136     throw std::invalid_argument(
0137         "ProtoAxis::makeGrid: Auto-range of the proto axis is not (yet) "
0138         "resolved, call setRange() first.");
0139   }
0140 
0141   return makeGrid<payload_t>(a.getAxis());
0142 }
0143 
0144 /// @brief Helper method to create a 2D grid from a two proto axes
0145 ///
0146 /// @tparam payload_t the grid payloat type
0147 ///
0148 /// @param a the first proto axis
0149 /// @param b the second proto axis
0150 ///
0151 /// @return an IGrid unique ptr and hence transfers ownership
0152 /// @deprecated Use makeGrid(const IAxis&, const IAxis&) instead
0153 template <typename payload_t>
0154 [[deprecated(
0155     "Use makeGrid(const IAxis&, const IAxis&) instead")]] std::unique_ptr<IGrid>
0156 makeGrid(const ProtoAxis& a, const ProtoAxis& b) {
0157   if (a.isAutorange() || b.isAutorange()) {
0158     throw std::invalid_argument(
0159         "ProtoAxis::makeGrid: Auto-range of the proto axis is not (yet) "
0160         "resolved, call setRange() first.");
0161   }
0162 
0163   return makeGrid<payload_t>(a.getAxis(), b.getAxis());
0164 }
0165 
0166 /// A Directed proto axis
0167 ///
0168 /// @deprecated Use AxisSpec with an AxisDirection instead
0169 struct [[deprecated("Use AxisSpec with an AxisDirection instead")]]
0170 DirectedProtoAxis : public ProtoAxis {
0171  public:
0172   /// Convenience constructors - for variable binning
0173   ///
0174   /// @param axisDir the axis direction
0175   /// @param abType the axis boundary type
0176   /// @param edges the bin edges (variable binning)
0177   DirectedProtoAxis(AxisDirection axisDir, AxisBoundaryType abType,
0178                     const std::vector<double>& edges);
0179 
0180   /// Convenience constructors - for equidistant binning
0181   ///
0182   /// @param axisDir the axis direction
0183   /// @param abType the axis boundary type
0184   /// @param minE the lowest edge of the binning
0185   /// @param maxE the highest edge of the binning
0186   /// @param nbins the number of bins
0187   DirectedProtoAxis(AxisDirection axisDir, AxisBoundaryType abType, double minE,
0188                     double maxE, std::size_t nbins);
0189 
0190   /// Placeholder constructor for auto-range binning
0191   ///
0192   /// @param axisDir the axis direction
0193   /// @param abType the axis boundary type
0194   /// @param nbins the number of bins
0195   ///
0196   /// @note that auto-range is only supported for equidistant binning
0197   DirectedProtoAxis(AxisDirection axisDir, AxisBoundaryType abType,
0198                     std::size_t nbins);
0199 
0200   virtual ~DirectedProtoAxis() = default;
0201 
0202   /// Access to the AxisDirection
0203   /// @return the axis direction
0204   AxisDirection getAxisDirection() const;
0205 
0206   /// Dump into a string
0207   /// @return the string representation
0208   std::string toString() const;
0209 
0210  private:
0211   /// @brief Hidden friend ostream operator
0212   /// @param os the output stream
0213   /// @param a the proto axis
0214   /// @return the streamed into operator
0215   friend std::ostream& operator<<(std::ostream& os,
0216                                   const DirectedProtoAxis& a) {
0217     os << a.toString();
0218     return os;
0219   }
0220 
0221   /// Dispatch to the correct stream operator
0222   /// @param os output stream
0223   void toStream(std::ostream& os) const;
0224 
0225   AxisDirection m_direction;
0226 };
0227 
0228 // A deprecated declaration only silences directly named types, not the ones it
0229 // names as template arguments
0230 ACTS_PUSH_IGNORE_DEPRECATED()
0231 
0232 /// Stream operator for vector of ProtoAxis
0233 /// @param os Output stream
0234 /// @param a Vector of ProtoAxis to output
0235 /// @return Reference to output stream
0236 /// @deprecated Use AxisSpec instead
0237 [[deprecated("Use AxisSpec instead")]]
0238 std::ostream& operator<<(std::ostream& os, const std::vector<ProtoAxis>& a);
0239 
0240 /// Stream operator for vector of DirectedProtoAxis
0241 /// @param os Output stream
0242 /// @param a Vector of DirectedProtoAxis to output
0243 /// @return Reference to output stream
0244 /// @deprecated Use AxisSpec with an AxisDirection instead
0245 [[deprecated("Use AxisSpec with an AxisDirection instead")]]
0246 std::ostream& operator<<(std::ostream& os,
0247                          const std::vector<DirectedProtoAxis>& a);
0248 
0249 ACTS_POP_IGNORE_DEPRECATED()
0250 
0251 }  // namespace Acts