Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-19 07:58:23

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 "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     /// Helper function to test if the automatic geometry conversion works
0044     ///
0045     /// @param rootFileName is the name of the GDML file
0046     /// @param sensitiveMatches is a list of strings to match sensitive volumes
0047     /// @param localAxes is the TGeo->ACTS axis conversion convention
0048     /// @param scaleConversion is a unit scalor conversion factor
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           // Return vector
0055           std::vector<std::shared_ptr<const TGeoDetectorElement>> tgElements;
0056           // TGeo import
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           // Return the elements
0084           return tgElements;
0085         });
0086   }
0087 }
0088 
0089 }  // namespace ActsPython