File indexing completed on 2025-10-19 07:58:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/Root/TGeoDetectorElement.hpp"
0010 #include "ActsPlugins/Root/TGeoLayerBuilder.hpp"
0011 #include "ActsPlugins/Root/TGeoParser.hpp"
0012 #include "ActsPython/Utilities/Helpers.hpp"
0013
0014 #include <vector>
0015
0016 #include <TGeoManager.h>
0017 #include <TGeoVolume.h>
0018 #include <pybind11/pybind11.h>
0019 #include <pybind11/stl.h>
0020 #include <pybind11/stl/filesystem.h>
0021
0022 namespace py = pybind11;
0023 using namespace pybind11::literals;
0024
0025 using namespace Acts;
0026 using namespace ActsPlugins;
0027
0028 namespace ActsPython {
0029 void addTGeo(Context& ctx) {
0030 auto [m, mex] = ctx.get("main", "examples");
0031
0032 auto tgeo = mex.def_submodule("tgeo");
0033
0034 {
0035 py::class_<TGeoDetectorElement, std::shared_ptr<TGeoDetectorElement>>(
0036 tgeo, "TGeoDetectorElement")
0037 .def("surface", [](const TGeoDetectorElement& self) {
0038 return self.surface().getSharedPtr();
0039 });
0040 }
0041
0042 {
0043
0044
0045
0046
0047
0048
0049 tgeo.def(
0050 "_convertToElements",
0051 [](const std::string& rootFileName,
0052 const std::vector<std::string>& sensitiveMatches,
0053 const std::string& localAxes, double scaleConversion) {
0054
0055 std::vector<std::shared_ptr<const TGeoDetectorElement>> tgElements;
0056
0057 TGeoManager::Import(rootFileName.c_str());
0058 if (gGeoManager != nullptr) {
0059 auto tVolume = gGeoManager->GetTopVolume();
0060 if (tVolume != nullptr) {
0061 TGeoHMatrix gmatrix = TGeoIdentity(tVolume->GetName());
0062
0063 TGeoParser::Options tgpOptions;
0064 tgpOptions.volumeNames = {tVolume->GetName()};
0065 tgpOptions.targetNames = sensitiveMatches;
0066 tgpOptions.unit = scaleConversion;
0067 TGeoParser::State tgpState;
0068 tgpState.volume = tVolume;
0069 tgpState.onBranch = true;
0070
0071 TGeoParser::select(tgpState, tgpOptions, gmatrix);
0072 tgElements.reserve(tgpState.selectedNodes.size());
0073
0074 for (const auto& snode : tgpState.selectedNodes) {
0075 auto identifier = TGeoDetectorElement::Identifier();
0076 auto tgElement = TGeoLayerBuilder::defaultElementFactory(
0077 identifier, *snode.node, *snode.transform, localAxes,
0078 scaleConversion, nullptr);
0079 tgElements.emplace_back(tgElement);
0080 }
0081 }
0082 }
0083
0084 return tgElements;
0085 });
0086 }
0087 }
0088
0089 }