Logo ROOT  
Reference Guide
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 */
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
RVec< PromoteType< T > > tan(const RVec< T > &v)
Definition: RVec.hxx:1777
RVec< PromoteTypes< T0, T1 > > pow(const T0 &x, const RVec< T1 > &v)
Definition: RVec.hxx:1770
RVec< PromoteType< T > > log(const RVec< T > &v)
Definition: RVec.hxx:1765
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
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
double epsilon
Definition: triangle.c:618