herwig is hosted by Hepforge, IPPP Durham
 Herwig  7.1.5
Maths.h
1 // -*- C++ -*-
2 //
3 // Maths.h is a part of Herwig - A multi-purpose Monte Carlo event generator
4 // Copyright (C) 2002-2017 The Herwig Collaboration
5 //
6 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef HERWIG_Math_H
10 #define HERWIG_Math_H
11
12 #include <cmath>
13 #include <vector>
14 #include "ThePEG/Config/Complex.h"
15 #include "ThePEG/Utilities/Maths.h"
16
17 namespace Herwig {
18 using ThePEG::Complex;
19 using std::complex;
20
23 namespace Math {
24
29
33  long double ReLi2(long double);
34
38  inline double angleZeroTo2Pi(double angle) {
39  double ret = fmod(angle, 2 * M_PI);
40  if (ret < 0) ret += 2 * M_PI;
41  return ret;
42  }
43
47  inline double angleMinusPiToPi(double angle) {
48  double ret = angleZeroTo2Pi(angle);
49  if (ret > M_PI) ret -= 2 * M_PI;
50  return ret;
51  }
52
57  template <typename T>
58  inline T median(std::vector<T> v) {
59  if (v.empty()) return T();
60  sort ( v.begin(), v.end() );
61  const size_t N = v.size();
62  return (N % 2) ? v.at((N+1)/2 - 1) : v.at(N/2 - 1);
63  }
64
65 }
66
67 }
68
69 #endif /* HERWIG_Math_H */
T median(std::vector< T > v)
Calculates the (lower) median of a vector of T objects.
Definition: Maths.h:58
std::complex< double > Complex
Complex Li2(Complex)
The dilog function taken from FORTRAN Herwig.
double angleMinusPiToPi(double angle)
Fold angles into the range (-Pi,Pi)
Definition: Maths.h:47
-*- C++ -*-
long double ReLi2(long double)
The real part of the dilog function taken from FORTRAN Herwig.
double angleZeroTo2Pi(double angle)
Fold angles into the range (0,2 Pi)
Definition: Maths.h:38