Skip to content

Commit

Permalink
Merge branch 'main' into refactor/portal-fuse
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Nov 29, 2023
2 parents 3dbd73c + cf84e21 commit b03e2ac
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Examples/Scripts/generic_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ def main(
h = histograms.get(col)
values = awkward.flatten(df[col], axis=None)

if len(values) == 0:
print(f"WARNING: Branch '{col}' is empty. Skipped.")
continue

if h is None:
# try to find config
found = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void convert(nlohmann::json& jIndexedVolumes,
auto castedDelegate = dynamic_cast<const DelegateType*>(instance);
if (castedDelegate != nullptr) {
jIndexedVolumes = IndexedGridJsonHelper::convertImpl<DelegateType>(
*castedDelegate, detray);
*castedDelegate, detray, false);
if (detray) {
jIndexedVolumes["volume_link"] = 1;
nlohmann::json jAccLink;
Expand Down
18 changes: 12 additions & 6 deletions Plugins/Json/include/Acts/Plugins/Json/GridJsonConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ nlohmann::json toJson(const grid_type& grid) {
///
/// @tparam grid_type the type of the grid
/// @param grid the grid object
/// @param swapAxis - this is needed for detray
///
/// @note detray has a different offset for the
/// local indices, it starts at 0
///
/// @return a json object to represent the grid
template <typename grid_type>
nlohmann::json toJsonDetray(const grid_type& grid) {
nlohmann::json toJsonDetray(const grid_type& grid, bool swapAxis = false) {
nlohmann::json jGrid;

auto axes = grid.axes();
Expand All @@ -106,7 +110,7 @@ nlohmann::json toJsonDetray(const grid_type& grid) {
if constexpr (grid_type::DIM == 1u) {
for (unsigned int ib0 = 1u; ib0 <= axes[0u]->getNBins(); ++ib0) {
typename grid_type::index_t lbin;
lbin[0u] = ib0;
lbin[0u] = ib0 - 1u;
nlohmann::json jBin;
jBin["loc_index"] = lbin;
jBin["content"] = grid.atLocalBins(lbin);
Expand All @@ -116,11 +120,13 @@ nlohmann::json toJsonDetray(const grid_type& grid) {

// 2D connections
if constexpr (grid_type::DIM == 2u) {
for (unsigned int ib0 = 1u; ib0 <= axes[0u]->getNBins(); ++ib0) {
for (unsigned int ib1 = 1u; ib1 <= axes[1u]->getNBins(); ++ib1) {
unsigned int iaxis0 = swapAxis ? 1u : 0u;
unsigned int iaxis1 = swapAxis ? 0u : 1u;
for (unsigned int ib0 = 1u; ib0 <= axes[iaxis0]->getNBins(); ++ib0) {
for (unsigned int ib1 = 1u; ib1 <= axes[iaxis1]->getNBins(); ++ib1) {
typename grid_type::index_t lbin;
lbin[0u] = ib0;
lbin[1u] = ib1;
lbin[0u] = ib0 - 1u;
lbin[1u] = ib1 - 1u;
nlohmann::json jBin;
jBin["loc_index"] = lbin;
jBin["content"] = grid.atLocalBins(lbin);
Expand Down
14 changes: 12 additions & 2 deletions Plugins/Json/include/Acts/Plugins/Json/IndexedGridJsonHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ using namespace Experimental::detail::GridAxisGenerators;
namespace IndexedGridJsonHelper {

/// @brief The actual conversion method
///
/// @param indexGrid is the index grid to be written
/// @param detray is a flag indicating detray writout
/// @param checkSwap is a flag indicating if the axes should be swapped
template <typename index_grid>
nlohmann::json convertImpl(const index_grid& indexGrid, bool detray = false) {
nlohmann::json convertImpl(const index_grid& indexGrid, bool detray = false,
bool checkSwap = false) {
nlohmann::json jIndexedGrid;

// Axis swapping
bool swapAxes = checkSwap;

// Fill the casts
nlohmann::json jCasts;
// 1D casts
Expand All @@ -36,12 +44,14 @@ nlohmann::json convertImpl(const index_grid& indexGrid, bool detray = false) {
if constexpr (index_grid::grid_type::DIM == 2u) {
jCasts.push_back(indexGrid.casts[0u]);
jCasts.push_back(indexGrid.casts[1u]);
swapAxes = checkSwap &&
(indexGrid.casts[0u] == binZ && indexGrid.casts[1u] == binPhi);
}
jIndexedGrid["casts"] = jCasts;
jIndexedGrid["transform"] =
Transform3JsonConverter::toJson(indexGrid.transform);
if (detray) {
jIndexedGrid = GridJsonConverter::toJsonDetray(indexGrid.grid);
jIndexedGrid = GridJsonConverter::toJsonDetray(indexGrid.grid, swapAxes);
} else {
jIndexedGrid["grid"] = GridJsonConverter::toJson(indexGrid.grid);
}
Expand Down
17 changes: 17 additions & 0 deletions Plugins/Json/src/DetectorJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ nlohmann::json Acts::DetectorJsonConverter::toJsonDetray(
if (jSurfacesDelegate.is_null()) {
continue;
}
// Patch axes for cylindrical grid surfaces, axes are swapped
// at this point
auto jAccLink = jSurfacesDelegate["acc_link"];
std::size_t accLinkType = jAccLink["type"];
if (accLinkType == 4u) {
// Radial value to transfer phi to rphi
std::vector<ActsScalar> bValues = volume->volumeBounds().values();
ActsScalar rRef = 0.5 * (bValues[1] + bValues[0]);
// Get the axes
auto& jAxes = jSurfacesDelegate["axes"];
// r*phi axis is the first one
std::vector<ActsScalar> jAxesEdges = jAxes[0u]["edges"];
std::for_each(jAxesEdges.begin(), jAxesEdges.end(),
[rRef](ActsScalar& phi) { phi *= rRef; });
// Write back the patches axis edges
jSurfacesDelegate["axes"][0u]["edges"] = jAxesEdges;
}
// Colplete the grid json for detray usage
jSurfacesDelegate["volume_link"] = iv;
// jSurfacesDelegate["acc_link"] =
Expand Down
11 changes: 6 additions & 5 deletions Plugins/Json/src/PortalJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Acts/Surfaces/RegularSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/Enumerate.hpp"
#include "Acts/Utilities/VectorHelpers.hpp"

#include <algorithm>
#include <iterator>
Expand Down Expand Up @@ -134,11 +135,11 @@ std::vector<nlohmann::json> Acts::PortalJsonConverter::toJsonDetray(
const auto& cast = multiLink1D->indexedUpdater.casts[0u];
const auto& transform = multiLink1D->indexedUpdater.transform;
const auto& volumes = multiLink1D->indexedUpdater.extractor.dVolumes;
if (!transform.isApprox(Transform3::Identity())) {
std::runtime_error(
"PortalJsonConverter: transformed boundary link implementation not "
"(yet) supported");
}

// Apply the correction from local to global boundaries
ActsScalar gCorr = VectorHelpers::cast(transform.translation(), cast);
std::for_each(boundaries.begin(), boundaries.end(),
[&gCorr](ActsScalar& b) { b -= gCorr; });

// Get the volume indices
auto surfaceType = surfaceAdjusted->type();
Expand Down

0 comments on commit b03e2ac

Please sign in to comment.