// This file is part of the ACTS project. // // Copyright (C) 2016 CERN for the benefit of the ACTS project // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. #include "Acts/Geometry/CylinderVolumeBounds.hpp" #include "Acts/Geometry/NavigationPolicyFactory.hpp" #include "Acts/Geometry/TrackingVolume.hpp" #include "Acts/Navigation/SurfaceArrayNavigationPolicy.hpp" #include "Acts/Navigation/TryAllNavigationPolicy.hpp" #include "Acts/Surfaces/CylinderBounds.hpp" #include "Acts/Surfaces/CylinderSurface.hpp" #include "Acts/Surfaces/SurfaceArray.hpp" #include "Acts/Utilities/Logger.hpp" #include "ActsPython/Utilities/Helpers.hpp" #include "ActsPython/Utilities/Macros.hpp" #include #include #include #include #include #include namespace py = pybind11; using namespace pybind11::literals; using namespace Acts; namespace ActsPython { namespace Test { class DetectorElementStub : public SurfacePlacementBase { public: DetectorElementStub() = default; const Transform3& localToGlobalTransform( const GeometryContext& /*gctx*/) const override { return m_transform; } /// Is the detector element a sensitive element bool isSensitive() const override { return true; } /// Return surface representation - const return pattern const Surface& surface() const override { throw std::runtime_error("Not implemented"); } /// Non-const return pattern Surface& surface() override { throw std::runtime_error("Not implemented"); } private: Transform3 m_transform{Transform3::Identity()}; }; } // namespace Test /// @brief Add the navigation bindings to a module. /// @param m the module to add the bindings to void addNavigation(py::module_& m) { { auto tryAll = py::class_(m, "TryAllNavigationPolicy"); using Config = TryAllNavigationPolicy::Config; auto c = py::class_(tryAll, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT(c, portals, sensitives); } py::class_>( m, "NavigationPolicyFactory") // only to mirror the C++ API .def_static("make", []() { return NavigationPolicyFactory{}; }) .def("add", [](NavigationPolicyFactory* self, const py::object& cls) { auto mod = py::module_::import("acts"); if (py::object o = mod.attr("TryAllNavigationPolicy"); cls.is(o)) { return std::move(*self).template add(); } else { throw std::invalid_argument( "Unknown navigation policy class: " + cls.attr("__name__").cast()); } }) .def("add", [](NavigationPolicyFactory* self, const py::object& cls, const SurfaceArrayNavigationPolicy::Config& config) { auto mod = py::module_::import("acts"); if (py::object o = mod.attr("SurfaceArrayNavigationPolicy"); !cls.is(o)) { throw std::invalid_argument( "Unknown navigation policy class: " + cls.attr("__name__").cast()); } return std::move(*self).template add( config); }) .def("add", [](NavigationPolicyFactory* self, const py::object& cls, const TryAllNavigationPolicy::Config& config) { auto mod = py::module_::import("acts"); if (py::object o = mod.attr("TryAllNavigationPolicy"); !cls.is(o)) { throw std::invalid_argument( "Unknown navigation policy class: " + cls.attr("__name__").cast()); } return std::move(*self).template add( config); }) .def("_buildTest", [](NavigationPolicyFactory* self) { auto vol1 = std::make_shared( Transform3::Identity(), std::make_shared(30, 40, 100)); vol1->setVolumeName("TestVolume"); auto detElem = std::make_unique(); auto surface = Surface::makeShared( Transform3::Identity(), std::make_shared(30, 40)); surface->assignSurfacePlacement(*detElem); vol1->addSurface(std::move(surface)); std::unique_ptr result = self->build(GeometryContext::dangerouslyDefaultConstruct(), *vol1, *getDefaultLogger("Test", Logging::VERBOSE)); }); { auto saPolicy = py::class_( m, "SurfaceArrayNavigationPolicy"); using LayerType = SurfaceArrayNavigationPolicy::LayerType; py::enum_(saPolicy, "LayerType") .value("Cylinder", LayerType::Cylinder) .value("Disc", LayerType::Disc) .value("Plane", LayerType::Plane); using Config = SurfaceArrayNavigationPolicy::Config; auto c = py::class_(saPolicy, "Config").def(py::init<>()); ACTS_PYTHON_STRUCT(c, layerType, bins); } } } // namespace ActsPython