forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use common direction transform Jacobian (acts-project#2782)
I found the same code in a few places and there seems to be a bit of simplification opportunity in the math
- Loading branch information
Showing
8 changed files
with
137 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Utilities/VectorHelpers.hpp" | ||
|
||
namespace Acts { | ||
|
||
/// @brief Calculates the Jacobian for spherical to free | ||
/// direction vector transformation | ||
/// | ||
/// @note We use the direction vector as an input because | ||
/// the trigonometric simplify that way | ||
/// | ||
/// @param direction The normalised direction vector | ||
/// | ||
/// @return The Jacobian d(dir_x, dir_y, dir_z) / d(phi, theta) | ||
/// | ||
inline ActsMatrix<3, 2> sphericalToFreeDirectionJacobian( | ||
const Vector3& direction) { | ||
auto [cosPhi, sinPhi, cosTheta, sinTheta] = | ||
VectorHelpers::evaluateTrigonomics(direction); | ||
|
||
// clang-format off | ||
ActsMatrix<3, 2> jacobian; | ||
jacobian << | ||
-direction.y(), cosTheta * cosPhi, | ||
direction.x(), cosTheta * sinPhi, | ||
0, -sinTheta; | ||
// clang-format on | ||
|
||
return jacobian; | ||
} | ||
|
||
/// @brief Calculates the Jacobian for free to spherical | ||
/// direction vector transformation | ||
/// | ||
/// @note We use the direction vector as an input because | ||
/// the trigonometric simplify that way | ||
/// | ||
/// @param direction The normalised direction vector | ||
/// | ||
/// @return The Jacobian d(phi, theta) / d(dir_x, dir_y, dir_z) | ||
/// | ||
inline ActsMatrix<2, 3> freeToSphericalDirectionJacobian( | ||
const Vector3& direction) { | ||
auto [cosPhi, sinPhi, cosTheta, sinTheta] = | ||
VectorHelpers::evaluateTrigonomics(direction); | ||
ActsScalar invSinTheta = 1. / sinTheta; | ||
|
||
// clang-format off | ||
ActsMatrix<2, 3> jacobian; | ||
jacobian << | ||
-sinPhi * invSinTheta, cosPhi * invSinTheta, 0, | ||
cosPhi * cosTheta, sinPhi * cosTheta, -sinTheta; | ||
// clang-format on | ||
|
||
return jacobian; | ||
} | ||
|
||
} // namespace Acts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.