Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-09 09:26:47

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 "ActsExamples/TGeoDetector/TGeoDetector.hpp"
0010 #include "ActsPython/Utilities/Helpers.hpp"
0011 #include "ActsPython/Utilities/Macros.hpp"
0012 
0013 #include <pybind11/pybind11.h>
0014 #include <pybind11/stl.h>
0015 
0016 namespace py = pybind11;
0017 using namespace pybind11::literals;
0018 
0019 using namespace Acts;
0020 using namespace ActsExamples;
0021 using namespace ActsPython;
0022 
0023 PYBIND11_MODULE(ActsExamplesPythonBindingsTGeo, tgeo) {
0024   {
0025     auto d = py::class_<TGeoDetector, Detector, std::shared_ptr<TGeoDetector>>(
0026                  tgeo, "TGeoDetector")
0027                  .def(py::init<const TGeoDetector::Config&>());
0028 
0029     py::class_<Options::Interval>(tgeo, "Interval")
0030         .def(py::init<>())
0031         .def(py::init<std::optional<double>, std::optional<double>>())
0032         .def_readwrite("lower", &Options::Interval::lower)
0033         .def_readwrite("upper", &Options::Interval::upper);
0034 
0035     auto c = py::class_<TGeoDetector::Config>(d, "Config").def(py::init<>());
0036 
0037     c.def_property("jsonFile", nullptr,
0038                    [](TGeoDetector::Config& cfg, const std::string& file) {
0039                      cfg.readJson(file);
0040                    });
0041 
0042     py::enum_<TGeoDetector::Config::SubVolume>(c, "SubVolume")
0043         .value("Negative", TGeoDetector::Config::SubVolume::Negative)
0044         .value("Central", TGeoDetector::Config::SubVolume::Central)
0045         .value("Positive", TGeoDetector::Config::SubVolume::Positive);
0046 
0047     py::enum_<BinningType>(c, "BinningType")
0048         .value("equidistant", BinningType::equidistant)
0049         .value("arbitrary", BinningType::arbitrary);
0050 
0051     auto volume =
0052         py::class_<TGeoDetector::Config::Volume>(c, "Volume").def(py::init<>());
0053     ACTS_PYTHON_STRUCT(
0054         volume, name, binToleranceR, binTolerancePhi, binToleranceZ,
0055         cylinderDiscSplit, cylinderNZSegments, cylinderNPhiSegments,
0056         discNRSegments, discNPhiSegments, itkModuleSplit, barrelMap, discMap,
0057         splitPatterns, layers, subVolumeName, sensitiveNames, sensitiveAxes,
0058         rRange, zRange, splitTolR, splitTolZ, binning0, binning1);
0059 
0060     auto regTriplet = [&c](const std::string& name, auto v) {
0061       using type = decltype(v);
0062       py::class_<TGeoDetector::Config::LayerTriplet<type>>(c, name.c_str())
0063           .def(py::init<>())
0064           .def(py::init<type>())
0065           .def(py::init<type, type, type>())
0066           .def_readwrite("negative",
0067                          &TGeoDetector::Config::LayerTriplet<type>::negative)
0068           .def_readwrite("central",
0069                          &TGeoDetector::Config::LayerTriplet<type>::central)
0070           .def_readwrite("positive",
0071                          &TGeoDetector::Config::LayerTriplet<type>::positive)
0072           .def("at", py::overload_cast<TGeoDetector::Config::SubVolume>(
0073                          &TGeoDetector::Config::LayerTriplet<type>::at));
0074     };
0075 
0076     regTriplet("LayerTripletBool", true);
0077     regTriplet("LayerTripletString", std::string{""});
0078     regTriplet("LayerTripletVectorString", std::vector<std::string>{});
0079     regTriplet("LayerTripletInterval", Options::Interval{});
0080     regTriplet("LayerTripletDouble", double{5.5});
0081     regTriplet("LayerTripletVectorBinning",
0082                std::vector<std::pair<int, BinningType>>{});
0083 
0084     ACTS_PYTHON_STRUCT(c, surfaceLogLevel, layerLogLevel, volumeLogLevel,
0085                        fileName, buildBeamPipe, beamPipeRadius,
0086                        beamPipeHalflengthZ, beamPipeLayerThickness,
0087                        beamPipeEnvelopeR, layerEnvelopeR, unitScalor,
0088                        materialDecorator, volumes);
0089 
0090     patchKwargsConstructor(c);
0091   }
0092 }