Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:13

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2019-2020 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Utilities/TypeTraits.hpp"
0015 
0016 #include <optional>
0017 #include <type_traits>
0018 
0019 namespace Acts {
0020 
0021 class Surface;
0022 
0023 namespace Concepts {
0024 
0025 // nested types that must be available
0026 template <typename T>
0027 using TypeScalar = typename T::Scalar;
0028 template <typename T>
0029 using TypeParametersVector = typename T::ParametersVector;
0030 template <typename T>
0031 using TypeCovarianceMatrix = typename T::CovarianceMatrix;
0032 
0033 template <typename T>
0034 using ReturnTypeParameters = decltype(std::declval<T>().parameters());
0035 template <typename T>
0036 using ReturnTypeCovariance = decltype(std::declval<T>().covariance());
0037 template <typename T>
0038 using ReturnTypeFourPositionFromContext =
0039     decltype(std::declval<T>().fourPosition(std::declval<GeometryContext>()));
0040 template <typename T>
0041 using ReturnTypeFourPosition = decltype(std::declval<T>().fourPosition());
0042 template <typename T>
0043 using ReturnTypePositionFromContext =
0044     decltype(std::declval<T>().position(std::declval<GeometryContext>()));
0045 template <typename T>
0046 using ReturnTypePosition = decltype(std::declval<T>().position());
0047 template <typename T>
0048 using ReturnTypeTime = decltype(std::declval<T>().time());
0049 template <typename T>
0050 using ReturnTypeDirection = decltype(std::declval<T>().direction());
0051 template <typename T>
0052 using ReturnTypeAbsoluteMomentum =
0053     decltype(std::declval<T>().absoluteMomentum());
0054 template <typename T>
0055 using ReturnTypeCharge = decltype(std::declval<T>().charge());
0056 template <typename T>
0057 using ReturnTypeReferenceSurface =
0058     decltype(std::declval<T>().referenceSurface());
0059 
0060 template <typename T>
0061 struct BoundTrackParametersConceptImpl {
0062   // check for required nested types
0063   constexpr static bool hasTypeScalar = exists<TypeScalar, const T>;
0064   constexpr static bool hasTypeParametersVector =
0065       exists<TypeParametersVector, const T>;
0066   constexpr static bool hasTypeCovarianceMatrix =
0067       exists<TypeCovarianceMatrix, const T>;
0068 
0069   // check for required methods
0070   constexpr static bool hasMethodParameters =
0071       std::is_convertible_v<ReturnTypeParameters<T>, BoundVector>;
0072   constexpr static bool hasMethodCovariance =
0073       std::is_convertible_v<ReturnTypeCovariance<T>,
0074                             std::optional<BoundSquareMatrix>>;
0075   constexpr static bool hasMethodFourPositionFromContext =
0076       identical_to<Vector4, ReturnTypeFourPositionFromContext, const T>;
0077   constexpr static bool hasMethodPositionFromContext =
0078       identical_to<Vector3, ReturnTypePositionFromContext, const T>;
0079   constexpr static bool hasMethodTime =
0080       identical_to<TypeScalar<T>, ReturnTypeTime, const T>;
0081   constexpr static bool hasMethodDirection =
0082       identical_to<Vector3, ReturnTypeDirection, const T>;
0083   constexpr static bool hasMethodAbsoluteMomentum =
0084       identical_to<TypeScalar<T>, ReturnTypeAbsoluteMomentum, const T>;
0085   constexpr static bool hasMethodCharge =
0086       identical_to<TypeScalar<T>, ReturnTypeCharge, const T>;
0087   constexpr static bool hasMethodReferenceSurface =
0088       identical_to<const Surface&, ReturnTypeReferenceSurface, const T>;
0089 
0090   // provide meaningful error messages in case of non-compliance
0091   static_assert(hasTypeScalar, "Scalar type is missing");
0092   static_assert(hasTypeParametersVector, "Parameters vector type is missing");
0093   static_assert(hasTypeCovarianceMatrix, "Covariance matrix type is missing");
0094   static_assert(hasMethodParameters, "Missing or invalid 'parameters' method");
0095   static_assert(hasMethodCovariance, "Missing or invalid 'covariance' method");
0096   static_assert(hasMethodFourPositionFromContext,
0097                 "Missing or invalid 'fourPosition' method");
0098   static_assert(hasMethodPositionFromContext,
0099                 "Missing or invalid 'position' method");
0100   static_assert(hasMethodTime, "Missing or invalid 'time' method");
0101   static_assert(hasMethodDirection, "Missing or invalid 'direction' method");
0102   static_assert(hasMethodAbsoluteMomentum,
0103                 "Missing or invalid 'absoluteMomentum' method");
0104   static_assert(hasMethodCharge, "Missing or invalid 'charge' method");
0105   static_assert(hasMethodReferenceSurface,
0106                 "Missing or invalid 'referenceSurface' method");
0107 
0108   constexpr static bool value =
0109       require<hasTypeScalar, hasTypeParametersVector, hasTypeCovarianceMatrix,
0110               hasMethodParameters, hasMethodCovariance,
0111               hasMethodFourPositionFromContext, hasMethodPositionFromContext,
0112               hasMethodTime, hasMethodDirection, hasMethodAbsoluteMomentum,
0113               hasMethodCharge, hasMethodReferenceSurface>;
0114 };
0115 
0116 template <typename T>
0117 struct FreeTrackParametersConceptImpl {
0118   // check for required nested types
0119   constexpr static bool hasTypeScalar = exists<TypeScalar, const T>;
0120   constexpr static bool hasTypeParametersVector =
0121       exists<TypeParametersVector, const T>;
0122   constexpr static bool hasTypeCovarianceMatrix =
0123       exists<TypeCovarianceMatrix, const T>;
0124 
0125   // check for required methods
0126   constexpr static bool hasMethodParameters =
0127       std::is_convertible_v<ReturnTypeParameters<T>, FreeVector>;
0128   constexpr static bool hasMethodCovariance =
0129       std::is_convertible_v<ReturnTypeCovariance<T>,
0130                             std::optional<FreeSquareMatrix>>;
0131   constexpr static bool hasMethodFourPosition =
0132       identical_to<Vector4, ReturnTypeFourPosition, const T>;
0133   constexpr static bool hasMethodPosition =
0134       identical_to<Vector3, ReturnTypePosition, const T>;
0135   constexpr static bool hasMethodTime =
0136       identical_to<TypeScalar<T>, ReturnTypeTime, const T>;
0137   constexpr static bool hasMethodDirection =
0138       identical_to<Vector3, ReturnTypeDirection, const T>;
0139   constexpr static bool hasMethodAbsoluteMomentum =
0140       identical_to<TypeScalar<T>, ReturnTypeAbsoluteMomentum, const T>;
0141   constexpr static bool hasMethodCharge =
0142       identical_to<TypeScalar<T>, ReturnTypeCharge, const T>;
0143 
0144   // provide meaningful error messages in case of non-compliance
0145   static_assert(hasTypeScalar, "Scalar type is missing");
0146   static_assert(hasTypeParametersVector, "Parameters vector type is missing");
0147   static_assert(hasTypeCovarianceMatrix, "Covariance matrix type is missing");
0148   static_assert(hasMethodParameters, "Missing or invalid 'parameters' method");
0149   static_assert(hasMethodCovariance, "Missing or invalid 'covariance' method");
0150   static_assert(hasMethodFourPosition,
0151                 "Missing or invalid 'fourPosition' method");
0152   static_assert(hasMethodPosition, "Missing or invalid 'position' method");
0153   static_assert(hasMethodTime, "Missing or invalid 'time' method");
0154   static_assert(hasMethodDirection, "Missing or invalid 'direction' method");
0155   static_assert(hasMethodAbsoluteMomentum,
0156                 "Missing or invalid 'absoluteMomentum' method");
0157   static_assert(hasMethodCharge, "Missing or invalid 'charge' method");
0158 
0159   constexpr static bool value =
0160       require<hasTypeScalar, hasTypeParametersVector, hasTypeCovarianceMatrix,
0161               hasMethodParameters, hasMethodCovariance, hasMethodFourPosition,
0162               hasMethodPosition, hasMethodTime, hasMethodDirection,
0163               hasMethodAbsoluteMomentum, hasMethodCharge>;
0164 };
0165 
0166 template <typename parameters_t>
0167 constexpr bool BoundTrackParametersConcept =
0168     BoundTrackParametersConceptImpl<parameters_t>::value;
0169 
0170 template <typename parameters_t>
0171 constexpr bool FreeTrackParametersConcept =
0172     FreeTrackParametersConceptImpl<parameters_t>::value;
0173 
0174 }  // namespace Concepts
0175 }  // namespace Acts