File indexing completed on 2025-10-25 07:56:17
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Detector/Detector.hpp"
0010
0011 #include "Acts/Geometry/DetectorElementBase.hpp"
0012 #include "Acts/Geometry/TrackingGeometry.hpp"
0013 #include "Acts/Material/IMaterialDecorator.hpp"
0014 #include "Acts/Utilities/BinningType.hpp"
0015 #include "ActsExamples/DetectorCommons/Detector.hpp"
0016 #include "ActsExamples/DetectorCommons/StructureSelector.hpp"
0017 #include "ActsExamples/Framework/IContextDecorator.hpp"
0018 #include "ActsExamples/GenericDetector/AlignedGenericDetector.hpp"
0019 #include "ActsExamples/GenericDetector/GenericDetector.hpp"
0020 #include "ActsExamples/TGeoDetector/TGeoDetector.hpp"
0021 #include "ActsExamples/TelescopeDetector/TelescopeDetector.hpp"
0022 #include "ActsExamples/Utilities/Options.hpp"
0023 #include "ActsPython/Utilities/Helpers.hpp"
0024 #include "ActsPython/Utilities/Macros.hpp"
0025
0026 #include <memory>
0027 #include <optional>
0028 #include <string>
0029 #include <utility>
0030 #include <vector>
0031
0032 #include <pybind11/pybind11.h>
0033 #include <pybind11/stl.h>
0034 #include <pybind11/stl/filesystem.h>
0035
0036 namespace py = pybind11;
0037
0038 using namespace Acts;
0039 using namespace ActsExamples;
0040
0041 namespace ActsPython {
0042
0043 void addDetector(Context& ctx) {
0044 auto& mex = ctx.get("examples");
0045
0046 {
0047 py::class_<Detector, std::shared_ptr<Detector>>(mex, "DetectorBase")
0048 .def("nominalGeometryContext", &Detector::nominalGeometryContext)
0049 .def("trackingGeometry", &Detector::trackingGeometry)
0050 .def("gen2Geometry", &Detector::gen2Geometry)
0051 .def("contextDecorators", &Detector::contextDecorators)
0052 .def("__enter__",
0053 [](const std::shared_ptr<Detector>& self) { return self; })
0054 .def("__exit__",
0055 [](std::shared_ptr<Detector>& self,
0056 const std::optional<py::object>&,
0057 const std::optional<py::object>&,
0058 const std::optional<py::object>&) { self.reset(); });
0059 }
0060
0061 {
0062 py::class_<StructureSelector, std::shared_ptr<StructureSelector>>(
0063 mex, "StructureSelector")
0064 .def(py::init<std::shared_ptr<const TrackingGeometry>>())
0065 .def("selectSurfaces", &StructureSelector::selectSurfaces)
0066 .def("selectedTransforms", &StructureSelector::selectedTransforms);
0067 }
0068
0069 {
0070 auto d =
0071 py::class_<GenericDetector, Detector, std::shared_ptr<GenericDetector>>(
0072 mex, "GenericDetector")
0073 .def(py::init<const GenericDetector::Config&>());
0074
0075 auto c = py::class_<GenericDetector::Config>(d, "Config").def(py::init<>());
0076 ACTS_PYTHON_STRUCT(c, buildLevel, logLevel, surfaceLogLevel, layerLogLevel,
0077 volumeLogLevel, buildProto, materialDecorator, gen3,
0078 graphvizFile);
0079 }
0080
0081 {
0082 auto ad = py::class_<AlignedGenericDetector, GenericDetector,
0083 std::shared_ptr<AlignedGenericDetector>>(
0084 mex, "AlignedGenericDetector")
0085 .def(py::init<const GenericDetector::Config&>());
0086 }
0087
0088 {
0089 auto d =
0090 py::class_<TelescopeDetector, Detector,
0091 std::shared_ptr<TelescopeDetector>>(mex, "TelescopeDetector")
0092 .def(py::init<const TelescopeDetector::Config&>());
0093
0094 auto c =
0095 py::class_<TelescopeDetector::Config>(d, "Config").def(py::init<>());
0096 ACTS_PYTHON_STRUCT(c, positions, stereos, offsets, bounds, thickness,
0097 surfaceType, binValue, materialDecorator, logLevel);
0098 }
0099
0100 {
0101 auto d = py::class_<TGeoDetector, Detector, std::shared_ptr<TGeoDetector>>(
0102 mex, "TGeoDetector")
0103 .def(py::init<const TGeoDetector::Config&>());
0104
0105 py::class_<Options::Interval>(mex, "Interval")
0106 .def(py::init<>())
0107 .def(py::init<std::optional<double>, std::optional<double>>())
0108 .def_readwrite("lower", &Options::Interval::lower)
0109 .def_readwrite("upper", &Options::Interval::upper);
0110
0111 auto c = py::class_<TGeoDetector::Config>(d, "Config").def(py::init<>());
0112
0113 c.def_property("jsonFile", nullptr,
0114 [](TGeoDetector::Config& cfg, const std::string& file) {
0115 cfg.readJson(file);
0116 });
0117
0118 py::enum_<TGeoDetector::Config::SubVolume>(c, "SubVolume")
0119 .value("Negative", TGeoDetector::Config::SubVolume::Negative)
0120 .value("Central", TGeoDetector::Config::SubVolume::Central)
0121 .value("Positive", TGeoDetector::Config::SubVolume::Positive);
0122
0123 py::enum_<BinningType>(c, "BinningType")
0124 .value("equidistant", BinningType::equidistant)
0125 .value("arbitrary", BinningType::arbitrary);
0126
0127 auto volume =
0128 py::class_<TGeoDetector::Config::Volume>(c, "Volume").def(py::init<>());
0129 ACTS_PYTHON_STRUCT(
0130 volume, name, binToleranceR, binTolerancePhi, binToleranceZ,
0131 cylinderDiscSplit, cylinderNZSegments, cylinderNPhiSegments,
0132 discNRSegments, discNPhiSegments, itkModuleSplit, barrelMap, discMap,
0133 splitPatterns, layers, subVolumeName, sensitiveNames, sensitiveAxes,
0134 rRange, zRange, splitTolR, splitTolZ, binning0, binning1);
0135
0136 auto regTriplet = [&c](const std::string& name, auto v) {
0137 using type = decltype(v);
0138 py::class_<TGeoDetector::Config::LayerTriplet<type>>(c, name.c_str())
0139 .def(py::init<>())
0140 .def(py::init<type>())
0141 .def(py::init<type, type, type>())
0142 .def_readwrite("negative",
0143 &TGeoDetector::Config::LayerTriplet<type>::negative)
0144 .def_readwrite("central",
0145 &TGeoDetector::Config::LayerTriplet<type>::central)
0146 .def_readwrite("positive",
0147 &TGeoDetector::Config::LayerTriplet<type>::positive)
0148 .def("at", py::overload_cast<TGeoDetector::Config::SubVolume>(
0149 &TGeoDetector::Config::LayerTriplet<type>::at));
0150 };
0151
0152 regTriplet("LayerTripletBool", true);
0153 regTriplet("LayerTripletString", std::string{""});
0154 regTriplet("LayerTripletVectorString", std::vector<std::string>{});
0155 regTriplet("LayerTripletInterval", Options::Interval{});
0156 regTriplet("LayerTripletDouble", double{5.5});
0157 regTriplet("LayerTripletVectorBinning",
0158 std::vector<std::pair<int, BinningType>>{});
0159
0160 ACTS_PYTHON_STRUCT(c, surfaceLogLevel, layerLogLevel, volumeLogLevel,
0161 fileName, buildBeamPipe, beamPipeRadius,
0162 beamPipeHalflengthZ, beamPipeLayerThickness,
0163 beamPipeEnvelopeR, layerEnvelopeR, unitScalor,
0164 materialDecorator, volumes);
0165
0166 patchKwargsConstructor(c);
0167 }
0168
0169 {
0170 py::class_<DetectorElementBase, std::shared_ptr<DetectorElementBase>>(
0171 mex, "DetectorElementBase");
0172 }
0173 }
0174
0175 }