ECCE @ 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 = std::vector<Range>(9, maxrange);
37 
38  // Constructor
39  Extent() = default;
40 
43  void extend(const Extent& other) {
44  for (auto ir = 0; ir < other.ranges.size(); ++ir) {
45  ranges[ir].first = std::min(ranges[ir].first, other.ranges[ir].first);
46  ranges[ir].second = std::max(ranges[ir].second, other.ranges[ir].second);
47  }
48  }
49 
52  std::ostream& toStream(std::ostream& sl) const;
53 
56  double min(BinningValue bval) const { return ranges[bval].first; }
57 
60  double max(BinningValue bval) const { return ranges[bval].second; }
61 
64  double medium(BinningValue bval) const {
65  return 0.5 * (ranges[bval].first + ranges[bval].second);
66  }
67 
70  double range(BinningValue bval) const {
71  return std::abs(ranges[bval].second - ranges[bval].first);
72  }
73 
76  void check(const Vector3D& vtx) {
77  // min/max value check
78  auto minMax = [&](BinningValue bval, double value) -> void {
79  ranges[bval].first = std::min(value, ranges[bval].first);
80  ranges[bval].second = std::max(value, ranges[bval].second);
81  };
82  // Walk through the binning parameters
83  for (int bval = 0; bval < binValues; ++bval) {
84  BinningValue bValue = static_cast<BinningValue>(bval);
85  minMax(bValue, VectorHelpers::cast(vtx, bValue));
86  }
87  }
88 };
89 
91 std::ostream& operator<<(std::ostream& sl, const Extent& ext);
92 
93 } // namespace Acts