Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ traccc_add_library( traccc_core core TYPE SHARED
"include/traccc/edm/track_collection.hpp"
"include/traccc/edm/impl/track_collection.ipp"
"include/traccc/edm/track_container.hpp"
"include/traccc/edm/DeviceMultiTrajectory.hpp"
"include/traccc/edm/impl/DeviceMultiTrajectory.ipp"
"src/edm/DeviceMultiTrajectory.cpp"
"include/traccc/edm/DeviceTrackBackend.hpp"
"src/edm/DeviceTrackBackend.cpp"
"include/traccc/edm/DeviceTrackContainer.hpp"
# Magnetic field description.
"include/traccc/bfield/magnetic_field_types.hpp"
"include/traccc/bfield/magnetic_field.hpp"
Expand Down
181 changes: 181 additions & 0 deletions core/include/traccc/edm/DeviceMultiTrajectory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/edm/track_container.hpp"
#include "traccc/geometry/host_detector.hpp"

// Acts include(s).
#include <Acts/EventData/MultiTrajectory.hpp>
#include <Acts/EventData/MultiTrajectoryBackendConcept.hpp>
#include <Acts/Geometry/TrackingGeometry.hpp>

// System include(s).
#include <any>
#include <functional>

namespace traccc::edm {

/// @c Acts::MultiTrajectory specialisation for traccc produced tracks
class DeviceMultiTrajectory
: public Acts::MultiTrajectory<DeviceMultiTrajectory> {

public:
/// Constructor from a track container and Acts/Detray tracking geometries
///
/// @param tracks The track container holding the data
/// @param actsGeometry The Acts tracking geometry associated with the
/// trajectories
/// @param detrayGeometry The Detray tracking geometry associated with the
/// trajectories
///
explicit DeviceMultiTrajectory(
const track_container<default_algebra>::const_view& tracks,
const Acts::TrackingGeometry& actsGeometry,
const host_detector& detrayGeometry);
/// Copy constructor
DeviceMultiTrajectory(const DeviceMultiTrajectory&) = default;

/// Copy assignment operator
DeviceMultiTrajectory& operator=(const DeviceMultiTrajectory&) = default;

/// @name Functions required by @c Acts::MultiTrajectory
/// @{

/// Get the size of the object (number of track states)
///
/// @return The total number of track states
///
IndexType size_impl() const;

/// Get the calibrated size of a given track state (measurement dimension)
///
/// @param istate The index of the track state
/// @return The calibrated size (measurement dimension)
///
IndexType calibratedSize_impl(IndexType istate) const;

/// Check if a given component exists for a given track state
///
/// @param key The key of the component to check
/// @param istate The index of the track state to check
/// @return @c true if the component exists, @c false otherwise
///
bool has_impl(Acts::HashedString key, IndexType istate) const;

/// Check if a given track state column exists
///
/// @param key The key of the column to check
/// @return @c true if the column exists, @c false otherwise
///
bool hasColumn_impl(Acts::HashedString key) const;

/// Retrieve a given component of a track state
///
/// @param key The key of the component to retrieve
/// @param istate The index of the track state to retrieve from
/// @return The component as an @c std::any object
///
std::any component_impl(Acts::HashedString key, IndexType istate) const;

/// Retrieve the parameters of a given track state
///
/// @param index Index into the parameter column
/// @return The Eigen object representing the parameters
///
ConstTrackStateProxy::ConstParameters parameters_impl(
IndexType index) const;

/// Retrieve the covariance of a given track state
///
/// @param index Index into the covariance column
/// @return The Eigen object representing the covariance
///
ConstTrackStateProxy::ConstCovariance covariance_impl(
IndexType index) const;

/// Retrieve the calibrated measurement (positions) of a given track state
///
/// @tparam MEASDIM the measurement dimension
/// @param istate The track state index
/// @return The Eigen object representing the calibrated measurement
///
template <std::size_t MEASDIM>
ConstTrackStateProxy::Calibrated<MEASDIM> calibrated_impl(
IndexType istate) const;

/// Retrieve the calibrated measurement covariance of a given track state
///
/// @tparam MEASDIM the measurement dimension
/// @param index The track state index
/// @return The Eigen object representing the calibrated measurement
/// covariance
///
template <std::size_t MEASDIM>
ConstTrackStateProxy::CalibratedCovariance<MEASDIM>
calibratedCovariance_impl(IndexType index) const;

/// Retrieve the jacobian of a given track state
///
/// @param istate The track state
/// @return The Eigen object representing the jacobian
///
ConstTrackStateProxy::ConstCovariance jacobian_impl(IndexType istate) const;

/// Retrieve the reference surface of a given track state
///
/// @param index Index into the track state container
/// @return A pointer to the reference surface
///
const Acts::Surface* referenceSurface_impl(IndexType index) const;

/// Dynamic keys available in this multi-trajectory
///
/// By definition, it will always be empty for traccc multi-trajectories.
///
/// @return The list of dynamic keys
///
const std::vector<Acts::HashedString>& dynamicKeys_impl() const;

/// Retrieve the uncalibrated source link of a given track state
///
/// @param istate The index of the track state
/// @return The source link object
///
Acts::SourceLink getUncalibratedSourceLink_impl(IndexType istate) const;

/// @}

private:
/// The track container holding the data
track_container<default_algebra>::const_device m_tracks;
/// The tracking geometry associated with the trajectories
std::reference_wrapper<const Acts::TrackingGeometry> m_actsGeometry;
/// The Detray tracking geometry associated with the trajectories
std::reference_wrapper<const host_detector> m_detrayGeometry;

}; // class DeviceMultiTrajectory

/// Make sure that @c DeviceMultiTrajectory meets the concept requirements
static_assert(Acts::ConstMultiTrajectoryBackend<DeviceMultiTrajectory>);

} // namespace traccc::edm

namespace Acts {

/// Declare that @c traccc::edm::DeviceMultiTrajectory is a read-only
/// multi-trajectory
template <>
struct IsReadOnlyMultiTrajectory<traccc::edm::DeviceMultiTrajectory>
: std::true_type {};

} // namespace Acts

// Include the template implementation.
#include "traccc/edm/impl/DeviceMultiTrajectory.ipp"
145 changes: 145 additions & 0 deletions core/include/traccc/edm/DeviceTrackBackend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/edm/track_container.hpp"
#include "traccc/geometry/host_detector.hpp"

// Acts include(s).
#include <Acts/EventData/MultiTrajectory.hpp>
#include <Acts/EventData/TrackContainer.hpp>
#include <Acts/EventData/TrackContainerBackendConcept.hpp>
#include <Acts/EventData/TrackStateProxy.hpp>
#include <Acts/Geometry/TrackingGeometry.hpp>

// System include(s).
#include <any>
#include <functional>

namespace traccc::edm {

/// Implementation of the @c Acts::ConstTrackContainerBackend concept for traccc
/// produced tracks
class DeviceTrackBackend {

public:
/// Constructor from a track container and Acts/Detray tracking geometries
///
/// @param tracks The track container holding the data
/// @param actsGeometry The Acts tracking geometry associated with the
/// trajectories
/// @param detrayGeometry The Detray tracking geometry associated with the
/// trajectories
///
explicit DeviceTrackBackend(
const track_container<default_algebra>::const_view& tracks,
const Acts::TrackingGeometry& actsGeometry,
const host_detector& detrayGeometry);
/// Copy constructor
DeviceTrackBackend(const DeviceTrackBackend&) = default;

/// Copy assignment operator
DeviceTrackBackend& operator=(const DeviceTrackBackend&) = default;

/// Track index type
using IndexType = Acts::MultiTrajectoryTraits::IndexType;
/// Track parameters type
using ConstParameters =
Acts::detail_lt::FixedSizeTypes<Acts::eBoundSize,
true>::CoefficientsMap;
/// Track covariance type
using ConstCovariance =
Acts::detail_lt::FixedSizeTypes<Acts::eBoundSize, true>::CovarianceMap;

/// @name Functions required by @c Acts::TrackContainer
/// @{

/// Get the size of the object (the number of tracks)
///
/// @return The total number of tracks
///
std::size_t size_impl() const;

/// Retrieve the parameters of a given track
///
/// @param index Index into the parameter column
/// @return The Eigen object representing the parameters
///
ConstParameters parameters(IndexType index) const;

/// Retrieve the covariance of a given track state
///
/// @param index Index into the covariance column
/// @return The Eigen object representing the covariance
///
ConstCovariance covariance(IndexType index) const;

/// Check if a given track column exists
///
/// @param key The key of the column to check
/// @return @c true if the column exists, @c false otherwise
///
bool hasColumn_impl(Acts::HashedString key) const;

/// Retrieve a given component of a track
///
/// @param key The key of the component to retrieve
/// @param itrack The index of the track to retrieve from
/// @return The component as an @c std::any object
///
std::any component_impl(Acts::HashedString key, IndexType itrack) const;

/// Particle hypothesis of a given track
///
/// @param itrack The index of the track
/// @return The particle hypothesis
///
Acts::ParticleHypothesis particleHypothesis_impl(IndexType itrack) const;

/// Retrieve the reference surface of a given track
///
/// @param index Index into the track container
/// @return A pointer to the reference surface
///
const Acts::Surface* referenceSurface_impl(IndexType index) const;

/// Dynamic keys available in this track container
///
/// By definition, it will always be empty for traccc tracks.
///
/// @return The list of dynamic keys
///
const std::vector<Acts::HashedString>& dynamicKeys_impl() const;

/// @}

private:
/// The track container holding the data
track_container<default_algebra>::const_device m_tracks;
/// The tracking geometry associated with the trajectories
std::reference_wrapper<const Acts::TrackingGeometry> m_actsGeometry;
/// The Detray tracking geometry associated with the trajectories
std::reference_wrapper<const host_detector> m_detrayGeometry;

}; // class DeviceTrackBackend

/// Make sure that @c DeviceTrackBackend meets the concept requirements
static_assert(Acts::ConstTrackContainerBackend<DeviceTrackBackend>);

} // namespace traccc::edm

namespace Acts {

/// Declare that @c traccc::edm::DeviceTrackBackend is a read-only track
/// container
template <>
struct IsReadOnlyTrackContainer<traccc::edm::DeviceTrackBackend>
: std::true_type {};

} // namespace Acts
24 changes: 24 additions & 0 deletions core/include/traccc/edm/DeviceTrackContainer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Local include(s).
#include "traccc/edm/DeviceMultiTrajectory.hpp"
#include "traccc/edm/DeviceTrackBackend.hpp"

// Acts include(s).
#include <Acts/EventData/TrackContainer.hpp>

namespace traccc::edm {

/// @c Acts::TrackContainer specialisation for traccc produced tracks
using DeviceTrackContainer =
Acts::TrackContainer<DeviceTrackBackend, DeviceMultiTrajectory,
Acts::detail::ValueHolder>;

} // namespace traccc::edm
32 changes: 32 additions & 0 deletions core/include/traccc/edm/impl/DeviceMultiTrajectory.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** TRACCC library, part of the ACTS project (R&D line)
*
* (c) 2025 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

namespace traccc::edm {

template <std::size_t MEASDIM>
auto DeviceMultiTrajectory::calibrated_impl(IndexType istate) const
-> ConstTrackStateProxy::Calibrated<MEASDIM> {

return ConstTrackStateProxy::Calibrated<MEASDIM>{
m_tracks.measurements.at(m_tracks.states.measurement_index().at(istate))
.local_position()
.data()};
}

template <std::size_t MEASDIM>
auto DeviceMultiTrajectory::calibratedCovariance_impl(IndexType) const
-> ConstTrackStateProxy::CalibratedCovariance<MEASDIM> {

// We don't provide this at the moment.
throw std::runtime_error(
"traccc::edm::DeviceMultiTrajectory::calibratedCovariance_impl is not "
"supported");

Check warning on line 29 in core/include/traccc/edm/impl/DeviceMultiTrajectory.ipp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define and throw a dedicated exception instead of using a generic one.

See more on https://sonarcloud.io/project/issues?id=acts-project_traccc&issues=AZqDO8Qxw9kFgf37Jw2n&open=AZqDO8Qxw9kFgf37Jw2n&pullRequest=1197
}

} // namespace traccc::edm
Loading
Loading