forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
AngleHelpers.hpp
to help with eta/theta conversions (acts…
…-project#3767) Adds central conversion between $\eta$ and $\theta$
- Loading branch information
Showing
14 changed files
with
126 additions
and
45 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
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,35 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include <cmath> | ||
|
||
namespace Acts::AngleHelpers { | ||
|
||
/// Calculate the pseudorapidity from the polar angle theta. | ||
/// | ||
/// @param theta is the polar angle in radian towards the z-axis. | ||
/// | ||
/// @return the pseudorapidity towards the z-axis. | ||
template <typename Scalar> | ||
Scalar etaFromTheta(Scalar theta) { | ||
return -std::log(std::tan(0.5 * theta)); | ||
} | ||
|
||
/// Calculate the polar angle theta from the pseudorapidity. | ||
/// | ||
/// @param eta is the pseudorapidity towards the z-axis. | ||
/// | ||
/// @return the polar angle in radian towards the z-axis. | ||
template <typename Scalar> | ||
Scalar thetaFromEta(Scalar eta) { | ||
return 2 * std::atan(std::exp(-eta)); | ||
} | ||
|
||
} // namespace Acts::AngleHelpers |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" | ||
#include "Acts/Utilities/AngleHelpers.hpp" | ||
|
||
#include <numbers> | ||
|
||
using Acts::AngleHelpers::etaFromTheta; | ||
using Acts::AngleHelpers::thetaFromEta; | ||
|
||
BOOST_AUTO_TEST_SUITE(AngleHelpers) | ||
|
||
BOOST_AUTO_TEST_CASE(EtaThetaConversion) { | ||
CHECK_CLOSE_ABS(0.0, etaFromTheta(std::numbers::pi / 2), 1e-6); | ||
|
||
CHECK_CLOSE_ABS(1.0, etaFromTheta(thetaFromEta(1.0)), 1e-6); | ||
|
||
CHECK_CLOSE_ABS(1.0, thetaFromEta(etaFromTheta(1.0)), 1e-6); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp" | ||
#include "Acts/Utilities/VectorHelpers.hpp" | ||
|
||
#include <numbers> | ||
|
||
using Acts::VectorHelpers::eta; | ||
using Acts::VectorHelpers::theta; | ||
|
||
BOOST_AUTO_TEST_SUITE(AngleHelpers) | ||
|
||
BOOST_AUTO_TEST_CASE(EtaFromVector) { | ||
CHECK_CLOSE_ABS(0.0, eta(Acts::Vector3{1, 0, 0}), 1e-6); | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(ThetaFromVector) { | ||
CHECK_CLOSE_ABS(std::numbers::pi / 2, theta(Acts::Vector3{1, 0, 0}), 1e-6); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |