Skip to content

Commit

Permalink
spearate concepts into detail
Browse files Browse the repository at this point in the history
  • Loading branch information
ssdetlab committed Nov 20, 2024
1 parent 0748382 commit 369cfd2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 66 deletions.
49 changes: 49 additions & 0 deletions Core/include/Acts/EventData/detail/TrackParametersUtils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This file is part of the ACTS project.
//
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/EventData/GenericBoundTrackParameters.hpp"
#include "Acts/EventData/TrackParametersConcept.hpp"

namespace Acts::detail {

/// @brief Shorthand for Bound or Free track parameters
template <class parameters_t>
concept isBoundOrFreeTrackParams =
Acts::FreeTrackParametersConcept<parameters_t> ||
Acts::BoundTrackParametersConcept<parameters_t>;

/// @brief Shorthand for GenericBoundTrackParameters
template <class parameters_t>
concept isGenericBoundTrackParams =
std::same_as<parameters_t, Acts::GenericBoundTrackParameters<
typename parameters_t::ParticleHypothesis>>;

/// @brief Concept that restricts the type of the
/// accumulation grid cell
template <typename grid_t>
concept TrackParamsGrid = requires {
typename grid_t::value_type::first_type;
typename grid_t::value_type::second_type;

requires isBoundOrFreeTrackParams<
typename grid_t::value_type::first_type::element_type>;
requires isBoundOrFreeTrackParams<
typename grid_t::value_type::second_type::element_type>;

requires requires(typename grid_t::value_type val) {
{
val.first
} -> std::same_as<
std::shared_ptr<typename decltype(val.first)::element_type>&>;
{ val.second } -> std::same_as<decltype(val.first)&>;
};
};

} // namespace Acts::detail
48 changes: 5 additions & 43 deletions Core/include/Acts/TrackFinding/TrackParamsLookupAccumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,15 @@

#pragma once

#include "Acts/EventData/GenericBoundTrackParameters.hpp"
#include "Acts/EventData/TrackParametersConcept.hpp"
#include "Acts/EventData/detail/TrackParametersUtils.hpp"
#include "Acts/Geometry/GeometryContext.hpp"

#include <concepts>
#include <map>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <utility>

namespace {

/// @brief Shorthand for track parameters
template <class parameters_t>
concept TrackParameters = Acts::FreeTrackParametersConcept<parameters_t> ||
Acts::BoundTrackParametersConcept<parameters_t>;

/// @brief Shorthand for GenericBoundTrackParameters
template <class parameters_t>
concept IsGenericBound =
std::same_as<parameters_t, Acts::GenericBoundTrackParameters<
typename parameters_t::ParticleHypothesis>>;

/// @brief Concept that restricts the type of the
/// accumulation grid cell
template <typename grid_t>
concept TrackParamsGrid = requires {
typename grid_t::value_type::first_type;
typename grid_t::value_type::second_type;

requires TrackParameters<
typename grid_t::value_type::first_type::element_type>;
requires TrackParameters<
typename grid_t::value_type::first_type::element_type>;

requires requires(typename grid_t::value_type val) {
{
val.first
} -> std::same_as<
std::shared_ptr<typename decltype(val.first)::element_type>&>;
{ val.second } -> std::same_as<decltype(val.first)&>;
};
};

} // namespace

namespace Acts {

/// @brief Class to accumulate and average track lookup tables
Expand All @@ -67,7 +29,7 @@ namespace Acts {
///
/// @note Geometry context is left to be handled by the user
/// outside of accumulation
template <TrackParamsGrid grid_t>
template <detail::TrackParamsGrid grid_t>
class TrackParamsLookupAccumulator {
public:
using LookupGrid = grid_t;
Expand Down Expand Up @@ -112,7 +74,7 @@ class TrackParamsLookupAccumulator {
/// @return Grid with the bin track parameters averaged
LookupGrid finalizeLookup() {
auto meanTrack = [&](const TrackParameters& track, std::size_t count) {
if constexpr (IsGenericBound<TrackParameters>) {
if constexpr (detail::isGenericBoundTrackParams<TrackParameters>) {
Acts::GeometryContext gctx;

auto res = TrackParameters::create(
Expand Down Expand Up @@ -169,7 +131,7 @@ class TrackParamsLookupAccumulator {
throw std::invalid_argument(
"Cannot accumulate track parameters with different charges");
}
if constexpr (IsGenericBound<TrackParameters>) {
if constexpr (detail::isGenericBoundTrackParams<TrackParameters>) {
if (a.referenceSurface() != b.referenceSurface()) {
throw std::invalid_argument(
"Cannot accumulate bound track parameters with different reference "
Expand All @@ -180,7 +142,7 @@ class TrackParamsLookupAccumulator {
Acts::Vector3 momentum = a.momentum() + b.momentum();

// Assume track parameters being i.i.d.
if constexpr (IsGenericBound<TrackParameters>) {
if constexpr (detail::isGenericBoundTrackParams<TrackParameters>) {
Acts::GeometryContext gctx;

Acts::Vector4 fourPosition = a.fourPosition(gctx) + b.fourPosition(gctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,12 @@

#pragma once

#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/Plugins/Json/ActsJson.hpp"
#include "Acts/Definitions/PdgParticle.hpp"
#include "Acts/EventData/detail/TrackParametersUtils.hpp"
#include "Acts/Plugins/Json/SurfaceJsonConverter.hpp"

#include <nlohmann/json.hpp>

namespace {

// Alias to bound adl_serializer specialization
// only to track parameters
template <class parameters_t>
concept TrackParameters = Acts::FreeTrackParametersConcept<parameters_t> ||
Acts::BoundTrackParametersConcept<parameters_t>;

// Shorthand for bound track parameters
template <class parameters_t>
concept IsGenericBound =
std::same_as<parameters_t, Acts::GenericBoundTrackParameters<
typename parameters_t::ParticleHypothesis>>;

} // namespace

namespace Acts {
NLOHMANN_JSON_SERIALIZE_ENUM(Acts::PdgParticle,

Expand Down Expand Up @@ -67,7 +51,7 @@ namespace nlohmann {
/// convention is followed.
///
/// @tparam parameters_t The track parameters type
template <TrackParameters parameters_t>
template <Acts::detail::isBoundOrFreeTrackParams parameters_t>
struct adl_serializer<parameters_t> {
/// Covariance matrix type attached to the parameters
using CovarianceMatrix = typename parameters_t::CovarianceMatrix;
Expand Down Expand Up @@ -101,7 +85,7 @@ struct adl_serializer<parameters_t> {
// Bound track parameters have
// reference surface attached
// and position takes a geometry context
if constexpr (IsGenericBound<parameters_t>) {
if constexpr (Acts::detail::isBoundOrFreeTrackParams<parameters_t>) {
Acts::GeometryContext gctx;
j["position"] = t.fourPosition(gctx);

Expand Down Expand Up @@ -152,7 +136,7 @@ struct adl_serializer<parameters_t> {
// reference surface attached
// and constructor is hidden
// behind a factory method
if constexpr (IsGenericBound<parameters_t>) {
if constexpr (Acts::detail::isBoundOrFreeTrackParams<parameters_t>) {
Acts::GeometryContext gctx;
auto referenceSurface =
Acts::SurfaceJsonConverter::fromJson(j.at("referenceSurface"));
Expand All @@ -178,7 +162,7 @@ struct adl_serializer<parameters_t> {
/// convention is followed.
///
/// @tparam parameters_t The track parameters type
template <TrackParameters parameters_t>
template <Acts::detail::isBoundOrFreeTrackParams parameters_t>
struct adl_serializer<std::shared_ptr<parameters_t>> {
using CovarianceMatrix = typename parameters_t::CovarianceMatrix;
static void to_json(nlohmann::json& j,
Expand All @@ -202,7 +186,7 @@ struct adl_serializer<std::shared_ptr<parameters_t>> {
/// convention is followed.
///
/// @tparam parameters_t The track parameters type
template <TrackParameters parameters_t>
template <Acts::detail::isBoundOrFreeTrackParams parameters_t>
struct adl_serializer<std::unique_ptr<parameters_t>> {
using CovarianceMatrix = typename parameters_t::CovarianceMatrix;
static void to_json(nlohmann::json& j,
Expand Down

0 comments on commit 369cfd2

Please sign in to comment.