Fork me on GitHub

source: git/external/fastjet/plugins/D0RunICone/inline_maths.h@ f08474a

Last change on this file since f08474a was d7d2da3, checked in by pavel <pavel@…>, 12 years ago

move branches/ModularDelphes to trunk

  • Property mode set to 100644
File size: 2.8 KB
Line 
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// 2011-10-06 Gregory Soyez <soyez@fastjet.fr>
17//
18// * put the code in the fastjet::d0runi namespace
19
20#include <cmath>
21#include <cerrno>
22#include <fastjet/internal/base.hh>
23
24FASTJET_BEGIN_NAMESPACE
25
26//using namespace std;
27
28namespace d0runi{
29namespace inline_maths {
30
31const double PI = fabs(acos(-1.));
32
33const double TWOPI = 2*PI;
34
35
36inline double sqr(double a) {
37 return a*a;
38}
39
40
41
42inline double min(double a, double b) {
43 return (a < b) ? a : b;
44}
45
46
47
48inline double delta_phi(double phi1, double phi2) {
49 double dphi = min( double(fabs(phi1-phi2)), double(2.*PI-fabs(phi1-phi2)) );
50 return (phi1 < phi2) ? -dphi : dphi;
51}
52
53
54
55inline double phi(double px, double py) {
56 return atan2(py, px);
57}
58
59
60
61inline double y(double E, double pz) {
62 errno=0;
63 double y;
64 //cout << "inline_maths: ";
65 if (fabs(E-pz) == 0.) {
66 // cout << "Error in header mathe.h: division by 0 in function y!" << " p=" << p << " pz=" << pz << endl;
67 // exit(721);
68 errno=721;
69 y = 99999.;
70 }
71 else {
72 y = 0.5*log((E+pz)/(E-pz));
73 }
74 //cout << "y: E=" << E << " pz=" << pz << " y=" << y << endl;
75 return y;
76}
77
78
79
80
81inline double eta(double p, double pz) {
82 errno=0;
83 double eta;
84 //cout << "inline_maths: ";
85 if (fabs(p-pz) == 0.) {
86 // cout << "Error in header mathe.h: division by 0 in function eta!" << " p=" << p << " pz=" << pz << endl;
87 // exit(721);
88 errno=721;
89 eta = 99999.;
90 }
91 else {
92 eta = 0.5*log((p+pz)/(p-pz));
93 }
94 //cout << "eta: p=" << p << " pz=" << pz << " eta=" << eta << endl;
95 return eta;
96}
97
98
99
100
101 inline double eta(double px, double py, double pz) {
102 errno=0;
103 double eta;
104 //cout << "inline_maths: ";
105 double p = sqrt(px*px+py*py+pz*pz);
106 if (fabs(p-pz) == 0.) {
107 // cout << "Error in header mathe.h: division by 0 in function eta!" << " p=" << p << " pz=" << pz << endl;
108 // exit(721);
109 errno=721;
110 eta = 99999.;
111 }
112 else {
113 eta = 0.5*log((p+pz)/(p-pz));
114 }
115 //cout << "eta: p=" << p << " pz=" << pz << " eta=" << eta << endl;
116 return eta;
117}
118
119
120
121 inline double eta(double theta) {
122 double eta = -log(tan(theta/2.));
123
124 return eta;
125 }
126
127
128 inline double theta(double eta) {
129 double theta = 2.*atan(exp(-eta));
130
131 return theta;
132 }
133
134 inline double theta(double px, double py, double pz) {
135 double Eta = eta(px, py, pz);
136 double theta = 2.*atan(exp(-Eta));
137
138 return theta;
139 }
140
141
142
143} //end usename inline_maths
144} //end usename d0runi
145
146FASTJET_END_NAMESPACE
147
148
149#endif
Note: See TracBrowser for help on using the repository browser.