EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Extent.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Extent.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
14 
15 #include <iosfwd>
16 #include <utility>
17 #include <vector>
18 
19 namespace Acts {
20 
21 using Range = std::pair<double, double>;
22 
23 // @brief Extent in space
28 struct Extent {
30  static constexpr double maxval = std::numeric_limits<double>::max();
31 
33  static constexpr Range maxrange = {maxval, -maxval};
34 
35  // The different ranges
36  std::vector<Range> ranges{(int)binValues, maxrange};
37 
38  // Constructor
39  Extent() = default;
40 
45  bool intersects(const Extent& other, BinningValue bVal = binValues,
46  double tolerance = s_epsilon) {
47  // Helper to check
48  auto checkRange = [&](BinningValue bvc) -> bool {
49  auto& a = ranges[bvc];
50  auto& b = other.ranges[bvc];
51  return (a.second + tolerance > b.first and
52  a.first - tolerance < b.second);
53  };
54 
55  // Check all
56  if (bVal == binValues) {
57  for (int ibv = 0; ibv < (int)binValues; ++ibv) {
58  if (checkRange((BinningValue)ibv)) {
59  return true;
60  }
61  }
62  return false;
63  }
64  // Check specific
65  return checkRange(bVal);
66  }
67 
70  void extend(const Extent& other) {
71  for (std::size_t ir = 0; ir < other.ranges.size(); ++ir) {
72  ranges[ir].first = std::min(ranges[ir].first, other.ranges[ir].first);
73  ranges[ir].second = std::max(ranges[ir].second, other.ranges[ir].second);
74  }
75  }
76 
79  std::ostream& toStream(std::ostream& sl) const;
80 
83  double& min(BinningValue bval) { return ranges[bval].first; }
84 
87  double min(BinningValue bval) const { return ranges[bval].first; }
88 
91  double& max(BinningValue bval) { return ranges[bval].second; }
92 
95  double max(BinningValue bval) const { return ranges[bval].second; }
96 
99  double medium(BinningValue bval) const {
100  return 0.5 * (ranges[bval].first + ranges[bval].second);
101  }
102 
105  double range(BinningValue bval) const {
106  return std::abs(ranges[bval].second - ranges[bval].first);
107  }
108 
111  void check(const Vector3D& vtx) {
112  // min/max value check
113  auto minMax = [&](BinningValue bval, double value) -> void {
114  ranges[bval].first = std::min(value, ranges[bval].first);
115  ranges[bval].second = std::max(value, ranges[bval].second);
116  };
117  // Walk through the binning parameters
118  for (int bval = 0; bval < binValues; ++bval) {
119  BinningValue bValue = static_cast<BinningValue>(bval);
120  minMax(bValue, VectorHelpers::cast(vtx, bValue));
121  }
122  }
123 };
124 
126 std::ostream& operator<<(std::ostream& sl, const Extent& ext);
127 
128 } // namespace Acts