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