rivet is hosted by Hepforge, IPPP Durham
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.
bool fuzzyEquals (long a, long b, double UNUSED(tolerance)=1E-5)
 Compare two integral-type numbers for equality with a degree of fuzziness.
bool fuzzyGtrEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for >= with a degree of fuzziness.
bool fuzzyGtrEquals (long a, long b, double UNUSED(tolerance)=1E-5)
 Compare two integral-type numbers for >= with a degree of fuzziness.
bool fuzzyLessEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for <= with a degree of fuzziness.
bool fuzzyLessEquals (long a, long b, double UNUSED(tolerance)=1E-5)
 Compare two integral-type numbers for <= with a degree of fuzziness.
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 (size_t nbins, double start, double end)
 Make a list of nbins + 1 values equally spaced between start and end inclusive.
vector< double > logspace (size_t nbins, double start, double end)
 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.
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)
 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].
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 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.
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.
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.