Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:01:56

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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/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 ///
0064 class SpacePointUtility {
0065  public:
0066   /// Constructor
0067   SpacePointUtility(SpacePointBuilderConfig cfg) : m_config(std::move(cfg)) {}
0068 
0069   /// @brief Getter method for the global coordinates of a SourceLink
0070   ///
0071   /// @param gctx The current geometry context object, e.g. alignment
0072   /// @param slink SourceLink that holds the necessary
0073   /// information
0074   /// @param surfaceAccessor function to extract surface from SourceLink
0075   /// @param par local position
0076   /// @param cov local covariance
0077   /// @return vectors of the global coordinates and covariance of the SourceLink
0078   std::tuple<Vector3, std::optional<ActsScalar>, Vector2,
0079              std::optional<ActsScalar>>
0080   globalCoords(const GeometryContext& gctx, const SourceLink& slink,
0081                const SourceLinkSurfaceAccessor& surfaceAccessor,
0082                const BoundVector& par, const BoundSquareMatrix& cov) const;
0083 
0084   /// @brief Get rho and z covariance from the local position and covariance
0085   /// @param gctx The current geometry context object, e.g. alignment
0086   /// @param surface The surface associated
0087   /// @param globalPos The global position
0088   /// @param localCov The local covariance matrix
0089   /// @return (rho, z) components of the global covariance
0090   Vector2 rhoZCovariance(const GeometryContext& gctx, const Surface& surface,
0091                          const Vector3& globalPos,
0092                          const SquareMatrix2& localCov) const;
0093 
0094   /// @brief Calculate the rho and z covariance from the front and back SourceLink in the strip SP formation
0095   /// @param gctx The current geometry context object, e.g. alignment
0096   /// @param slinkFront The SourceLink on the front layer
0097   /// @param slinkBack The SourceLink on the back layer
0098   /// @param paramCovAccessor function to extract local position and covariance from SourceLink
0099   /// @param surfaceAccessor function to extract surface from SourceLink
0100   /// @param globalPos global position
0101   /// @param theta The angle between the two strips
0102   /// @return (rho, z) components of the global covariance
0103   Vector2 calcRhoZVars(const GeometryContext& gctx,
0104                        const SourceLink& slinkFront,
0105                        const SourceLink& slinkBack,
0106                        const SourceLinkSurfaceAccessor& surfaceAccessor,
0107                        const ParamCovAccessor& paramCovAccessor,
0108                        const Vector3& globalPos, const double theta) const;
0109 
0110   /// @brief This function performs a straight forward calculation of a space
0111   /// point and returns whether it was successful or not.
0112   ///
0113   /// @param [in] stripEnds1 Top and bottom end of the first strip
0114   /// @param [in] stripEnds2 Top and bottom end of the second strip
0115   /// @param [in] posVertex Position of the vertex
0116   /// @param [in, out] spParams Data container of the calculations
0117   /// @param [in] stripLengthTolerance Tolerance scaling factor on the strip
0118   /// detector element length
0119   ///
0120   /// @return Result whether the space point calculation was successful
0121   Result<void> calculateStripSPPosition(
0122       const std::pair<Vector3, Vector3>& stripEnds1,
0123       const std::pair<Vector3, Vector3>& stripEnds2, const Vector3& posVertex,
0124       SpacePointParameters& spParams, const double stripLengthTolerance) const;
0125 
0126   /// @brief This function tests if a space point can be estimated by a more
0127   /// tolerant treatment of construction. In fact, this function indirectly
0128   /// allows shifts of the vertex.
0129   ///
0130   /// @param [in] spParams container that stores geometric parameters and rules of
0131   /// the space point formation
0132   /// @param [in] stripLengthGapTolerance Tolerance scaling factor of the gap
0133   /// between strip detector elements
0134   ///
0135   /// @return indicator if the test was successful
0136   Result<void> recoverSpacePoint(SpacePointParameters& spParams,
0137                                  double stripLengthGapTolerance) const;
0138 
0139   /// @brief Calculates (Delta theta)^2 + (Delta phi)^2 between two SourceLinks
0140   ///
0141   /// @param [in] pos1 position of the first SourceLink
0142   /// @param [in] pos2 position the second SourceLink
0143   /// @param [in] posVertex Position of the vertex
0144   /// @param [in] maxDistance Maximum distance between two SourceLinks
0145   /// @param [in] maxAngleTheta2 Maximum squared theta angle between two
0146   /// SourceLinks
0147   /// @param [in] maxAnglePhi2 Maximum squared phi angle between two SourceLinks
0148   ///
0149   /// @return Result with the squared sum within configuration parameters.
0150   Result<double> differenceOfMeasurementsChecked(
0151       const Vector3& pos1, const Vector3& pos2, const Vector3& posVertex,
0152       const double maxDistance, const double maxAngleTheta2,
0153       const double maxAnglePhi2) const;
0154 
0155   /// @brief Calculates a space point without using the vertex
0156   /// @note This is mostly to resolve space points from cosmic data
0157   /// @param stripEnds1 The ends of one strip
0158   /// @param stripEnds2 The ends of another strip
0159   /// @param spParams SpacePointParamaters for the SP
0160   /// @return parameter that indicates the location of the space point; returns
0161   /// 1. if it failed
0162   /// @note The meaning of the parameter is explained in more detail in the
0163   /// function body
0164   Result<double> calcPerpendicularProjection(
0165       const std::pair<Vector3, Vector3>& stripEnds1,
0166       const std::pair<Vector3, Vector3>& stripEnds2,
0167       SpacePointParameters& spParams) const;
0168 
0169  private:
0170   SpacePointBuilderConfig m_config;
0171   std::error_code m_error;
0172 };
0173 
0174 }  // namespace Acts