From e3b6fa84767af14a4046da988457c8bd2993e09c Mon Sep 17 00:00:00 2001 From: Frederik Date: Thu, 20 Jun 2024 13:31:05 +0200 Subject: [PATCH] Merge request changes --- Plugins/Traccc/CMakeLists.txt | 2 +- .../Acts/Plugins/Traccc/CellConversion.hpp | 2 +- .../Traccc/Detail/AlgebraConversion.hpp | 13 +- .../Plugins/Traccc/MeasurementConversion.hpp | 164 ------------------ .../Acts/Plugins/Traccc/TrackConversion.hpp | 72 ++++++-- Plugins/Traccc/src/CellConversion.cpp | 4 +- Plugins/Traccc/src/Detail/Module.cpp | 2 - 7 files changed, 69 insertions(+), 190 deletions(-) delete mode 100644 Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp diff --git a/Plugins/Traccc/CMakeLists.txt b/Plugins/Traccc/CMakeLists.txt index 9b79f3cb93d3..e59112d2d032 100644 --- a/Plugins/Traccc/CMakeLists.txt +++ b/Plugins/Traccc/CMakeLists.txt @@ -10,7 +10,7 @@ target_include_directories( $) target_link_libraries( ActsPluginTraccc - INTERFACE + PUBLIC ActsCore traccc::core traccc::io diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp index 7657586ee686..d0f4f3745b51 100644 --- a/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp @@ -43,7 +43,7 @@ namespace Acts::TracccPlugin { /// @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 std::tuple createCellsAndModules( +std::tuple createCellsAndModules( vecmem::memory_resource* mr, std::map> cellsMap, const traccc::geometry* geom, const traccc::digitization_config* dconfig, diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp index dd4c1fd5ef16..82f39080f166 100644 --- a/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp @@ -19,14 +19,21 @@ namespace Acts::TracccPlugin::detail { /// @brief Creates a new Acts vector from another vector type. template inline Acts::ActsVector toActsVector(const dvector_t& dvec) { - Acts::ActsVector res = Eigen::Map>(dvec.data()).template cast(); + 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 toActsSquareMatrix(const matrixNxN_t& mat) { - Acts::ActsSquareMatrix res = Eigen::Map>(mat.data()).template cast(); + 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; } diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp deleted file mode 100644 index d1afbb52ea7c..000000000000 --- a/Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp +++ /dev/null @@ -1,164 +0,0 @@ -// 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::toActsVector(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::toActsVector(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 index a0d6effcd49a..4c8f9711e7f0 100644 --- a/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp @@ -13,11 +13,15 @@ // Acts include(s) #include "Acts/Definitions/Algebra.hpp" +#include "Acts/Definitions/TrackParametrization.hpp" +#include "Acts/EventData/detail/ParameterTraits.hpp" +#include "Acts/EventData/SourceLink.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" +#include "Acts/Utilities/detail/Subspace.hpp" // Detray include(s) #include "detray/core/detector.hpp" @@ -45,10 +49,11 @@ template inline auto newParams(const detray::bound_track_parameters& dparams, const detray::detector& detector, const Acts::TrackingGeometry& trackingGeometry) { - Acts::ActsVector<6U> parameterVector = - detail::toActsVector<6U>(dparams.vector()[0]); + constexpr std::size_t kFullSize = Acts::detail::kParametersSize; + Acts::ActsVector parameterVector = + detail::toActsVector(dparams.vector()[0]); typename Acts::BoundTrackParameters::CovarianceMatrix cov = - detail::toActsSquareMatrix<6U>(dparams.covariance()); + detail::toActsSquareMatrix(dparams.covariance()); Acts::ParticleHypothesis particleHypothesis = Acts::ParticleHypothesis::pion(); @@ -86,7 +91,6 @@ inline void copyFittingResult( 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()); @@ -97,7 +101,7 @@ inline void copyFittingResult( /// @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 Sets the uncalibrated source link and calibrated measurement the traccc measurement. +/// @note Sets the uncalibrated source link and calibrated measurement to the traccc measurement. template inline void copyTrackState( @@ -105,6 +109,10 @@ inline void copyTrackState( Acts::TrackStateProxy& destination, const detray::detector& detector, const Acts::TrackingGeometry& trackingGeometry) { + + constexpr std::size_t kFullSize = Acts::detail::kParametersSize; + constexpr std::size_t kSize = 2UL; + auto geoID = Acts::GeometryIdentifier(detector.surface(source.surface_link()).source); auto surface = trackingGeometry.findSurface(geoID)->getSharedPtr(); @@ -116,22 +124,22 @@ inline void copyTrackState( typename Acts::TrackStateProxy::Covariance; destination.predicted() = - Parameters(detail::toActsVector<6U>(source.predicted().vector()[0]).data()); + Parameters(detail::toActsVector(source.predicted().vector()[0]).data()); destination.predictedCovariance() = Covariance( - detail::toActsSquareMatrix<6U>(source.predicted().covariance()).data()); + detail::toActsSquareMatrix(source.predicted().covariance()).data()); destination.smoothed() = - Parameters(detail::toActsVector<6U>(source.smoothed().vector()[0]).data()); + Parameters(detail::toActsVector(source.smoothed().vector()[0]).data()); destination.smoothedCovariance() = Covariance( - detail::toActsSquareMatrix<6U>(source.smoothed().covariance()).data()); + detail::toActsSquareMatrix(source.smoothed().covariance()).data()); destination.filtered() = - Parameters(detail::toActsVector<6U>(source.filtered().vector()[0]).data()); + Parameters(detail::toActsVector(source.filtered().vector()[0]).data()); destination.filteredCovariance() = Covariance( - detail::toActsSquareMatrix<6U>(source.filtered().covariance()).data()); + detail::toActsSquareMatrix(source.filtered().covariance()).data()); destination.jacobian() = - Covariance(detail::toActsSquareMatrix<6U>(source.jacobian()).data()); + Covariance(detail::toActsSquareMatrix(source.jacobian()).data()); destination.chi2() = source.smoothed_chi2(); @@ -145,18 +153,31 @@ inline void copyTrackState( } typeFlags.set(TrackStateFlag::MeasurementFlag); - //destination.setUncalibratedSourceLink(m.sourceLink()); - //destination.setCalibrated(m); + const traccc::measurement& measurement = source.get_measurement(); + + destination.setUncalibratedSourceLink(Acts::SourceLink{measurement}); + + destination.allocateCalibrated(kSize); + + destination.template calibrated() = detail::toActsVector(measurement.local); + + auto cov = Eigen::DiagonalMatrix( + detail::toActsVector(measurement.variance)) + .toDenseMatrix(); + destination.template calibratedCovariance() = cov; + + Acts::detail::FixedSizeSubspace subspace(measurement.subs.get_indices()); + destination.setProjector(subspace.template projector()); } /// @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 trackContainer The Acts track container. The new tracks will be added to this container. /// @param detector The detray detector. /// @param trackingGeometry The Acts tracking geometry. -/// @note Sets the uncalibrated source link and calibrated measurement the traccc measurement. +/// @note Sets the uncalibrated source link and calibrated measurement to the traccc measurement. template class holder_t, typename metadata_t, @@ -185,4 +206,23 @@ inline auto makeTrack( return track; } +/// @brief Creates a new track in the Acts track container for each track in the traccc track container. +/// The new tracks will contain data copied from the traccc track container +/// element (track and track state data). +/// @param tracccTrackContainer The traccc container containing the traccc tracks. +/// @param trackContainer The Acts track container. The new tracks will be added to this container. +/// @param detector The detray detector. +/// @param trackingGeometry The Acts tracking geometry. +/// @note Sets the uncalibrated source link and calibrated measurement to the traccc measurement. +template class holder_t, typename metadata_t, typename container_t> +inline void makeTracks( + const traccc_track_container_t& tracccTrackContainer, + Acts::TrackContainer& trackContainer, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + for (std::size_t i = 0; i < tracccTrackContainer.size(); i++) { + makeTrack(tracccTrackContainer[i], trackContainer, detector, trackingGeometry); + } +} + } // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/src/CellConversion.cpp b/Plugins/Traccc/src/CellConversion.cpp index 9b84d654f634..bb3943968308 100644 --- a/Plugins/Traccc/src/CellConversion.cpp +++ b/Plugins/Traccc/src/CellConversion.cpp @@ -6,8 +6,6 @@ // 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" @@ -57,7 +55,7 @@ struct CellOrder { namespace Acts::TracccPlugin { -inline std::tuple createCellsAndModules( +std::tuple createCellsAndModules( vecmem::memory_resource* mr, std::map> cellsMap, const traccc::geometry* geom, const traccc::digitization_config* dconfig, diff --git a/Plugins/Traccc/src/Detail/Module.cpp b/Plugins/Traccc/src/Detail/Module.cpp index 32655fac639c..cbdbf5cde1eb 100644 --- a/Plugins/Traccc/src/Detail/Module.cpp +++ b/Plugins/Traccc/src/Detail/Module.cpp @@ -6,8 +6,6 @@ // 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/Module.hpp"