-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Detray plugin geometry (#3299)
- Loading branch information
Showing
10 changed files
with
702 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2024 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 http://mozilla.org/MPL/2.0/. | ||
|
||
#include "Acts/Detector/Detector.hpp" | ||
#include "Acts/Plugins/Detray/DetrayConverter.hpp" | ||
#include "Acts/Plugins/Python/Utilities.hpp" | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <vecmem/memory/host_memory_resource.hpp> | ||
#include <vecmem/memory/memory_resource.hpp> | ||
|
||
#include "detray/builders/detector_builder.hpp" | ||
#include "detray/io/frontend/detector_reader_config.hpp" | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
using namespace Acts; | ||
using namespace detray; | ||
using namespace detray::io::detail; | ||
|
||
namespace Acts::Python { | ||
|
||
void addDetray(Context& ctx) { | ||
auto [m, mex] = ctx.get("main", "examples"); | ||
|
||
{ | ||
py::class_<detector<default_metadata>, | ||
std::shared_ptr<detector<default_metadata>>>(m, | ||
"detray_detector"); | ||
} | ||
|
||
{ mex.def("writeToJson", &DetrayConverter::writeToJson); } | ||
/** | ||
{ | ||
/// @brief Converts an Acts::Detector to a detray::detector | ||
mex.def("convertDetectorToDetray", | ||
[](const Acts::GeometryContext& gctx, | ||
const Acts::Experimental::Detector& acts_detector, | ||
const std::string& name) -> auto | ||
{//detector<default_metadata> | ||
// Create a host memory resource | ||
vecmem::host_memory_resource host_mr; | ||
// Convert Acts detector to detray detector using the | ||
detray converter function auto det_tuple = | ||
DetrayConverter::detrayConvert(acts_detector, gctx, host_mr); | ||
return true; //TO DO:: cannot return tuple | ||
}); | ||
} | ||
**/ | ||
} | ||
} // 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,13 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2024 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 http://mozilla.org/MPL/2.0/. | ||
|
||
#include "Acts/Plugins/Python/Utilities.hpp" | ||
|
||
namespace Acts::Python { | ||
void addDetray(Context& /*ctx*/) {} | ||
} // 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
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,34 @@ | ||
add_library( | ||
ActsPluginDetray SHARED | ||
src/DetrayConverter.cpp) | ||
|
||
add_dependencies(ActsPluginDetray | ||
detray::core | ||
covfie::core | ||
vecmem::core) | ||
|
||
target_include_directories( | ||
ActsPluginDetray | ||
PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/> | ||
$<INSTALL_INTERFACE:include>) | ||
|
||
target_link_libraries( | ||
ActsPluginDetray | ||
PUBLIC | ||
ActsCore | ||
detray::core | ||
detray::core_array | ||
detray::io | ||
detray::utils | ||
detray::svgtools | ||
vecmem::core) | ||
|
||
install( | ||
TARGETS ActsPluginDetray | ||
EXPORT ActsPluginDetrayTargets | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
|
||
install( | ||
DIRECTORY include/Acts | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) |
117 changes: 117 additions & 0 deletions
117
Plugins/Detray/include/Acts/Plugins/Detray/DetrayConversionHelper.hpp
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,117 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Surfaces/SurfaceBounds.hpp" | ||
#include "Acts/Utilities/BinningData.hpp" | ||
|
||
#include <string> | ||
#include <tuple> | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
#include "detray/io/frontend/definitions.hpp" | ||
|
||
namespace Acts::DetrayConversionHelper { | ||
|
||
/// @brief Helper function to switch keys from ACTS to detray | ||
/// | ||
/// DETRAY types @todo change to detray imports when available | ||
/// annulus2 = 0u, | ||
/// cuboid3 = 1u, | ||
/// cylinder2 = 2u, | ||
/// cylinder3 = 3u, | ||
/// portal_cylinder2 = 4u, | ||
/// rectangle2 = 5u, | ||
/// ring2 = 6u, | ||
/// trapezoid2 = 7u, | ||
/// cell_wire = 8u, | ||
/// straw_wire = 9u, | ||
/// single1 = 10u, | ||
/// single2 = 11u, | ||
/// single3 = 12u, | ||
/// unknown = 13u | ||
/// | ||
/// @param sBounds is the surface bounds type | ||
/// @param portal is the flag for conversion into detray portal format | ||
/// | ||
/// @return type and value array in detray format | ||
inline static std::tuple<unsigned int, std::vector<ActsScalar>> maskFromBounds( | ||
const Acts::SurfaceBounds& sBounds, bool portal = false) { | ||
auto bType = sBounds.type(); | ||
auto bValues = sBounds.values(); | ||
// Return value | ||
unsigned int type = 13u; | ||
std::vector<double> boundaries = bValues; | ||
// Special treatment for some portals | ||
if (portal && bType == SurfaceBounds::BoundsType::eCylinder) { | ||
boundaries = {bValues[0u], -bValues[1u], bValues[1u]}; | ||
type = 4u; | ||
} else { | ||
switch (bType) { | ||
case SurfaceBounds::BoundsType::eAnnulus: { | ||
type = 0u; | ||
} break; | ||
case SurfaceBounds::BoundsType::eRectangle: { | ||
type = 5u; | ||
// ACTS: eMinX = 0, eMinY = 1, eMaxX = 2, eMaxY = 3, | ||
// detray: e_half_x, e_half_y | ||
boundaries = {0.5 * (bValues[2] - bValues[0]), | ||
0.5 * (bValues[3] - bValues[1])}; | ||
} break; | ||
case SurfaceBounds::BoundsType::eCylinder: { | ||
boundaries = {bValues[0u], -bValues[1u], bValues[1u]}; | ||
type = 2u; | ||
} break; | ||
case SurfaceBounds::BoundsType::eTrapezoid: { | ||
type = 7u; | ||
boundaries = {bValues[0u], bValues[1u], bValues[2u], | ||
1 / (2 * bValues[2u])}; | ||
} break; | ||
case SurfaceBounds::BoundsType::eDisc: { | ||
boundaries = {bValues[0u], bValues[1u]}; | ||
type = 6u; | ||
} break; | ||
default: | ||
break; | ||
} | ||
} | ||
return std::tie(type, boundaries); | ||
} | ||
|
||
/// Determine the acceleration link from a grid | ||
/// | ||
/// @param casts are the grid axes cast types | ||
/// | ||
/// @return the acceleration link idnetifier | ||
template <typename binning_values_t> | ||
inline static std::size_t accelerationLink(const binning_values_t& casts) { | ||
// Default is `brute_force` | ||
std::size_t accLink = detray::io::accel_id::brute_force; | ||
if (casts.size() == 2u) { | ||
if (casts[0u] == binX && casts[1u] == binY) { | ||
accLink = detray::io::accel_id::cartesian2_grid; | ||
} else if (casts[0u] == binR && casts[1u] == binPhi) { | ||
accLink = detray::io::accel_id::polar2_grid; | ||
} else if (casts[0u] == binZ && casts[1u] == binPhi) { | ||
accLink = detray::io::accel_id::cylinder2_grid; | ||
} else if (casts[0u] == binZ && casts[1u] == binR) { | ||
accLink = detray::io::accel_id::cylinder3_grid; | ||
} | ||
} else if (casts.size() == 3u) { | ||
if (casts[0u] == binX && casts[1u] == binY && casts[2u] == binZ) { | ||
accLink = detray::io::accel_id::cuboid3_grid; | ||
} else if (casts[0u] == binZ && casts[1u] == binPhi && casts[2u] == binR) { | ||
accLink = detray::io::accel_id::cylinder3_grid; | ||
} | ||
} | ||
return accLink; | ||
} | ||
|
||
} // namespace Acts::DetrayConversionHelper |
Oops, something went wrong.