Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:50:44

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