Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiLayerSurfacesUpdator.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MultiLayerSurfacesUpdator.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
16 
17 #include <array>
18 #include <memory>
19 
20 namespace Acts {
21 namespace Experimental {
22 
23 template <typename grid_t, typename path_generator>
25  public:
27  using grid_type = grid_t;
28 
31 
33  path_generator pgenerator;
34 
36  std::array<BinningValue, grid_type::DIM> casts{};
37 
39  Transform3 transform = Transform3::Identity();
40 
46  grid_type&& igrid, const std::array<BinningValue, grid_type::DIM>& icasts,
47  const Transform3& itr = Transform3::Identity())
48  : grid(std::move(igrid)), casts(icasts), transform(itr) {}
49 
51 
53  auto step = std::sqrt(std::pow(grid.binWidth()[0], 2) +
54  std::pow(grid.binWidth()[1], 2));
55  auto path = pgenerator(nState.position, nState.direction, step,
56  grid.numLocalBins()[1]);
57 
58  std::vector<const Acts::Surface*> surfCandidates = {};
59 
60  for (const auto& p : path) {
61  const auto& entry = grid.atPosition(castPosition(p));
62  const auto extracted =
64  surfCandidates.insert(surfCandidates.end(), extracted.begin(),
65  extracted.end());
66  }
67 
68  resolveDuplicates(gctx, surfCandidates);
69  SurfacesFiller::fill(nState, surfCandidates);
70 
71  updateCandidates(gctx, nState);
72  }
73 
77  std::array<ActsScalar, grid_type::DIM> castPosition(
78  const Vector3& position) const {
79  // Transform into local 3D frame
80  Vector3 tposition = transform * position;
81 
82  std::array<ActsScalar, grid_type::DIM> casted{};
83  fillCasts(tposition, casted,
84  std::make_integer_sequence<std::size_t, grid_type::DIM>{});
85  return casted;
86  }
87 
93  std::vector<const Acts::Surface*>& surfaces) const {
94  // sorting the surfaces according to their radial distance
95  std::sort(surfaces.begin(), surfaces.end(),
96  [&gctx](const auto& surf1, const auto& surf2) {
97  if (surf1->center(gctx).x() != surf2->center(gctx).x()) {
98  return surf1->center(gctx).x() < surf2->center(gctx).x();
99  }
100  if (surf1->center(gctx).y() != surf2->center(gctx).y()) {
101  return surf1->center(gctx).y() < surf2->center(gctx).y();
102  }
103  return surf1->center(gctx).z() < surf2->center(gctx).z();
104  });
105 
106  // Remove the duplicates
107  surfaces.erase(std::unique(surfaces.begin(), surfaces.end()),
108  surfaces.end());
109  }
110 
111  private:
115  template <typename Array, std::size_t... idx>
116  void fillCasts(const Vector3& position, Array& a,
117  std::index_sequence<idx...> /*indices*/) const {
118  ((a[idx] = VectorHelpers::cast(position, casts[idx])), ...);
119  }
120 };
121 
123  std::vector<Vector3> operator()(Vector3 startPosition,
124  const Vector3& direction, ActsScalar stepSize,
125  std::size_t numberOfSteps) const {
126  std::vector<Vector3> pathCoordinates = {};
127  pathCoordinates.reserve(numberOfSteps);
128 
129  auto tposition = std::move(startPosition);
130  auto stepSizeY = stepSize * sin(Acts::VectorHelpers::phi(direction));
131  auto stepSizeX = stepSize * cos(Acts::VectorHelpers::phi(direction));
132 
133  for (std::size_t i = 0; i < numberOfSteps; i++) {
134  pathCoordinates.push_back(tposition);
135  tposition.y() = tposition.y() + stepSizeY;
136  tposition.x() = tposition.x() + stepSizeX;
137  }
138 
139  return pathCoordinates;
140  }
141 };
142 
143 } // namespace Experimental
144 
145 } // namespace Acts