ROOT   6.14/05 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
20 #include "Math/GenVector/etaMax.h"
21
22
23 #include <limits>
24 #include <cmath>
25
26
27 namespace 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  if (std::fabs(z_scaled) < big_z_scaled) {
56  return log(z_scaled + sqrt(z_scaled * z_scaled + 1.0));
57  } else {
58  // apply correction using first order Taylor expansion of sqrt
59  return z > 0 ? log(2.0 * z_scaled + 0.5 / z_scaled) : -log(-2.0 * z_scaled);
60  }
61  }
62  // case vector has rho = 0
63  else if (z==0) {
64  return 0;
65  }
66  else if (z>0) {
67  return z + etaMax<Scalar>();
68  }
69  else {
70  return z - etaMax<Scalar>();
71  }
72
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  */
80  template<typename Scalar>
81  inline Scalar Eta_FromTheta(Scalar theta, Scalar r) {
82  Scalar tanThetaOver2 = tan(theta / 2.);
83  if (tanThetaOver2 == 0) {
84  return r + etaMax<Scalar>();
85  }
86  else if (tanThetaOver2 > std::numeric_limits<Scalar>::max()) {
87  return -r - etaMax<Scalar>();
88  }
89  else {
90  return -log(tanThetaOver2);
91  }
92
93  }
94
95  } // end namespace Impl
96
97  } // namespace Math
98
99 } // namespace ROOT
100
101
102 #endif /* ROOT_Math_GenVector_etaMax */
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
VecExpr< UnaryOp< Sqrt< T >, VecExpr< A, T, D >, T >, T, D > sqrt(const VecExpr< A, T, D > &rhs)
Scalar Eta_FromTheta(Scalar theta, Scalar r)
Implementation of eta from -log(tan(theta/2)).
Definition: eta.h:81
double pow(double, double)
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
ROOT::R::TRInterface & r
Definition: Object.C:4
Scalar Eta_FromRhoZ(Scalar rho, Scalar z)
Calculate eta given rho and zeta.
Definition: eta.h:48
REAL epsilon
Definition: triangle.c:617
Namespace for new Math classes and functions.
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
double tan(double)
Rotation3D::Scalar Scalar
double log(double)