From 737ed7eb0e136b2526aa973f5c70f53deb843fb5 Mon Sep 17 00:00:00 2001 From: Andreas Salzburger Date: Thu, 7 Mar 2024 11:20:37 +0100 Subject: [PATCH] feat: python bindings for telescope like detector (#3006) This PR adds some needed Python bindings for 1D binned detectors (such as telescopes) and a binding for the CuboidalDetectorBuilder. It allows to build a first version of the NA60+ Silicon detector. Co-authored-by: Paul Gessinger <1058585+paulgessinger@users.noreply.github.com> --- Examples/Python/src/Geometry.cpp | 89 ++++++++++++++++++++++++++------ 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/Examples/Python/src/Geometry.cpp b/Examples/Python/src/Geometry.cpp index c1ded96e433..a50ff68efc6 100644 --- a/Examples/Python/src/Geometry.cpp +++ b/Examples/Python/src/Geometry.cpp @@ -7,6 +7,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "Acts/Definitions/Algebra.hpp" +#include "Acts/Detector/CuboidalContainerBuilder.hpp" #include "Acts/Detector/CylindricalContainerBuilder.hpp" #include "Acts/Detector/Detector.hpp" #include "Acts/Detector/DetectorBuilder.hpp" @@ -275,36 +276,61 @@ void addExperimentalGeometry(Context& ctx) { } { - using Range2D = Acts::RangeXD<2u, Acts::ActsScalar>; - using KdtSurfaces2D = Acts::Experimental::KdtSurfaces<2u, 100u>; - using KdtSurfacesProvider2D = + using RangeXDDim1 = Acts::RangeXD<1u, Acts::ActsScalar>; + using KdtSurfacesDim1Bin100 = Acts::Experimental::KdtSurfaces<1u, 100u>; + using KdtSurfacesProviderDim1Bin100 = + Acts::Experimental::KdtSurfacesProvider<1u, 100u>; + + py::class_(m, "RangeXDDim1") + .def(py::init([](const std::array& irange) { + RangeXDDim1 range; + range[0].shrink(irange[0], irange[1]); + return range; + })); + + py::class_>( + m, "KdtSurfacesDim1Bin100") + .def(py::init>&, + const std::array&>()) + .def("surfaces", py::overload_cast( + &KdtSurfacesDim1Bin100::surfaces, py::const_)); + + py::class_>( + m, "KdtSurfacesProviderDim1Bin100") + .def(py::init, const Extent&>()); + } + + { + using RangeXDDim2 = Acts::RangeXD<2u, Acts::ActsScalar>; + using KdtSurfacesDim2Bin100 = Acts::Experimental::KdtSurfaces<2u, 100u>; + using KdtSurfacesProviderDim2Bin100 = Acts::Experimental::KdtSurfacesProvider<2u, 100u>; - py::class_(m, "Range2D") + py::class_(m, "RangeXDDim2") .def(py::init([](const std::array& range0, const std::array& range1) { - Range2D range; + RangeXDDim2 range; range[0].shrink(range0[0], range0[1]); range[1].shrink(range1[0], range1[1]); return range; })); - py::class_>(m, - "KdtSurfaces2D") + py::class_>( + m, "KdtSurfacesDim2Bin100") .def(py::init>&, const std::array&>()) - .def("surfaces", [](KdtSurfaces2D& self, const Range2D& range) { - return self.surfaces(range); - }); + .def("surfaces", py::overload_cast( + &KdtSurfacesDim2Bin100::surfaces, py::const_)); - py::class_>(m, - "KdtSurfacesProvider2D") - .def(py::init( - [](std::shared_ptr kdt, const Extent& extent) { - return std::make_shared(kdt, extent); - })); + py::class_>( + m, "KdtSurfacesProviderDim2Bin100") + .def(py::init, const Extent&>()); } { @@ -445,6 +471,35 @@ void addExperimentalGeometry(Context& ctx) { ACTS_PYTHON_STRUCT_END(); } + { + // Cuboidal container builder + auto ccBuilder = + py::class_>( + m, "CuboidalContainerBuilder") + .def(py::init([](const CuboidalContainerBuilder::Config& config, + const std::string& name, + Acts::Logging::Level level) { + return std::make_shared( + config, getDefaultLogger(name, level)); + })) + .def("construct", &CuboidalContainerBuilder::construct); + + auto ccConfig = + py::class_(ccBuilder, "Config") + .def(py::init<>()); + + ACTS_PYTHON_STRUCT_BEGIN(ccConfig, CuboidalContainerBuilder::Config); + ACTS_PYTHON_MEMBER(builders); + ACTS_PYTHON_MEMBER(binning); + ACTS_PYTHON_MEMBER(rootVolumeFinderBuilder); + ACTS_PYTHON_MEMBER(geoIdGenerator); + ACTS_PYTHON_MEMBER(geoIdReverseGen); + ACTS_PYTHON_MEMBER(auxiliary); + ACTS_PYTHON_STRUCT_END(); + } + { // Detector builder auto dBuilder =