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
60 return math_log(z_scaled + math_sqrt(z_scaled * z_scaled + 1.0));
61 } else {
62 // apply correction using first order Taylor expansion of sqrt
63 return z > 0 ? math_log(2.0 * z_scaled + 0.5 / z_scaled) : -math_log(-2.0 * z_scaled);
64 }
65 }
66 // case vector has rho = 0
67 else if (z == 0) {
68 return 0;
69 } else if (z > 0) {
70 return z + etaMax<Scalar>();
71 } else {
72 return z - etaMax<Scalar>();
73 }
74}
75
76/**
77 Implementation of eta from -log(tan(theta/2)).
78 This is convenient when theta is already known (for example in a polar coorindate system)
79*/
80template <typename Scalar>
82{
83 Scalar tanThetaOver2 = tan(theta / 2.);
84 if (tanThetaOver2 == 0) {
85 return r + etaMax<Scalar>();
86 } else if (tanThetaOver2 > std::numeric_limits<Scalar>::max()) {
87 return -r - etaMax<Scalar>();
88 } else {
89 return -math_log(tanThetaOver2);
90 }
91}
92
93} // end namespace Impl
94
95} // namespace ROOT_MATH_ARCH
96
97} // namespace ROOT
98
99#endif /* ROOT_MathX_GenVectorX_etaMax */
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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:81
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)