diff --git a/CMakeLists.txt b/CMakeLists.txt index dafc65b5438..329bf02f5e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -309,6 +315,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) diff --git a/Core/include/Acts/EventData/MultiTrajectory.hpp b/Core/include/Acts/EventData/MultiTrajectory.hpp index b0410d52274..8991c55d944 100644 --- a/Core/include/Acts/EventData/MultiTrajectory.hpp +++ b/Core/include/Acts/EventData/MultiTrajectory.hpp @@ -90,6 +90,12 @@ class TrackStateRange { } } + Iterator operator++(int) { + Iterator tmp(*this); + operator++(); + return tmp; + } + bool operator==(const Iterator& other) const { if (!proxy && !other.proxy) { return true; @@ -109,8 +115,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; diff --git a/Examples/Python/python/acts/examples/reconstruction.py b/Examples/Python/python/acts/examples/reconstruction.py index fc1e7f8ab37..3ab21517e4c 100644 --- a/Examples/Python/python/acts/examples/reconstruction.py +++ b/Examples/Python/python/acts/examples/reconstruction.py @@ -1875,7 +1875,7 @@ def addAmbiguityResolutionMLDBScan( addTrackWriters( s, name="ambiMLDBScan", - trajectories=alg.config.outputTracks, + tracks=alg.config.outputTracks, outputDirRoot=outputDirRoot, outputDirCsv=outputDirCsv, writeStates=writeTrajectories, diff --git a/Plugins/CMakeLists.txt b/Plugins/CMakeLists.txt index fff533d1b37..e60c2da425d 100644 --- a/Plugins/CMakeLists.txt +++ b/Plugins/CMakeLists.txt @@ -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) diff --git a/Plugins/Traccc/CMakeLists.txt b/Plugins/Traccc/CMakeLists.txt new file mode 100644 index 00000000000..a72692805ba --- /dev/null +++ b/Plugins/Traccc/CMakeLists.txt @@ -0,0 +1,26 @@ +add_library( + ActsPluginTraccc INTERFACE) + +target_include_directories( + ActsPluginTraccc + INTERFACE + $ + $) +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}) diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp new file mode 100644 index 00000000000..f518b5bc0f8 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp @@ -0,0 +1,41 @@ +// 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 +#include +#include +#include +#include +#include + +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 +inline std::map createBarcodeMap( + const detray::detector& detector) { + // Construct a map from Acts surface identifiers to Detray barcodes. + std::map barcodeMap; + for (const auto& surface : detector.surfaces()) { + barcodeMap[surface.source] = surface.barcode(); + } + return barcodeMap; +} + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp new file mode 100644 index 00000000000..6e2db856926 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp @@ -0,0 +1,96 @@ +// 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 +#include +#include +#include +#include +#include + +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 + +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> cellsMap, + const traccc::geometry* geom, const traccc::digitization_config* dconfig, + const std::map* 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)); +} + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp new file mode 100644 index 00000000000..43cf8601f84 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp @@ -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 + +namespace Acts::TracccPlugin::Detail { + +/// @brief Creates a new Acts vector from another vector type. +template +inline Acts::ActsVector newVector(const dvector_t& dvec) { + Acts::ActsVector res; + for (std::size_t i = 0; i < N; i++) { + res(i) = static_cast(dvec[i]); + } + return res; +} +/// @brief Creates a new Acts square matrix from another square matrix type. +template +inline Acts::ActsSquareMatrix newSqaureMatrix(const matrixNxN_t& mat) { + Acts::ActsSquareMatrix res; + for (std::size_t x = 0; x < N; x++) { + for (std::size_t y = 0; y < N; y++) { + res(x, y) = static_cast(mat[x][y]); + } + } + return res; +} + +} // namespace Acts::TracccPlugin::Detail diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/Module.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/Module.hpp new file mode 100644 index 00000000000..ef495f975ff --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/Module.hpp @@ -0,0 +1,84 @@ +// 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" + +// 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 +#include +#include +#include +#include +#include + +namespace Acts::TracccPlugin::Detail { + +/// 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 get_module(const std::uint64_t geometryID, + const traccc::geometry* geom, + const traccc::digitization_config* dconfig, + const std::uint64_t originalGeometryID) { + traccc::cell_module result; + result.surface_link = detray::geometry::barcode{geometryID}; + + // Find/set the 3D position of the detector module. + if (geom != nullptr) { + // Check if the module ID is known. + if (!geom->contains(result.surface_link.value())) { + throw std::runtime_error("Could not find placement for geometry ID " + + std::to_string(result.surface_link.value())); + } + + // Set the value on the module description. + result.placement = (*geom)[result.surface_link.value()]; + } + + // Find/set the digitization configuration of the detector module. + if (dconfig != nullptr) { + // Check if the module ID is known. + const traccc::digitization_config::Iterator geoIt = + dconfig->find(originalGeometryID); + if (geoIt == dconfig->end()) { + throw std::runtime_error( + "Could not find digitization config for geometry ID " + + std::to_string(originalGeometryID)); + } + + // Set the value on the module description. + const auto& binning_data = geoIt->segmentation.binningData(); + assert(binning_data.size() > 0); + result.pixel.min_corner_x = binning_data[0].min; + result.pixel.pitch_x = binning_data[0].step; + if (binning_data.size() > 1) { + result.pixel.min_corner_y = binning_data[1].min; + result.pixel.pitch_y = binning_data[1].step; + } + // result.pixel.dimension = geoIt->dimensions; + // result.pixel.variance_y = geoIt->variance_y; + } + + return result; +} + +} // namespace Acts::TracccPlugin::Detail diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp new file mode 100644 index 00000000000..d268dd441ed --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp @@ -0,0 +1,164 @@ +// 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 + +// Plugin include(s) +#include "Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp" + +// Acts include(s) +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Definitions/TrackParametrization.hpp" +#include "Acts/EventData/Measurement.hpp" +#include "Acts/EventData/SourceLink.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" + +// Detray include(s) +#include "detray/core/detector.hpp" +#include "detray/tracks/bound_track_parameters.hpp" + +// Traccc include(s) +#include "traccc/definitions/qualifiers.hpp" +#include "traccc/definitions/track_parametrization.hpp" +#include "traccc/edm/measurement.hpp" +#include "traccc/edm/track_state.hpp" + +// System include(s) +#include +#include + +namespace Acts::TracccPlugin { + +/// @brief Converts a traccc bound index to an Acts bound index. +/// @param tracccBoundIndex the traccc bound index. +/// @returns an Acts bound index. +inline Acts::BoundIndices boundIndex( + const traccc::bound_indices tracccBoundIndex) { + switch (tracccBoundIndex) { + case traccc::bound_indices::e_bound_loc0: + return Acts::BoundIndices::eBoundLoc0; + case traccc::bound_indices::e_bound_loc1: + return Acts::BoundIndices::eBoundLoc1; + case traccc::bound_indices::e_bound_phi: + return Acts::BoundIndices::eBoundPhi; + case traccc::bound_indices::e_bound_theta: + return Acts::BoundIndices::eBoundTheta; + case traccc::bound_indices::e_bound_qoverp: + return Acts::BoundIndices::eBoundQOverP; + case traccc::bound_indices::e_bound_time: + return Acts::BoundIndices::eBoundTime; + case traccc::bound_indices::e_bound_size: + return Acts::BoundIndices::eBoundSize; + default: + throw std::runtime_error("Could not convert traccc bound index"); + } +} + +/// @brief Creates an Acts measurement from a traccc measurement. +/// @tparam the dimension of the Acts measurement (subspace size). +/// @param m the traccc measurement. +/// @param sl the Acts source link to use for the Acts measurement. +/// @returns an Acts measurement with data copied from the traccc measurement +/// and with its source link set to the one provided to the function. +template +inline Acts::Measurement measurement( + const traccc::measurement& m, const Acts::SourceLink sl) { + auto params = Detail::newVector(m.local); + std::array indices; + for (unsigned int i = 0; i < dim; i++) { + indices[i] = boundIndex(traccc::bound_indices(m.subs.get_indices()[i])); + } + auto cov = Eigen::DiagonalMatrix(dim)>( + Detail::newVector(m.variance)) + .toDenseMatrix(); + return Acts::Measurement(std::move(sl), indices, + params, cov); +} + +/// @brief Creates an Acts bound variant measurement from a traccc measurement. +/// Using recursion, the functions determines the dimension of the traccc +/// measurement which is used for the Acts measurement that the bound variant +/// measurement holds. The dimension must lie between [0; max_dim]. +/// @tparam max_dim the largest possible dimension of any measurement type in the variant (default = 4). +/// @param m the traccc measurement. +/// @param sl the Acts source link to use for the Acts measurement. +/// @returns an Acts bound variant measurement with data copied from the traccc measurement +/// and with its source link set to the one provided to the function. +template +inline Acts::BoundVariantMeasurement boundVariantMeasurement( + const traccc::measurement& m, const Acts::SourceLink sl) { + if constexpr (max_dim == 0UL) { + std::string errorMsg = "Invalid/mismatching measurement dimension: " + + std::to_string(m.meas_dim); + throw std::runtime_error(errorMsg.c_str()); + } else { + if (m.meas_dim == max_dim) { + return measurement(m, sl); + } + return boundVariantMeasurement(m, sl); + } +} + +/// @brief Gets the the local position of the measurement. +/// @param measurement the Acts measurement. +/// @returns A two-dimensional vector containing the local position. +/// The first item in the vector is local position on axis 0 and +/// I.e., [local position (axis 0), local position (axis 1)]. +template +inline Acts::ActsVector<2> getLocal( + const Acts::Measurement& measurement) { + traccc::scalar loc0 = 0; + traccc::scalar loc1 = 0; + if constexpr (dim > Acts::BoundIndices::eBoundLoc0) { + loc0 = measurement.parameters()(Acts::BoundIndices::eBoundLoc0); + } + if constexpr (dim > Acts::BoundIndices::eBoundLoc1) { + loc1 = measurement.parameters()(Acts::BoundIndices::eBoundLoc1); + } + return Acts::ActsVector<2>(loc0, loc1); +} + +/// @brief Get the the local position of the measurement. +/// @param measurement the Acts bound variant measurement. +/// @return A two-dimensional vector containing the local position. +/// I.e., [local position (axis 0), local position (axis 1)]. +inline Acts::ActsVector<2> getLocal( + const Acts::BoundVariantMeasurement& measurement) { + return std::visit([](auto& m) { return getLocal(m); }, measurement); +} + +/// @brief Get the the variance of the measurement. +/// @param measurement the Acts measurement. +/// @return A two-dimensional vector containing the variance. +/// I.e., [variance (axis 0), variance (axis 1)]. +template +inline Acts::ActsVector<2> getVariance( + const Acts::Measurement& measurement) { + traccc::scalar var0 = 0; + traccc::scalar var1 = 0; + if constexpr (dim >= Acts::BoundIndices::eBoundLoc0) { + var0 = measurement.covariance()(Acts::BoundIndices::eBoundLoc0, + Acts::BoundIndices::eBoundLoc0); + } + if constexpr (dim > Acts::BoundIndices::eBoundLoc1) { + var1 = measurement.covariance()(Acts::BoundIndices::eBoundLoc1, + Acts::BoundIndices::eBoundLoc1); + } + return Acts::ActsVector<2>(var0, var1); +} + +/// @brief Get the the variance of the measurement. +/// @param measurement the Acts bound variant measurement. +/// @return A two-dimensional vector containing the variance. +/// I.e., [variance (axis 0), variance (axis 1)]. +inline Acts::ActsVector<2> getVariance( + const Acts::BoundVariantMeasurement& measurement) { + return std::visit([](auto& m) { return getVariance(m); }, measurement); +} + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp new file mode 100644 index 00000000000..254b2422f81 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp @@ -0,0 +1,271 @@ +// 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 + +// Plugin include(s) +#include "Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp" + +// Acts include(s) +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/EventData/ParticleHypothesis.hpp" +#include "Acts/EventData/TrackContainer.hpp" +#include "Acts/EventData/TrackParameters.hpp" +#include "Acts/EventData/TrackProxy.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" + +// Detray include(s) +#include "detray/core/detector.hpp" +#include "detray/tracks/bound_track_parameters.hpp" + +// Traccc include(s) +#include "traccc/edm/track_state.hpp" + +// Boost include(s) +#include + +// System include(s) +#include +#include +#include + +namespace Acts::TracccPlugin { + +/// @brief Creates a new Acts bound track parameters from detray bound track parameters. +/// @param dparams the detray bound track parameters. +/// @param detector the detray detector. +/// @param trackingGeometry the Acts tracking geometry. +/// @return An Acts BoundTrackParameters with data copied from a detray bound_track_parameters. +template +inline auto newParams(const detray::bound_track_parameters& dparams, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + Acts::ActsVector<6U> parameterVector = + Detail::newVector<6U>(dparams.vector()[0]); + typename Acts::BoundTrackParameters::CovarianceMatrix cov = + Detail::newSqaureMatrix<6U>(dparams.covariance()); + Acts::ParticleHypothesis particleHypothesis = + Acts::ParticleHypothesis::pion(); + + auto geoID = + Acts::GeometryIdentifier(detector.surface(dparams.surface_link()).source); + + auto surface = trackingGeometry.findSurface(geoID); + + if (surface == nullptr) { + throw std::runtime_error( + "Mismatch between Acts geometry and detray detector: Acts tracking " + "geometry does not contain geometry ID " + + std::to_string(geoID.value())); + } + + Acts::BoundTrackParameters params(surface->getSharedPtr(), parameterVector, + std::make_optional(std::move(cov)), + particleHypothesis); + + return params; +} + +/// @brief Copies data from a traccc fitting result to an Acts track proxy. +/// @param source the traccc track fitting result to copy from. +/// @param destination the Acts track proxy to copy to. +/// @param detector the detray detector of the traccc track fitting result. +/// @param trackingGeometry the Acts tracking geometry. +template class holder_t, typename metadata_t, + typename container_t> +inline void copyFittingResult( + const traccc::fitting_result& source, + Acts::TrackProxy& + destination, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + const auto params = newParams(source.fit_params, detector, trackingGeometry); + // track.tipIndex() = kalmanResult.lastMeasurementIndex; + destination.parameters() = params.parameters(); + destination.covariance() = params.covariance().value(); + destination.setReferenceSurface(params.referenceSurface().getSharedPtr()); +} + +/// @brief Copies data from a traccc track state to a Acts track state proxy. +/// @param source the traccc track state to copy from. +/// @param destination the Acts track state proxy to copy to. +/// @param detector the detray detector of the traccc track track state. +/// @param trackingGeometry the Acts tracking geometry. +/// @note Does not set the uncalibrated source link and calibrated measurements. +template +inline void copyTrackState( + const traccc::track_state& source, + Acts::TrackStateProxy& destination, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + auto geoID = + Acts::GeometryIdentifier(detector.surface(source.surface_link()).source); + auto surface = trackingGeometry.findSurface(geoID)->getSharedPtr(); + destination.setReferenceSurface(surface); + + using Parameters = + typename Acts::TrackStateProxy::Parameters; + using Covariance = + typename Acts::TrackStateProxy::Covariance; + + destination.predicted() = + Parameters(Detail::newVector<6U>(source.predicted().vector()[0]).data()); + destination.predictedCovariance() = Covariance( + Detail::newSqaureMatrix<6U>(source.predicted().covariance()).data()); + + destination.smoothed() = + Parameters(Detail::newVector<6U>(source.smoothed().vector()[0]).data()); + destination.smoothedCovariance() = Covariance( + Detail::newSqaureMatrix<6U>(source.smoothed().covariance()).data()); + + destination.filtered() = + Parameters(Detail::newVector<6U>(source.filtered().vector()[0]).data()); + destination.filteredCovariance() = Covariance( + Detail::newSqaureMatrix<6U>(source.filtered().covariance()).data()); + + destination.jacobian() = + Covariance(Detail::newSqaureMatrix<6U>(source.jacobian()).data()); + + destination.chi2() = source.smoothed_chi2(); + + auto typeFlags = destination.typeFlags(); + typeFlags.set(TrackStateFlag::ParameterFlag); + if (surface->surfaceMaterial() != nullptr) { + typeFlags.set(TrackStateFlag::MaterialFlag); + } + if (source.is_hole) { + typeFlags.set(TrackStateFlag::HoleFlag); + } + typeFlags.set(TrackStateFlag::MeasurementFlag); +} + +/// @brief Gets the fitting result of a traccc container element. +/// @param e the traccc container element. +/// @return the fitting result contained in the container element (i.e., e.header). +template +inline auto& getFittingResult( + const traccc::container_element& + tracccTrack) { + return tracccTrack.header; +} + +/// @brief Gets the track states of a traccc container element. +/// @param e the traccc container element. +/// @return the track states contained in the container element (i.e., e.items). +template +inline auto& getTrackStates( + const traccc::container_element& + tracccTrack) { + return tracccTrack.items; +} + +/// @brief Creates a new track in the Acts track container. +/// This new track will contain data copied from the traccc track container +/// element (track and track state data). +/// @param tracccTrack The traccc container element to copy from. +/// @param actsTrackContainer The Acts track container. This is the new track will be made in this container. +/// @param detector The detray detector. +/// @param trackingGeometry The Acts tracking geometry. +/// @note Does not set the uncalibrated source link and calibrated measurements. +template class holder_t, typename metadata_t, + typename container_t> +inline auto makeTrack( + const traccc::container_element& + tracccTrack, + Acts::TrackContainer& + actsTrackContainer, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + auto fittingResult = getFittingResult(tracccTrack); + auto trackStates = getTrackStates(tracccTrack); + + auto track = actsTrackContainer.makeTrack(); + copyFittingResult(fittingResult, track, detector, trackingGeometry); + + // Make the track states. + for (const auto& tstate : trackStates) { + auto astate = track.appendTrackState(); + copyTrackState(tstate, astate, detector, trackingGeometry); + } + + track.linkForward(); + + return track; +} + +/// @brief Creates a vector of Acts and traccc track state pairs. +/// The states in the pairs are paired 1:1 by index. +/// @tparam traccc_track_t type of traccc container_element. +/// @tparam acts_track_t type of Acts track proxy. +/// @param tracccTrack the traccc track. +/// @param actsTrack the Acts track. +/// @returns a vector of tuples. +/// @note The Acts track and traccc track must contain the same number of track states. +template +auto trackStateZipView(traccc_track_t& tracccTrack, acts_track_t& actsTrack) { + auto& tracccTrackStates = getTrackStates(tracccTrack); + auto actsTrackStates = actsTrack.trackStates(); + + using TracccTrackStateType = typename std::iterator_traits< + decltype(tracccTrackStates.begin())>::value_type; + using ActsTrackStateType = typename std::iterator_traits< + decltype(actsTrackStates.begin())>::value_type; + + std::vector> + zippedTrackStates; + zippedTrackStates.reserve(tracccTrackStates.size()); + + auto tracccIter = tracccTrackStates.begin(); + auto actsIter = actsTrackStates.begin(); + while (tracccIter != tracccTrackStates.end() && + actsIter != actsTrackStates.end()) { + zippedTrackStates.emplace_back(*tracccIter, *actsIter); + ++tracccIter; + ++actsIter; + } + + return zippedTrackStates; +} + +/// @brief Sets the uncalibrated source link and calibrated measurement of the Acts track state. +/// @param actsTrackState the Acts track state. +/// @param measurement the Acts bound variant measurement. +/// @note The uncalibrated source link and calibrated measurement are set to the same measurement. +template +void setSourceAndMeasurement( + Acts::TrackStateProxy& actsTrackState, + const Acts::BoundVariantMeasurement& measurement) { + std::visit( + [&actsTrackState](auto& m) { + actsTrackState.setUncalibratedSourceLink(m.sourceLink()); + actsTrackState.setCalibrated(m); + }, + measurement); +} + +/// @brief Sets the uncalibrated source link and calibrated measurement of the Acts track state +/// using the measurement data in their traccc pair. +/// @param trackStatePairs a list of tuples: (traccc track state, Acts track state) +/// @param map the map from traccc measurement to acts measurement. +template +void setSourceAndMeasurements( + track_state_pairs_t& trackStatePairs, + const std::map& map) { + for (auto pair : trackStatePairs) { + // First item in pair is the traccc track. + // Second item in pair is the acts track. + auto& measurement = map.at(std::get<0>(pair).get_measurement()); + setSourceAndMeasurement(std::get<1>(pair), measurement); + } +} + +} // namespace Acts::TracccPlugin diff --git a/cmake/ActsConfig.cmake.in b/cmake/ActsConfig.cmake.in index d8619193b13..e8cade3feb8 100644 --- a/cmake/ActsConfig.cmake.in +++ b/cmake/ActsConfig.cmake.in @@ -79,6 +79,9 @@ endif() if(PluginCovfie IN_LIST Acts_COMPONENTS) find_dependency(covfie @covfie_VERSION@ CONFIG EXACT) endif() +if(PluginTraccc IN_LIST Acts_COMPONENTS) + find_dependency(traccc @traccc_VERSION@ CONFIG EXACT) +endif() # dependencies that we have built ourselves but cannot be # straightforwardly handed to cmake diff --git a/cmake/ActsExternSources.cmake b/cmake/ActsExternSources.cmake index 461090be5f9..b1e1f8ab687 100644 --- a/cmake/ActsExternSources.cmake +++ b/cmake/ActsExternSources.cmake @@ -15,11 +15,11 @@ set( ACTS_COVFIE_SOURCE mark_as_advanced( ACTS_COVFIE_SOURCE ) set( ACTS_DETRAY_SOURCE - "URL;https://github.com/acts-project/detray/archive/refs/tags/v0.65.1.tar.gz;URL_MD5;fbf57a881565fa6019d79d13409b588f" CACHE STRING "Source to take DETRAY from") + "URL;https://github.com/acts-project/detray/archive/refs/tags/v0.66.1.tar.gz;URL_MD5;000a0a36f953f74466c9e889261dd166" CACHE STRING "Source to take DETRAY from") mark_as_advanced( ACTS_DETRAY_SOURCE ) set( ACTS_TRACCC_SOURCE - "URL;https://github.com/acts-project/traccc/archive/refs/tags/v0.10.0.tar.gz;URL_MD5;131399d26e3280c4d7f7ca2995efd256" CACHE STRING "Source to take TRACCC from") + "URL;https://github.com/acts-project/traccc/archive/refs/tags/v0.11.0.tar.gz;URL_MD5;42b0d65b34428e7aee5e0f60a5f1bcf1" CACHE STRING "Source to take TRACCC from") mark_as_advanced( ACTS_TRACCC_SOURCE ) set( ACTS_DFELIBS_SOURCE diff --git a/thirdparty/traccc/CMakeLists.txt b/thirdparty/traccc/CMakeLists.txt index b62c9ba35f0..8834253ec23 100644 --- a/thirdparty/traccc/CMakeLists.txt +++ b/thirdparty/traccc/CMakeLists.txt @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.14) include(FetchContent) # Tell the user what's happening. -message( STATUS "Building tracc as part of the Acts project" ) +message( STATUS "Building traccc as part of the Acts project" ) set( TRACCC_VERSION "${_acts_traccc_version}")