Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AdaptiveGridTrackDensity.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file AdaptiveGridTrackDensity.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-2023 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
13 
14 #include <unordered_map>
15 
16 #include <boost/functional/hash.hpp>
17 
18 namespace Acts {
19 
36 template <int spatialTrkGridSize = 15, int temporalTrkGridSize = 1>
38  // Assert odd spatial and temporal track grid size
39  static_assert(spatialTrkGridSize % 2);
40  static_assert(temporalTrkGridSize % 2);
41 
42  public:
43  // The first (second) integer indicates the bin's z (t) position
44  using Bin = std::pair<int, int>;
45  // Mapping between bins and track densities
46  using DensityMap = std::unordered_map<Bin, float, boost::hash<Bin>>;
47  // Coordinates in the z-t plane; the t value will be set to 0 if time
48  // vertex seeding is disabled
49  using ZTPosition = std::pair<float, float>;
50  // z-t position of a maximum and its width
51  using ZTPositionAndWidth = std::pair<ZTPosition, float>;
52 
54  struct Config {
56  Config(float spatialBinExtent_) : spatialBinExtent(spatialBinExtent_) {
57  if constexpr (temporalTrkGridSize > 1) {
58  throw std::invalid_argument(
59  "temporalBinExtent must be provided if temporalTrkGridSize > 1 "
60  "(i.e., if time vertex seeding is enabled).");
61  }
62  }
63 
67  Config(float spatialBinExtent_, float temporalBinExtent_)
68  : spatialBinExtent(spatialBinExtent_),
69  temporalBinExtent(temporalBinExtent_) {
70  if constexpr (temporalTrkGridSize == 1) {
71  throw std::invalid_argument(
72  "temporalBinExtent must not be provided if temporalTrkGridSize == "
73  "1 (i.e., if time vertex seeding is disabled).");
74  }
75  }
76 
77  // Spatial extent of a bin in d0 and z0 direction, should always be set to a
78  // positive value
79  float spatialBinExtent = 0.; // mm
80 
81  // Temporal extent of a bin, should be set to 0 if time vertex seeding is
82  // disabled (i.e., if temporalTrkGridSize = 1)
83  float temporalBinExtent = 0.; // mm
84 
85  // Do NOT use just the z-bin with the highest
86  // track density, but instead check (up to)
87  // first three density maxima (only those that have
88  // a maximum relative deviation of 'relativeDensityDev'
89  // from the main maximum) and take the z-bin of the
90  // maximum with the highest surrounding density sum
91  bool useHighestSumZPosition = false;
92 
93  // The maximum relative density deviation from the main
94  // maximum to consider the second and third maximum for
95  // the highest-sum approach from above
96  float maxRelativeDensityDev = 0.01;
97  };
98 
100 
105  static float getBinCenter(int bin, float binExtent);
106 
111  static int getBin(float value, float binExtent);
112 
117  DensityMap::const_iterator highestDensityEntry(
118  const DensityMap& densityMap) const;
119 
130 
140  DensityMap& densityMap) const;
141 
149  DensityMap& mainDensityMap) const;
150 
157  void subtractTrack(const DensityMap& trackDensityMap,
158  DensityMap& mainDensityMap) const;
159 
160  private:
168  DensityMap createTrackGrid(const Acts::Vector3& impactParams,
169  const Bin& centralBin,
170  const Acts::SquareMatrix3& cov) const;
171 
182  Result<float> estimateSeedWidth(const DensityMap& densityMap,
183  const ZTPosition& maxZT) const;
184 
195  template <unsigned int nDim>
198 
207  Bin highestDensitySumBin(DensityMap& densityMap) const;
208 
216  float getDensitySum(const DensityMap& densityMap, const Bin& bin) const;
217 
219 };
220 
221 } // namespace Acts
222