Skip to content

Commit

Permalink
feat: python bindings for telescope like detector (#3006)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
asalzburger and paulgessinger authored Mar 7, 2024
1 parent d455e02 commit 737ed7e
Showing 1 changed file with 72 additions and 17 deletions.
89 changes: 72 additions & 17 deletions Examples/Python/src/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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_<RangeXDDim1>(m, "RangeXDDim1")
.def(py::init([](const std::array<Acts::ActsScalar, 2u>& irange) {
RangeXDDim1 range;
range[0].shrink(irange[0], irange[1]);
return range;
}));

py::class_<KdtSurfacesDim1Bin100, std::shared_ptr<KdtSurfacesDim1Bin100>>(
m, "KdtSurfacesDim1Bin100")
.def(py::init<const GeometryContext&,
const std::vector<std::shared_ptr<Acts::Surface>>&,
const std::array<Acts::BinningValue, 1u>&>())
.def("surfaces", py::overload_cast<const RangeXDDim1&>(
&KdtSurfacesDim1Bin100::surfaces, py::const_));

py::class_<KdtSurfacesProviderDim1Bin100,
Acts::Experimental::ISurfacesProvider,
std::shared_ptr<KdtSurfacesProviderDim1Bin100>>(
m, "KdtSurfacesProviderDim1Bin100")
.def(py::init<std::shared_ptr<KdtSurfacesDim1Bin100>, 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_<Range2D>(m, "Range2D")
py::class_<RangeXDDim2>(m, "RangeXDDim2")
.def(py::init([](const std::array<Acts::ActsScalar, 2u>& range0,
const std::array<Acts::ActsScalar, 2u>& range1) {
Range2D range;
RangeXDDim2 range;
range[0].shrink(range0[0], range0[1]);
range[1].shrink(range1[0], range1[1]);
return range;
}));

py::class_<KdtSurfaces2D, std::shared_ptr<KdtSurfaces2D>>(m,
"KdtSurfaces2D")
py::class_<KdtSurfacesDim2Bin100, std::shared_ptr<KdtSurfacesDim2Bin100>>(
m, "KdtSurfacesDim2Bin100")
.def(py::init<const GeometryContext&,
const std::vector<std::shared_ptr<Acts::Surface>>&,
const std::array<Acts::BinningValue, 2u>&>())
.def("surfaces", [](KdtSurfaces2D& self, const Range2D& range) {
return self.surfaces(range);
});
.def("surfaces", py::overload_cast<const RangeXDDim2&>(
&KdtSurfacesDim2Bin100::surfaces, py::const_));

py::class_<KdtSurfacesProvider2D, Acts::Experimental::ISurfacesProvider,
std::shared_ptr<KdtSurfacesProvider2D>>(m,
"KdtSurfacesProvider2D")
.def(py::init(
[](std::shared_ptr<KdtSurfaces2D> kdt, const Extent& extent) {
return std::make_shared<KdtSurfacesProvider2D>(kdt, extent);
}));
py::class_<KdtSurfacesProviderDim2Bin100,
Acts::Experimental::ISurfacesProvider,
std::shared_ptr<KdtSurfacesProviderDim2Bin100>>(
m, "KdtSurfacesProviderDim2Bin100")
.def(py::init<std::shared_ptr<KdtSurfacesDim2Bin100>, const Extent&>());
}

{
Expand Down Expand Up @@ -445,6 +471,35 @@ void addExperimentalGeometry(Context& ctx) {
ACTS_PYTHON_STRUCT_END();
}

{
// Cuboidal container builder
auto ccBuilder =
py::class_<CuboidalContainerBuilder,
Acts::Experimental::IDetectorComponentBuilder,
std::shared_ptr<CuboidalContainerBuilder>>(
m, "CuboidalContainerBuilder")
.def(py::init([](const CuboidalContainerBuilder::Config& config,
const std::string& name,
Acts::Logging::Level level) {
return std::make_shared<CuboidalContainerBuilder>(
config, getDefaultLogger(name, level));
}))
.def("construct", &CuboidalContainerBuilder::construct);

auto ccConfig =
py::class_<CuboidalContainerBuilder::Config>(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 =
Expand Down

0 comments on commit 737ed7e

Please sign in to comment.