ROOT  6.06/09
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 #ifndef ROOT_Math_GenVector_etaMax
21 #include "Math/GenVector/etaMax.h"
22 #endif
23 
24 
25 #include <limits>
26 #include <cmath>
27 
28 
29 namespace ROOT {
30 
31  namespace Math {
32 
33  namespace 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 appoximate 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  */
49  template<typename Scalar>
50  inline Scalar Eta_FromRhoZ(Scalar rho, Scalar z) {
51  if (rho > 0) {
52 
53  // value to control Taylor expansion of sqrt
54  static const Scalar big_z_scaled =
55  std::pow(std::numeric_limits<Scalar>::epsilon(),static_cast<Scalar>(-.25));
56 
57  Scalar z_scaled = z/rho;
58  if (std::fabs(z_scaled) < big_z_scaled) {
59  return std::log(z_scaled+std::sqrt(z_scaled*z_scaled+1.0));
60  } else {
61  // apply correction using first order Taylor expansion of sqrt
62  return z>0 ? std::log(2.0*z_scaled + 0.5/z_scaled) : -std::log(-2.0*z_scaled);
63  }
64  }
65  // case vector has rho = 0
66  else if (z==0) {
67  return 0;
68  }
69  else if (z>0) {
70  return z + etaMax<Scalar>();
71  }
72  else {
73  return z - etaMax<Scalar>();
74  }
75 
76  }
77 
78 
79  /**
80  Implementation of eta from -log(tan(theta/2)).
81  This is convenient when theta is already known (for example in a polar coorindate system)
82  */
83  template<typename Scalar>
84  inline Scalar Eta_FromTheta(Scalar theta, Scalar r) {
85 
86  Scalar tanThetaOver2 = std::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  return -std::log(tanThetaOver2);
95  }
96 
97  }
98 
99  } // end namespace Impl
100 
101  } // namespace Math
102 
103 } // namespace ROOT
104 
105 
106 #endif /* ROOT_Math_GenVector_etaMax */
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
double sqrt(double)
Scalar Eta_FromTheta(Scalar theta, Scalar r)
Implementation of eta from -log(tan(theta/2)).
Definition: eta.h:84
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:50
REAL epsilon
Definition: triangle.c:617
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Namespace for new Math classes and functions.
double tan(double)
Plane3D::Scalar Scalar
Definition: Plane3D.cxx:29
double log(double)