Hammer  1.0.0
Helicity Amplitude Module for Matrix Element Reweighting
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinnedIndexing.hh
Go to the documentation of this file.
1 ///
2 /// @file BinnedIndexing.hh
3 /// @brief Binned tensor (histogram) indexer
4 ///
5 
6 //**** This file is a part of the HAMMER library
7 //**** Copyright (C) 2016 - 2020 The HAMMER Collaboration
8 //**** HAMMER is licensed under version 3 of the GPL; see COPYING for details
9 //**** Please note the MCnet academic guidelines; see GUIDELINES for details
10 
11 // -*- C++ -*-
12 #ifndef HAMMER_MATH_MULTIDIM_BinnedIndexing
13 #define HAMMER_MATH_MULTIDIM_BinnedIndexing
14 
16 
17 namespace Hammer {
18 
19  namespace MultiDimensional {
20 
21 
22  using BinValue = std::vector<double>;
23  using BinEdgeList = std::vector<std::vector<double>>;
24  using BinRange = std::pair<double, double>;
25  using BinRangeList = std::vector<BinRange>;
26 
27  template<class BasicIndexing>
28  class BinnedIndexing : public BasicIndexing {
29 
30  public:
32 
34  BinnedIndexing(IndexList dimensions, BinRangeList ranges, bool hasUnderOverFlow);
35  BinnedIndexing(BinEdgeList edges, bool hasUnderOverFlow);
36 
37  BinnedIndexing(const BinnedIndexing&) = default;
38  BinnedIndexing(BinnedIndexing&&) = default;
39  BinnedIndexing& operator=(const BinnedIndexing&) = default;
41 
42  ~BinnedIndexing() noexcept = default;
43 
44  public:
45  using BasicIndexing::dim;
46 
47  /// @brief get the labels of all the indices at once
48  /// @return the list of labels
49  const BinEdgeList& edges() const;
50 
51  const BinValue& edge(IndexType pos) const;
52 
53  IndexList valueToPos(const BinValue& point) const;
54  bool isValid(const BinValue& point) const;
55 
56  BinRangeList binEdges(IndexList position) const;
57  BinRange binEdge(IndexType position, IndexType coord) const;
58 
59  bool isSameBinShape(const BinEdgeList& otherEdges, const IndexList& otherIndices, bool otherUnderOverFlow) const;
60  bool isSameBinShape(const BinRangeList& otherRanges, const IndexList& otherIndices, bool otherUnderOverFlow) const;
61 
62  template<typename S>
63  bool isSameBinShape(const BinnedIndexing<S>& other) const;
64 
65  bool hasUnderOverFlow() const;
66 
67  typename BasicIndexing::StrideMap getBinStrides(const UniqueIndexList& positions) const;
68 
69  private:
70 
71  bool isValid() const;
72  void fillEdges(const BinRangeList& ranges);
73 
74  static IndexList processEdges(const BinEdgeList& edges, bool hasUnderOverFlow);
75  static IndexList processRanges(const IndexList& dimensions, bool hasUnderOverFlow);
76 
77  private:
78  BinEdgeList _edges; ///< the labels of each tensor index
80 
81  };
82 
83  }
84 
85 } // namespace Hammer
86 
88 
89 #endif
BasicIndexing::StrideMap getBinStrides(const UniqueIndexList &positions) const
Binned tensor (histogram) indexer template method definitions.
BinnedIndexing & operator=(const BinnedIndexing &)=default
const BinEdgeList & edges() const
get the labels of all the indices at once
std::vector< std::vector< double >> BinEdgeList
bool isSameBinShape(const BinEdgeList &otherEdges, const IndexList &otherIndices, bool otherUnderOverFlow) const
BinRangeList binEdges(IndexList position) const
uint16_t IndexType
Forward declarations of types used in the tensor classes.
IndexList valueToPos(const BinValue &point) const
std::vector< IndexType > IndexList
const BinValue & edge(IndexType pos) const
BinEdgeList _edges
the labels of each tensor index
std::set< IndexType > UniqueIndexList
static IndexList processEdges(const BinEdgeList &edges, bool hasUnderOverFlow)
void fillEdges(const BinRangeList &ranges)
std::vector< BinRange > BinRangeList
BinRange binEdge(IndexType position, IndexType coord) const
std::pair< double, double > BinRange
std::vector< double > BinValue
static IndexList processRanges(const IndexList &dimensions, bool hasUnderOverFlow)