Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-12 07:52:35

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 #include "Acts/Geometry/GeometryContext.hpp"
0010 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0011 #include "Acts/Material/BinnedSurfaceMaterialAccumulater.hpp"
0012 #include "Acts/Material/HomogeneousSurfaceMaterial.hpp"
0013 #include "Acts/Material/IMaterialDecorator.hpp"
0014 #include "Acts/Material/ISurfaceMaterial.hpp"
0015 #include "Acts/Material/IVolumeMaterial.hpp"
0016 #include "Acts/Material/IntersectionMaterialAssigner.hpp"
0017 #include "Acts/Material/MaterialMapper.hpp"
0018 #include "Acts/Material/MaterialValidater.hpp"
0019 #include "Acts/Material/PropagatorMaterialAssigner.hpp"
0020 #include "Acts/Material/ProtoSurfaceMaterial.hpp"
0021 #include "Acts/Material/SurfaceMaterialMapper.hpp"
0022 #include "Acts/Material/VolumeMaterialMapper.hpp"
0023 #include "Acts/Plugins/Json/ActsJson.hpp"
0024 #include "Acts/Plugins/Json/MaterialMapJsonConverter.hpp"
0025 #include "Acts/Plugins/Python/Utilities.hpp"
0026 #include "Acts/Utilities/Logger.hpp"
0027 #include "ActsExamples/Framework/ProcessCode.hpp"
0028 #include "ActsExamples/MaterialMapping/CoreMaterialMapping.hpp"
0029 #include "ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp"
0030 #include "ActsExamples/MaterialMapping/MaterialMapping.hpp"
0031 #include "ActsExamples/MaterialMapping/MaterialValidation.hpp"
0032 
0033 #include <array>
0034 #include <map>
0035 #include <memory>
0036 #include <tuple>
0037 #include <utility>
0038 #include <vector>
0039 
0040 #include <pybind11/pybind11.h>
0041 #include <pybind11/stl.h>
0042 
0043 namespace Acts {
0044 class TrackingGeometry;
0045 }  // namespace Acts
0046 namespace ActsExamples {
0047 class IAlgorithm;
0048 }  // namespace ActsExamples
0049 
0050 namespace py = pybind11;
0051 using namespace pybind11::literals;
0052 
0053 using namespace ActsExamples;
0054 
0055 namespace Acts::Python {
0056 void addMaterial(Context& ctx) {
0057   auto [m, mex] = ctx.get("main", "examples");
0058 
0059   {
0060     py::class_<Acts::ISurfaceMaterial, std::shared_ptr<ISurfaceMaterial>>(
0061         m, "ISurfaceMaterial")
0062         .def("toString", &Acts::ISurfaceMaterial::toString);
0063 
0064     py::class_<Acts::ProtoGridSurfaceMaterial, Acts::ISurfaceMaterial,
0065                std::shared_ptr<ProtoGridSurfaceMaterial>>(
0066         m, "ProtoGridSurfaceMaterial");
0067 
0068     py::class_<Acts::ProtoSurfaceMaterial, Acts::ISurfaceMaterial,
0069                std::shared_ptr<ProtoSurfaceMaterial>>(m,
0070                                                       "ProtoSurfaceMaterial");
0071 
0072     py::class_<Acts::HomogeneousSurfaceMaterial, Acts::ISurfaceMaterial,
0073                std::shared_ptr<HomogeneousSurfaceMaterial>>(
0074         m, "HomogeneousSurfaceMaterial");
0075 
0076     py::class_<Acts::IVolumeMaterial, std::shared_ptr<IVolumeMaterial>>(
0077         m, "IVolumeMaterial");
0078   }
0079 
0080   {
0081     py::class_<Acts::IMaterialDecorator,
0082                std::shared_ptr<Acts::IMaterialDecorator>>(m,
0083                                                           "IMaterialDecorator")
0084         .def("decorate", py::overload_cast<Surface&>(
0085                              &Acts::IMaterialDecorator::decorate, py::const_));
0086   }
0087 
0088   {
0089     py::class_<MappingMaterialDecorator, Acts::IMaterialDecorator,
0090                std::shared_ptr<MappingMaterialDecorator>>(
0091         m, "MappingMaterialDecorator")
0092         .def(py::init<const Acts::TrackingGeometry&, Acts::Logging::Level, bool,
0093                       bool>(),
0094              py::arg("tGeometry"), py::arg("level"),
0095              py::arg("clearSurfaceMaterial") = true,
0096              py::arg("clearVolumeMaterial") = true)
0097         .def("binningMap", &MappingMaterialDecorator::binningMap)
0098         .def("setBinningMap", &MappingMaterialDecorator::setBinningMap);
0099   }
0100 
0101   {
0102     using Alg = ActsExamples::MaterialMapping;
0103 
0104     auto alg = py::class_<Alg, ActsExamples::IAlgorithm, std::shared_ptr<Alg>>(
0105                    mex, "MaterialMapping")
0106                    .def(py::init<const Alg::Config&, Acts::Logging::Level>(),
0107                         py::arg("config"), py::arg("level"))
0108                    .def("scoringParameters", &Alg::scoringParameters)
0109                    .def_property_readonly("config", &Alg::config);
0110 
0111     auto c = py::class_<Alg::Config>(alg, "Config")
0112                  .def(py::init<const Acts::GeometryContext&,
0113                                const Acts::MagneticFieldContext&>());
0114 
0115     ACTS_PYTHON_STRUCT(c, inputMaterialTracks, mappingMaterialCollection,
0116                        materialSurfaceMapper, materialVolumeMapper,
0117                        materialWriters, trackingGeometry, geoContext,
0118                        magFieldContext);
0119   }
0120 
0121   {
0122     auto cls =
0123         py::class_<SurfaceMaterialMapper,
0124                    std::shared_ptr<SurfaceMaterialMapper>>(
0125             m, "SurfaceMaterialMapper")
0126             .def(py::init([](const SurfaceMaterialMapper::Config& config,
0127                              SurfaceMaterialMapper::StraightLinePropagator prop,
0128                              Acts::Logging::Level level) {
0129                    return std::make_shared<SurfaceMaterialMapper>(
0130                        config, std::move(prop),
0131                        getDefaultLogger("SurfaceMaterialMapper", level));
0132                  }),
0133                  py::arg("config"), py::arg("propagator"), py::arg("level"));
0134 
0135     auto c = py::class_<SurfaceMaterialMapper::Config>(cls, "Config")
0136                  .def(py::init<>());
0137     ACTS_PYTHON_STRUCT(c, etaRange, emptyBinCorrection, mapperDebugOutput,
0138                        computeVariance);
0139   }
0140 
0141   {
0142     auto cls =
0143         py::class_<VolumeMaterialMapper, std::shared_ptr<VolumeMaterialMapper>>(
0144             m, "VolumeMaterialMapper")
0145             .def(py::init([](const VolumeMaterialMapper::Config& config,
0146                              VolumeMaterialMapper::StraightLinePropagator prop,
0147                              Acts::Logging::Level level) {
0148                    return std::make_shared<VolumeMaterialMapper>(
0149                        config, std::move(prop),
0150                        getDefaultLogger("VolumeMaterialMapper", level));
0151                  }),
0152                  py::arg("config"), py::arg("propagator"), py::arg("level"));
0153 
0154     auto c = py::class_<VolumeMaterialMapper::Config>(cls, "Config")
0155                  .def(py::init<>());
0156     ACTS_PYTHON_STRUCT(c, mappingStep);
0157   }
0158 
0159   {
0160     py::class_<Acts::IAssignmentFinder,
0161                std::shared_ptr<Acts::IAssignmentFinder>>(m,
0162                                                          "IAssignmentFinder");
0163   }
0164 
0165   {
0166     auto isma =
0167         py::class_<Acts::IntersectionMaterialAssigner, Acts::IAssignmentFinder,
0168                    std::shared_ptr<Acts::IntersectionMaterialAssigner>>(
0169             m, "IntersectionMaterialAssigner")
0170             .def(py::init([](const Acts::IntersectionMaterialAssigner::Config&
0171                                  config,
0172                              Acts::Logging::Level level) {
0173                    return std::make_shared<Acts::IntersectionMaterialAssigner>(
0174                        config,
0175                        getDefaultLogger("IntersectionMaterialAssigner", level));
0176                  }),
0177                  py::arg("config"), py::arg("level"))
0178             .def("assignmentCandidates",
0179                  &Acts::IntersectionMaterialAssigner::assignmentCandidates);
0180 
0181     auto c =
0182         py::class_<Acts::IntersectionMaterialAssigner::Config>(isma, "Config")
0183             .def(py::init<>());
0184     ACTS_PYTHON_STRUCT(c, surfaces, trackingVolumes, detectorVolumes);
0185   }
0186 
0187   {
0188     py::class_<Acts::ISurfaceMaterialAccumulater,
0189                std::shared_ptr<Acts::ISurfaceMaterialAccumulater>>(
0190         m, "ISurfaceMaterialAccumulater");
0191   }
0192 
0193   {
0194     auto bsma =
0195         py::class_<BinnedSurfaceMaterialAccumulater,
0196                    ISurfaceMaterialAccumulater,
0197                    std::shared_ptr<BinnedSurfaceMaterialAccumulater>>(
0198             m, "BinnedSurfaceMaterialAccumulater")
0199             .def(
0200                 py::init(
0201                     [](const BinnedSurfaceMaterialAccumulater::Config& config,
0202                        Acts::Logging::Level level) {
0203                       return std::make_shared<BinnedSurfaceMaterialAccumulater>(
0204                           config,
0205                           getDefaultLogger("BinnedSurfaceMaterialAccumulater",
0206                                            level));
0207                     }),
0208                 py::arg("config"), py::arg("level"))
0209             .def("createState", &BinnedSurfaceMaterialAccumulater::createState)
0210             .def("accumulate", &BinnedSurfaceMaterialAccumulater::accumulate)
0211             .def("finalizeMaterial",
0212                  &BinnedSurfaceMaterialAccumulater::finalizeMaterial);
0213 
0214     auto c =
0215         py::class_<BinnedSurfaceMaterialAccumulater::Config>(bsma, "Config")
0216             .def(py::init<>());
0217     ACTS_PYTHON_STRUCT(c, emptyBinCorrection, materialSurfaces);
0218   }
0219 
0220   {
0221     auto mm = py::class_<MaterialMapper, std::shared_ptr<MaterialMapper>>(
0222                   m, "MaterialMapper")
0223                   .def(py::init([](const MaterialMapper::Config& config,
0224                                    Acts::Logging::Level level) {
0225                          return std::make_shared<MaterialMapper>(
0226                              config, getDefaultLogger("MaterialMapper", level));
0227                        }),
0228                        py::arg("config"), py::arg("level"));
0229 
0230     auto c = py::class_<MaterialMapper::Config>(mm, "Config").def(py::init<>());
0231     ACTS_PYTHON_STRUCT(c, assignmentFinder, surfaceMaterialAccumulater);
0232   }
0233 
0234   {
0235     auto mmca = py::class_<CoreMaterialMapping, IAlgorithm,
0236                            std::shared_ptr<CoreMaterialMapping>>(
0237                     mex, "CoreMaterialMapping")
0238                     .def(py::init<const CoreMaterialMapping::Config&,
0239                                   Acts::Logging::Level>(),
0240                          py::arg("config"), py::arg("level"));
0241 
0242     auto c = py::class_<CoreMaterialMapping::Config>(mmca, "Config")
0243                  .def(py::init<>());
0244     ACTS_PYTHON_STRUCT(c, inputMaterialTracks, mappedMaterialTracks,
0245                        unmappedMaterialTracks, materialMapper,
0246                        materiaMaplWriters);
0247   }
0248 
0249   {
0250     auto mvc =
0251         py::class_<MaterialValidater, std::shared_ptr<MaterialValidater>>(
0252             m, "MaterialValidater")
0253             .def(py::init([](const MaterialValidater::Config& config,
0254                              Acts::Logging::Level level) {
0255                    return std::make_shared<MaterialValidater>(
0256                        config, getDefaultLogger("MaterialValidater", level));
0257                  }),
0258                  py::arg("config"), py::arg("level"))
0259             .def("recordMaterial", &MaterialValidater::recordMaterial);
0260 
0261     auto c =
0262         py::class_<MaterialValidater::Config>(mvc, "Config").def(py::init<>());
0263     ACTS_PYTHON_STRUCT(c, materialAssigner);
0264   }
0265 
0266   {
0267     auto mv = py::class_<MaterialValidation, IAlgorithm,
0268                          std::shared_ptr<MaterialValidation>>(
0269                   mex, "MaterialValidation")
0270                   .def(py::init<const MaterialValidation::Config&,
0271                                 Acts::Logging::Level>(),
0272                        py::arg("config"), py::arg("level"))
0273                   .def("execute", &MaterialValidation::execute)
0274                   .def_property_readonly("config", &MaterialValidation::config);
0275 
0276     auto c =
0277         py::class_<MaterialValidation::Config>(mv, "Config").def(py::init<>());
0278     ACTS_PYTHON_STRUCT(c, ntracks, startPosition, phiRange, etaRange,
0279                        randomNumberSvc, materialValidater,
0280                        outputMaterialTracks);
0281   }
0282 }
0283 
0284 }  // namespace Acts::Python