Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:24:28

0001 // -*- C++ -*-
0002 //
0003 // Maths.h is a part of Herwig - A multi-purpose Monte Carlo event generator
0004 // Copyright (C) 2002-2019 The Herwig Collaboration
0005 //
0006 // Herwig is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef HERWIG_Math_H
0010 #define HERWIG_Math_H
0011 
0012 #include <cmath>
0013 #include <vector>
0014 #include "ThePEG/Config/Complex.h"
0015 #include "ThePEG/Utilities/Maths.h"
0016 #include "ThePEG/Config/TemplateTools.h"
0017 
0018 namespace Herwig {
0019 using ThePEG::Complex;
0020 using std::complex;
0021 
0022 /** The Math namespace includes the declaration of some useful
0023  *  mathematical functions. */
0024 namespace Math {
0025 
0026   /**
0027    * The dilog function taken from FORTRAN Herwig
0028    */
0029   Complex Li2(Complex);
0030 
0031   /**
0032    * The real part of the dilog function taken from FORTRAN Herwig
0033    */
0034   long double ReLi2(long double);
0035   
0036   /**
0037    * Fold angles into the range (0,2 Pi)
0038    */
0039   inline double angleZeroTo2Pi(double angle) {
0040     double ret = fmod(angle, 2 * M_PI);
0041     if (ret < 0) ret += 2 * M_PI;
0042     return ret;
0043   }
0044 
0045   /**
0046    * Fold angles into the range (-Pi,Pi)
0047    */
0048   inline double angleMinusPiToPi(double angle) {
0049     double ret = angleZeroTo2Pi(angle);
0050     if (ret > M_PI) ret -= 2 * M_PI;
0051     return ret;
0052   }
0053 
0054   /**
0055    * Calculates the (lower) median of a vector of T objects. T has to be
0056    * comparable, i.e. T::operator< must be defined.
0057    */
0058   template <typename T>
0059   inline T median(std::vector<T> v) {
0060     if (v.empty()) return T();
0061     sort ( v.begin(), v.end() );
0062     const size_t N = v.size();
0063     return (N % 2) ? v.at((N+1)/2 - 1) : v.at(N/2 - 1);
0064   }
0065 
0066 }
0067 
0068 }
0069 
0070 #endif /* HERWIG_Math_H */