Skip to content

Commit

Permalink
Traccc Plugin (conversion)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredevb committed Jul 28, 2024
1 parent 06a6c03 commit e32b12f
Show file tree
Hide file tree
Showing 12 changed files with 621 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ endmacro()
# the same package twice. This avoids having complex if/else trees to sort out
# when a particular package is actually needed.

add_definitions(-DALGEBRA_PLUGINS_INCLUDE_ARRAY)

# plugin dependencies

if(ACTS_BUILD_PLUGIN_ACTSVG)
Expand Down
10 changes: 8 additions & 2 deletions Core/include/Acts/EventData/MultiTrajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class TrackStateRange {
}
}

Iterator operator++(int) {
Iterator tmp(*this);
operator++();
return tmp;
}

bool operator==(const Iterator& other) const {
if (!proxy && !other.proxy) {
return true;
Expand All @@ -107,8 +113,8 @@ class TrackStateRange {
TrackStateRange(ProxyType _begin) : m_begin{_begin} {}
TrackStateRange() : m_begin{std::nullopt} {}

Iterator begin() { return m_begin; }
Iterator end() { return Iterator{std::nullopt}; }
Iterator begin() const { return m_begin; }
Iterator end() const { return Iterator{std::nullopt}; }

private:
Iterator m_begin;
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/python/acts/examples/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ def addAmbiguityResolutionMLDBScan(
addTrackWriters(
s,
name="ambiMLDBScan",
trajectories=alg.config.outputTracks,
tracks=alg.config.outputTracks,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
writeStates=writeTrajectories,
Expand Down
28 changes: 28 additions & 0 deletions Plugins/Traccc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
add_library(
ActsPluginTraccc SHARED
src/Detail/Module.cpp
src/CellConversion.cpp)

target_include_directories(
ActsPluginTraccc
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(
ActsPluginTraccc
PUBLIC
ActsCore
traccc::core
traccc::io
vecmem::core
detray::utils
detray::io
ActsPluginCovfie)

install(
TARGETS ActsPluginTraccc
EXPORT ActsPluginTracccTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(
DIRECTORY include/Acts
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
42 changes: 42 additions & 0 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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

// Acts include(s)
#include "Acts/Geometry/GeometryIdentifier.hpp"

// Detray include(s)
#include "detray/core/detector.hpp"

// System include(s)
#include <cstdint>
#include <cstdlib>
#include <map>
#include <memory>
#include <tuple>
#include <utility>

namespace Acts::TracccPlugin {

/// @brief Creates a map from Acts geometry ID (value) to detray barcode.
/// @param detector the detray detector.
/// @return A map (key = geometry ID value, value = detray geometry barcode).
template <typename metadata_t, typename container_t>
inline std::map<Acts::GeometryIdentifier::Value, detray::geometry::barcode>
createBarcodeMap(const detray::detector<metadata_t, container_t>& detector) {
// Construct a map from Acts surface identifiers to Detray barcodes.
std::map<Acts::GeometryIdentifier::Value, detray::geometry::barcode>
barcodeMap;
for (const auto& surface : detector.surfaces()) {
barcodeMap[surface.source] = surface.barcode();
}
return barcodeMap;
}

} // namespace Acts::TracccPlugin
56 changes: 56 additions & 0 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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

// Acts include(s)
#include "Acts/Geometry/GeometryHierarchyMap.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"

// Plugin include(s)
#include "Acts/Plugins/Traccc/BarcodeMap.hpp"
#include "Acts/Plugins/Traccc/Detail/Module.hpp"

// Detray include(s)
#include "detray/core/detector.hpp"

// Traccc include(s)
#include "traccc/edm/cell.hpp"
#include "traccc/geometry/geometry.hpp"
#include "traccc/io/digitization_config.hpp"
#include "traccc/io/read_geometry.hpp"
#include "traccc/io/reader_edm.hpp"

// System include(s)
#include <cstdint>
#include <cstdlib>
#include <map>
#include <memory>
#include <tuple>
#include <utility>

namespace Acts::TracccPlugin {

/// @brief Converts a "geometry ID -> traccc cells" map to traccc cells and modules.
/// @param mr The memory resource to use.
/// @param cellsMap A map from Acts geometry ID value to traccc cells.
/// @param geom The traccc geometry.
/// @param dconfig The traccc digitization configuration.
/// @param barcode_map A map from Acts geometry ID value to detray barcode.
/// @return A tuple containing the traccc cells (first item) and traccc modules (second item).
std::tuple<traccc::cell_collection_types::host,
traccc::cell_module_collection_types::host>
createCellsAndModules(
vecmem::memory_resource* mr,
std::map<Acts::GeometryIdentifier::Value, std::vector<traccc::cell>>
cellsMap,
const traccc::geometry* geom, const traccc::digitization_config* dconfig,
const std::map<Acts::GeometryIdentifier::Value, detray::geometry::barcode>*
barcodeMap);

} // namespace Acts::TracccPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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

// Acts include(s)
#include "Acts/Definitions/Algebra.hpp"

// System include(s)
#include <cstddef>

namespace Acts::TracccPlugin::detail {

/// @brief Creates a new Acts vector from another vector type.
template <std::size_t N, typename dvector_t>
inline Acts::ActsVector<N> toActsVector(const dvector_t& dvec) {
Acts::ActsVector<N> res;
for (std::size_t i = 0; i < N; i++) {
res(i) = static_cast<Acts::ActsScalar>(dvec[i]);
}
return res;
}
/// @brief Creates a new Acts square matrix from another square matrix type.
template <std::size_t N, typename matrixNxN_t>
inline Acts::ActsSquareMatrix<N> toActsSquareMatrix(const matrixNxN_t& mat) {
Acts::ActsSquareMatrix<N> res;
for (std::size_t x = 0; x < N; x++) {
for (std::size_t y = 0; y < N; y++) {
res(x, y) = static_cast<Acts::ActsScalar>(mat[x][y]);
}
}
return res;
}

} // namespace Acts::TracccPlugin::detail
29 changes: 29 additions & 0 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/Module.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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

// Acts include(s)
#include "Acts/Geometry/GeometryIdentifier.hpp"

// Traccc include(s)
#include "traccc/edm/cell.hpp"
#include "traccc/geometry/geometry.hpp"
#include "traccc/io/digitization_config.hpp"

namespace Acts::TracccPlugin::detail {

/// @brief Helper function which finds module from csv::cell in the geometry and
/// digitization config, and initializes the modules limits with the cell's
/// properties.
traccc::cell_module getModule(
const Acts::GeometryIdentifier::Value geometryID,
const traccc::geometry* geom, const traccc::digitization_config* dconfig,
const Acts::GeometryIdentifier::Value originalGeometryID);

} // namespace Acts::TracccPlugin::detail
Loading

0 comments on commit e32b12f

Please sign in to comment.