-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2cf38f7
commit d949c49
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "Acts/Plugins/Python/Utilities.hpp" | ||
#include "Acts/Plugins/TGeo/TGeoDetectorElement.hpp" | ||
#include "Acts/Plugins/TGeo/TGeoLayerBuilder.hpp" | ||
#include "Acts/Plugins/TGeo/TGeoParser.hpp" | ||
|
||
#include <vector> | ||
|
||
#include <TGeoManager.h> | ||
#include <TGeoVolume.h> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <pybind11/stl/filesystem.h> | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
namespace Acts::Python { | ||
void addTGeo(Context& ctx) { | ||
auto [m, mex] = ctx.get("main", "examples"); | ||
|
||
auto tgeo = mex.def_submodule("tgeo"); | ||
|
||
{ | ||
py::class_<Acts::TGeoDetectorElement, | ||
std::shared_ptr<Acts::TGeoDetectorElement>>( | ||
tgeo, "TGeoDetectorElement") | ||
.def("surface", [](const Acts::TGeoDetectorElement& self) { | ||
return self.surface().getSharedPtr(); | ||
}); | ||
} | ||
|
||
{ | ||
/// Helper function to test if the automatic geometry conversion works | ||
/// | ||
/// @param rootFileName is the name of the GDML file | ||
/// @param sensitiveMatches is a list of strings to match sensitive volumes | ||
/// @param localAxes is the TGeo->ACTS axis covnersion convention | ||
/// @param convertMaterial is a flag to convert the material | ||
tgeo.def("convertToElements", | ||
[](const std::string& rootFileName, | ||
const std::vector<std::string>& sensitiveMatches, | ||
const std::string& localAxes, double scaleConversion, | ||
bool convertMaterial) { | ||
// Return vector | ||
std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>> | ||
tgElements; | ||
// TGeo import | ||
TGeoManager::Import(rootFileName.c_str()); | ||
if (gGeoManager != nullptr) { | ||
auto tVolume = gGeoManager->GetTopVolume(); | ||
if (tVolume != nullptr) { | ||
TGeoHMatrix gmatrix = TGeoIdentity(tVolume->GetName()); | ||
|
||
TGeoParser::Options tgpOptions; | ||
tgpOptions.volumeNames = {tVolume->GetName()}; | ||
tgpOptions.targetNames = sensitiveMatches; | ||
tgpOptions.parseRanges = {}; | ||
tgpOptions.unit = scaleConversion; | ||
TGeoParser::State tgpState; | ||
tgpState.volume = tVolume; | ||
tgpState.onBranch = true; | ||
|
||
TGeoParser::select(tgpState, tgpOptions, gmatrix); | ||
tgElements.reserve(tgpState.selectedNodes.size()); | ||
|
||
for (auto& snode : tgpState.selectedNodes) { | ||
auto identifier = Acts::TGeoDetectorElement::Identifier(); | ||
auto tgElement = TGeoLayerBuilder::defaultElementFactory( | ||
identifier, *snode.node, *snode.transform, localAxes, | ||
scaleConversion, nullptr); | ||
tgElements.emplace_back(tgElement); | ||
} | ||
} | ||
} | ||
// Return the elements | ||
return tgElements; | ||
}); | ||
} | ||
} | ||
|
||
} // namespace Acts::Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
namespace Acts::Python { | ||
struct Context; | ||
} // namespace Acts::Python | ||
|
||
namespace Acts::Python { | ||
void addTGeo(Context& /*ctx*/) {} | ||
} // namespace Acts::Python |