File indexing completed on 2025-10-30 07:54:43
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/Geometry/ITrackingGeometryBuilder.hpp"
0018 #include "Acts/Surfaces/AnnulusBounds.hpp"
0019 #include "Acts/Surfaces/DiscSurface.hpp"
0020 #include "Acts/Surfaces/PlaneSurface.hpp"
0021 #include "Acts/Surfaces/RectangleBounds.hpp"
0022 #include "ActsExamples/GeoModelDetector/GeoModelDetector.hpp"
0023 #include "ActsExamples/GeoModelDetector/GeoModelMuonMockupBuilder.hpp"
0024 #include "ActsExamples/ITkModuleSplitting/ITkModuleSplitting.hpp"
0025 #include "ActsExamples/MuonSpectrometerMockupDetector/GeoMuonMockupExperiment.hpp"
0026 #include "ActsPlugins/GeoModel/GeoModelBlueprintCreater.hpp"
0027 #include "ActsPlugins/GeoModel/GeoModelConverters.hpp"
0028 #include "ActsPlugins/GeoModel/GeoModelDetectorElement.hpp"
0029 #include "ActsPlugins/GeoModel/GeoModelDetectorElementITk.hpp"
0030 #include "ActsPlugins/GeoModel/GeoModelDetectorObjectFactory.hpp"
0031 #include "ActsPlugins/GeoModel/GeoModelReader.hpp"
0032 #include "ActsPlugins/GeoModel/GeoModelTree.hpp"
0033 #include "ActsPlugins/GeoModel/IGeoShapeConverter.hpp"
0034 #include "ActsPython/Utilities/Helpers.hpp"
0035 #include "ActsPython/Utilities/Macros.hpp"
0036
0037 #include <string>
0038
0039 #include <GeoModelKernel/GeoFullPhysVol.h>
0040 #include <GeoModelKernel/GeoVPhysVol.h>
0041 #include <pybind11/pybind11.h>
0042 #include <pybind11/stl.h>
0043
0044 namespace py = pybind11;
0045 using namespace pybind11::literals;
0046
0047 using namespace Acts;
0048 using namespace ActsPlugins;
0049 using namespace ActsExamples;
0050
0051 namespace ActsPython {
0052
0053 void addGeoModel(Context& ctx) {
0054 auto m = ctx.get("main");
0055
0056 auto gm = m.def_submodule("geomodel");
0057
0058 py::class_<GeoModelTree::FpvConstLink>(gm, "GeoModelTree::FpvConstLink")
0059 .def(py::init<>())
0060 .def("get", &GeoModelTree::FpvConstLink::get,
0061 py::return_value_policy::reference);
0062
0063 py::class_<GeoModelTree>(gm, "GeoModelTree").def(py::init<>());
0064
0065 gm.def("readFromDb", &GeoModelReader::readFromDb);
0066
0067 py::class_<GeoModelDetectorElement, std::shared_ptr<GeoModelDetectorElement>>(
0068 gm, "GeoModelDetectorElement")
0069 .def("logVolName", &GeoModelDetectorElement::logVolName)
0070 .def("databaseEntryName", &GeoModelDetectorElement::databaseEntryName)
0071 .def("surface", [](GeoModelDetectorElement self) {
0072 return self.surface().getSharedPtr();
0073 });
0074
0075 {
0076 auto f =
0077 py::class_<GeoModelDetector, Detector,
0078 std::shared_ptr<GeoModelDetector>>(gm, "GeoModelDetector")
0079 .def(py::init<const GeoModelDetector::Config&>())
0080 .def("buildTrackingGeometry",
0081 &GeoModelDetector::buildTrackingGeometry);
0082
0083 auto c =
0084 py::class_<GeoModelDetector::Config>(f, "Config").def(py::init<>());
0085 ACTS_PYTHON_STRUCT(c, geoModelTree, logLevel, path);
0086
0087
0088 patchKwargsConstructor(c);
0089 }
0090 {
0091
0092 py::class_<ITrackingGeometryBuilder,
0093 std::shared_ptr<ITrackingGeometryBuilder>>(
0094 gm, "ITrackingGeometryBuilder");
0095 auto gmMuonBuilder =
0096 py::class_<GeoModelMuonMockupBuilder, ITrackingGeometryBuilder,
0097 std::shared_ptr<GeoModelMuonMockupBuilder>>(
0098 gm, "GeoModelMuonMockupBuilder")
0099 .def(py::init([](const GeoModelMuonMockupBuilder::Config& config,
0100 const std::string& name, Logging::Level level) {
0101 return std::make_shared<GeoModelMuonMockupBuilder>(
0102 config, getDefaultLogger(name, level));
0103 }))
0104 .def("trackingGeometry",
0105 &GeoModelMuonMockupBuilder::trackingGeometry);
0106 auto gmMuonConfig =
0107 py::class_<GeoModelMuonMockupBuilder::Config>(gmMuonBuilder, "Config")
0108 .def(py::init<>());
0109 ACTS_PYTHON_STRUCT(gmMuonConfig, volumeBoxFPVs, stationNames,
0110 volumeBoundFactory);
0111 }
0112
0113
0114 {
0115 py::class_<IGeoShapeConverter, std::shared_ptr<IGeoShapeConverter>>(
0116 gm, "IGeoShapeConverter");
0117
0118 py::class_<GeoBoxConverter, IGeoShapeConverter,
0119 std::shared_ptr<GeoBoxConverter>>(gm, "GeoBoxConverter")
0120 .def(py::init<>())
0121 .def("toSensitiveSurface", &GeoBoxConverter::toSensitiveSurface)
0122 .def("toPassiveSurface", &GeoBoxConverter::toPassiveSurface);
0123
0124 py::class_<GeoTrdConverter, IGeoShapeConverter,
0125 std::shared_ptr<GeoTrdConverter>>(gm, "GeoTrdConverter")
0126 .def(py::init<>())
0127 .def("toSensitiveSurface", &GeoTrdConverter::toSensitiveSurface)
0128 .def("toPassiveSurface", &GeoTrdConverter::toPassiveSurface);
0129
0130 py::class_<GeoTubeConverter, IGeoShapeConverter,
0131 std::shared_ptr<GeoTubeConverter>>(gm, "GeoTubeConverter")
0132 .def(py::init<>())
0133 .def("toSensitiveSurface", &GeoTubeConverter::toSensitiveSurface)
0134 .def("toPassiveSurface", &GeoTubeConverter::toPassiveSurface);
0135
0136 py::class_<GeoUnionDoubleTrdConverter, IGeoShapeConverter,
0137 std::shared_ptr<GeoUnionDoubleTrdConverter>>(
0138 gm, "GeoUnionDoubleTrdConverter")
0139 .def(py::init<>())
0140 .def("toSensitiveSurface",
0141 &GeoUnionDoubleTrdConverter::toSensitiveSurface)
0142 .def("toPassiveSurface", &GeoUnionDoubleTrdConverter::toPassiveSurface);
0143
0144 py::class_<GeoIntersectionAnnulusConverter, IGeoShapeConverter,
0145 std::shared_ptr<GeoIntersectionAnnulusConverter>>(
0146 gm, "GeoIntersectionAnnulusConverter")
0147 .def(py::init<>())
0148 .def("toSensitiveSurface",
0149 &GeoIntersectionAnnulusConverter::toSensitiveSurface)
0150 .def("toPassiveSurface",
0151 &GeoIntersectionAnnulusConverter::toPassiveSurface);
0152
0153 py::class_<GeoShiftConverter, IGeoShapeConverter,
0154 std::shared_ptr<GeoShiftConverter>>(gm, "GeoShiftConverter")
0155 .def(py::init<>())
0156 .def("toSensitiveSurface", &GeoShiftConverter::toSensitiveSurface)
0157 .def("toPassiveSurface", &GeoShiftConverter::toPassiveSurface);
0158 }
0159 {
0160
0161 auto f =
0162 py::class_<GeoMuonMockupExperiment,
0163 std::shared_ptr<GeoMuonMockupExperiment>>(
0164 gm, "GeoMuonMockupExperiment")
0165 .def(py::init([](const GeoMuonMockupExperiment::Config& config,
0166 const std::string& name, Logging::Level level) {
0167 return std::make_shared<GeoMuonMockupExperiment>(
0168 config, getDefaultLogger(name, level));
0169 }))
0170 .def("constructMS", &GeoMuonMockupExperiment::constructMS);
0171 auto c = py::class_<GeoMuonMockupExperiment::Config>(f, "Config")
0172 .def(py::init<>());
0173 ACTS_PYTHON_STRUCT(c,
0174
0175 dumpTree, dbName,
0176
0177 innerTubeRadius, tubeWallThickness, nTubeLayers, nTubes,
0178 mdtFoamThickness, multiLayerSeparation,
0179
0180 nRpcGasGaps, nRpcAlongZ, nRpcAlongPhi,
0181
0182 barrelRadii, nSectors, nEtaStations, stationDistInZ,
0183 stationDistInR, endCapWheelLowR, bigWheelDistZ,
0184 buildEndcaps, nInnerMultiplets, nInnerGasGapsPerMl);
0185 }
0186
0187 {
0188 auto a =
0189 py::class_<GeoModelDetectorObjectFactory,
0190 std::shared_ptr<GeoModelDetectorObjectFactory>>(
0191 gm, "GeoModelDetectorObjectFactory")
0192 .def(py::init([](const GeoModelDetectorObjectFactory::Config& cfg,
0193 Logging::Level level) {
0194 return std::make_shared<GeoModelDetectorObjectFactory>(
0195 cfg,
0196 getDefaultLogger("GeoModelDetectorObjectFactory", level));
0197 }))
0198 .def("construct", &GeoModelDetectorObjectFactory::construct);
0199
0200 py::class_<GeoModelDetectorObjectFactory::Config>(a, "Config")
0201 .def(py::init<>())
0202 .def_readwrite(
0203 "convertSubVolumes",
0204 &GeoModelDetectorObjectFactory::Config::convertSubVolumes)
0205 .def_readwrite("nameList",
0206 &GeoModelDetectorObjectFactory::Config::nameList)
0207 .def_readwrite("convertBox",
0208 &GeoModelDetectorObjectFactory::Config::convertBox)
0209 .def_readwrite("materialList",
0210 &GeoModelDetectorObjectFactory::Config::materialList);
0211
0212 auto convVol = py::class_<GeoModelDetectorObjectFactory::ConvertedGeoVol>(
0213 a, "ConvertedGeoVol");
0214
0215 ACTS_PYTHON_STRUCT(convVol, volume, gen2Volume, fullPhysVol, name,
0216 surfaces);
0217 py::class_<GeoModelDetectorObjectFactory::Cache>(a, "Cache")
0218 .def(py::init<>())
0219 .def_readwrite("sensitiveSurfaces",
0220 &GeoModelDetectorObjectFactory::Cache::sensitiveSurfaces)
0221 .def_readwrite("boundingBoxes",
0222 &GeoModelDetectorObjectFactory::Cache::volumeBoxFPVs);
0223
0224 py::class_<GeoModelDetectorObjectFactory::Options>(a, "Options")
0225 .def(py::init<>())
0226 .def_readwrite("queries",
0227 &GeoModelDetectorObjectFactory::Options::queries);
0228 }
0229
0230 {
0231 py::class_<GeoModelBlueprintCreater::Blueprint,
0232 std::shared_ptr<GeoModelBlueprintCreater::Blueprint>>(
0233 gm, "Blueprint")
0234 .def("convertToBuilder", [](GeoModelBlueprintCreater::Blueprint& self,
0235 Logging::Level level) {
0236
0237 return std::make_shared<Experimental::CylindricalContainerBuilder>(
0238 self.node(), level);
0239 });
0240
0241 auto bpc =
0242 py::class_<GeoModelBlueprintCreater,
0243 std::shared_ptr<GeoModelBlueprintCreater>>(
0244 gm, "GeoModelBlueprintCreater")
0245 .def(py::init([](const GeoModelBlueprintCreater::Config& cfg,
0246 Logging::Level level) {
0247 return std::make_shared<GeoModelBlueprintCreater>(
0248 cfg, getDefaultLogger("GeoModelBlueprintCreater", level));
0249 }))
0250 .def("create", &GeoModelBlueprintCreater::create);
0251
0252 py::class_<GeoModelBlueprintCreater::Config>(bpc, "Config")
0253 .def(py::init<>())
0254 .def_readwrite("detectorSurfaces",
0255 &GeoModelBlueprintCreater::Config::detectorSurfaces)
0256 .def_readwrite("kdtBinning",
0257 &GeoModelBlueprintCreater::Config::kdtBinning);
0258
0259 py::class_<GeoModelBlueprintCreater::Options>(bpc, "Options")
0260 .def(py::init<>())
0261 .def_readwrite("topEntry", &GeoModelBlueprintCreater::Options::topEntry)
0262 .def_readwrite("topBoundsOverride",
0263 &GeoModelBlueprintCreater::Options::topBoundsOverride)
0264 .def_readwrite("table", &GeoModelBlueprintCreater::Options::table)
0265 .def_readwrite("dotGraph",
0266 &GeoModelBlueprintCreater::Options::dotGraph);
0267 }
0268
0269 gm.def(
0270 "splitBarrelModule",
0271 [](const GeometryContext& gctx,
0272 std::shared_ptr<const GeoModelDetectorElement> detElement,
0273 unsigned nSegments, Logging::Level logLevel) {
0274 auto logger = getDefaultLogger("ITkSlitBarrel", logLevel);
0275 auto name = detElement->databaseEntryName();
0276
0277 auto factory = [&](const auto& trafo, const auto& bounds) {
0278 return GeoModelDetectorElement::createDetectorElement<
0279 PlaneSurface, RectangleBounds>(detElement->physicalVolume(),
0280 bounds, trafo,
0281 detElement->thickness());
0282 };
0283
0284 return ITk::splitBarrelModule(gctx, detElement, nSegments, factory,
0285 name, *logger);
0286 },
0287 "gxtx"_a, "detElement"_a, "nSegments"_a, "logLevel"_a = Logging::INFO);
0288
0289 gm.def(
0290 "splitDiscModule",
0291 [](const GeometryContext& gctx,
0292 std::shared_ptr<const GeoModelDetectorElement> detElement,
0293 const std::vector<std::pair<double, double>>& patterns,
0294 Logging::Level logLevel) {
0295 auto logger = getDefaultLogger("ITkSlitBarrel", logLevel);
0296 auto name = detElement->databaseEntryName();
0297
0298 auto factory = [&](const auto& trafo, const auto& bounds) {
0299 return GeoModelDetectorElement::createDetectorElement<DiscSurface,
0300 AnnulusBounds>(
0301 detElement->physicalVolume(), bounds, trafo,
0302 detElement->thickness());
0303 };
0304
0305 return ITk::splitDiscModule(gctx, detElement, patterns, factory, name,
0306 *logger);
0307 },
0308 "gxtx"_a, "detElement"_a, "splitRanges"_a, "logLevel"_a = Logging::INFO);
0309
0310 py::class_<GeoModelDetectorElementITk,
0311 std::shared_ptr<GeoModelDetectorElementITk>>(
0312 gm, "GeoModelDetectorElementITk")
0313 .def("surface", [](GeoModelDetectorElementITk& self) {
0314 return self.surface().getSharedPtr();
0315 });
0316 gm.def("convertToItk", &GeoModelDetectorElementITk::convertFromGeomodel);
0317 }
0318
0319 }