Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DupletSearch.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DupletSearch.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020-2021 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 
11 // Local include(s).
13 
14 #include "../Utilities/Arrays.hpp"
15 #include "SpacePointType.hpp"
16 
17 // VecMem include(s).
18 #include "vecmem/containers/data/jagged_vector_view.hpp"
19 #include "vecmem/containers/data/vector_view.hpp"
20 #include "vecmem/containers/device_vector.hpp"
21 #include "vecmem/containers/jagged_device_vector.hpp"
22 
23 // SYCL include(s).
24 #include <CL/sycl.hpp>
25 
26 // System include(s).
27 #include <cstdint>
28 
29 namespace Acts::Sycl::detail {
30 
32 template <SpacePointType OtherSPType>
33 class DupletSearch {
34  // Sanity check(s).
35  static_assert((OtherSPType == SpacePointType::Bottom) ||
36  (OtherSPType == SpacePointType::Top),
37  "Class must be instantiated with either "
38  "Acts::Sycl::detail::SpacePointType::Bottom or "
39  "Acts::Sycl::detail::SpacePointType::Top");
40 
41  public:
43  DupletSearch(vecmem::data::vector_view<const DeviceSpacePoint> middleSPs,
44  vecmem::data::vector_view<const DeviceSpacePoint> otherSPs,
45  vecmem::data::jagged_vector_view<uint32_t> middleOtherSPIndices,
47  : m_middleSPs(middleSPs),
48  m_otherSPs(otherSPs),
49  m_middleOtherSPIndices(middleOtherSPIndices),
50  m_config(config) {}
51 
53  void operator()(cl::sycl::nd_item<2> item) const {
54  // Get the indices of the spacepoints to evaluate.
55  const auto middleIndex = item.get_global_id(0);
56  const auto otherIndex = item.get_global_id(1);
57 
58  // We check whether this thread actually makes sense (within bounds).
59  // The number of threads is usually a factor of 2, or 3*2^k (k \in N), etc.
60  // Without this check we may index out of arrays.
61  if ((middleIndex >= m_middleSPs.size()) ||
62  (otherIndex >= m_otherSPs.size())) {
63  return;
64  }
65 
66  // Create a copy of the spacepoint objects for the current thread. On
67  // dedicated GPUs this provides a better performance than accessing
68  // variables one-by-one from global device memory.
69  const vecmem::device_vector<const DeviceSpacePoint> middleSPs(m_middleSPs);
70  const DeviceSpacePoint middleSP = middleSPs[middleIndex];
71  const vecmem::device_vector<const DeviceSpacePoint> otherSPs(m_otherSPs);
72  const DeviceSpacePoint otherSP = otherSPs[otherIndex];
73 
74  // Calculate the variables that the duplet quality selection are based on.
75  // Note that the asserts of the functor make sure that 'OtherSPType' must be
76  // either SpacePointType::Bottom or SpacePointType::Top.
77  float deltaR = 0.0f, cotTheta = 0.0f;
78  if constexpr (OtherSPType == SpacePointType::Bottom) {
79  deltaR = middleSP.r - otherSP.r;
80  cotTheta = (middleSP.z - otherSP.z) / deltaR;
81  } else {
82  deltaR = otherSP.r - middleSP.r;
83  cotTheta = (otherSP.z - middleSP.z) / deltaR;
84  }
85  const float zOrigin = middleSP.z - middleSP.r * cotTheta;
86 
87  // Check if the duplet passes our quality requirements.
88  if ((deltaR >= m_config.deltaRMin) && (deltaR <= m_config.deltaRMax) &&
89  (cl::sycl::abs(cotTheta) <= m_config.cotThetaMax) &&
90  (zOrigin >= m_config.collisionRegionMin) &&
91  (zOrigin <= m_config.collisionRegionMax)) {
92  // Create device vector based on the view and push to it
93  vecmem::jagged_device_vector<uint32_t> middleOtherSPIndices(
95  middleOtherSPIndices.at(middleIndex).push_back(otherIndex);
96  }
97  }
98 
99  private:
101  vecmem::data::vector_view<const DeviceSpacePoint> m_middleSPs;
103  vecmem::data::vector_view<const DeviceSpacePoint> m_otherSPs;
104 
106  vecmem::data::jagged_vector_view<uint32_t> m_middleOtherSPIndices;
107 
110 
111 }; // struct DupletSearch
112 
113 } // namespace Acts::Sycl::detail