FastJet  3.1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
inline_maths.h
1 #ifndef INLINE_MATHS
2 #define INLINE_MATHS
3 
4 // This file is distributed with FastJet under the terms of the GNU
5 // General Public License (v2). Permission to do so has been granted
6 // by Lars Sonnenschein and the D0 collaboration (see COPYING for
7 // details)
8 //
9 // History of changes in FastJet compared tothe original version of
10 // inline_math.h
11 //
12 // 2011-12-13 Gregory Soyez <soyez@fastjet.fr>
13 //
14 // * added license information
15 //
16 // 2009-01-17 Gregory Soyez <soyez@fastjet.fr>
17 //
18 // * put the code in the fastjet::d0 namespace
19 
20 #include <cerrno>
21 
22 #include <fastjet/internal/base.hh>
23 
24 FASTJET_BEGIN_NAMESPACE
25 
26 namespace d0{
27 
28 namespace inline_maths {
29 
30 const double PI = fabs(acos(-1.));
31 
32 const double TWOPI = 2*PI;
33 
34 
35 inline double sqr(double a) {
36  return a*a;
37 }
38 
39 
40 
41 inline double min(double a, double b) {
42  return (a < b) ? a : b;
43 }
44 
45 
46 
47 inline double delta_phi(double phi1, double phi2) {
48  return min( double(fabs(phi1-phi2)), double(2.*PI-fabs(phi1-phi2)) );
49 }
50 
51 
52 
53 inline double phi(double px, double py) {
54  return atan2(py, px);
55 }
56 
57 
58 
59 inline double y(double E, double pz) {
60  errno=0;
61  double y;
62  //cout << "inline_maths: ";
63  if (fabs(E-pz) == 0.) {
64  // cout << "Error in header mathe.h: division by 0 in function eta!" << " p=" << p << " pz=" << pz << endl;
65  // exit(721);
66  errno=721;
67  y = 99999.;
68  }
69  else {
70  y = 0.5*log((E+pz)/(E-pz));
71  }
72  //cout << "y: E=" << E << " pz=" << pz << " y=" << y << endl;
73  return y;
74 }
75 
76 
77 } //end usename inline_maths
78 
79 
80 } // namespace d0
81 
82 FASTJET_END_NAMESPACE
83 
84 #endif