File indexing completed on 2025-01-18 09:12:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #include <GeoModelRead/ReadGeoModel.h>
0014
0015
0016 #include "Acts/Detector/CylindricalContainerBuilder.hpp"
0017 #include "Acts/Plugins/GeoModel/GeoModelBlueprintCreater.hpp"
0018 #include "Acts/Plugins/GeoModel/GeoModelConverters.hpp"
0019 #include "Acts/Plugins/GeoModel/GeoModelDetectorElement.hpp"
0020 #include "Acts/Plugins/GeoModel/GeoModelDetectorElementITk.hpp"
0021 #include "Acts/Plugins/GeoModel/GeoModelDetectorObjectFactory.hpp"
0022 #include "Acts/Plugins/GeoModel/GeoModelReader.hpp"
0023 #include "Acts/Plugins/GeoModel/GeoModelTree.hpp"
0024 #include "Acts/Plugins/GeoModel/IGeoShapeConverter.hpp"
0025 #include "Acts/Plugins/Python/Utilities.hpp"
0026 #include "Acts/Surfaces/AnnulusBounds.hpp"
0027 #include "Acts/Surfaces/DiscSurface.hpp"
0028 #include "Acts/Surfaces/PlaneSurface.hpp"
0029 #include "Acts/Surfaces/RectangleBounds.hpp"
0030 #include "ActsExamples/GeoModelDetector/GeoModelDetector.hpp"
0031 #include "ActsExamples/ITkModuleSplitting/ITkModuleSplitting.hpp"
0032
0033 #include <string>
0034
0035 #include <GeoModelKernel/GeoFullPhysVol.h>
0036 #include <GeoModelKernel/GeoVPhysVol.h>
0037 #include <pybind11/pybind11.h>
0038 #include <pybind11/stl.h>
0039
0040 namespace py = pybind11;
0041 using namespace pybind11::literals;
0042
0043 namespace Acts::Python {
0044
0045 void addGeoModel(Context& ctx) {
0046 auto m = ctx.get("main");
0047
0048 auto gm = m.def_submodule("geomodel");
0049
0050 py::class_<Acts::GeoModelTree>(gm, "GeoModelTree").def(py::init<>());
0051
0052 gm.def("readFromDb", &Acts::GeoModelReader::readFromDb);
0053
0054 py::class_<Acts::GeoModelDetectorElement,
0055 std::shared_ptr<Acts::GeoModelDetectorElement>>(
0056 gm, "GeoModelDetectorElement")
0057 .def("logVolName", &Acts::GeoModelDetectorElement::logVolName)
0058 .def("databaseEntryName",
0059 &Acts::GeoModelDetectorElement::databaseEntryName)
0060 .def("surface", [](Acts::GeoModelDetectorElement self) {
0061 return self.surface().getSharedPtr();
0062 });
0063
0064 {
0065 auto f =
0066 py::class_<ActsExamples::GeoModelDetector, ActsExamples::Detector,
0067 std::shared_ptr<ActsExamples::GeoModelDetector>>(
0068 gm, "GeoModelDetector")
0069 .def(py::init<const ActsExamples::GeoModelDetector::Config&>());
0070
0071 auto c = py::class_<ActsExamples::GeoModelDetector::Config>(f, "Config")
0072 .def(py::init<>());
0073 ACTS_PYTHON_STRUCT_BEGIN(c, ActsExamples::GeoModelDetector::Config);
0074 ACTS_PYTHON_MEMBER(path);
0075 ACTS_PYTHON_MEMBER(logLevel);
0076 ACTS_PYTHON_STRUCT_END();
0077 }
0078
0079
0080 {
0081 py::class_<Acts::IGeoShapeConverter,
0082 std::shared_ptr<Acts::IGeoShapeConverter>>(gm,
0083 "IGeoShapeConverter");
0084
0085 py::class_<Acts::GeoBoxConverter, Acts::IGeoShapeConverter,
0086 std::shared_ptr<Acts::GeoBoxConverter>>(gm, "GeoBoxConverter")
0087 .def(py::init<>())
0088 .def("toSensitiveSurface", &Acts::GeoBoxConverter::toSensitiveSurface)
0089 .def("toPassiveSurface", &Acts::GeoBoxConverter::toPassiveSurface);
0090
0091 py::class_<Acts::GeoTrdConverter, Acts::IGeoShapeConverter,
0092 std::shared_ptr<Acts::GeoTrdConverter>>(gm, "GeoTrdConverter")
0093 .def(py::init<>())
0094 .def("toSensitiveSurface", &Acts::GeoTrdConverter::toSensitiveSurface)
0095 .def("toPassiveSurface", &Acts::GeoTrdConverter::toPassiveSurface);
0096
0097 py::class_<Acts::GeoTubeConverter, Acts::IGeoShapeConverter,
0098 std::shared_ptr<Acts::GeoTubeConverter>>(gm, "GeoTubeConverter")
0099 .def(py::init<>())
0100 .def("toSensitiveSurface", &Acts::GeoTubeConverter::toSensitiveSurface)
0101 .def("toPassiveSurface", &Acts::GeoTubeConverter::toPassiveSurface);
0102
0103 py::class_<Acts::GeoUnionDoubleTrdConverter, Acts::IGeoShapeConverter,
0104 std::shared_ptr<Acts::GeoUnionDoubleTrdConverter>>(
0105 gm, "GeoUnionDoubleTrdConverter")
0106 .def(py::init<>())
0107 .def("toSensitiveSurface",
0108 &Acts::GeoUnionDoubleTrdConverter::toSensitiveSurface)
0109 .def("toPassiveSurface",
0110 &Acts::GeoUnionDoubleTrdConverter::toPassiveSurface);
0111
0112 py::class_<Acts::GeoIntersectionAnnulusConverter, Acts::IGeoShapeConverter,
0113 std::shared_ptr<Acts::GeoIntersectionAnnulusConverter>>(
0114 gm, "GeoIntersectionAnnulusConverter")
0115 .def(py::init<>())
0116 .def("toSensitiveSurface",
0117 &Acts::GeoIntersectionAnnulusConverter::toSensitiveSurface)
0118 .def("toPassiveSurface",
0119 &Acts::GeoIntersectionAnnulusConverter::toPassiveSurface);
0120
0121 py::class_<Acts::GeoShiftConverter, Acts::IGeoShapeConverter,
0122 std::shared_ptr<Acts::GeoShiftConverter>>(gm,
0123 "GeoShiftConverter")
0124 .def(py::init<>())
0125 .def("toSensitiveSurface", &Acts::GeoShiftConverter::toSensitiveSurface)
0126 .def("toPassiveSurface", &Acts::GeoShiftConverter::toPassiveSurface);
0127 }
0128
0129
0130 {
0131 auto a =
0132 py::class_<Acts::GeoModelDetectorObjectFactory,
0133 std::shared_ptr<Acts::GeoModelDetectorObjectFactory>>(
0134 gm, "GeoModelDetectorObjectFactory")
0135 .def(py::init(
0136 [](const Acts::GeoModelDetectorObjectFactory::Config& cfg,
0137 Acts::Logging::Level level) {
0138 return std::make_shared<Acts::GeoModelDetectorObjectFactory>(
0139 cfg, Acts::getDefaultLogger(
0140 "GeoModelDetectorObjectFactory", level));
0141 }))
0142 .def("construct", &Acts::GeoModelDetectorObjectFactory::construct);
0143
0144 py::class_<Acts::GeoModelDetectorObjectFactory::Config>(a, "Config")
0145 .def(py::init<>())
0146 .def_readwrite(
0147 "convertSubVolumes",
0148 &Acts::GeoModelDetectorObjectFactory::Config::convertSubVolumes)
0149 .def_readwrite("nameList",
0150 &Acts::GeoModelDetectorObjectFactory::Config::nameList)
0151 .def_readwrite("convertBox",
0152 &Acts::GeoModelDetectorObjectFactory::Config::convertBox)
0153 .def_readwrite(
0154 "materialList",
0155 &Acts::GeoModelDetectorObjectFactory::Config::materialList);
0156
0157 py::class_<Acts::GeoModelDetectorObjectFactory::Cache>(a, "Cache")
0158 .def(py::init<>())
0159 .def_readwrite(
0160 "sensitiveSurfaces",
0161 &Acts::GeoModelDetectorObjectFactory::Cache::sensitiveSurfaces)
0162 .def_readwrite(
0163 "boundingBoxes",
0164 &Acts::GeoModelDetectorObjectFactory::Cache::boundingBoxes);
0165
0166 py::class_<Acts::GeoModelDetectorObjectFactory::Options>(a, "Options")
0167 .def(py::init<>())
0168 .def_readwrite("queries",
0169 &Acts::GeoModelDetectorObjectFactory::Options::queries);
0170 }
0171
0172 {
0173 py::class_<Acts::GeoModelBlueprintCreater::Blueprint,
0174 std::shared_ptr<Acts::GeoModelBlueprintCreater::Blueprint>>(
0175 gm, "Blueprint")
0176 .def("convertToBuilder",
0177 [](Acts::GeoModelBlueprintCreater::Blueprint& self,
0178 Acts::Logging::Level level) {
0179
0180 return std::make_shared<
0181 Acts::Experimental::CylindricalContainerBuilder>(self.node(),
0182 level);
0183 });
0184
0185 auto bpc =
0186 py::class_<Acts::GeoModelBlueprintCreater,
0187 std::shared_ptr<Acts::GeoModelBlueprintCreater>>(
0188 gm, "GeoModelBlueprintCreater")
0189 .def(py::init([](const Acts::GeoModelBlueprintCreater::Config& cfg,
0190 Acts::Logging::Level level) {
0191 return std::make_shared<Acts::GeoModelBlueprintCreater>(
0192 cfg,
0193 Acts::getDefaultLogger("GeoModelBlueprintCreater", level));
0194 }))
0195 .def("create", &Acts::GeoModelBlueprintCreater::create);
0196
0197 py::class_<Acts::GeoModelBlueprintCreater::Config>(bpc, "Config")
0198 .def(py::init<>())
0199 .def_readwrite(
0200 "detectorSurfaces",
0201 &Acts::GeoModelBlueprintCreater::Config::detectorSurfaces)
0202 .def_readwrite("kdtBinning",
0203 &Acts::GeoModelBlueprintCreater::Config::kdtBinning);
0204
0205 py::class_<Acts::GeoModelBlueprintCreater::Options>(bpc, "Options")
0206 .def(py::init<>())
0207 .def_readwrite("topEntry",
0208 &Acts::GeoModelBlueprintCreater::Options::topEntry)
0209 .def_readwrite(
0210 "topBoundsOverride",
0211 &Acts::GeoModelBlueprintCreater::Options::topBoundsOverride)
0212 .def_readwrite("table", &Acts::GeoModelBlueprintCreater::Options::table)
0213 .def_readwrite("dotGraph",
0214 &Acts::GeoModelBlueprintCreater::Options::dotGraph);
0215 }
0216
0217 gm.def(
0218 "splitBarrelModule",
0219 [](const Acts::GeometryContext& gctx,
0220 std::shared_ptr<const GeoModelDetectorElement> detElement,
0221 unsigned nSegments, Acts::Logging::Level logLevel) {
0222 auto logger = Acts::getDefaultLogger("ITkSlitBarrel", logLevel);
0223 auto name = detElement->databaseEntryName();
0224
0225 auto factory = [&](const auto& trafo, const auto& bounds) {
0226 return Acts::GeoModelDetectorElement::createDetectorElement<
0227 Acts::PlaneSurface, Acts::RectangleBounds>(
0228 detElement->physicalVolume(), bounds, trafo,
0229 detElement->thickness());
0230 };
0231
0232 return ActsExamples::ITk::splitBarrelModule(gctx, detElement, nSegments,
0233 factory, name, *logger);
0234 },
0235 "gxtx"_a, "detElement"_a, "nSegments"_a,
0236 "logLevel"_a = Acts::Logging::INFO);
0237
0238 gm.def(
0239 "splitDiscModule",
0240 [](const Acts::GeometryContext& gctx,
0241 std::shared_ptr<const GeoModelDetectorElement> detElement,
0242 const std::vector<std::pair<double, double>>& patterns,
0243 Acts::Logging::Level logLevel) {
0244 auto logger = Acts::getDefaultLogger("ITkSlitBarrel", logLevel);
0245 auto name = detElement->databaseEntryName();
0246
0247 auto factory = [&](const auto& trafo, const auto& bounds) {
0248 return Acts::GeoModelDetectorElement::createDetectorElement<
0249 Acts::DiscSurface, Acts::AnnulusBounds>(
0250 detElement->physicalVolume(), bounds, trafo,
0251 detElement->thickness());
0252 };
0253
0254 return ActsExamples::ITk::splitDiscModule(gctx, detElement, patterns,
0255 factory, name, *logger);
0256 },
0257 "gxtx"_a, "detElement"_a, "splitRanges"_a,
0258 "logLevel"_a = Acts::Logging::INFO);
0259
0260 py::class_<Acts::GeoModelDetectorElementITk,
0261 std::shared_ptr<Acts::GeoModelDetectorElementITk>>(
0262 gm, "GeoModelDetectorElementITk")
0263 .def("surface", [](Acts::GeoModelDetectorElementITk& self) {
0264 return self.surface().getSharedPtr();
0265 });
0266 gm.def("convertToItk", &GeoModelDetectorElementITk::convertFromGeomodel);
0267 }
0268
0269 }