Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:03:11

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 // Must be on top to avoid some conflict between forward declare and typedef
0010 // Needed until https://gitlab.cern.ch/GeoModelDev/GeoModel/-/merge_requests/351
0011 // is deployed
0012 // clang-format off
0013 #include <GeoModelRead/ReadGeoModel.h>
0014 // clang-format on
0015 
0016 #include "Acts/Detector/CylindricalContainerBuilder.hpp"
0017 #include "Acts/Geometry/ITrackingGeometryBuilder.hpp"
0018 #include "Acts/Plugins/GeoModel/GeoModelBlueprintCreater.hpp"
0019 #include "Acts/Plugins/GeoModel/GeoModelConverters.hpp"
0020 #include "Acts/Plugins/GeoModel/GeoModelDetectorElement.hpp"
0021 #include "Acts/Plugins/GeoModel/GeoModelDetectorElementITk.hpp"
0022 #include "Acts/Plugins/GeoModel/GeoModelDetectorObjectFactory.hpp"
0023 #include "Acts/Plugins/GeoModel/GeoModelReader.hpp"
0024 #include "Acts/Plugins/GeoModel/GeoModelTree.hpp"
0025 #include "Acts/Plugins/GeoModel/IGeoShapeConverter.hpp"
0026 #include "Acts/Plugins/Python/Utilities.hpp"
0027 #include "Acts/Surfaces/AnnulusBounds.hpp"
0028 #include "Acts/Surfaces/DiscSurface.hpp"
0029 #include "Acts/Surfaces/PlaneSurface.hpp"
0030 #include "Acts/Surfaces/RectangleBounds.hpp"
0031 #include "ActsExamples/GeoModelDetector/GeoModelDetector.hpp"
0032 #include "ActsExamples/GeoModelDetector/GeoModelMuonMockupBuilder.hpp"
0033 #include "ActsExamples/ITkModuleSplitting/ITkModuleSplitting.hpp"
0034 #include "ActsExamples/MuonSpectrometerMockupDetector/GeoMuonMockupExperiment.hpp"
0035 
0036 #include <string>
0037 
0038 #include <GeoModelKernel/GeoFullPhysVol.h>
0039 #include <GeoModelKernel/GeoVPhysVol.h>
0040 #include <pybind11/pybind11.h>
0041 #include <pybind11/stl.h>
0042 
0043 namespace py = pybind11;
0044 using namespace pybind11::literals;
0045 
0046 namespace Acts::Python {
0047 
0048 void addGeoModel(Context& ctx) {
0049   auto m = ctx.get("main");
0050 
0051   auto gm = m.def_submodule("geomodel");
0052 
0053   py::class_<GeoModelTree::FpvConstLink>(gm, "GeoModelTree::FpvConstLink")
0054       .def(py::init<>())
0055       .def("get", &GeoModelTree::FpvConstLink::get,
0056            py::return_value_policy::reference);
0057 
0058   py::class_<Acts::GeoModelTree>(gm, "GeoModelTree").def(py::init<>());
0059 
0060   gm.def("readFromDb", &Acts::GeoModelReader::readFromDb);
0061 
0062   py::class_<Acts::GeoModelDetectorElement,
0063              std::shared_ptr<Acts::GeoModelDetectorElement>>(
0064       gm, "GeoModelDetectorElement")
0065       .def("logVolName", &Acts::GeoModelDetectorElement::logVolName)
0066       .def("databaseEntryName",
0067            &Acts::GeoModelDetectorElement::databaseEntryName)
0068       .def("surface", [](Acts::GeoModelDetectorElement self) {
0069         return self.surface().getSharedPtr();
0070       });
0071 
0072   {
0073     auto f = py::class_<ActsExamples::GeoModelDetector, ActsExamples::Detector,
0074                         std::shared_ptr<ActsExamples::GeoModelDetector>>(
0075                  gm, "GeoModelDetector")
0076                  .def(py::init<const ActsExamples::GeoModelDetector::Config&>())
0077                  .def("buildTrackingGeometry",
0078                       &ActsExamples::GeoModelDetector::buildTrackingGeometry);
0079 
0080     auto c = py::class_<ActsExamples::GeoModelDetector::Config>(f, "Config")
0081                  .def(py::init<>());
0082     ACTS_PYTHON_STRUCT(c, geoModelTree, logLevel, path);
0083 
0084     // patch the constructor
0085     patchKwargsConstructor(c);
0086   }
0087   {
0088     // GeomodelMuonMockupBuilder
0089     py::class_<Acts::ITrackingGeometryBuilder,
0090                std::shared_ptr<Acts::ITrackingGeometryBuilder>>(
0091         gm, "ITrackingGeometryBuilder");
0092     auto gmMuonBuilder =
0093         py::class_<ActsExamples::GeoModelMuonMockupBuilder,
0094                    Acts::ITrackingGeometryBuilder,
0095                    std::shared_ptr<ActsExamples::GeoModelMuonMockupBuilder>>(
0096             gm, "GeoModelMuonMockupBuilder")
0097             .def(py::init([](const ActsExamples::GeoModelMuonMockupBuilder::
0098                                  Config& config,
0099                              const std::string& name,
0100                              Acts::Logging::Level level) {
0101               return std::make_shared<ActsExamples::GeoModelMuonMockupBuilder>(
0102                   config, getDefaultLogger(name, level));
0103             }))
0104             .def("trackingGeometry",
0105                  &ActsExamples::GeoModelMuonMockupBuilder::trackingGeometry);
0106     auto gmMuonConfig =
0107         py::class_<ActsExamples::GeoModelMuonMockupBuilder::Config>(
0108             gmMuonBuilder, "Config")
0109             .def(py::init<>());
0110     ACTS_PYTHON_STRUCT(gmMuonConfig, volumeBoxFPVs, stationNames,
0111                        volumeBoundFactory);
0112   }
0113 
0114   // Shape converters
0115   {
0116     py::class_<Acts::IGeoShapeConverter,
0117                std::shared_ptr<Acts::IGeoShapeConverter>>(gm,
0118                                                           "IGeoShapeConverter");
0119 
0120     py::class_<Acts::GeoBoxConverter, Acts::IGeoShapeConverter,
0121                std::shared_ptr<Acts::GeoBoxConverter>>(gm, "GeoBoxConverter")
0122         .def(py::init<>())
0123         .def("toSensitiveSurface", &Acts::GeoBoxConverter::toSensitiveSurface)
0124         .def("toPassiveSurface", &Acts::GeoBoxConverter::toPassiveSurface);
0125 
0126     py::class_<Acts::GeoTrdConverter, Acts::IGeoShapeConverter,
0127                std::shared_ptr<Acts::GeoTrdConverter>>(gm, "GeoTrdConverter")
0128         .def(py::init<>())
0129         .def("toSensitiveSurface", &Acts::GeoTrdConverter::toSensitiveSurface)
0130         .def("toPassiveSurface", &Acts::GeoTrdConverter::toPassiveSurface);
0131 
0132     py::class_<Acts::GeoTubeConverter, Acts::IGeoShapeConverter,
0133                std::shared_ptr<Acts::GeoTubeConverter>>(gm, "GeoTubeConverter")
0134         .def(py::init<>())
0135         .def("toSensitiveSurface", &Acts::GeoTubeConverter::toSensitiveSurface)
0136         .def("toPassiveSurface", &Acts::GeoTubeConverter::toPassiveSurface);
0137 
0138     py::class_<Acts::GeoUnionDoubleTrdConverter, Acts::IGeoShapeConverter,
0139                std::shared_ptr<Acts::GeoUnionDoubleTrdConverter>>(
0140         gm, "GeoUnionDoubleTrdConverter")
0141         .def(py::init<>())
0142         .def("toSensitiveSurface",
0143              &Acts::GeoUnionDoubleTrdConverter::toSensitiveSurface)
0144         .def("toPassiveSurface",
0145              &Acts::GeoUnionDoubleTrdConverter::toPassiveSurface);
0146 
0147     py::class_<Acts::GeoIntersectionAnnulusConverter, Acts::IGeoShapeConverter,
0148                std::shared_ptr<Acts::GeoIntersectionAnnulusConverter>>(
0149         gm, "GeoIntersectionAnnulusConverter")
0150         .def(py::init<>())
0151         .def("toSensitiveSurface",
0152              &Acts::GeoIntersectionAnnulusConverter::toSensitiveSurface)
0153         .def("toPassiveSurface",
0154              &Acts::GeoIntersectionAnnulusConverter::toPassiveSurface);
0155 
0156     py::class_<Acts::GeoShiftConverter, Acts::IGeoShapeConverter,
0157                std::shared_ptr<Acts::GeoShiftConverter>>(gm,
0158                                                          "GeoShiftConverter")
0159         .def(py::init<>())
0160         .def("toSensitiveSurface", &Acts::GeoShiftConverter::toSensitiveSurface)
0161         .def("toPassiveSurface", &Acts::GeoShiftConverter::toPassiveSurface);
0162   }
0163   {
0164     // GeoMuonMockupExperiment
0165     auto f =
0166         py::class_<ActsExamples::GeoMuonMockupExperiment,
0167                    std::shared_ptr<ActsExamples::GeoMuonMockupExperiment>>(
0168             gm, "GeoMuonMockupExperiment")
0169             .def(py::init(
0170                 [](const ActsExamples::GeoMuonMockupExperiment::Config& config,
0171                    const std::string& name, Acts::Logging::Level level) {
0172                   return std::make_shared<
0173                       ActsExamples::GeoMuonMockupExperiment>(
0174                       config, getDefaultLogger(name, level));
0175                 }))
0176             .def("constructMS",
0177                  &ActsExamples::GeoMuonMockupExperiment::constructMS);
0178     auto c =
0179         py::class_<ActsExamples::GeoMuonMockupExperiment::Config>(f, "Config")
0180             .def(py::init<>());
0181     ACTS_PYTHON_STRUCT(c,
0182                        /// General properties
0183                        dumpTree, dbName,
0184                        /// Mdt properties
0185                        innerTubeRadius, tubeWallThickness, nTubeLayers, nTubes,
0186                        mdtFoamThickness, multiLayerSeparation,
0187                        /// Rpc properties
0188                        nRpcGasGaps, nRpcAlongZ, nRpcAlongPhi,
0189                        /// Station properties
0190                        barrelRadii, nSectors, nEtaStations, stationDistInZ,
0191                        stationDistInR, endCapWheelLowR, bigWheelDistZ,
0192                        buildEndcaps);
0193   }
0194   // Volume factory
0195   {
0196     auto a =
0197         py::class_<Acts::GeoModelDetectorObjectFactory,
0198                    std::shared_ptr<Acts::GeoModelDetectorObjectFactory>>(
0199             gm, "GeoModelDetectorObjectFactory")
0200             .def(py::init(
0201                 [](const Acts::GeoModelDetectorObjectFactory::Config& cfg,
0202                    Acts::Logging::Level level) {
0203                   return std::make_shared<Acts::GeoModelDetectorObjectFactory>(
0204                       cfg, Acts::getDefaultLogger(
0205                                "GeoModelDetectorObjectFactory", level));
0206                 }))
0207             .def("construct", &Acts::GeoModelDetectorObjectFactory::construct);
0208 
0209     py::class_<Acts::GeoModelDetectorObjectFactory::Config>(a, "Config")
0210         .def(py::init<>())
0211         .def_readwrite(
0212             "convertSubVolumes",
0213             &Acts::GeoModelDetectorObjectFactory::Config::convertSubVolumes)
0214         .def_readwrite("nameList",
0215                        &Acts::GeoModelDetectorObjectFactory::Config::nameList)
0216         .def_readwrite("convertBox",
0217                        &Acts::GeoModelDetectorObjectFactory::Config::convertBox)
0218         .def_readwrite(
0219             "materialList",
0220             &Acts::GeoModelDetectorObjectFactory::Config::materialList);
0221 
0222     auto convVol =
0223         py::class_<Acts::GeoModelDetectorObjectFactory::ConvertedGeoVol>(
0224             a, "ConvertedGeoVol");
0225 
0226     ACTS_PYTHON_STRUCT(convVol, volume, gen2Volume, fullPhysVol, name,
0227                        surfaces);
0228     py::class_<Acts::GeoModelDetectorObjectFactory::Cache>(a, "Cache")
0229         .def(py::init<>())
0230         .def_readwrite(
0231             "sensitiveSurfaces",
0232             &Acts::GeoModelDetectorObjectFactory::Cache::sensitiveSurfaces)
0233         .def_readwrite(
0234             "boundingBoxes",
0235             &Acts::GeoModelDetectorObjectFactory::Cache::volumeBoxFPVs);
0236 
0237     py::class_<Acts::GeoModelDetectorObjectFactory::Options>(a, "Options")
0238         .def(py::init<>())
0239         .def_readwrite("queries",
0240                        &Acts::GeoModelDetectorObjectFactory::Options::queries);
0241   }
0242 
0243   {
0244     py::class_<Acts::GeoModelBlueprintCreater::Blueprint,
0245                std::shared_ptr<Acts::GeoModelBlueprintCreater::Blueprint>>(
0246         gm, "Blueprint")
0247         .def("convertToBuilder",
0248              [](Acts::GeoModelBlueprintCreater::Blueprint& self,
0249                 Acts::Logging::Level level) {
0250                // It's a container builder
0251                return std::make_shared<
0252                    Acts::Experimental::CylindricalContainerBuilder>(self.node(),
0253                                                                     level);
0254              });
0255 
0256     auto bpc =
0257         py::class_<Acts::GeoModelBlueprintCreater,
0258                    std::shared_ptr<Acts::GeoModelBlueprintCreater>>(
0259             gm, "GeoModelBlueprintCreater")
0260             .def(py::init([](const Acts::GeoModelBlueprintCreater::Config& cfg,
0261                              Acts::Logging::Level level) {
0262               return std::make_shared<Acts::GeoModelBlueprintCreater>(
0263                   cfg,
0264                   Acts::getDefaultLogger("GeoModelBlueprintCreater", level));
0265             }))
0266             .def("create", &Acts::GeoModelBlueprintCreater::create);
0267 
0268     py::class_<Acts::GeoModelBlueprintCreater::Config>(bpc, "Config")
0269         .def(py::init<>())
0270         .def_readwrite(
0271             "detectorSurfaces",
0272             &Acts::GeoModelBlueprintCreater::Config::detectorSurfaces)
0273         .def_readwrite("kdtBinning",
0274                        &Acts::GeoModelBlueprintCreater::Config::kdtBinning);
0275 
0276     py::class_<Acts::GeoModelBlueprintCreater::Options>(bpc, "Options")
0277         .def(py::init<>())
0278         .def_readwrite("topEntry",
0279                        &Acts::GeoModelBlueprintCreater::Options::topEntry)
0280         .def_readwrite(
0281             "topBoundsOverride",
0282             &Acts::GeoModelBlueprintCreater::Options::topBoundsOverride)
0283         .def_readwrite("table", &Acts::GeoModelBlueprintCreater::Options::table)
0284         .def_readwrite("dotGraph",
0285                        &Acts::GeoModelBlueprintCreater::Options::dotGraph);
0286   }
0287 
0288   gm.def(
0289       "splitBarrelModule",
0290       [](const Acts::GeometryContext& gctx,
0291          std::shared_ptr<const GeoModelDetectorElement> detElement,
0292          unsigned nSegments, Acts::Logging::Level logLevel) {
0293         auto logger = Acts::getDefaultLogger("ITkSlitBarrel", logLevel);
0294         auto name = detElement->databaseEntryName();
0295 
0296         auto factory = [&](const auto& trafo, const auto& bounds) {
0297           return Acts::GeoModelDetectorElement::createDetectorElement<
0298               Acts::PlaneSurface, Acts::RectangleBounds>(
0299               detElement->physicalVolume(), bounds, trafo,
0300               detElement->thickness());
0301         };
0302 
0303         return ActsExamples::ITk::splitBarrelModule(gctx, detElement, nSegments,
0304                                                     factory, name, *logger);
0305       },
0306       "gxtx"_a, "detElement"_a, "nSegments"_a,
0307       "logLevel"_a = Acts::Logging::INFO);
0308 
0309   gm.def(
0310       "splitDiscModule",
0311       [](const Acts::GeometryContext& gctx,
0312          std::shared_ptr<const GeoModelDetectorElement> detElement,
0313          const std::vector<std::pair<double, double>>& patterns,
0314          Acts::Logging::Level logLevel) {
0315         auto logger = Acts::getDefaultLogger("ITkSlitBarrel", logLevel);
0316         auto name = detElement->databaseEntryName();
0317 
0318         auto factory = [&](const auto& trafo, const auto& bounds) {
0319           return Acts::GeoModelDetectorElement::createDetectorElement<
0320               Acts::DiscSurface, Acts::AnnulusBounds>(
0321               detElement->physicalVolume(), bounds, trafo,
0322               detElement->thickness());
0323         };
0324 
0325         return ActsExamples::ITk::splitDiscModule(gctx, detElement, patterns,
0326                                                   factory, name, *logger);
0327       },
0328       "gxtx"_a, "detElement"_a, "splitRanges"_a,
0329       "logLevel"_a = Acts::Logging::INFO);
0330 
0331   py::class_<Acts::GeoModelDetectorElementITk,
0332              std::shared_ptr<Acts::GeoModelDetectorElementITk>>(
0333       gm, "GeoModelDetectorElementITk")
0334       .def("surface", [](Acts::GeoModelDetectorElementITk& self) {
0335         return self.surface().getSharedPtr();
0336       });
0337   gm.def("convertToItk", &GeoModelDetectorElementITk::convertFromGeomodel);
0338 }
0339 
0340 }  // namespace Acts::Python