Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-05 08:29:44

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 
0013 #include <ostream>
0014 
0015 namespace Acts {
0016 /// Enum which determines how the axis handle its outer boundaries
0017 /// possible values values
0018 enum class AxisBoundaryType {
0019   /// Default behaviour: out of bounds
0020   /// positions are filled into the over or underflow bins
0021   Open,
0022   /// Out-of-bounds positions resolve to first/last bin
0023   /// respectively
0024   Bound,
0025   /// Out-of-bounds positions resolve to the outermost
0026   /// bin on the opposite side
0027   Closed,
0028 };
0029 
0030 /// Tag helper type for Axis constructors with class template deduction
0031 /// @tparam bdt the boundary type
0032 template <AxisBoundaryType bdt>
0033 struct AxisBoundaryTypeTag {};
0034 
0035 /// Convenience typedefs for AxisBoundaryTypeTag
0036 constexpr auto AxisOpen = AxisBoundaryTypeTag<AxisBoundaryType::Open>{};
0037 constexpr auto AxisBound = AxisBoundaryTypeTag<AxisBoundaryType::Bound>{};
0038 constexpr auto AxisClosed = AxisBoundaryTypeTag<AxisBoundaryType::Closed>{};
0039 
0040 inline std::ostream& operator<<(std::ostream& os, AxisBoundaryType bdt) {
0041   switch (bdt) {
0042     case AxisBoundaryType::Open:
0043       os << "Open";
0044       break;
0045     case AxisBoundaryType::Bound:
0046       os << "Bound";
0047       break;
0048     case AxisBoundaryType::Closed:
0049       os << "Closed";
0050       break;
0051   }
0052   return os;
0053 }
0054 
0055 /// Enum which determines the binning type of the axis
0056 enum class AxisType {
0057   /// An axis where all bins have the same size
0058   Equidistant,
0059   /// An axis where bins can have different sizes
0060   Variable,
0061 };
0062 
0063 inline std::ostream& operator<<(std::ostream& os, AxisType type) {
0064   switch (type) {
0065     case AxisType::Equidistant:
0066       os << "Equidistant";
0067       break;
0068     case AxisType::Variable:
0069       os << "Variable";
0070       break;
0071   }
0072   return os;
0073 }
0074 
0075 /// @brief calculate bin indices from a given binning structure
0076 ///
0077 /// This class provides some basic functionality for calculating bin indices
0078 /// for a given binning configuration. Both equidistant as well as variable
0079 /// binning structures are supported.
0080 ///
0081 /// Bin intervals are defined such that the lower bound is closed and the
0082 /// upper bound is open.
0083 ///
0084 /// @tparam equidistant flag whether binning is equidistant (@c true)
0085 ///                     or not (@c false)
0086 template <AxisType type, AxisBoundaryType bdt = AxisBoundaryType::Open>
0087 class Axis;
0088 
0089 Axis(ActsScalar min, ActsScalar max,
0090      std::size_t bins) -> Axis<AxisType::Equidistant, AxisBoundaryType::Open>;
0091 
0092 template <AxisBoundaryType bdt>
0093 Axis(AxisBoundaryTypeTag<bdt> /*bdt*/, ActsScalar min, ActsScalar max,
0094      std::size_t bins) -> Axis<AxisType::Equidistant, bdt>;
0095 
0096 Axis(std::vector<ActsScalar> bins)
0097     -> Axis<AxisType::Variable, AxisBoundaryType::Open>;
0098 
0099 template <AxisBoundaryType bdt>
0100 Axis(AxisBoundaryTypeTag<bdt> /*bdt*/,
0101      std::vector<ActsScalar> bins) -> Axis<AxisType::Variable, bdt>;
0102 
0103 }  // namespace Acts