ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
link_utils.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/core/concepts.hpp"
13#include "detray/geometry/surface.hpp"
14#include "detray/utils/invalid_values.hpp"
15
16// Plugin include(s)
17#include "detray/plugins/svgtools/utils/surface_kernels.hpp"
18
19// System include(s)
20#include <cassert>
21#include <tuple>
22
23namespace detray::svgtools::utils {
24
26template <concepts::detector detector_t>
27inline auto is_not_world_portal(
28 const detray::geometry::surface<detector_t>& d_portal) {
29 const auto d_link_idx = d_portal.volume_links();
30 bool is_world_pt{false};
31 for (const auto vol_link : d_link_idx) {
32 is_world_pt = is_world_pt || detray::detail::is_invalid_value(vol_link);
33 }
34 return !is_world_pt;
35}
36
39template <concepts::detector detector_t>
40inline auto get_linked_volume(
41 const detector_t& detector,
42 const detray::geometry::surface<detector_t>& d_portal,
43 [[maybe_unused]] const std::size_t mask_idx) {
44 assert(is_not_world_portal(d_portal));
45 const auto d_link_idx = d_portal.volume_links();
46
47 return tracking_volume{detector, d_link_idx.at(mask_idx)};
48}
49
53template <concepts::detector detector_t>
54inline auto link_points(const typename detector_t::geometry_context& context,
55 const detector_t& detector,
56 const detray::geometry::surface<detector_t>& d_portal,
57 typename detector_t::vector3_type dir,
58 const double link_length,
59 const std::size_t mask_idx = 0u) {
60 assert(is_not_world_portal(d_portal));
61
62 // Calculating the start position:
63 const auto start = d_portal.template visit_mask<link_start_getter>(
64 d_portal.transform(context), mask_idx);
65
66 // Calculating the end position:
67 const auto n =
68 d_portal.normal(context, d_portal.global_to_local(context, start, dir));
69 const auto volume = get_linked_volume(detector, d_portal, mask_idx);
70 const auto end = d_portal.template visit_mask<link_end_getter>(
71 detector, volume, start, n, link_length, mask_idx);
72
73 return std::make_tuple(start, end);
74}
75
76} // namespace detray::svgtools::utils
constexpr point3_type global_to_local(const context &ctx, const point3_type &global, const vector3_type &dir) const
Definition surface.hpp:258
constexpr auto transform(const context &ctx) const -> const transform3_type &
Definition surface.hpp:197
constexpr auto normal(const context &ctx, const point_t &p) const -> vector3_type
Definition surface.hpp:239
constexpr auto volume_links() const
Definition surface.hpp:174