Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
eta.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 , FNAL MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header source file for function calculating eta
12//
13// Created by: Lorenzo Moneta at 14 Jun 2007
14
15#ifndef ROOT_MathX_GenVectorX_eta
16#define ROOT_MathX_GenVectorX_eta 1
17
19
21
23
24using namespace ROOT::ROOT_MATH_ARCH;
25
26#include <limits>
27#include <cmath>
28
29namespace ROOT {
30
31namespace ROOT_MATH_ARCH {
32
33namespace Impl {
34
35/**
36 Calculate eta given rho and zeta.
37 This formula is faster than the standard calculation (below) from log(tan(theta/2)
38 but one has to be careful when rho is much smaller than z (large eta values)
39 Formula is eta = log( zs + sqrt(zs^2 + 1) ) where zs = z/rho
40
41 For large value of z_scaled (tan(theta) ) one can approximate the sqrt via a Taylor expansion
42 We do the approximation of the sqrt if the numerical error is of the same order of second term of
43 the sqrt.expansion:
44 eps > 1/zs^4 => zs > 1/(eps^0.25)
45
46 When rho == 0 we use etaMax (see definition in etaMax.h)
47
48 */
49template <typename Scalar>
51{
52 if (rho > 0) {
53
54 // value to control Taylor expansion of sqrt
55 Scalar big_z_scaled = math_pow(std::numeric_limits<Scalar>::epsilon(), static_cast<Scalar>(-.25));
56
57 Scalar z_scaled = z / rho;
58
59 // eta is odd in zs: use |zs| in the formula, which then has no cancellation, and apply the sign of zs.
60 // For large |zs|, use the first order Taylor expansion of sqrt.
61 const Scalar abs_z_scaled = math_fabs(z_scaled);
62 const Scalar abs_eta = abs_z_scaled < big_z_scaled
63 ? math_log(abs_z_scaled + math_sqrt(abs_z_scaled * abs_z_scaled + 1.0))
64 : math_log(2.0 * abs_z_scaled + 0.5 / abs_z_scaled);
65 return z_scaled < 0 ? -abs_eta : abs_eta;
66 }
67 // case vector has rho = 0
68 else if (z == 0) {
69 return 0;
70 } else if (z > 0) {
71 return z + etaMax<Scalar>();
72 } else {
73 return z - etaMax<Scalar>();
74 }
75}
76
77/**
78 Implementation of eta from -log(tan(theta/2)).
79 This is convenient when theta is already known (for example in a polar coorindate system)
80*/
81template <typename Scalar>
83{
84 Scalar tanThetaOver2 = tan(theta / 2.);
85 if (tanThetaOver2 == 0) {
86 return r + etaMax<Scalar>();
87 } else if (tanThetaOver2 > std::numeric_limits<Scalar>::max()) {
88 return -r - etaMax<Scalar>();
89 } else {
90 return -math_log(tanThetaOver2);
91 }
92}
93
94} // end namespace Impl
95
96} // namespace ROOT_MATH_ARCH
97
98} // namespace ROOT
99
100#endif /* ROOT_MathX_GenVectorX_etaMax */
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Scalar Eta_FromTheta(Scalar theta, Scalar r)
Implementation of eta from -log(tan(theta/2)).
Definition eta.h:82
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition eta.h:50
Scalar math_log(Scalar x)
Scalar math_pow(Scalar x, Scalar y)
Rotation3D::Scalar Scalar
Scalar math_sqrt(Scalar x)
Scalar math_fabs(Scalar x)