Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:01

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/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/ContextualDetector/AlignedDetector.hpp"
0017 #include "ActsExamples/DetectorCommons/Detector.hpp"
0018 #include "ActsExamples/Framework/IContextDecorator.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 
0033 namespace py = pybind11;
0034 using namespace ActsExamples;
0035 
0036 namespace Acts::Python {
0037 
0038 void addDetector(Context& ctx) {
0039   auto [m, mex] = ctx.get("main", "examples");
0040 
0041   {
0042     py::class_<IContextDecorator, std::shared_ptr<IContextDecorator>>(
0043         mex, "IContextDecorator")
0044         .def("decorate", &IContextDecorator::decorate)
0045         .def("name", &IContextDecorator::name);
0046   }
0047 
0048   {
0049     py::class_<Detector, std::shared_ptr<Detector>>(mex, "DetectorBase")
0050         .def("nominalGeometryContext", &Detector::nominalGeometryContext)
0051         .def("trackingGeometry", &Detector::trackingGeometry)
0052         .def("gen2Geometry", &Detector::gen2Geometry)
0053         .def("contextDecorators", &Detector::contextDecorators)
0054         .def("__enter__",
0055              [](const std::shared_ptr<Detector>& self) { return self; })
0056         .def("__exit__",
0057              [](std::shared_ptr<Detector>& self,
0058                 const std::optional<py::object>&,
0059                 const std::optional<py::object>&,
0060                 const std::optional<py::object>&) { self.reset(); });
0061   }
0062 
0063   {
0064     auto d =
0065         py::class_<GenericDetector, Detector, std::shared_ptr<GenericDetector>>(
0066             mex, "GenericDetector")
0067             .def(py::init<const GenericDetector::Config&>());
0068 
0069     auto c = py::class_<GenericDetector::Config>(d, "Config").def(py::init<>());
0070     ACTS_PYTHON_STRUCT_BEGIN(c, GenericDetector::Config);
0071     ACTS_PYTHON_MEMBER(buildLevel);
0072     ACTS_PYTHON_MEMBER(logLevel);
0073     ACTS_PYTHON_MEMBER(surfaceLogLevel);
0074     ACTS_PYTHON_MEMBER(layerLogLevel);
0075     ACTS_PYTHON_MEMBER(volumeLogLevel);
0076     ACTS_PYTHON_MEMBER(buildProto);
0077     ACTS_PYTHON_MEMBER(materialDecorator);
0078     ACTS_PYTHON_STRUCT_END();
0079   }
0080 
0081   {
0082     auto d =
0083         py::class_<TelescopeDetector, Detector,
0084                    std::shared_ptr<TelescopeDetector>>(mex, "TelescopeDetector")
0085             .def(py::init<const TelescopeDetector::Config&>());
0086 
0087     auto c =
0088         py::class_<TelescopeDetector::Config>(d, "Config").def(py::init<>());
0089     ACTS_PYTHON_STRUCT_BEGIN(c, TelescopeDetector::Config);
0090     ACTS_PYTHON_MEMBER(positions);
0091     ACTS_PYTHON_MEMBER(stereos);
0092     ACTS_PYTHON_MEMBER(offsets);
0093     ACTS_PYTHON_MEMBER(bounds);
0094     ACTS_PYTHON_MEMBER(thickness);
0095     ACTS_PYTHON_MEMBER(surfaceType);
0096     ACTS_PYTHON_MEMBER(binValue);
0097     ACTS_PYTHON_MEMBER(materialDecorator);
0098     ACTS_PYTHON_MEMBER(logLevel);
0099     ACTS_PYTHON_STRUCT_END();
0100   }
0101 
0102   {
0103     auto d =
0104         py::class_<AlignedDetector, Detector, std::shared_ptr<AlignedDetector>>(
0105             mex, "AlignedDetector")
0106             .def(py::init<const AlignedDetector::Config&>());
0107 
0108     auto c = py::class_<AlignedDetector::Config, GenericDetector::Config>(
0109                  d, "Config")
0110                  .def(py::init<>());
0111     ACTS_PYTHON_STRUCT_BEGIN(c, AlignedDetector::Config);
0112     ACTS_PYTHON_MEMBER(seed);
0113     ACTS_PYTHON_MEMBER(iovSize);
0114     ACTS_PYTHON_MEMBER(flushSize);
0115     ACTS_PYTHON_MEMBER(doGarbageCollection);
0116     ACTS_PYTHON_MEMBER(sigmaInPlane);
0117     ACTS_PYTHON_MEMBER(sigmaOutPlane);
0118     ACTS_PYTHON_MEMBER(sigmaInRot);
0119     ACTS_PYTHON_MEMBER(sigmaOutRot);
0120     ACTS_PYTHON_MEMBER(firstIovNominal);
0121     ACTS_PYTHON_MEMBER(decoratorLogLevel);
0122     ACTS_PYTHON_MEMBER(mode);
0123     ACTS_PYTHON_STRUCT_END();
0124 
0125     py::enum_<AlignedDetector::Config::Mode>(c, "Mode")
0126         .value("Internal", AlignedDetector::Config::Mode::Internal)
0127         .value("External", AlignedDetector::Config::Mode::External);
0128   }
0129 
0130   {
0131     auto d = py::class_<TGeoDetector, Detector, std::shared_ptr<TGeoDetector>>(
0132                  mex, "TGeoDetector")
0133                  .def(py::init<const TGeoDetector::Config&>());
0134 
0135     py::class_<Options::Interval>(mex, "Interval")
0136         .def(py::init<>())
0137         .def(py::init<std::optional<double>, std::optional<double>>())
0138         .def_readwrite("lower", &Options::Interval::lower)
0139         .def_readwrite("upper", &Options::Interval::upper);
0140 
0141     auto c = py::class_<TGeoDetector::Config>(d, "Config").def(py::init<>());
0142 
0143     c.def_property("jsonFile", nullptr,
0144                    [](TGeoDetector::Config& cfg, const std::string& file) {
0145                      cfg.readJson(file);
0146                    });
0147 
0148     py::enum_<TGeoDetector::Config::SubVolume>(c, "SubVolume")
0149         .value("Negative", TGeoDetector::Config::SubVolume::Negative)
0150         .value("Central", TGeoDetector::Config::SubVolume::Central)
0151         .value("Positive", TGeoDetector::Config::SubVolume::Positive);
0152 
0153     py::enum_<Acts::BinningType>(c, "BinningType")
0154         .value("equidistant", Acts::BinningType::equidistant)
0155         .value("arbitrary", Acts::BinningType::arbitrary);
0156 
0157     auto volume =
0158         py::class_<TGeoDetector::Config::Volume>(c, "Volume").def(py::init<>());
0159     ACTS_PYTHON_STRUCT_BEGIN(volume, TGeoDetector::Config::Volume);
0160     ACTS_PYTHON_MEMBER(name);
0161     ACTS_PYTHON_MEMBER(binToleranceR);
0162     ACTS_PYTHON_MEMBER(binTolerancePhi);
0163     ACTS_PYTHON_MEMBER(binToleranceZ);
0164     ACTS_PYTHON_MEMBER(cylinderDiscSplit);
0165     ACTS_PYTHON_MEMBER(cylinderNZSegments);
0166     ACTS_PYTHON_MEMBER(cylinderNPhiSegments);
0167     ACTS_PYTHON_MEMBER(discNRSegments);
0168     ACTS_PYTHON_MEMBER(discNPhiSegments);
0169     ACTS_PYTHON_MEMBER(itkModuleSplit);
0170     ACTS_PYTHON_MEMBER(barrelMap);
0171     ACTS_PYTHON_MEMBER(discMap);
0172     ACTS_PYTHON_MEMBER(splitPatterns);
0173 
0174     ACTS_PYTHON_MEMBER(layers);
0175     ACTS_PYTHON_MEMBER(subVolumeName);
0176     ACTS_PYTHON_MEMBER(sensitiveNames);
0177     ACTS_PYTHON_MEMBER(sensitiveAxes);
0178     ACTS_PYTHON_MEMBER(rRange);
0179     ACTS_PYTHON_MEMBER(zRange);
0180     ACTS_PYTHON_MEMBER(splitTolR);
0181     ACTS_PYTHON_MEMBER(splitTolZ);
0182     ACTS_PYTHON_MEMBER(binning0);
0183     ACTS_PYTHON_MEMBER(binning1);
0184     ACTS_PYTHON_STRUCT_END();
0185 
0186     auto regTriplet = [&c](const std::string& name, auto v) {
0187       using type = decltype(v);
0188       py::class_<TGeoDetector::Config::LayerTriplet<type>>(c, name.c_str())
0189           .def(py::init<>())
0190           .def(py::init<type>())
0191           .def(py::init<type, type, type>())
0192           .def_readwrite("negative",
0193                          &TGeoDetector::Config::LayerTriplet<type>::negative)
0194           .def_readwrite("central",
0195                          &TGeoDetector::Config::LayerTriplet<type>::central)
0196           .def_readwrite("positive",
0197                          &TGeoDetector::Config::LayerTriplet<type>::positive)
0198           .def("at", py::overload_cast<TGeoDetector::Config::SubVolume>(
0199                          &TGeoDetector::Config::LayerTriplet<type>::at));
0200     };
0201 
0202     regTriplet("LayerTripletBool", true);
0203     regTriplet("LayerTripletString", std::string{""});
0204     regTriplet("LayerTripletVectorString", std::vector<std::string>{});
0205     regTriplet("LayerTripletInterval", Options::Interval{});
0206     regTriplet("LayerTripletDouble", double{5.5});
0207     regTriplet("LayerTripletVectorBinning",
0208                std::vector<std::pair<int, Acts::BinningType>>{});
0209 
0210     ACTS_PYTHON_STRUCT_BEGIN(c, TGeoDetector::Config);
0211     ACTS_PYTHON_MEMBER(surfaceLogLevel);
0212     ACTS_PYTHON_MEMBER(layerLogLevel);
0213     ACTS_PYTHON_MEMBER(volumeLogLevel);
0214     ACTS_PYTHON_MEMBER(fileName);
0215     ACTS_PYTHON_MEMBER(buildBeamPipe);
0216     ACTS_PYTHON_MEMBER(beamPipeRadius);
0217     ACTS_PYTHON_MEMBER(beamPipeHalflengthZ);
0218     ACTS_PYTHON_MEMBER(beamPipeLayerThickness);
0219     ACTS_PYTHON_MEMBER(beamPipeEnvelopeR);
0220     ACTS_PYTHON_MEMBER(layerEnvelopeR);
0221     ACTS_PYTHON_MEMBER(unitScalor);
0222     ACTS_PYTHON_MEMBER(volumes);
0223     ACTS_PYTHON_STRUCT_END();
0224 
0225     patchKwargsConstructor(c);
0226   }
0227 
0228   {
0229     py::class_<Acts::DetectorElementBase,
0230                std::shared_ptr<Acts::DetectorElementBase>>(
0231         mex, "DetectorElementBase");
0232   }
0233 }
0234 
0235 }  // namespace Acts::Python