Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Core/include/Acts/Utilities/VectorHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@
}
}

/// Calculate the pseudo rapdity from anything implementing a method
/// like `theta()` returning anything convertible to `double`.
/// @tparam T anything that has a theta method
/// @param v Any type that implements a theta method
/// @return The pseudo rapidity value
template <typename T>
double eta(const T& v) noexcept

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why not double eta(double theta), wouldn't that be even more generic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was taking the phi implementation as my template here. Yeah, that would be another option

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the best case we could have both. we have many implementations for eta -> theta and the other way flying around which could be centralized. but a scalar transformation is out of scope for vector helpers I believe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we already have a central eta implementation?

@benjaminhuth benjaminhuth Jun 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah make sense that its not for vector helpers. But I think code like eta(myFancyType) which internally calls myFancyType.theta() is just less transparent as eta(myFancyType.theta())...

So I don't like the phi function either I think :D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah we actually have a helper

/// Conversion limits for `double` eta/theta calculations.
///
/// Defines safe min/max theta and eta values for `double` precision.
template <>
struct EtaThetaConversionTraits<double> {
/// Minimum theta value for double precision
static constexpr double minTheta = 1e-12;
/// Maximum theta value for double precision
static constexpr double maxTheta = std::numbers::pi - minTheta;
/// Maximum eta value for double precision
static constexpr double maxEta = 700.0;
/// Minimum eta value for double precision
static constexpr double minEta = -maxEta;
};
/// Calculate the pseudorapidity from the polar angle theta.
///
/// This function aims to be FPE safe and returns infinity for theta values
/// outside the floating point precision range.
///
/// @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) {
if (theta <= EtaThetaConversionTraits<Scalar>::minTheta) {
return std::numeric_limits<Scalar>::infinity();
}
if (theta >= EtaThetaConversionTraits<Scalar>::maxTheta) {
return -std::numeric_limits<Scalar>::infinity();
}
return -std::log(std::tan(theta / 2));
}
/// Calculate the polar angle theta from the pseudorapidity.
///
/// This function aims to be FPE safe and returns 0/pi for eta values outside
/// the floating point precision range.
///
/// @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) {
if (eta <= EtaThetaConversionTraits<Scalar>::minEta) {
return std::numbers::pi_v<Scalar>;
}
if (eta >= EtaThetaConversionTraits<Scalar>::maxEta) {
return 0;
}
return 2 * std::atan(std::exp(-eta));
}

requires requires {

Check warning on line 153 in Core/include/Acts/Utilities/VectorHelpers.hpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this requires expression into a named concept.

See more on https://sonarcloud.io/project/issues?id=acts-project_acts&issues=AZ7SaitsGTnYtFigQtFH&open=AZ7SaitsGTnYtFigQtFH&pullRequest=5598
{ v.theta() } -> std::floating_point;
}
{
return -std::log(std::tan(0.5 * v.theta()));
}

/// @brief Fast evaluation of trigonomic functions.
///
/// @param direction for this evaluatoin
Expand Down
Loading