Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:14

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 /// @note This file is foreseen for the `Geometry` module to replace `Extent`
0012 
0013 #include "Acts/Definitions/Algebra.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include "Acts/Utilities/Enumerate.hpp"
0016 #include "Acts/Utilities/RangeXD.hpp"
0017 
0018 #include <array>
0019 #include <bitset>
0020 #include <ostream>
0021 #include <string>
0022 #include <vector>
0023 
0024 namespace Acts {
0025 
0026 using Envelope = std::array<ActsScalar, 2>;
0027 using ExtentEnvelope = std::array<Envelope, binValues>;
0028 
0029 constexpr Envelope zeroEnvelope = {0, 0};
0030 constexpr ExtentEnvelope zeroEnvelopes = {
0031     zeroEnvelope, zeroEnvelope, zeroEnvelope, zeroEnvelope,
0032     zeroEnvelope, zeroEnvelope, zeroEnvelope, zeroEnvelope};
0033 
0034 /// A class representing the geometric extent of an object in its possible
0035 /// dimensions, these can be all dimensions that are described as BinningValues
0036 ///
0037 /// The extent object can have an optional envelope in all of those values
0038 /// @note that the consistency of the different envelopes is not checked
0039 ///
0040 class Extent {
0041  public:
0042   /// Constructor with (optional) @param envelope
0043   Extent(const ExtentEnvelope& envelope = zeroEnvelopes);
0044 
0045   /// Define a comparison operator
0046   bool operator==(const Extent& e) const;
0047 
0048   /// Define a comparison operator
0049   bool operator!=(const Extent& e) const { return (!operator==(e)); }
0050 
0051   /// Extend with a position vertex
0052   ///
0053   /// @param vtx the vertex to be used for extending
0054   /// @param bValues the binning values
0055   /// @param applyEnv boolean to steer if envelope should be applied
0056   /// @param fillHistograms is a boolean flag to steer whether the values
0057   ///        to fill this extent should be stored
0058   void extend(const Vector3& vtx,
0059               const std::vector<BinningValue>& bValues = s_binningValues,
0060               bool applyEnv = true, bool fillHistograms = false);
0061 
0062   /// Extend with a set of vectors by iterators
0063   ///
0064   /// @param start the start iterator of the loop
0065   /// @param end the end iterator of the loop
0066   /// @param bValues the binning values
0067   /// @param applyEnv boolean to steer if envelope should be applied
0068   /// @param fillHistograms is a boolean flag to steer whether the values
0069   ///        to fill this extent should be stored
0070   template <typename vector_iterator_t>
0071   void extend(const vector_iterator_t& start, const vector_iterator_t& end,
0072               const std::vector<BinningValue>& bValues = s_binningValues,
0073               bool applyEnv = true, bool fillHistograms = false) {
0074     for (vector_iterator_t vIt = start; vIt < end; ++vIt) {
0075       extend(*vIt, bValues, applyEnv, fillHistograms);
0076     }
0077   }
0078 
0079   /// Extend with another geometric extent, usually pushes the
0080   /// current range to the boundaries of the rhs extent,
0081   /// unless the current extent is already bigger.
0082   ///
0083   /// @note the extent can also simply set an envelope
0084   /// which then is applied to the current one
0085   ///
0086   /// @param rhs is the other source Extent
0087   /// @param bValues the binning values
0088   /// @param applyEnv boolean to steer if envelope should be applied
0089   ///        on the constraint values, if only an envelope is given
0090   ///        but the value not constraint, then it is always applied
0091   ///
0092   /// @note that the histogram values can not be filled in this call
0093   void extend(const Extent& rhs,
0094               const std::vector<BinningValue>& bValues = s_binningValues,
0095               bool applyEnv = true);
0096 
0097   /// Constrain an extent by another one, this is
0098   /// - values that are already constrained are not touched
0099   /// - values not constrained by @param rhs are not touched
0100   /// - values that are constrained by the external one, but not
0101   /// by the current one, are touched
0102   ///
0103   /// @param envelope an envelope applied to the constrained value
0104   void addConstrain(const Extent& rhs,
0105                     const ExtentEnvelope& envelope = zeroEnvelopes);
0106 
0107   /// Set a range for a dedicated binning value
0108   ///
0109   /// @param bValue the binning identification
0110   /// @param min the minimum parameter
0111   /// @param max the maximum parameter
0112   void set(BinningValue bValue, ActsScalar min, ActsScalar max);
0113 
0114   /// (re-)Set the envelope
0115   ///
0116   /// @param envelope new envelope to be set
0117   void setEnvelope(const ExtentEnvelope& envelope = zeroEnvelopes);
0118 
0119   /// Return the individual 1-dimensional range
0120   ///
0121   /// @param bValue is the binning value to be returned
0122   ///
0123   /// @return a one dimensional arrange
0124   auto range(BinningValue bValue) { return m_range[bValue]; }
0125 
0126   /// Return the individual 1-dimensional range
0127   ///
0128   /// @param bValue is the binning value to be returned
0129   ///
0130   /// @return a one dimensional arrange
0131   Range1D<ActsScalar> range(BinningValue bValue) const;
0132 
0133   /// Return the N-dimension range
0134   const RangeXD<binValues, ActsScalar>& range() const;
0135 
0136   /// Return an D-dimensional sub range according to the
0137   /// the given @param binValues
0138   template <unsigned int kSUBDIM>
0139   RangeXD<kSUBDIM, ActsScalar> range(
0140       const std::array<BinningValue, kSUBDIM>& binValues) const {
0141     RangeXD<kSUBDIM, ActsScalar> rRange;
0142     for (auto [i, v] : enumerate(binValues)) {
0143       rRange[i] = range(v);
0144     }
0145     return rRange;
0146   }
0147 
0148   /// Return the envelope - non-const access
0149   ExtentEnvelope& envelope();
0150 
0151   /// Return the envelope - const access
0152   const ExtentEnvelope& envelope() const;
0153 
0154   /// Return the histogram store
0155   ///
0156   /// The histogram store can be used for automated binning detection
0157   const std::array<std::vector<ActsScalar>, binValues>& valueHistograms() const;
0158 
0159   /// Access the minimum parameter
0160   ///
0161   /// @param bValue the binning identification
0162   ActsScalar min(BinningValue bValue) const { return m_range[bValue].min(); }
0163 
0164   /// Access the maximum parameter
0165   ///
0166   /// @param bValue the binning identification
0167   ActsScalar max(BinningValue bValue) const { return m_range[bValue].max(); }
0168 
0169   /// Access the midpoint
0170   ///
0171   /// @param bValue the binning identification
0172   ActsScalar medium(BinningValue bValue) const {
0173     return 0.5 * (m_range[bValue].min() + m_range[bValue].max());
0174   }
0175 
0176   /// Access the parameter interval (i.e. the range span)
0177   ///
0178   /// @param bValue the binning identification
0179   ActsScalar interval(BinningValue bValue) const {
0180     return m_range[bValue].size();
0181   }
0182 
0183   /// Contains check
0184   ///
0185   /// @param rhs the extent that is check if it is contained
0186   /// @param bValue is the binning value, if set to binValues
0187   ///               the check on all is done
0188   ///
0189   /// @return true if the rhs is contained
0190   bool contains(const Extent& rhs, BinningValue bValue = binValues) const;
0191 
0192   /// Contains check for a single point
0193   ///
0194   /// @param vtx the point that is check if it is contained
0195   ///
0196   /// @return true if the rhs is contained
0197   bool contains(const Vector3& vtx) const;
0198 
0199   /// Intersection checks
0200   ///
0201   /// @param rhs the extent that is check for intersection
0202   /// @param bValue is the binning value, if set to binValues
0203   ///               the check on all is done
0204   ///
0205   /// @return true if the rhs intersects
0206   bool intersects(const Extent& rhs, BinningValue bValue = binValues) const;
0207 
0208   /// Constraints check
0209   ///
0210   /// @param bValue is the binning value, if all the check on all is done
0211   bool constrains(BinningValue bValue = binValues) const;
0212 
0213   /// Convert to output stream for screen output
0214   ///
0215   /// @param indent indentation for the screen display
0216   std::string toString(const std::string& indent = "") const;
0217 
0218  private:
0219   /// A bitset that remembers the constraint values
0220   std::bitset<binValues> m_constrains{0};
0221   /// The actual range store
0222   RangeXD<binValues, ActsScalar> m_range;
0223   /// A potential envelope
0224   ExtentEnvelope m_envelope = zeroEnvelopes;
0225   /// (Optional) Value histograms for bin detection
0226   std::array<std::vector<ActsScalar>, binValues> m_valueHistograms;
0227 };
0228 
0229 inline Range1D<ActsScalar> Acts::Extent::range(BinningValue bValue) const {
0230   return m_range[bValue];
0231 }
0232 
0233 inline const RangeXD<binValues, ActsScalar>& Extent::range() const {
0234   return m_range;
0235 }
0236 
0237 inline ExtentEnvelope& Extent::envelope() {
0238   return m_envelope;
0239 }
0240 
0241 inline const ExtentEnvelope& Extent::envelope() const {
0242   return m_envelope;
0243 }
0244 
0245 inline const std::array<std::vector<ActsScalar>, binValues>&
0246 Extent::valueHistograms() const {
0247   return m_valueHistograms;
0248 }
0249 
0250 /// Overload of << operator for std::ostream for debug output
0251 std::ostream& operator<<(std::ostream& sl, const Extent& rhs);
0252 
0253 }  // namespace Acts