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
12// Header source file for function calculating eta
13//
14// Created by: Lorenzo Moneta at 14 Jun 2007
15
16
17#ifndef ROOT_Math_GenVector_eta
18#define ROOT_Math_GenVector_eta 1
19
21
22
23#include <limits>
24#include <cmath>
25
26
27namespace ROOT {
28
29 namespace Math {
30
31 namespace Impl {
32
33 /**
34 Calculate eta given rho and zeta.
35 This formula is faster than the standard calculation (below) from log(tan(theta/2)
36 but one has to be careful when rho is much smaller than z (large eta values)
37 Formula is eta = log( zs + sqrt(zs^2 + 1) ) where zs = z/rho
38
39 For large value of z_scaled (tan(theta) ) one can appoximate the sqrt via a Taylor expansion
40 We do the approximation of the sqrt if the numerical error is of the same order of second term of
41 the sqrt.expansion:
42 eps > 1/zs^4 => zs > 1/(eps^0.25)
43
44 When rho == 0 we use etaMax (see definition in etaMax.h)
45
46 */
47 template<typename Scalar>
49 if (rho > 0) {
50
51 // value to control Taylor expansion of sqrt
52 static const Scalar big_z_scaled = pow(std::numeric_limits<Scalar>::epsilon(), static_cast<Scalar>(-.25));
53
54 Scalar z_scaled = z/rho;
55 using std::fabs;
56 if (std::fabs(z_scaled) < big_z_scaled) {
57 using std::sqrt;
58 using std::log;
59 return log(z_scaled + std::sqrt(z_scaled * z_scaled + 1.0));
60 } else {
61 // apply correction using first order Taylor expansion of sqrt
62 using std::log;
63 return z > 0 ? log(2.0 * z_scaled + 0.5 / z_scaled) : -log(-2.0 * z_scaled);
64 }
65 }
66 // case vector has rho = 0
67 else if (z==0) {
68 return 0;
69 }
70 else if (z>0) {
71 return z + etaMax<Scalar>();
72 }
73 else {
74 return z - etaMax<Scalar>();
75 }
76
77 }
78
79
80 /**
81 Implementation of eta from -log(tan(theta/2)).
82 This is convenient when theta is already known (for example in a polar coorindate system)
83 */
84 template<typename Scalar>
86 Scalar tanThetaOver2 = tan(theta / 2.);
87 if (tanThetaOver2 == 0) {
88 return r + etaMax<Scalar>();
89 }
90 else if (tanThetaOver2 > std::numeric_limits<Scalar>::max()) {
91 return -r - etaMax<Scalar>();
92 }
93 else {
94 using std::log;
95 return -log(tanThetaOver2);
96 }
97
98 }
99
100 } // end namespace Impl
101
102 } // namespace Math
103
104} // namespace ROOT
105
106
107#endif /* ROOT_Math_GenVector_etaMax */
ROOT::R::TRInterface & r
Definition Object.C:4
double pow(double, double)
double tan(double)
double log(double)
Namespace for new Math classes and functions.
Scalar Eta_FromTheta(Scalar theta, Scalar r)
Implementation of eta from -log(tan(theta/2)).
Definition eta.h:85
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition eta.h:48
Rotation3D::Scalar Scalar
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...