Skip to content

feat: VectorHelpers - Add generic eta method#5598

Open
junggjo9 wants to merge 2 commits into
acts-project:mainfrom
junggjo9:AddGenericEta
Open

feat: VectorHelpers - Add generic eta method#5598
junggjo9 wants to merge 2 commits into
acts-project:mainfrom
junggjo9:AddGenericEta

Conversation

@junggjo9

Copy link
Copy Markdown
Contributor

PLEASE DESCRIBE YOUR CHANGES.
THIS MESSAGE ENDS UP AS THE COMMIT MESSAGE.
DO NOT USE @-MENTIONS HERE!

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

Johannes Junggeburth added 2 commits June 16, 2026 21:50
@github-actions github-actions Bot added this to the next milestone Jun 16, 2026
@github-actions github-actions Bot added the Component - Core Affects the Core module label Jun 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📊: Physics performance monitoring for e1d9282

Full contents

physmon summary

@sonarqubecloud

Copy link
Copy Markdown

/// @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));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component - Core Affects the Core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants