forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTGeo.cpp
More file actions
106 lines (94 loc) · 3.8 KB
/
TGeo.cpp
File metadata and controls
106 lines (94 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 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 "ActsPlugins/Root/TGeoAxes.hpp"
#include "ActsPlugins/Root/TGeoDetectorElement.hpp"
#include "ActsPlugins/Root/TGeoLayerBuilder.hpp"
#include "ActsPlugins/Root/TGeoParser.hpp"
#include "ActsPython/Utilities/Helpers.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;
PYBIND11_MODULE(ActsPluginsPythonBindingsTGeo, tgeo) {
using namespace Acts;
using namespace ActsPlugins;
// Basic bindings: detector axes
{
py::class_<TGeoAxes>(tgeo, "TGeoAxes")
.def(py::init([](std::string s) { return TGeoAxes::parse(s); }))
.def("value", &TGeoAxes::value)
.def("__repr__",
[](const TGeoAxes& self) {
return "TGeoAxes('" + std::string(self.value()) + "')";
})
.def("__str__",
[](const TGeoAxes& self) { return std::string(self.value()); })
.def("__eq__",
[](const TGeoAxes& self, const TGeoAxes& other) {
return self.value() == other.value();
})
.def("__ne__", [](const TGeoAxes& self, const TGeoAxes& other) {
return self.value() != other.value();
});
py::implicitly_convertible<std::string, TGeoAxes>();
}
// Basic bindings: detector element
{
py::class_<TGeoDetectorElement, std::shared_ptr<TGeoDetectorElement>>(
tgeo, "TGeoDetectorElement")
.def("surface", [](const 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 conversion convention
/// @param scaleConversion is a unit scalor conversion factor
tgeo.def(
"convertToElements",
[](const std::string& rootFileName,
const std::vector<std::string>& sensitiveMatches,
const TGeoAxes& localAxes, double scaleConversion) {
// Return vector
std::vector<std::shared_ptr<const 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.unit = scaleConversion;
TGeoParser::State tgpState;
tgpState.volume = tVolume;
tgpState.onBranch = true;
TGeoParser::select(tgpState, tgpOptions, gmatrix);
tgElements.reserve(tgpState.selectedNodes.size());
for (const auto& snode : tgpState.selectedNodes) {
auto identifier = TGeoDetectorElement::Identifier();
auto tgElement = TGeoLayerBuilder::defaultElementFactory(
identifier, *snode.node, *snode.transform, localAxes,
scaleConversion, nullptr);
tgElements.emplace_back(tgElement);
}
}
}
// Return the elements
return tgElements;
});
}
}