Skip to content

Commit

Permalink
Merge request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fredevb committed Jun 20, 2024
1 parent 5dcb04c commit e3b6fa8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 190 deletions.
2 changes: 1 addition & 1 deletion Plugins/Traccc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(
ActsPluginTraccc
INTERFACE
PUBLIC
ActsCore
traccc::core
traccc::io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<traccc::cell_collection_types::host, traccc::cell_module_collection_types::host> createCellsAndModules(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ 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 = Eigen::Map<const Eigen::Matrix<typename dvector_t::value_type, N, 1>>(dvec.data()).template cast<ActsScalar>();
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 = Eigen::Map<const Eigen::Matrix<typename matrixNxN_t::value_type, N, N>>(mat.data()).template cast<ActsScalar>();
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;
}

Expand Down
164 changes: 0 additions & 164 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/MeasurementConversion.hpp

This file was deleted.

72 changes: 56 additions & 16 deletions Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -45,10 +49,11 @@ template <typename algebra_t, typename metadata_t, typename container_t>
inline auto newParams(const detray::bound_track_parameters<algebra_t>& dparams,
const detray::detector<metadata_t, container_t>& detector,
const Acts::TrackingGeometry& trackingGeometry) {
Acts::ActsVector<6U> parameterVector =
detail::toActsVector<6U>(dparams.vector()[0]);
constexpr std::size_t kFullSize = Acts::detail::kParametersSize<Acts::BoundIndices>;
Acts::ActsVector<kFullSize> parameterVector =
detail::toActsVector<kFullSize>(dparams.vector()[0]);
typename Acts::BoundTrackParameters::CovarianceMatrix cov =
detail::toActsSquareMatrix<6U>(dparams.covariance());
detail::toActsSquareMatrix<kFullSize>(dparams.covariance());
Acts::ParticleHypothesis particleHypothesis =
Acts::ParticleHypothesis::pion();

Expand Down Expand Up @@ -86,7 +91,6 @@ inline void copyFittingResult(
const detray::detector<metadata_t, container_t>& 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());
Expand All @@ -97,14 +101,18 @@ 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 <typename algebra_t, typename metadata_t, typename container_t,
typename trajectory_t, std::size_t M>
inline void copyTrackState(
const traccc::track_state<algebra_t>& source,
Acts::TrackStateProxy<trajectory_t, M, false>& destination,
const detray::detector<metadata_t, container_t>& detector,
const Acts::TrackingGeometry& trackingGeometry) {

constexpr std::size_t kFullSize = Acts::detail::kParametersSize<Acts::BoundIndices>;
constexpr std::size_t kSize = 2UL;

auto geoID =
Acts::GeometryIdentifier(detector.surface(source.surface_link()).source);
auto surface = trackingGeometry.findSurface(geoID)->getSharedPtr();
Expand All @@ -116,22 +124,22 @@ inline void copyTrackState(
typename Acts::TrackStateProxy<trajectory_t, M, false>::Covariance;

destination.predicted() =
Parameters(detail::toActsVector<6U>(source.predicted().vector()[0]).data());
Parameters(detail::toActsVector<kFullSize>(source.predicted().vector()[0]).data());
destination.predictedCovariance() = Covariance(
detail::toActsSquareMatrix<6U>(source.predicted().covariance()).data());
detail::toActsSquareMatrix<kFullSize>(source.predicted().covariance()).data());

destination.smoothed() =
Parameters(detail::toActsVector<6U>(source.smoothed().vector()[0]).data());
Parameters(detail::toActsVector<kFullSize>(source.smoothed().vector()[0]).data());
destination.smoothedCovariance() = Covariance(
detail::toActsSquareMatrix<6U>(source.smoothed().covariance()).data());
detail::toActsSquareMatrix<kFullSize>(source.smoothed().covariance()).data());

destination.filtered() =
Parameters(detail::toActsVector<6U>(source.filtered().vector()[0]).data());
Parameters(detail::toActsVector<kFullSize>(source.filtered().vector()[0]).data());
destination.filteredCovariance() = Covariance(
detail::toActsSquareMatrix<6U>(source.filtered().covariance()).data());
detail::toActsSquareMatrix<kFullSize>(source.filtered().covariance()).data());

destination.jacobian() =
Covariance(detail::toActsSquareMatrix<6U>(source.jacobian()).data());
Covariance(detail::toActsSquareMatrix<kFullSize>(source.jacobian()).data());

destination.chi2() = source.smoothed_chi2();

Expand All @@ -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<kSize>() = detail::toActsVector<kSize>(measurement.local);

auto cov = Eigen::DiagonalMatrix<Acts::ActsScalar, kSize>(
detail::toActsVector<kSize>(measurement.variance))
.toDenseMatrix();
destination.template calibratedCovariance<kSize>() = cov;

Acts::detail::FixedSizeSubspace<kFullSize, kSize> subspace(measurement.subs.get_indices());
destination.setProjector(subspace.template projector<Acts::ActsScalar>());
}

/// @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 <typename fitting_result_t, typename track_state_vector_t,
typename track_container_t, typename trajectory_t,
template <typename> class holder_t, typename metadata_t,
Expand Down Expand Up @@ -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 <typename traccc_track_container_t, typename track_container_t, typename trajectory_t, template <typename> class holder_t, typename metadata_t, typename container_t>
inline void makeTracks(
const traccc_track_container_t& tracccTrackContainer,
Acts::TrackContainer<track_container_t, trajectory_t, holder_t>& trackContainer,
const detray::detector<metadata_t, container_t>& detector,
const Acts::TrackingGeometry& trackingGeometry) {
for (std::size_t i = 0; i < tracccTrackContainer.size(); i++) {
makeTrack(tracccTrackContainer[i], trackContainer, detector, trackingGeometry);
}
}

} // namespace Acts::TracccPlugin
4 changes: 1 addition & 3 deletions Plugins/Traccc/src/CellConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -57,7 +55,7 @@ struct CellOrder {

namespace Acts::TracccPlugin {

inline std::tuple<traccc::cell_collection_types::host, traccc::cell_module_collection_types::host> createCellsAndModules(
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,
Expand Down
2 changes: 0 additions & 2 deletions Plugins/Traccc/src/Detail/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit e3b6fa8

Please sign in to comment.