Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-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 #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, ActsScalar 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, ActsScalar time,
0069     const Acts::Vector3& direction, ActsScalar qOverP,
0070     const Acts::Surface& surface, const Acts::GeometryContext& geoCtx,
0071     ActsScalar tolerance) {
0072   // initialize the bound vector
0073   BoundVector bp = BoundVector::Zero();
0074   // convert global to local position on the surface
0075   auto result = surface.globalToLocal(geoCtx, position, direction, tolerance);
0076   if (!result.ok()) {
0077     return Result<Acts::BoundVector>::failure(result.error());
0078   }
0079 
0080   auto localPosition = result.value();
0081   bp[eBoundLoc0] = localPosition[ePos0];
0082   bp[eBoundLoc1] = localPosition[ePos1];
0083 
0084   bp[eBoundTime] = time;
0085   bp[eBoundPhi] = VectorHelpers::phi(direction);
0086   bp[eBoundTheta] = VectorHelpers::theta(direction);
0087   bp[eBoundQOverP] = qOverP;
0088   return Result<Acts::BoundVector>::success(bp);
0089 }
0090 
0091 Acts::BoundVector Acts::transformFreeToCurvilinearParameters(
0092     ActsScalar time, ActsScalar phi, ActsScalar theta, ActsScalar qOverP) {
0093   BoundVector bp = BoundVector::Zero();
0094   // local coordinates are zero by construction
0095   bp[eBoundTime] = time;
0096   bp[eBoundPhi] = phi;
0097   bp[eBoundTheta] = theta;
0098   bp[eBoundQOverP] = qOverP;
0099   return bp;
0100 }
0101 
0102 Acts::BoundVector Acts::transformFreeToCurvilinearParameters(
0103     ActsScalar time, const Vector3& direction, ActsScalar qOverP) {
0104   BoundVector bp = BoundVector::Zero();
0105   // local coordinates are zero by construction
0106   bp[eBoundTime] = time;
0107   bp[eBoundPhi] = VectorHelpers::phi(direction);
0108   bp[eBoundTheta] = VectorHelpers::theta(direction);
0109   bp[eBoundQOverP] = qOverP;
0110   return bp;
0111 }