Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 07:47:20

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 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 https://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/EventData/SourceLink.hpp"
0014 #include "Acts/Geometry/GeometryContext.hpp"
0015 #include "Acts/Geometry/GeometryIdentifier.hpp"
0016 #include "Acts/Geometry/TrackingGeometry.hpp"
0017 #include "Acts/SpacePointFormation/SpacePointBuilderConfig.hpp"
0018 #include "Acts/SpacePointFormation/SpacePointBuilderOptions.hpp"
0019 #include "Acts/Utilities/Result.hpp"
0020 
0021 #include <array>
0022 #include <cstddef>
0023 #include <functional>
0024 #include <iostream>
0025 #include <memory>
0026 #include <system_error>
0027 #include <utility>
0028 #include <vector>
0029 
0030 namespace Acts {
0031 class SourceLink;
0032 
0033 /// @brief Storage container for variables related to the calculation of space
0034 /// points
0035 struct SpacePointParameters {
0036   /// Vector pointing from bottom to top end of first SDE
0037   Vector3 firstBtmToTop{};
0038   /// Vector pointing from bottom to top end of second SDE
0039   Vector3 secondBtmToTop{};
0040   /// Twice the vector pointing from vertex to to midpoint of first SDE
0041   Vector3 vtxToFirstMid2{};
0042   /// Twice the vector pointing from vertex to to midpoint of second SDE
0043   Vector3 vtxToSecondMid2{};
0044   /// Cross product between firstBtmToTop and vtxToFirstMid2
0045   Vector3 firstBtmToTopXvtxToFirstMid2{};
0046   /// Cross product between secondBtmToTop and vtxToSecondMid2
0047   Vector3 secondBtmToTopXvtxToSecondMid2{};
0048   /// Magnitude of SpacePointParameters::firstBtmToTop
0049   double mag_firstBtmToTop = 0.;
0050   /// Parameter that determines the hit position on the first SDE
0051   double m = 0.;
0052   /// Parameter that determines the hit position on the second SDE
0053   double n = 0.;
0054   /// Regular limit of the absolute values of SpacePointParameters::m and
0055   /// SpacePointParameters::n
0056   double limit = 1.;
0057   /// Limit of SpacePointParameters::m and SpacePointParameters::n in case of
0058   /// variable vertex
0059   double limitExtended = 0.;
0060 };
0061 
0062 /// @class SpacePointUtility
0063 /// Utility helper for space point calculations.
0064 class SpacePointUtility {
0065  public:
0066   /// Constructor
0067   /// @param cfg Configuration for the space point builder
0068   explicit SpacePointUtility(SpacePointBuilderConfig cfg)
0069       : m_config(std::move(cfg)) {}
0070 
0071   /// @brief Getter method for the global coordinates of a SourceLink
0072   ///
0073   /// @param gctx The current geometry context object, e.g. alignment
0074   /// @param slink SourceLink that holds the necessary
0075   /// information
0076   /// @param surfaceAccessor function to extract surface from SourceLink
0077   /// @param par local position
0078   /// @param cov local covariance
0079   /// @return vectors of the global coordinates and covariance of the SourceLink
0080   std::tuple<Vector3, std::optional<double>, Vector2, std::optional<double>>
0081   globalCoords(const GeometryContext& gctx, const SourceLink& slink,
0082                const SourceLinkSurfaceAccessor& surfaceAccessor,
0083                const BoundVector& par, const BoundMatrix& cov) const;
0084 
0085   /// @brief Get rho and z covariance from the local position and covariance
0086   /// @param gctx The current geometry context object, e.g. alignment
0087   /// @param surface The surface associated
0088   /// @param globalPos The global position
0089   /// @param localCov The local covariance matrix
0090   /// @return (rho, z) components of the global covariance
0091   Vector2 rhoZCovariance(const GeometryContext& gctx, const Surface& surface,
0092                          const Vector3& globalPos,
0093                          const SquareMatrix2& localCov) const;
0094 
0095   /// @brief Calculate the rho and z covariance from the front and back SourceLink in the strip SP formation
0096   /// @param gctx The current geometry context object, e.g. alignment
0097   /// @param slinkFront The SourceLink on the front layer
0098   /// @param slinkBack The SourceLink on the back layer
0099   /// @param paramCovAccessor function to extract local position and covariance from SourceLink
0100   /// @param surfaceAccessor function to extract surface from SourceLink
0101   /// @param globalPos global position
0102   /// @param theta The angle between the two strips
0103   /// @return (rho, z) components of the global covariance
0104   Vector2 calcRhoZVars(const GeometryContext& gctx,
0105                        const SourceLink& slinkFront,
0106                        const SourceLink& slinkBack,
0107                        const SourceLinkSurfaceAccessor& surfaceAccessor,
0108                        const ParamCovAccessor& paramCovAccessor,
0109                        const Vector3& globalPos, const double theta) const;
0110 
0111   /// @brief This function performs a straight forward calculation of a space
0112   /// point and returns whether it was successful or not.
0113   ///
0114   /// @param [in] stripEnds1 Top and bottom end of the first strip
0115   /// @param [in] stripEnds2 Top and bottom end of the second strip
0116   /// @param [in] posVertex Position of the vertex
0117   /// @param [in, out] spParams Data container of the calculations
0118   /// @param [in] stripLengthTolerance Tolerance scaling factor on the strip
0119   /// detector element length
0120   ///
0121   /// @return Result whether the space point calculation was successful
0122   Result<void> calculateStripSPPosition(
0123       const std::pair<Vector3, Vector3>& stripEnds1,
0124       const std::pair<Vector3, Vector3>& stripEnds2, const Vector3& posVertex,
0125       SpacePointParameters& spParams, const double stripLengthTolerance) const;
0126 
0127   /// @brief This function tests if a space point can be estimated by a more
0128   /// tolerant treatment of construction. In fact, this function indirectly
0129   /// allows shifts of the vertex.
0130   ///
0131   /// @param [in] spParams container that stores geometric parameters and rules of
0132   /// the space point formation
0133   /// @param [in] stripLengthGapTolerance Tolerance scaling factor of the gap
0134   /// between strip detector elements
0135   ///
0136   /// @return indicator if the test was successful
0137   Result<void> recoverSpacePoint(SpacePointParameters& spParams,
0138                                  double stripLengthGapTolerance) const;
0139 
0140   /// @brief Calculates (Delta theta)^2 + (Delta phi)^2 between two SourceLinks
0141   ///
0142   /// @param [in] pos1 position of the first SourceLink
0143   /// @param [in] pos2 position the second SourceLink
0144   /// @param [in] posVertex Position of the vertex
0145   /// @param [in] maxDistance Maximum distance between two SourceLinks
0146   /// @param [in] maxAngleTheta2 Maximum squared theta angle between two
0147   /// SourceLinks
0148   /// @param [in] maxAnglePhi2 Maximum squared phi angle between two SourceLinks
0149   ///
0150   /// @return Result with the squared sum within configuration parameters.
0151   Result<double> differenceOfMeasurementsChecked(
0152       const Vector3& pos1, const Vector3& pos2, const Vector3& posVertex,
0153       const double maxDistance, const double maxAngleTheta2,
0154       const double maxAnglePhi2) const;
0155 
0156   /// @brief Calculates a space point without using the vertex
0157   /// @note This is mostly to resolve space points from cosmic data
0158   /// @param stripEnds1 The ends of one strip
0159   /// @param stripEnds2 The ends of another strip
0160   /// @param spParams SpacePointParamaters for the SP
0161   /// @return parameter that indicates the location of the space point; returns
0162   /// 1. if it failed
0163   /// @note The meaning of the parameter is explained in more detail in the
0164   /// function body
0165   Result<double> calcPerpendicularProjection(
0166       const std::pair<Vector3, Vector3>& stripEnds1,
0167       const std::pair<Vector3, Vector3>& stripEnds2,
0168       SpacePointParameters& spParams) const;
0169 
0170  private:
0171   SpacePointBuilderConfig m_config;
0172   std::error_code m_error;
0173 };
0174 
0175 }  // namespace Acts