Back to home page

EIC code displayed by LXR

 
 

    


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

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 #include "Acts/EventData/TransformationHelpers.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 #include "Acts/Utilities/Result.hpp"
0015 #include "Acts/Utilities/UnitVectors.hpp"
0016 
0017 #include <algorithm>
0018 
0019 Acts::FreeVector Acts::transformBoundToFreeParameters(
0020     const Acts::Surface& surface, const GeometryContext& geoCtx,
0021     const Acts::BoundVector& boundParams) {
0022   // convert angles to global unit direction vector
0023   Vector3 direction = makeDirectionFromPhiTheta(boundParams[eBoundPhi],
0024                                                 boundParams[eBoundTheta]);
0025 
0026   // convert local position to global position vector
0027   Vector2 local(boundParams[eBoundLoc0], boundParams[eBoundLoc1]);
0028   Vector3 position = surface.localToGlobal(geoCtx, local, direction);
0029 
0030   // construct full free-vector. time and q/p stay as-is.
0031   FreeVector freeParams = FreeVector::Zero();
0032   freeParams[eFreePos0] = position[ePos0];
0033   freeParams[eFreePos1] = position[ePos1];
0034   freeParams[eFreePos2] = position[ePos2];
0035   freeParams[eFreeTime] = boundParams[eBoundTime];
0036   freeParams[eFreeDir0] = direction[eMom0];
0037   freeParams[eFreeDir1] = direction[eMom1];
0038   freeParams[eFreeDir2] = direction[eMom2];
0039   freeParams[eFreeQOverP] = boundParams[eBoundQOverP];
0040   return freeParams;
0041 }
0042 
0043 Acts::Result<Acts::BoundVector> Acts::transformFreeToBoundParameters(
0044     const FreeVector& freeParams, const Surface& surface,
0045     const GeometryContext& geoCtx, double tolerance) {
0046   // initialize the bound vector
0047   BoundVector bp = BoundVector::Zero();
0048   // convert global to local position on the surface
0049   auto position = freeParams.segment<3>(eFreePos0);
0050   auto direction = freeParams.segment<3>(eFreeDir0);
0051   auto result = surface.globalToLocal(geoCtx, position, direction, tolerance);
0052   if (!result.ok()) {
0053     return Result<Acts::BoundVector>::failure(result.error());
0054   }
0055 
0056   auto localPosition = result.value();
0057   bp[eBoundLoc0] = localPosition[ePos0];
0058   bp[eBoundLoc1] = localPosition[ePos1];
0059 
0060   bp[eBoundTime] = freeParams[eFreeTime];
0061   bp[eBoundPhi] = VectorHelpers::phi(direction);
0062   bp[eBoundTheta] = VectorHelpers::theta(direction);
0063   bp[eBoundQOverP] = freeParams[eFreeQOverP];
0064   return Result<Acts::BoundVector>::success(bp);
0065 }
0066 
0067 Acts::Result<Acts::BoundVector> Acts::transformFreeToBoundParameters(
0068     const Acts::Vector3& position, double time, const Acts::Vector3& direction,
0069     double qOverP, const Acts::Surface& surface,
0070     const Acts::GeometryContext& geoCtx, double tolerance) {
0071   // initialize the bound vector
0072   BoundVector bp = BoundVector::Zero();
0073   // convert global to local position on the surface
0074   auto result = surface.globalToLocal(geoCtx, position, direction, tolerance);
0075   if (!result.ok()) {
0076     return Result<Acts::BoundVector>::failure(result.error());
0077   }
0078 
0079   auto localPosition = result.value();
0080   bp[eBoundLoc0] = localPosition[ePos0];
0081   bp[eBoundLoc1] = localPosition[ePos1];
0082 
0083   bp[eBoundTime] = time;
0084   bp[eBoundPhi] = VectorHelpers::phi(direction);
0085   bp[eBoundTheta] = VectorHelpers::theta(direction);
0086   bp[eBoundQOverP] = qOverP;
0087   return Result<Acts::BoundVector>::success(bp);
0088 }
0089 
0090 Acts::BoundVector Acts::transformFreeToCurvilinearParameters(double time,
0091                                                              double phi,
0092                                                              double theta,
0093                                                              double qOverP) {
0094   BoundVector bp = BoundVector::Zero();
0095   // local coordinates are zero by construction
0096   bp[eBoundTime] = time;
0097   bp[eBoundPhi] = phi;
0098   bp[eBoundTheta] = theta;
0099   bp[eBoundQOverP] = qOverP;
0100   return bp;
0101 }
0102 
0103 Acts::BoundVector Acts::transformFreeToCurvilinearParameters(
0104     double time, const Vector3& direction, double qOverP) {
0105   BoundVector bp = BoundVector::Zero();
0106   // local coordinates are zero by construction
0107   bp[eBoundTime] = time;
0108   bp[eBoundPhi] = VectorHelpers::phi(direction);
0109   bp[eBoundTheta] = VectorHelpers::theta(direction);
0110   bp[eBoundQOverP] = qOverP;
0111   return bp;
0112 }