MathUtils.hh File Reference

#include "Rivet/Math/MathHeader.hh"
#include "Rivet/RivetBoost.hh"
#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

bool isZero (double val, double tolerance=1E-8)
bool isZero (long val, double UNUSED(tolerance)=1E-8)
bool fuzzyEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for equality with a degree of fuzziness The tolerance parameter is fractional.
bool fuzzyEquals (long a, long b, double UNUSED(tolerance)=1E-5)
 Compare two integral-type numbers for equality with a degree of fuzziness. Since there is no risk of floating point error with integral types, this function just exists in case fuzzyEquals is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored, even if it would have an absolute magnitude greater than 1.
bool fuzzyGtrEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for >= with a degree of fuzziness The tolerance parameter on the equality test is as for fuzzyEquals.
bool fuzzyGtrEquals (long a, long b, double UNUSED(tolerance)=1E-5)
 Compare two integral-type numbers for >= with a degree of fuzziness. Since there is no risk of floating point error with integral types, this function just exists in case fuzzyGtrEquals is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored, even if it would have an absolute magnitude greater than 1.
bool fuzzyLessEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for <= with a degree of fuzziness The tolerance parameter on the equality test is as for fuzzyEquals.
bool fuzzyLessEquals (long a, long b, double UNUSED(tolerance)=1E-5)
 Compare two integral-type numbers for <= with a degree of fuzziness. Since there is no risk of floating point error with integral types, this function just exists in case fuzzyLessEquals is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored, even if it would have an absolute magnitude greater than 1.
Miscellaneous numerical helpers

template<typename NUM >
NUM sqr (NUM a)
 Named number-type squaring operation.
template<typename Num >
Num add_quad (Num a, Num b)
 Named number-type addition in quadrature operation.
template<typename Num >
Num add_quad (Num a, Num b, Num c)
 Named number-type addition in quadrature operation.
template<typename Num >
Num intpow (Num val, unsigned int exp)
 A more efficient version of pow for raising numbers to integer powers.
int sign (double val)
 Find the sign of a number.
int sign (int val)
 Find the sign of a number.
int sign (long val)
 Find the sign of a number.
Binning helper functions

vector< double > linspace (double start, double end, size_t nbins)
 Make a list of nbins + 1 values equally spaced between start and end inclusive.
vector< double > logspace (double start, double end, size_t nbins)
 Make a list of nbins + 1 values exponentially spaced between start and end inclusive.
template<typename NUM >
int index_between (const NUM &val, const vector< NUM > &binedges)
 Return the bin index of the given value, val, given a vector of bin edges NB. The binedges vector must be sorted.
Statistics functions

double mean (const vector< int > &sample)
 Calculate the mean of a sample.
double mean_err (const vector< int > &sample)
double covariance (const vector< int > &sample1, const vector< int > &sample2)
 Calculate the covariance (variance) between two samples.
double covariance_err (const vector< int > &sample1, const vector< int > &sample2)
 Calculate the error on the covariance (variance) of two samples, assuming poissonian errors.
double correlation (const vector< int > &sample1, const vector< int > &sample2)
 Calculate the correlation strength between two samples.
double correlation_err (const vector< int > &sample1, const vector< int > &sample2)
 Calculate the error of the correlation strength between two samples assuming Poissonian errors.
Angle range mappings

double _mapAngleM2PITo2Pi (double angle)
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].
Phase space measure helpers

double deltaPhi (double phi1, double phi2)
double deltaEta (double eta1, double eta2)
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 NUM >
bool inRange (NUM value, NUM low, NUM high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Determine if value is in the range low to high, for floating point numbers Interval boundary types are defined by lowbound and highbound.
template<typename NUM >
bool inRange (NUM value, pair< NUM, NUM > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange for doubles, which accepts a pair for the range arguments.
bool inRange (int value, int low, int high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=CLOSED)
 Determine if value is in the range low to high, for integer types Interval boundary types are defined by lowbound and highbound.
bool inRange (int value, pair< int, int > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange for ints, which accepts a pair for the range arguments.