Rivet is hosted by Hepforge, IPPP Durham
MathUtils.hh File Reference
#include "Rivet/Math/MathHeader.hh"
#include <type_traits>
#include <cassert>
Include dependency graph for MathUtils.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  Rivet

Functions

Comparison functions for safe (floating point) equality tests
template<typename NUM >
std::enable_if
< std::is_floating_point< NUM >
::value, bool >::type 
isZero (NUM val, double tolerance=1e-8)
 Compare a number to zero.
template<typename NUM >
std::enable_if
< std::is_integral< NUM >
::value, bool >::type 
isZero (NUM val, double UNUSED(tolerance)=1e-8)
 Compare a number to zero.
template<typename N1 , typename N2 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&(std::is_floating_point< N1 >
::value||std::is_floating_point
< N2 >::value), bool >::type 
fuzzyEquals (N1 a, N2 b, double tolerance=1e-5)
 Compare two numbers for equality with a degree of fuzziness.
template<typename N1 , typename N2 >
std::enable_if
< std::is_integral< N1 >
::value &&std::is_integral< N2 >
::value, bool >::type 
fuzzyEquals (N1 a, N2 b, double UNUSED(tolerance)=1e-5)
 Compare two numbers for equality with a degree of fuzziness.
template<typename N1 , typename N2 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value, bool >::type 
fuzzyGtrEquals (N1 a, N2 b, double tolerance=1e-5)
 Compare two numbers for >= with a degree of fuzziness.
template<typename N1 , typename N2 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value, bool >::type 
fuzzyLessEquals (N1 a, N2 b, double tolerance=1e-5)
 Compare two floating point numbers for <= with a degree of fuzziness.
Miscellaneous numerical helpers
Todo:
Add pair-based versions of the named range-boundary functions
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, NUM >::type 
sqr (NUM a)
 Named number-type squaring operation.
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, NUM >::type 
add_quad (NUM a, NUM b)
 Named number-type addition in quadrature operation.
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, NUM >::type 
add_quad (NUM a, NUM b, NUM c)
double safediv (double num, double den, double fail=0.0)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, NUM >::type 
intpow (NUM val, unsigned int exp)
 A more efficient version of pow for raising numbers to integer powers.
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, int >::type 
sign (NUM val)
 Find the sign of a number.
Physics statistical distributions
double cdfBW (double x, double mu, double gamma)
 CDF for the Breit-Wigner distribution.
double invcdfBW (double p, double mu, double gamma)
 Inverse CDF for the Breit-Wigner distribution.
Binning helper functions
vector< double > linspace (size_t nbins, double start, double end, bool include_end=true)
 Make a list of nbins + 1 values equally spaced between start and end inclusive.
vector< double > logspace (size_t nbins, double start, double end, bool include_end=true)
 Make a list of nbins + 1 values exponentially spaced between start and end inclusive.
vector< double > bwspace (size_t nbins, double start, double end, double mu, double gamma)
 Make a list of nbins + 1 values spaced for equal area Breit-Wigner binning between start and end inclusive. mu and gamma are the Breit-Wigner parameters.
template<typename NUM1 , typename NUM2 >
std::enable_if
< std::is_arithmetic< NUM1 >
::value
&&std::is_floating_point< NUM2 >
::value, int >::type 
binIndex (NUM1 val, const vector< NUM2 > &binedges, bool allow_overflow=false)
 Return the bin index of the given value, val, given a vector of bin edges.
Discrete statistics functions
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, NUM >::type 
median (const vector< NUM > &sample)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, double >::type 
mean (const vector< NUM > &sample)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, double >::type 
mean_err (const vector< NUM > &sample)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, double >::type 
covariance (const vector< NUM > &sample1, const vector< NUM > &sample2)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, double >::type 
covariance_err (const vector< NUM > &sample1, const vector< NUM > &sample2)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, double >::type 
correlation (const vector< NUM > &sample1, const vector< NUM > &sample2)
template<typename NUM >
std::enable_if
< std::is_arithmetic< NUM >
::value, double >::type 
correlation_err (const vector< NUM > &sample1, const vector< NUM > &sample2)
Angle range mappings
double _mapAngleM2PITo2Pi (double angle)
 Reduce any number to the range [-2PI, 2PI].
double mapAngleMPiToPi (double angle)
 Map an angle into the range (-PI, PI].
double mapAngle0To2Pi (double angle)
 Map an angle into the range [0, 2PI).
double mapAngle0ToPi (double angle)
 Map an angle into the range [0, PI].
double mapAngle (double angle, PhiMapping mapping)
 Map an angle into the enum-specified range.
Phase space measure helpers
double deltaPhi (double phi1, double phi2)
 Calculate the difference between two angles in radians.
double deltaEta (double eta1, double eta2)
double deltaRap (double y1, double y2)
double deltaR (double rap1, double phi1, double rap2, double phi2)
double rapidity (double E, double pz)
 Calculate a rapidity value from the supplied energy E and longitudinal momentum pz.

Ranges and intervals

enum  RangeBoundary { OPEN = 0, SOFT = 0, CLOSED = 1, HARD = 1 }
template<typename N1 , typename N2 , typename N3 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&std::is_arithmetic< N3 >
::value, bool >::type 
inRange (N1 value, N2 low, N3 high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Determine if value is in the range low to high, for floating point numbers.
template<typename N1 , typename N2 , typename N3 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&std::is_arithmetic< N3 >
::value, bool >::type 
fuzzyInRange (N1 value, N2 low, N3 high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Determine if value is in the range low to high, for floating point numbers.
template<typename N1 , typename N2 , typename N3 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&std::is_arithmetic< N3 >
::value, bool >::type 
inRange (N1 value, pair< N2, N3 > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange which accepts a pair for the range arguments.
template<typename N1 , typename N2 , typename N3 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&std::is_arithmetic< N3 >
::value, bool >::type 
in_range (N1 val, N2 low, N3 high)
 Boolean function to determine if value is within the given range.
template<typename N1 , typename N2 , typename N3 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&std::is_arithmetic< N3 >
::value, bool >::type 
in_closed_range (N1 val, N2 low, N3 high)
 Boolean function to determine if value is within the given range.
template<typename N1 , typename N2 , typename N3 >
std::enable_if
< std::is_arithmetic< N1 >
::value &&std::is_arithmetic
< N2 >::value
&&std::is_arithmetic< N3 >
::value, bool >::type 
in_open_range (N1 val, N2 low, N3 high)
 Boolean function to determine if value is within the given range.