diff --git a/Core/include/Acts/Geometry/CylinderVolumeBounds.hpp b/Core/include/Acts/Geometry/CylinderVolumeBounds.hpp index c92e001fa9f..1951d96b2da 100644 --- a/Core/include/Acts/Geometry/CylinderVolumeBounds.hpp +++ b/Core/include/Acts/Geometry/CylinderVolumeBounds.hpp @@ -9,6 +9,7 @@ #pragma once #include "Acts/Definitions/Algebra.hpp" +#include "Acts/Geometry/BoundarySurfaceFace.hpp" #include "Acts/Geometry/Volume.hpp" #include "Acts/Geometry/VolumeBounds.hpp" #include "Acts/Utilities/BinningType.hpp" @@ -80,6 +81,18 @@ class CylinderVolumeBounds : public VolumeBounds { eSize }; + /// Enum describing the possible faces of a cylinder volume + /// @note These values are synchronized with the BoundarySurfaceFace enum. + /// Once Gen1 is removed, this can be changed. + enum class Face : unsigned int { + PositiveDisc = BoundarySurfaceFace::positiveFaceXY, + NegativeDisc = BoundarySurfaceFace::negativeFaceXY, + OuterCylinder = BoundarySurfaceFace::tubeOuterCover, + InnerCylinder = BoundarySurfaceFace::tubeInnerCover, + NegativePhiPlane = BoundarySurfaceFace::tubeSectorNegativePhi, + PositivePhiPlane = BoundarySurfaceFace::tubeSectorPositivePhi + }; + CylinderVolumeBounds() = delete; /// Constructor diff --git a/Core/include/Acts/Geometry/PortalShell.hpp b/Core/include/Acts/Geometry/PortalShell.hpp index 39e60b8774b..7405a64ad0a 100644 --- a/Core/include/Acts/Geometry/PortalShell.hpp +++ b/Core/include/Acts/Geometry/PortalShell.hpp @@ -8,7 +8,7 @@ #pragma once -#include "Acts/Geometry/BoundarySurfaceFace.hpp" +#include "Acts/Geometry/CylinderVolumeBounds.hpp" #include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Logger.hpp" @@ -68,19 +68,9 @@ class PortalShellBase { /// volumes class CylinderPortalShell : public PortalShellBase { public: - /// Enum describing the possible faces of a cylinder portal shell - /// @note These values are synchronized with the BoundarySurfaceFace enum. - /// Once Gen1 is removed, this can be changed. - enum class Face : unsigned int { - PositiveDisc = BoundarySurfaceFace::positiveFaceXY, - NegativeDisc = BoundarySurfaceFace::negativeFaceXY, - OuterCylinder = BoundarySurfaceFace::tubeOuterCover, - InnerCylinder = BoundarySurfaceFace::tubeInnerCover, - NegativePhiPlane = BoundarySurfaceFace::tubeSectorNegativePhi, - PositivePhiPlane = BoundarySurfaceFace::tubeSectorPositivePhi - }; - - using enum Face; + using Face = CylinderVolumeBounds::Face; + + using enum CylinderVolumeBounds::Face; /// Retrieve the portal associated to the given face. Can be nullptr if unset. /// @param face The face to retrieve the portal for diff --git a/Core/src/Geometry/PortalShell.cpp b/Core/src/Geometry/PortalShell.cpp index 59c83c1529f..b9baf403812 100644 --- a/Core/src/Geometry/PortalShell.cpp +++ b/Core/src/Geometry/PortalShell.cpp @@ -367,7 +367,7 @@ std::string CylinderStackPortalShell::label() const { std::ostream& operator<<(std::ostream& os, CylinderPortalShell::Face face) { switch (face) { - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; case PositiveDisc: return os << "PositiveDisc"; case NegativeDisc: diff --git a/Examples/Python/src/Base.cpp b/Examples/Python/src/Base.cpp index 4d5eec557bd..cc8a5f67dc1 100644 --- a/Examples/Python/src/Base.cpp +++ b/Examples/Python/src/Base.cpp @@ -364,12 +364,16 @@ void addBinning(Context& ctx) { .value("binY", Acts::BinningValue::binY) .value("binZ", Acts::BinningValue::binZ) .value("binR", Acts::BinningValue::binR) - .value("binPhi", Acts::BinningValue::binPhi); + .value("binPhi", Acts::BinningValue::binPhi) + .value("binRPhi", Acts::BinningValue::binRPhi) + .value("binH", Acts::BinningValue::binH) + .value("binEta", Acts::BinningValue::binEta) + .value("binMag", Acts::BinningValue::binMag); auto boundaryType = py::enum_(m, "AxisBoundaryType") - .value("bound", Acts::AxisBoundaryType::Bound) - .value("closed", Acts::AxisBoundaryType::Closed) - .value("open", Acts::AxisBoundaryType::Open); + .value("Bound", Acts::AxisBoundaryType::Bound) + .value("Closed", Acts::AxisBoundaryType::Closed) + .value("Open", Acts::AxisBoundaryType::Open); auto axisType = py::enum_(m, "AxisType") .value("equidistant", Acts::AxisType::Equidistant) diff --git a/Examples/Python/src/Geometry.cpp b/Examples/Python/src/Geometry.cpp index 8ec8ed97ef1..d676dbe6243 100644 --- a/Examples/Python/src/Geometry.cpp +++ b/Examples/Python/src/Geometry.cpp @@ -25,6 +25,7 @@ #include "Acts/Detector/interface/IInternalStructureBuilder.hpp" #include "Acts/Detector/interface/IRootVolumeFinderBuilder.hpp" #include "Acts/Geometry/CylinderVolumeBounds.hpp" +#include "Acts/Geometry/CylinderVolumeStack.hpp" #include "Acts/Geometry/Extent.hpp" #include "Acts/Geometry/GeometryContext.hpp" #include "Acts/Geometry/GeometryHierarchyMap.hpp" @@ -36,6 +37,7 @@ #include "Acts/Plugins/Python/Utilities.hpp" #include "Acts/Surfaces/Surface.hpp" #include "Acts/Surfaces/SurfaceArray.hpp" +#include "Acts/Utilities/BinningType.hpp" #include "Acts/Utilities/Helpers.hpp" #include "Acts/Utilities/RangeXD.hpp" #include "Acts/Visualization/ViewConfig.hpp" @@ -46,6 +48,7 @@ #include #include +#include #include #include @@ -106,7 +109,12 @@ void addGeometry(Context& ctx) { .def("approach", &Acts::GeometryIdentifier::approach) .def("sensitive", &Acts::GeometryIdentifier::sensitive) .def("extra", &Acts::GeometryIdentifier::extra) - .def("value", &Acts::GeometryIdentifier::value); + .def("value", &Acts::GeometryIdentifier::value) + .def("__str__", [](const Acts::GeometryIdentifier& self) { + std::stringstream ss; + ss << self; + return ss.str(); + }); } { @@ -178,15 +186,31 @@ void addGeometry(Context& ctx) { { py::class_>( - m, "VolumeBounds"); - - py::class_, Acts::VolumeBounds>( - m, "CylinderVolumeBounds") - .def(py::init(), - "rmin"_a, "rmax"_a, "halfz"_a, "halfphi"_a = M_PI, "avgphi"_a = 0., - "bevelMinZ"_a = 0., "bevelMaxZ"_a = 0.); + m, "VolumeBounds") + .def("type", &Acts::VolumeBounds::type) + .def("__str__", [](const Acts::VolumeBounds& self) { + std::stringstream ss; + ss << self; + return ss.str(); + }); + + auto cvb = + py::class_, + Acts::VolumeBounds>(m, "CylinderVolumeBounds") + .def(py::init(), + "rmin"_a, "rmax"_a, "halfz"_a, "halfphi"_a = M_PI, + "avgphi"_a = 0., "bevelMinZ"_a = 0., "bevelMaxZ"_a = 0.); + + py::enum_(cvb, "Face") + .value("PositiveDisc", CylinderVolumeBounds::Face::PositiveDisc) + .value("NegativeDisc", CylinderVolumeBounds::Face::NegativeDisc) + .value("OuterCylinder", CylinderVolumeBounds::Face::OuterCylinder) + .value("InnerCylinder", CylinderVolumeBounds::Face::InnerCylinder) + .value("NegativePhiPlane", CylinderVolumeBounds::Face::NegativePhiPlane) + .value("PositivePhiPlane", + CylinderVolumeBounds::Face::PositivePhiPlane); } { @@ -209,22 +233,72 @@ void addGeometry(Context& ctx) { })); } + py::class_(m, "ExtentEnvelope") + .def(py::init<>()) + .def(py::init()) + .def(py::init([](Envelope x, Envelope y, Envelope z, Envelope r, + Envelope phi, Envelope rPhi, Envelope h, Envelope eta, + Envelope mag) { + return ExtentEnvelope({.x = x, + .y = y, + .z = z, + .r = r, + .phi = phi, + .rPhi = rPhi, + .h = h, + .eta = eta, + .mag = mag}); + }), + py::arg("x") = zeroEnvelope, py::arg("y") = zeroEnvelope, + py::arg("z") = zeroEnvelope, py::arg("r") = zeroEnvelope, + py::arg("phi") = zeroEnvelope, py::arg("rPhi") = zeroEnvelope, + py::arg("h") = zeroEnvelope, py::arg("eta") = zeroEnvelope, + py::arg("mag") = zeroEnvelope) + .def_static("Zero", &ExtentEnvelope::Zero) + .def("__getitem__", [](ExtentEnvelope& self, + BinningValue bValue) { return self[bValue]; }) + .def("__setitem__", [](ExtentEnvelope& self, BinningValue bValue, + const Envelope& value) { self[bValue] = value; }) + .def("__str__", [](const ExtentEnvelope& self) { + std::array values; + + std::stringstream ss; + for (BinningValue val : allBinningValues()) { + ss << val << "=(" << self[val][0] << ", " << self[val][1] << ")"; + values.at(toUnderlying(val)) = ss.str(); + ss.str(""); + } + + ss.str(""); + ss << "ExtentEnvelope("; + ss << boost::algorithm::join(values, ", "); + ss << ")"; + return ss.str(); + }); + + py::class_(m, "Extent") + .def(py::init(), + py::arg("envelope") = ExtentEnvelope::Zero()) + .def("range", + [](const Acts::Extent& self, + Acts::BinningValue bval) -> std::array { + return {self.min(bval), self.max(bval)}; + }) + .def("__str__", &Extent::toString); + { - py::class_(m, "Extent") - .def(py::init( - [](const std::vector>>& - franges) { - Acts::Extent extent; - for (const auto& [bval, frange] : franges) { - extent.set(bval, frange[0], frange[1]); - } - return extent; - })) - .def("range", [](const Acts::Extent& self, Acts::BinningValue bval) { - return std::array{self.min(bval), - self.max(bval)}; - }); + auto cylStack = py::class_(m, "CylinderVolumeStack"); + + py::enum_(cylStack, + "AttachmentStrategy") + .value("Gap", CylinderVolumeStack::AttachmentStrategy::Gap) + .value("First", CylinderVolumeStack::AttachmentStrategy::First) + .value("Second", CylinderVolumeStack::AttachmentStrategy::Second) + .value("Midpoint", CylinderVolumeStack::AttachmentStrategy::Midpoint); + + py::enum_(cylStack, "ResizeStrategy") + .value("Gap", CylinderVolumeStack::ResizeStrategy::Gap) + .value("Expand", CylinderVolumeStack::ResizeStrategy::Expand); } } @@ -307,10 +381,15 @@ void addExperimentalGeometry(Context& ctx) { // Be able to construct a proto binning py::class_(m, "ProtoBinning") .def(py::init&, std::size_t>()) + const std::vector&, std::size_t>(), + "bValue"_a, "bType"_a, "e"_a, "exp"_a = 0u) .def(py::init()); + std::size_t>(), + "bValue"_a, "bType"_a, "minE"_a, "maxE"_a, "nbins"_a, "exp"_a = 0u) + .def(py::init(), + "bValue"_a, "bType"_a, "nbins"_a, "exp"_a = 0u); } { diff --git a/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp b/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp index 4c44617524a..15c5a9c7953 100644 --- a/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp +++ b/Tests/UnitTests/Core/Geometry/PortalShellTests.cpp @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(ConstructionFromVolume) { SingleCylinderPortalShell shell1{cyl1}; BOOST_CHECK_EQUAL(shell1.size(), 4); - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; const auto* pDisc = shell1.portal(PositiveDisc); BOOST_REQUIRE_NE(pDisc, nullptr); @@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(ConstructionFromVolume) { // inner cylinder BOOST_AUTO_TEST_CASE(PortalAssignment) { - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; TrackingVolume vol( Transform3::Identity(), std::make_shared(30_mm, 100_mm, 100_mm)); @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(PortalAssignment) { BOOST_AUTO_TEST_SUITE(CylinderStack) BOOST_AUTO_TEST_CASE(ZDirection) { - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; BOOST_TEST_CONTEXT("rMin>0") { TrackingVolume vol1( Transform3{Translation3{Vector3::UnitZ() * -100_mm}}, @@ -447,7 +447,7 @@ BOOST_AUTO_TEST_CASE(ZDirection) { } BOOST_AUTO_TEST_CASE(RDirection) { - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; BOOST_TEST_CONTEXT("rMin>0") { TrackingVolume vol1( Transform3::Identity(), @@ -610,7 +610,7 @@ BOOST_AUTO_TEST_CASE(NestedStacks) { gctx, {&stack, &shell3}, BinningValue::binZ, *logger}; BOOST_CHECK(stack2.isValid()); - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; auto lookup = [](auto& shell, CylinderPortalShell::Face face, Vector3 position, @@ -726,7 +726,7 @@ BOOST_AUTO_TEST_CASE(ConnectOuter) { SingleCylinderPortalShell shell{cyl1}; - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; BOOST_CHECK_EQUAL( shell.portal(OuterCylinder)->getLink(Direction::AlongNormal), nullptr); BOOST_CHECK_EQUAL( @@ -749,7 +749,7 @@ BOOST_AUTO_TEST_CASE(ConnectOuter) { } BOOST_AUTO_TEST_CASE(RegisterInto) { - using enum CylinderPortalShell::Face; + using enum CylinderVolumeBounds::Face; TrackingVolume vol1( Transform3::Identity(), std::make_shared(0_mm, 100_mm, 100_mm));