File indexing completed on 2025-01-18 09:12:03
0001
0002
0003
0004
0005
0006
0007
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/Io/Root/RootMaterialDecorator.hpp"
0029 #include "ActsExamples/MaterialMapping/CoreMaterialMapping.hpp"
0030 #include "ActsExamples/MaterialMapping/MappingMaterialDecorator.hpp"
0031 #include "ActsExamples/MaterialMapping/MaterialMapping.hpp"
0032 #include "ActsExamples/MaterialMapping/MaterialValidation.hpp"
0033
0034 #include <array>
0035 #include <map>
0036 #include <memory>
0037 #include <tuple>
0038 #include <utility>
0039 #include <vector>
0040
0041 #include <pybind11/pybind11.h>
0042 #include <pybind11/stl.h>
0043
0044 namespace Acts {
0045 class TrackingGeometry;
0046 }
0047 namespace ActsExamples {
0048 class IAlgorithm;
0049 }
0050
0051 namespace py = pybind11;
0052 using namespace pybind11::literals;
0053
0054 using namespace ActsExamples;
0055
0056 namespace Acts::Python {
0057 void addMaterial(Context& ctx) {
0058 auto [m, mex] = ctx.get("main", "examples");
0059
0060 {
0061 py::class_<Acts::ISurfaceMaterial, std::shared_ptr<ISurfaceMaterial>>(
0062 m, "ISurfaceMaterial")
0063 .def("toString", &Acts::ISurfaceMaterial::toString);
0064
0065 py::class_<Acts::ProtoGridSurfaceMaterial, Acts::ISurfaceMaterial,
0066 std::shared_ptr<ProtoGridSurfaceMaterial>>(
0067 m, "ProtoGridSurfaceMaterial");
0068
0069 py::class_<Acts::ProtoSurfaceMaterial, Acts::ISurfaceMaterial,
0070 std::shared_ptr<ProtoSurfaceMaterial>>(m,
0071 "ProtoSurfaceMaterial");
0072
0073 py::class_<Acts::HomogeneousSurfaceMaterial, Acts::ISurfaceMaterial,
0074 std::shared_ptr<HomogeneousSurfaceMaterial>>(
0075 m, "HomogeneousSurfaceMaterial");
0076
0077 py::class_<Acts::IVolumeMaterial, std::shared_ptr<IVolumeMaterial>>(
0078 m, "IVolumeMaterial");
0079 }
0080
0081 {
0082 py::class_<Acts::IMaterialDecorator,
0083 std::shared_ptr<Acts::IMaterialDecorator>>(m,
0084 "IMaterialDecorator")
0085 .def("decorate", py::overload_cast<Surface&>(
0086 &Acts::IMaterialDecorator::decorate, py::const_));
0087 }
0088
0089 {
0090 auto rmd =
0091 py::class_<RootMaterialDecorator, Acts::IMaterialDecorator,
0092 std::shared_ptr<RootMaterialDecorator>>(
0093 mex, "RootMaterialDecorator")
0094 .def(
0095 py::init<RootMaterialDecorator::Config, Acts::Logging::Level>(),
0096 py::arg("config"), py::arg("level"));
0097
0098 using Config = RootMaterialDecorator::Config;
0099 auto c = py::class_<Config>(rmd, "Config").def(py::init<>());
0100
0101 ACTS_PYTHON_STRUCT_BEGIN(c, Config);
0102 ACTS_PYTHON_MEMBER(voltag);
0103 ACTS_PYTHON_MEMBER(boutag);
0104 ACTS_PYTHON_MEMBER(laytag);
0105 ACTS_PYTHON_MEMBER(apptag);
0106 ACTS_PYTHON_MEMBER(sentag);
0107 ACTS_PYTHON_MEMBER(ntag);
0108 ACTS_PYTHON_MEMBER(vtag);
0109 ACTS_PYTHON_MEMBER(otag);
0110 ACTS_PYTHON_MEMBER(mintag);
0111 ACTS_PYTHON_MEMBER(maxtag);
0112 ACTS_PYTHON_MEMBER(ttag);
0113 ACTS_PYTHON_MEMBER(x0tag);
0114 ACTS_PYTHON_MEMBER(l0tag);
0115 ACTS_PYTHON_MEMBER(atag);
0116 ACTS_PYTHON_MEMBER(ztag);
0117 ACTS_PYTHON_MEMBER(rhotag);
0118 ACTS_PYTHON_MEMBER(fileName);
0119 ACTS_PYTHON_STRUCT_END();
0120 }
0121
0122 {
0123 py::class_<MappingMaterialDecorator, Acts::IMaterialDecorator,
0124 std::shared_ptr<MappingMaterialDecorator>>(
0125 m, "MappingMaterialDecorator")
0126 .def(py::init<const Acts::TrackingGeometry&, Acts::Logging::Level, bool,
0127 bool>(),
0128 py::arg("tGeometry"), py::arg("level"),
0129 py::arg("clearSurfaceMaterial") = true,
0130 py::arg("clearVolumeMaterial") = true)
0131 .def("binningMap", &MappingMaterialDecorator::binningMap)
0132 .def("setBinningMap", &MappingMaterialDecorator::setBinningMap);
0133 }
0134
0135 {
0136 using Alg = ActsExamples::MaterialMapping;
0137
0138 auto alg = py::class_<Alg, ActsExamples::IAlgorithm, std::shared_ptr<Alg>>(
0139 mex, "MaterialMapping")
0140 .def(py::init<const Alg::Config&, Acts::Logging::Level>(),
0141 py::arg("config"), py::arg("level"))
0142 .def("scoringParameters", &Alg::scoringParameters)
0143 .def_property_readonly("config", &Alg::config);
0144
0145 auto c = py::class_<Alg::Config>(alg, "Config")
0146 .def(py::init<const Acts::GeometryContext&,
0147 const Acts::MagneticFieldContext&>());
0148
0149 ACTS_PYTHON_STRUCT_BEGIN(c, Alg::Config);
0150 ACTS_PYTHON_MEMBER(inputMaterialTracks);
0151 ACTS_PYTHON_MEMBER(mappingMaterialCollection);
0152 ACTS_PYTHON_MEMBER(materialSurfaceMapper);
0153 ACTS_PYTHON_MEMBER(materialVolumeMapper);
0154 ACTS_PYTHON_MEMBER(materialWriters);
0155 ACTS_PYTHON_MEMBER(trackingGeometry);
0156 ACTS_PYTHON_MEMBER(geoContext);
0157 ACTS_PYTHON_MEMBER(magFieldContext);
0158 ACTS_PYTHON_STRUCT_END();
0159 }
0160
0161 {
0162 auto cls =
0163 py::class_<SurfaceMaterialMapper,
0164 std::shared_ptr<SurfaceMaterialMapper>>(
0165 m, "SurfaceMaterialMapper")
0166 .def(py::init([](const SurfaceMaterialMapper::Config& config,
0167 SurfaceMaterialMapper::StraightLinePropagator prop,
0168 Acts::Logging::Level level) {
0169 return std::make_shared<SurfaceMaterialMapper>(
0170 config, std::move(prop),
0171 getDefaultLogger("SurfaceMaterialMapper", level));
0172 }),
0173 py::arg("config"), py::arg("propagator"), py::arg("level"));
0174
0175 auto c = py::class_<SurfaceMaterialMapper::Config>(cls, "Config")
0176 .def(py::init<>());
0177 ACTS_PYTHON_STRUCT_BEGIN(c, SurfaceMaterialMapper::Config);
0178 ACTS_PYTHON_MEMBER(etaRange);
0179 ACTS_PYTHON_MEMBER(emptyBinCorrection);
0180 ACTS_PYTHON_MEMBER(mapperDebugOutput);
0181 ACTS_PYTHON_MEMBER(computeVariance);
0182 ACTS_PYTHON_STRUCT_END();
0183 }
0184
0185 {
0186 auto cls =
0187 py::class_<VolumeMaterialMapper, std::shared_ptr<VolumeMaterialMapper>>(
0188 m, "VolumeMaterialMapper")
0189 .def(py::init([](const VolumeMaterialMapper::Config& config,
0190 VolumeMaterialMapper::StraightLinePropagator prop,
0191 Acts::Logging::Level level) {
0192 return std::make_shared<VolumeMaterialMapper>(
0193 config, std::move(prop),
0194 getDefaultLogger("VolumeMaterialMapper", level));
0195 }),
0196 py::arg("config"), py::arg("propagator"), py::arg("level"));
0197
0198 auto c = py::class_<VolumeMaterialMapper::Config>(cls, "Config")
0199 .def(py::init<>());
0200 ACTS_PYTHON_STRUCT_BEGIN(c, VolumeMaterialMapper::Config);
0201 ACTS_PYTHON_MEMBER(mappingStep);
0202 ACTS_PYTHON_STRUCT_END();
0203 }
0204
0205 {
0206 py::class_<Acts::IAssignmentFinder,
0207 std::shared_ptr<Acts::IAssignmentFinder>>(m,
0208 "IAssignmentFinder");
0209 }
0210
0211 {
0212 auto isma =
0213 py::class_<Acts::IntersectionMaterialAssigner, Acts::IAssignmentFinder,
0214 std::shared_ptr<Acts::IntersectionMaterialAssigner>>(
0215 m, "IntersectionMaterialAssigner")
0216 .def(py::init([](const Acts::IntersectionMaterialAssigner::Config&
0217 config,
0218 Acts::Logging::Level level) {
0219 return std::make_shared<Acts::IntersectionMaterialAssigner>(
0220 config,
0221 getDefaultLogger("IntersectionMaterialAssigner", level));
0222 }),
0223 py::arg("config"), py::arg("level"))
0224 .def("assignmentCandidates",
0225 &Acts::IntersectionMaterialAssigner::assignmentCandidates);
0226
0227 auto c =
0228 py::class_<Acts::IntersectionMaterialAssigner::Config>(isma, "Config")
0229 .def(py::init<>());
0230 ACTS_PYTHON_STRUCT_BEGIN(c, Acts::IntersectionMaterialAssigner::Config);
0231 ACTS_PYTHON_MEMBER(surfaces);
0232 ACTS_PYTHON_MEMBER(trackingVolumes);
0233 ACTS_PYTHON_MEMBER(detectorVolumes);
0234 ACTS_PYTHON_STRUCT_END();
0235 }
0236
0237 {
0238 py::class_<Acts::ISurfaceMaterialAccumulater,
0239 std::shared_ptr<Acts::ISurfaceMaterialAccumulater>>(
0240 m, "ISurfaceMaterialAccumulater");
0241 }
0242
0243 {
0244 auto bsma =
0245 py::class_<BinnedSurfaceMaterialAccumulater,
0246 ISurfaceMaterialAccumulater,
0247 std::shared_ptr<BinnedSurfaceMaterialAccumulater>>(
0248 m, "BinnedSurfaceMaterialAccumulater")
0249 .def(
0250 py::init(
0251 [](const BinnedSurfaceMaterialAccumulater::Config& config,
0252 Acts::Logging::Level level) {
0253 return std::make_shared<BinnedSurfaceMaterialAccumulater>(
0254 config,
0255 getDefaultLogger("BinnedSurfaceMaterialAccumulater",
0256 level));
0257 }),
0258 py::arg("config"), py::arg("level"))
0259 .def("createState", &BinnedSurfaceMaterialAccumulater::createState)
0260 .def("accumulate", &BinnedSurfaceMaterialAccumulater::accumulate)
0261 .def("finalizeMaterial",
0262 &BinnedSurfaceMaterialAccumulater::finalizeMaterial);
0263
0264 auto c =
0265 py::class_<BinnedSurfaceMaterialAccumulater::Config>(bsma, "Config")
0266 .def(py::init<>());
0267 ACTS_PYTHON_STRUCT_BEGIN(c, BinnedSurfaceMaterialAccumulater::Config);
0268 ACTS_PYTHON_MEMBER(emptyBinCorrection);
0269 ACTS_PYTHON_MEMBER(materialSurfaces);
0270 ACTS_PYTHON_STRUCT_END();
0271 }
0272
0273 {
0274 auto mm = py::class_<MaterialMapper, std::shared_ptr<MaterialMapper>>(
0275 m, "MaterialMapper")
0276 .def(py::init([](const MaterialMapper::Config& config,
0277 Acts::Logging::Level level) {
0278 return std::make_shared<MaterialMapper>(
0279 config, getDefaultLogger("MaterialMapper", level));
0280 }),
0281 py::arg("config"), py::arg("level"));
0282
0283 auto c = py::class_<MaterialMapper::Config>(mm, "Config").def(py::init<>());
0284 ACTS_PYTHON_STRUCT_BEGIN(c, MaterialMapper::Config);
0285 ACTS_PYTHON_MEMBER(assignmentFinder);
0286 ACTS_PYTHON_MEMBER(surfaceMaterialAccumulater);
0287 ACTS_PYTHON_STRUCT_END();
0288 }
0289
0290 {
0291 auto mmca = py::class_<CoreMaterialMapping, IAlgorithm,
0292 std::shared_ptr<CoreMaterialMapping>>(
0293 mex, "CoreMaterialMapping")
0294 .def(py::init<const CoreMaterialMapping::Config&,
0295 Acts::Logging::Level>(),
0296 py::arg("config"), py::arg("level"));
0297
0298 auto c = py::class_<CoreMaterialMapping::Config>(mmca, "Config")
0299 .def(py::init<>());
0300 ACTS_PYTHON_STRUCT_BEGIN(c, CoreMaterialMapping::Config);
0301 ACTS_PYTHON_MEMBER(inputMaterialTracks);
0302 ACTS_PYTHON_MEMBER(mappedMaterialTracks);
0303 ACTS_PYTHON_MEMBER(unmappedMaterialTracks);
0304 ACTS_PYTHON_MEMBER(materialMapper);
0305 ACTS_PYTHON_MEMBER(materiaMaplWriters);
0306 ACTS_PYTHON_STRUCT_END();
0307 }
0308
0309 {
0310 auto mvc =
0311 py::class_<MaterialValidater, std::shared_ptr<MaterialValidater>>(
0312 m, "MaterialValidater")
0313 .def(py::init([](const MaterialValidater::Config& config,
0314 Acts::Logging::Level level) {
0315 return std::make_shared<MaterialValidater>(
0316 config, getDefaultLogger("MaterialValidater", level));
0317 }),
0318 py::arg("config"), py::arg("level"))
0319 .def("recordMaterial", &MaterialValidater::recordMaterial);
0320
0321 auto c =
0322 py::class_<MaterialValidater::Config>(mvc, "Config").def(py::init<>());
0323 ACTS_PYTHON_STRUCT_BEGIN(c, MaterialValidater::Config);
0324 ACTS_PYTHON_MEMBER(materialAssigner);
0325 ACTS_PYTHON_STRUCT_END();
0326 }
0327
0328 {
0329 auto mv = py::class_<MaterialValidation, IAlgorithm,
0330 std::shared_ptr<MaterialValidation>>(
0331 mex, "MaterialValidation")
0332 .def(py::init<const MaterialValidation::Config&,
0333 Acts::Logging::Level>(),
0334 py::arg("config"), py::arg("level"))
0335 .def("execute", &MaterialValidation::execute)
0336 .def_property_readonly("config", &MaterialValidation::config);
0337
0338 auto c =
0339 py::class_<MaterialValidation::Config>(mv, "Config").def(py::init<>());
0340 ACTS_PYTHON_STRUCT_BEGIN(c, MaterialValidation::Config);
0341 ACTS_PYTHON_MEMBER(ntracks);
0342 ACTS_PYTHON_MEMBER(startPosition);
0343 ACTS_PYTHON_MEMBER(phiRange);
0344 ACTS_PYTHON_MEMBER(etaRange);
0345 ACTS_PYTHON_MEMBER(randomNumberSvc);
0346 ACTS_PYTHON_MEMBER(materialValidater);
0347 ACTS_PYTHON_MEMBER(outputMaterialTracks);
0348 ACTS_PYTHON_STRUCT_END();
0349 }
0350 }
0351
0352 }