Skip to content

Commit

Permalink
Traccc Plugin (conversion)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredevb committed Jun 12, 2024
1 parent 8584d2a commit 97743b5
Show file tree
Hide file tree
Showing 21 changed files with 705 additions and 19 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ set_option_if(ACTS_SETUP_COVFIE
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_BUILD_PLUGIN_COVFIE
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_SETUP_DETRAY
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_SETUP_TRACCC
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_BUILD_PLUGIN_TRACCC
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)

# feature tests
include(CheckCXXSourceCompiles)
Expand Down Expand Up @@ -214,6 +220,7 @@ set(_acts_onnxruntime_version 1.12.0)
set(_acts_root_version 6.20)
set(_acts_tbb_version 2020.1)


# recommended dependency version. if there is an opportunity to reach
# this version we will try so.
set(_acts_boost_recommended_version 1.78.0)
Expand Down Expand Up @@ -309,6 +316,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_SETUP_COVFIE)
if(ACTS_USE_SYSTEM_COVFIE)
Expand Down Expand Up @@ -481,4 +490,4 @@ add_subdirectory_if(docs ACTS_BUILD_DOCS)

# create cmake configuration files and environment setup script
include(ActsCreatePackageConfig)
include(ActsCreateSetup)
include(ActsCreateSetup)
6 changes: 4 additions & 2 deletions Core/include/Acts/EventData/MultiTrajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ 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 @@ -109,8 +111,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/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ add_subdirectory(TruthTracking)
add_subdirectory(Vertexing)
add_subdirectory_if(Alignment ACTS_BUILD_ALIGNMENT)
add_subdirectory(Utilities)
add_subdirectory(AmbiguityResolution)
add_subdirectory(AmbiguityResolution)
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DigitizationAlgorithm final : public IAlgorithm {
using Digitizer = std::variant<CombinedDigitizer<0>, CombinedDigitizer<1>,
CombinedDigitizer<2>, CombinedDigitizer<3>,
CombinedDigitizer<4>>;

/// Configuration of the Algorithm
DigitizationConfig m_cfg;
/// Digitizers within geometry hierarchy
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 @@ -1875,7 +1875,7 @@ def addAmbiguityResolutionMLDBScan(
addTrackWriters(
s,
name="ambiMLDBScan",
trajectories=alg.config.outputTracks,
tracks=alg.config.outputTracks,
outputDirRoot=outputDirRoot,
outputDirCsv=outputDirCsv,
writeStates=writeTrajectories,
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/src/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void addMaterial(Context& ctx) {
std::shared_ptr<Acts::IMaterialDecorator>>(m,
"IMaterialDecorator");
}

{
auto rmd =
py::class_<RootMaterialDecorator, Acts::IMaterialDecorator,
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/src/ModuleEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void addTrackFitting(Context& ctx);
void addTrackFinding(Context& ctx);
void addVertexing(Context& ctx);
void addAmbiguityResolution(Context& ctx);

// Plugins
void addDigitization(Context& ctx);
void addPythia8(Context& ctx);
Expand All @@ -79,6 +78,7 @@ void addOnnx(Context& ctx);
void addOnnxNeuralCalibrator(Context& ctx);
void addCovfie(Context& ctx);


} // namespace Acts::Python

PYBIND11_MODULE(ActsPythonBindings, m) {
Expand Down
1 change: 1 addition & 0 deletions Plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_component_if(Legacy PluginLegacy ACTS_BUILD_PLUGIN_LEGACY)
add_component_if(Onnx PluginOnnx ACTS_BUILD_PLUGIN_ONNX)
add_component_if(ExaTrkX PluginExaTrkX ACTS_BUILD_PLUGIN_EXATRKX)
add_component_if(Covfie PluginCovfie ACTS_BUILD_PLUGIN_COVFIE)
add_component_if(Traccc PluginTraccc ACTS_BUILD_PLUGIN_TRACCC)

# dependent plugins. depend either on a independent plugins or on one another
add_component_if(TGeo PluginTGeo ACTS_BUILD_PLUGIN_TGEO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

namespace Acts::CovfiePlugin {

using builder_backend_t =
covfie::backend::strided<covfie::vector::size3,
covfie::backend::array<covfie::vector::float3>>;
using builder_backend_t = covfie::backend::strided<
covfie::vector::size3,
covfie::backend::array<covfie::vector::float3>>;

using interpolated_field_t = covfie::field<covfie::backend::clamp<
covfie::backend::affine<covfie::backend::linear<builder_backend_t>>>>;
using interpolated_field_t = covfie::field<covfie::backend::clamp<covfie::backend::affine<covfie::backend::linear<builder_backend_t>>>>;

using constant_field_t = covfie::field<
covfie::backend::constant<covfie::vector::float3, covfie::vector::float3>>;
Expand Down
26 changes: 26 additions & 0 deletions Plugins/Traccc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
add_library(
ActsPluginTraccc INTERFACE)

target_include_directories(
ActsPluginTraccc
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(
ActsPluginTraccc
INTERFACE
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})
40 changes: 40 additions & 0 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp
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/Geometry/GeometryIdentifier.hpp"

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

// System include(s)
#include <cstdint>
#include <cstdlib>
#include <map>
#include <tuple>
#include <memory>
#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<std::uint64_t, detray::geometry::barcode> createBarcodeMap(const detray::detector<metadata_t, container_t>& detector){
// Construct a map from Acts surface identifiers to Detray barcodes.
std::map<std::uint64_t, detray::geometry::barcode> barcodeMap;
for (const auto& surface : detector.surfaces()) {
barcodeMap[surface.source] = surface.barcode();
}
return barcodeMap;
}

}
97 changes: 97 additions & 0 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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/reader_edm.hpp"
#include "traccc/io/read_geometry.hpp"

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

namespace {

/// Comparator used for sorting cells. This sorting is one of the assumptions
/// made in the clusterization algorithm
struct cell_order {
bool operator()(const traccc::cell& lhs, const traccc::cell& rhs) const {
if (lhs.module_link != rhs.module_link) {
return lhs.module_link < rhs.module_link;
} else if (lhs.channel1 != rhs.channel1) {
return (lhs.channel1 < rhs.channel1);
} else {
return (lhs.channel0 < rhs.channel0);
}
}
}; // struct cell_order

}

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).
inline auto createCellsAndModules(
vecmem::memory_resource* mr,
std::map<std::uint64_t, std::vector<traccc::cell>> cellsMap,
const traccc::geometry* geom,
const traccc::digitization_config* dconfig,
const std::map<std::uint64_t, detray::geometry::barcode>* barcodeMap) {

traccc::io::cell_reader_output out(mr);

// Sort the cells.
for (auto& [_, cells] : cellsMap) {
std::sort(cells.begin(), cells.end(), cell_order());
}

// Fill the output containers with the ordered cells and modules.
for (const auto& [originalGeometryID, cells] : cellsMap) {
// Modify the geometry ID of the module if a barcode map is
// provided.
std::uint64_t geometryID = (barcodeMap != nullptr) ?
barcodeMap->at(originalGeometryID).value() : originalGeometryID;

// Add the module and its cells to the output.
out.modules.push_back(
Detail::get_module(geometryID, geom, dconfig, originalGeometryID));
for (auto& cell : cells) {
out.cells.push_back(cell);
// Set the module link.
out.cells.back().module_link = out.modules.size() - 1;
}
}
return std::make_tuple(std::move(out.cells), std::move(out.modules));
}

}
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> newVector(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> newSqaureMatrix(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;
}

}
Loading

0 comments on commit 97743b5

Please sign in to comment.