Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:02

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 namespace Acts {
0010 template <typename external_spacepoint_t, typename callable_t>
0011 inline LinCircle transformCoordinates(Acts::SpacePointMutableData& mutableData,
0012                                       const external_spacepoint_t& sp,
0013                                       const external_spacepoint_t& spM,
0014                                       bool bottom,
0015                                       callable_t&& extractFunction) {
0016   // The computation inside this function is exactly identical to that in the
0017   // vectorized version of this function, except that it operates on a single
0018   // spacepoint. Please see the other version of this function for more
0019   // detailed comments.
0020 
0021   auto [xM, yM, zM, rM, varianceRM, varianceZM] = extractFunction(spM);
0022   auto [xSP, ySP, zSP, rSP, varianceRSP, varianceZSP] = extractFunction(sp);
0023 
0024   float cosPhiM = xM / rM;
0025   float sinPhiM = yM / rM;
0026   float deltaX = xSP - xM;
0027   float deltaY = ySP - yM;
0028   float deltaZ = zSP - zM;
0029   float xNewFrame = deltaX * cosPhiM + deltaY * sinPhiM;
0030   float yNewFrame = deltaY * cosPhiM - deltaX * sinPhiM;
0031   float deltaR2 = (xNewFrame * xNewFrame + yNewFrame * yNewFrame);
0032   float iDeltaR2 = 1. / (deltaX * deltaX + deltaY * deltaY);
0033   float iDeltaR = std::sqrt(iDeltaR2);
0034   int bottomFactor = bottom ? -1 : 1;
0035   float cotTheta = deltaZ * iDeltaR * bottomFactor;
0036 
0037   // conformal transformation u=x/(x²+y²) v=y/(x²+y²) transform the
0038   // circle into straight lines in the u/v plane the line equation can
0039   // be described in terms of aCoef and bCoef, where v = aCoef * u +
0040   // bCoef
0041   const float U = xNewFrame * iDeltaR2;
0042   const float V = yNewFrame * iDeltaR2;
0043 
0044   // error term for sp-pair without correlation of middle space point
0045   const float Er = ((varianceZM + varianceZSP) +
0046                     (cotTheta * cotTheta) * (varianceRM + varianceRSP)) *
0047                    iDeltaR2;
0048 
0049   mutableData.setDeltaR(sp.index(), std::sqrt(deltaR2 + (deltaZ * deltaZ)));
0050   return LinCircle(cotTheta, iDeltaR, Er, U, V, xNewFrame, yNewFrame);
0051 }
0052 
0053 template <typename external_spacepoint_t>
0054 inline void transformCoordinates(
0055     Acts::SpacePointMutableData& mutableData,
0056     const std::vector<const external_spacepoint_t*>& vec,
0057     const external_spacepoint_t& spM, bool bottom,
0058     std::vector<LinCircle>& linCircleVec) {
0059   const float xM = spM.x();
0060   const float yM = spM.y();
0061   const float zM = spM.z();
0062   const float rM = spM.radius();
0063   const float varianceRM = spM.varianceR();
0064   const float varianceZM = spM.varianceZ();
0065 
0066   // resize + operator[] is faster than reserve and push_back
0067   linCircleVec.resize(vec.size());
0068 
0069   float cosPhiM = xM / rM;
0070   float sinPhiM = yM / rM;
0071 
0072   int bottomFactor = bottom ? -1 : 1;
0073 
0074   for (std::size_t idx(0); idx < vec.size(); ++idx) {
0075     const external_spacepoint_t* sp = vec[idx];
0076 
0077     const float xSP = sp->x();
0078     const float ySP = sp->y();
0079     const float zSP = sp->z();
0080     const float varianceRSP = sp->varianceR();
0081     const float varianceZSP = sp->varianceZ();
0082 
0083     const float deltaX = xSP - xM;
0084     const float deltaY = ySP - yM;
0085     const float deltaZ = zSP - zM;
0086     // calculate projection fraction of spM->sp vector pointing in same
0087     // direction as
0088     // vector origin->spM (x) and projection fraction of spM->sp vector pointing
0089     // orthogonal to origin->spM (y)
0090     const float xNewFrame = deltaX * cosPhiM + deltaY * sinPhiM;
0091     const float yNewFrame = deltaY * cosPhiM - deltaX * sinPhiM;
0092     // 1/(length of M -> SP)
0093     const float deltaR2 = (xNewFrame * xNewFrame + yNewFrame * yNewFrame);
0094     const float iDeltaR2 = 1. / deltaR2;
0095     const float iDeltaR = std::sqrt(iDeltaR2);
0096     //
0097     // cot_theta = (deltaZ/deltaR)
0098     const float cotTheta = deltaZ * iDeltaR * bottomFactor;
0099     // transformation of circle equation (x,y) into linear equation (u,v)
0100     // x^2 + y^2 - 2x_0*x - 2y_0*y = 0
0101     // is transformed into
0102     // 1 - 2x_0*u - 2y_0*v = 0
0103     // using the following m_U and m_V
0104     // (u = A + B*v); A and B are created later on
0105     const float U = xNewFrame * iDeltaR2;
0106     const float V = yNewFrame * iDeltaR2;
0107     // error term for sp-pair without correlation of middle space point
0108     const float Er = ((varianceZM + varianceZSP) +
0109                       (cotTheta * cotTheta) * (varianceRM + varianceRSP)) *
0110                      iDeltaR2;
0111 
0112     // Fill Line Circle
0113     linCircleVec[idx].cotTheta = cotTheta;
0114     linCircleVec[idx].iDeltaR = iDeltaR;
0115     linCircleVec[idx].Er = Er;
0116     linCircleVec[idx].U = U;
0117     linCircleVec[idx].V = V;
0118     linCircleVec[idx].x = xNewFrame;
0119     linCircleVec[idx].y = yNewFrame;
0120     mutableData.setDeltaR(sp->index(), std::sqrt(deltaR2 + (deltaZ * deltaZ)));
0121   }
0122 }
0123 
0124 template <typename external_spacepoint_t>
0125 inline bool xyzCoordinateCheck(
0126     const Acts::SeedFinderConfig<external_spacepoint_t>& m_config,
0127     const external_spacepoint_t& sp, const double* spacepointPosition,
0128     double* outputCoordinates) {
0129   // check the compatibility of SPs coordinates in xyz assuming the
0130   // Bottom-Middle direction with the strip measurement details
0131 
0132   using namespace Acts::HashedStringLiteral;
0133   const Acts::Vector3& topStripVector = sp.topStripVector();
0134   const Acts::Vector3& bottomStripVector = sp.bottomStripVector();
0135   const Acts::Vector3& stripCenterDistance = sp.stripCenterDistance();
0136 
0137   const double xTopStripVector = topStripVector[0];
0138   const double yTopStripVector = topStripVector[1];
0139   const double zTopStripVector = topStripVector[2];
0140   const double xBottomStripVector = bottomStripVector[0];
0141   const double yBottomStripVector = bottomStripVector[1];
0142   const double zBottomStripVector = bottomStripVector[2];
0143 
0144   // cross product between top strip vector and spacepointPosition
0145   double d1[3] = {yTopStripVector * spacepointPosition[2] -
0146                       zTopStripVector * spacepointPosition[1],
0147                   zTopStripVector * spacepointPosition[0] -
0148                       xTopStripVector * spacepointPosition[2],
0149                   xTopStripVector * spacepointPosition[1] -
0150                       yTopStripVector * spacepointPosition[0]};
0151 
0152   // scalar product between bottom strip vector and d1
0153   double bd1 = xBottomStripVector * d1[0] + yBottomStripVector * d1[1] +
0154                zBottomStripVector * d1[2];
0155 
0156   // compatibility check using distance between strips to evaluate if
0157   // spacepointPosition is inside the bottom detector element
0158   double s1 = (stripCenterDistance[0] * d1[0] + stripCenterDistance[1] * d1[1] +
0159                stripCenterDistance[2] * d1[2]);
0160   if (std::abs(s1) > std::abs(bd1) * m_config.toleranceParam) {
0161     return false;
0162   }
0163 
0164   // cross product between bottom strip vector and spacepointPosition
0165   double d0[3] = {yBottomStripVector * spacepointPosition[2] -
0166                       zBottomStripVector * spacepointPosition[1],
0167                   zBottomStripVector * spacepointPosition[0] -
0168                       xBottomStripVector * spacepointPosition[2],
0169                   xBottomStripVector * spacepointPosition[1] -
0170                       yBottomStripVector * spacepointPosition[0]};
0171 
0172   // compatibility check using distance between strips to evaluate if
0173   // spacepointPosition is inside the top detector element
0174   double s0 = (stripCenterDistance[0] * d0[0] + stripCenterDistance[1] * d0[1] +
0175                stripCenterDistance[2] * d0[2]);
0176   if (std::abs(s0) > std::abs(bd1) * m_config.toleranceParam) {
0177     return false;
0178   }
0179 
0180   // if arrive here spacepointPosition is compatible with strip directions and
0181   // detector elements
0182 
0183   const Acts::Vector3& topStripCenterPosition = sp.topStripCenterPosition();
0184 
0185   // spacepointPosition corrected with respect to the top strip position and
0186   // direction and the distance between the strips
0187   s0 = s0 / bd1;
0188   outputCoordinates[0] = topStripCenterPosition[0] + xTopStripVector * s0;
0189   outputCoordinates[1] = topStripCenterPosition[1] + yTopStripVector * s0;
0190   outputCoordinates[2] = topStripCenterPosition[2] + zTopStripVector * s0;
0191   return true;
0192 }
0193 }  // namespace Acts