File: inline_maths.h

package info (click to toggle)
fastjet 3.0.6%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 9,468 kB
  • ctags: 3,766
  • sloc: cpp: 21,498; sh: 10,546; fortran: 673; makefile: 518; ansic: 131
file content (149 lines) | stat: -rw-r--r-- 2,914 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef INLINE_MATHS
#define INLINE_MATHS

// This file is distributed with FastJet under the terms of the GNU
// General Public License (v2). Permission to do so has been granted
// by Lars Sonnenschein and the D0 collaboration (see COPYING for
// details)
//
// History of changes in FastJet compared tothe original version of
// inline_math.h
//
// 2011-12-13  Gregory Soyez  <soyez@fastjet.fr>
// 
//        * added license information
//
// 2011-10-06  Gregory Soyez  <soyez@fastjet.fr>
//
//        * put the code in the fastjet::d0runi namespace

#include <cmath>
#include <cerrno>
#include <fastjet/internal/base.hh>

FASTJET_BEGIN_NAMESPACE

//using namespace std;

namespace d0runi{
namespace inline_maths {

const double PI = fabs(acos(-1.));

const double TWOPI = 2*PI;


inline double sqr(double a) {
  return a*a;
}



inline double min(double a, double b) {
  return (a < b) ? a : b;
}



inline double delta_phi(double phi1, double phi2) {
  double dphi = min( double(fabs(phi1-phi2)), double(2.*PI-fabs(phi1-phi2)) );
  return (phi1 < phi2) ? -dphi : dphi;
}



inline double phi(double px, double py) {
  return atan2(py, px);
}



inline double y(double E, double pz) {
  errno=0;
  double y;
  //cout << "inline_maths: ";
  if (fabs(E-pz) == 0.) {
    //    cout << "Error in header mathe.h: division by 0 in function y!" <<  " p=" << p << " pz=" << pz << endl;
    //  exit(721);
    errno=721;
    y = 99999.;
  }
  else {
    y = 0.5*log((E+pz)/(E-pz));
  }
  //cout << "y: E=" << E << " pz=" << pz << " y=" << y << endl;
  return y;
}




inline double eta(double p, double pz) {
  errno=0;
  double eta;
  //cout << "inline_maths: ";
  if (fabs(p-pz) == 0.) {
    //    cout << "Error in header mathe.h: division by 0 in function eta!" <<  " p=" << p << " pz=" << pz << endl;
    //  exit(721);
    errno=721;
    eta = 99999.;
  }
  else {
    eta = 0.5*log((p+pz)/(p-pz));
  }
  //cout << "eta: p=" << p << " pz=" << pz << " eta=" << eta << endl;
  return eta;
}




 inline double eta(double px, double py, double pz) {
   errno=0;
   double eta;
  //cout << "inline_maths: ";
   double p = sqrt(px*px+py*py+pz*pz);
   if (fabs(p-pz) == 0.) {
    //    cout << "Error in header mathe.h: division by 0 in function eta!" <<  " p=" << p << " pz=" << pz << endl;
    //  exit(721);
    errno=721;
    eta = 99999.;
  }
  else {
    eta = 0.5*log((p+pz)/(p-pz));
  }
  //cout << "eta: p=" << p << " pz=" << pz << " eta=" << eta << endl;
  return eta;
}



 inline double eta(double theta) {
   double eta = -log(tan(theta/2.));
   
   return eta;
 }
 

 inline double theta(double eta) {
   double theta = 2.*atan(exp(-eta));
   
   return theta;
 }
 
 inline double theta(double px, double py, double pz) {
   double Eta = eta(px, py, pz);
   double theta = 2.*atan(exp(-Eta));
   
   return theta;
 }
 


} //end usename inline_maths
} //end usename d0runi

FASTJET_END_NAMESPACE


#endif