Rivet  3.1.2
MathUtils.hh
1 // -*- C++ -*-
2 #ifndef RIVET_MathUtils_HH
3 #define RIVET_MathUtils_HH
4 
5 #include "Rivet/Math/MathConstants.hh"
6 #include <type_traits>
7 #include <cassert>
8 
9 namespace Rivet {
10 
11 
13 
14 
19  template <typename NUM>
20  inline typename std::enable_if<std::is_floating_point<NUM>::value, bool>::type
21  isZero(NUM val, double tolerance=1e-8) {
22  return fabs(val) < tolerance;
23  }
24 
29  template <typename NUM>
30  inline typename std::enable_if<std::is_integral<NUM>::value, bool>::type
31  isZero(NUM val, double=1e-5) { //< NB. unused tolerance parameter for ints, still needs a default value!
32  return val == 0;
33  }
34 
36  template <typename NUM>
37  inline typename std::enable_if<std::is_floating_point<NUM>::value, bool>::type
38  isNaN(NUM val) { return std::isnan(val); }
39 
41  template <typename NUM>
42  inline typename std::enable_if<std::is_floating_point<NUM>::value, bool>::type
43  notNaN(NUM val) { return !std::isnan(val); }
44 
50  template <typename N1, typename N2>
51  inline typename std::enable_if<
52  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value &&
53  (std::is_floating_point<N1>::value || std::is_floating_point<N2>::value), bool>::type
54  fuzzyEquals(N1 a, N2 b, double tolerance=1e-5) {
55  const double absavg = (std::abs(a) + std::abs(b))/2.0;
56  const double absdiff = std::abs(a - b);
57  const bool rtn = (isZero(a) && isZero(b)) || absdiff < tolerance*absavg;
58  return rtn;
59  }
60 
65  template <typename N1, typename N2>
66  inline typename std::enable_if<
67  std::is_integral<N1>::value && std::is_integral<N2>::value, bool>::type
68  fuzzyEquals(N1 a, N2 b, double) { //< NB. unused tolerance parameter for ints, still needs a default value!
69  return a == b;
70  }
71 
72 
76  template <typename N1, typename N2>
77  inline typename std::enable_if<
78  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value, bool>::type
79  fuzzyGtrEquals(N1 a, N2 b, double tolerance=1e-5) {
80  return a > b || fuzzyEquals(a, b, tolerance);
81  }
82 
83 
87  template <typename N1, typename N2>
88  inline typename std::enable_if<
89  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value, bool>::type
90  fuzzyLessEquals(N1 a, N2 b, double tolerance=1e-5) {
91  return a < b || fuzzyEquals(a, b, tolerance);
92  }
93 
95 
96 
98 
99 
104  enum RangeBoundary { OPEN=0, SOFT=0, CLOSED=1, HARD=1 };
105 
109  template <typename N1, typename N2, typename N3>
110  inline typename std::enable_if<
111  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value && std::is_arithmetic<N3>::value, bool>::type
112  inRange(N1 value, N2 low, N3 high,
113  RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN) {
114  if (lowbound == OPEN && highbound == OPEN) {
115  return (value > low && value < high);
116  } else if (lowbound == OPEN && highbound == CLOSED) {
117  return (value > low && value <= high);
118  } else if (lowbound == CLOSED && highbound == OPEN) {
119  return (value >= low && value < high);
120  } else { // if (lowbound == CLOSED && highbound == CLOSED) {
121  return (value >= low && value <= high);
122  }
123  }
124 
129  template <typename N1, typename N2, typename N3>
130  inline typename std::enable_if<
131  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value && std::is_arithmetic<N3>::value, bool>::type
132  fuzzyInRange(N1 value, N2 low, N3 high,
133  RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN) {
134  if (lowbound == OPEN && highbound == OPEN) {
135  return (value > low && value < high);
136  } else if (lowbound == OPEN && highbound == CLOSED) {
137  return (value > low && fuzzyLessEquals(value, high));
138  } else if (lowbound == CLOSED && highbound == OPEN) {
139  return (fuzzyGtrEquals(value, low) && value < high);
140  } else { // if (lowbound == CLOSED && highbound == CLOSED) {
141  return (fuzzyGtrEquals(value, low) && fuzzyLessEquals(value, high));
142  }
143  }
144 
146  template <typename N1, typename N2, typename N3>
147  inline typename std::enable_if<
148  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value && std::is_arithmetic<N3>::value, bool>::type
149  inRange(N1 value, pair<N2, N3> lowhigh,
150  RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN) {
151  return inRange(value, lowhigh.first, lowhigh.second, lowbound, highbound);
152  }
153 
154 
155  // Alternative forms, with snake_case names and boundary types in names rather than as args -- from MCUtils
156 
160  template <typename N1, typename N2, typename N3>
161  inline typename std::enable_if<
162  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value && std::is_arithmetic<N3>::value, bool>::type
163  in_range(N1 val, N2 low, N3 high) {
164  return inRange(val, low, high, CLOSED, OPEN);
165  }
166 
170  template <typename N1, typename N2, typename N3>
171  inline typename std::enable_if<
172  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value && std::is_arithmetic<N3>::value, bool>::type
173  in_closed_range(N1 val, N2 low, N3 high) {
174  return inRange(val, low, high, CLOSED, CLOSED);
175  }
176 
180  template <typename N1, typename N2, typename N3>
181  inline typename std::enable_if<
182  std::is_arithmetic<N1>::value && std::is_arithmetic<N2>::value && std::is_arithmetic<N3>::value, bool>::type
183  in_open_range(N1 val, N2 low, N3 high) {
184  return inRange(val, low, high, OPEN, OPEN);
185  }
186 
188 
190 
191 
193 
194 
196  template <typename NUM>
197  inline typename std::enable_if<std::is_arithmetic<NUM>::value, NUM>::type
198  sqr(NUM a) {
199  return a*a;
200  }
201 
206  // template <typename N1, typename N2>
207  template <typename NUM>
208  inline typename std::enable_if<std::is_arithmetic<NUM>::value, NUM>::type
209  //std::common_type<N1, N2>::type
210  add_quad(NUM a, NUM b) {
211  return sqrt(a*a + b*b);
212  }
213 
218  // template <typename N1, typename N2>
219  template <typename NUM>
220  inline typename std::enable_if<std::is_arithmetic<NUM>::value, NUM>::type
221  //std::common_type<N1, N2, N3>::type
222  add_quad(NUM a, NUM b, NUM c) {
223  return sqrt(a*a + b*b + c*c);
224  }
225 
228  inline double safediv(double num, double den, double fail=0.0) {
229  return (!isZero(den)) ? num/den : fail;
230  }
231 
233  template <typename NUM>
234  inline typename std::enable_if<std::is_arithmetic<NUM>::value, NUM>::type
235  intpow(NUM val, unsigned int exp) {
236  assert(exp >= 0);
237  if (exp == 0) return (NUM) 1;
238  else if (exp == 1) return val;
239  return val * intpow(val, exp-1);
240  }
241 
243  template <typename NUM>
244  inline typename std::enable_if<std::is_arithmetic<NUM>::value, int>::type
245  sign(NUM val) {
246  if (isZero(val)) return ZERO;
247  const int valsign = (val > 0) ? PLUS : MINUS;
248  return valsign;
249  }
250 
252 
253 
255 
256 
258  inline double cdfBW(double x, double mu, double gamma) {
259  // normalize to (0;1) distribution
260  const double xn = (x - mu)/gamma;
261  return std::atan(xn)/M_PI + 0.5;
262  }
263 
265  inline double invcdfBW(double p, double mu, double gamma) {
266  const double xn = std::tan(M_PI*(p-0.5));
267  return gamma*xn + mu;
268  }
269 
271 
272 
274 
275 
282  inline vector<double> linspace(size_t nbins, double start, double end, bool include_end=true) {
283  assert(end >= start);
284  assert(nbins > 0);
285  vector<double> rtn;
286  const double interval = (end-start)/static_cast<double>(nbins);
287  for (size_t i = 0; i < nbins; ++i) {
288  rtn.push_back(start + i*interval);
289  }
290  assert(rtn.size() == nbins);
291  if (include_end) rtn.push_back(end); //< exact end, not result of n * interval
292  return rtn;
293  }
294 
295 
303  inline vector<double> logspace(size_t nbins, double start, double end, bool include_end=true) {
304  assert(end >= start);
305  assert(start > 0);
306  assert(nbins > 0);
307  const double logstart = std::log(start);
308  const double logend = std::log(end);
309  const vector<double> logvals = linspace(nbins, logstart, logend, false);
310  assert(logvals.size() == nbins);
311  vector<double> rtn; rtn.reserve(nbins+1);
312  rtn.push_back(start); //< exact start, not exp(log(start))
313  for (size_t i = 1; i < logvals.size(); ++i) {
314  rtn.push_back(std::exp(logvals[i]));
315  }
316  assert(rtn.size() == nbins);
317  if (include_end) rtn.push_back(end); //< exact end, not exp(n * loginterval)
318  return rtn;
319  }
320 
321 
323 
324 
332  inline vector<double> bwspace(size_t nbins, double start, double end, double mu, double gamma) {
333  assert(end >= start);
334  assert(nbins > 0);
335  const double pmin = cdfBW(start, mu, gamma);
336  const double pmax = cdfBW(end, mu, gamma);
337  const vector<double> edges = linspace(nbins, pmin, pmax);
338  assert(edges.size() == nbins+1);
339  vector<double> rtn;
340  for (double edge : edges) {
341  rtn.push_back(invcdfBW(edge, mu, gamma));
342  }
343  assert(rtn.size() == nbins+1);
344  return rtn;
345  }
346 
347 
349  template <typename NUM, typename CONTAINER>
350  inline typename std::enable_if<std::is_arithmetic<NUM>::value && std::is_arithmetic<typename CONTAINER::value_type>::value, int>::type
351  _binIndex(NUM val, const CONTAINER& binedges, bool allow_overflow=false) {
352  if (val < *begin(binedges)) return -1;
353  // CONTAINER::iterator_type itend =
354  if (val >= *(end(binedges)-1)) return allow_overflow ? int(binedges.size())-1 : -1;
355  auto it = std::upper_bound(begin(binedges), end(binedges), val);
356  return std::distance(begin(binedges), --it);
357  }
358 
367  template <typename NUM1, typename NUM2>
368  inline typename std::enable_if<std::is_arithmetic<NUM1>::value && std::is_arithmetic<NUM2>::value, int>::type
369  binIndex(NUM1 val, std::initializer_list<NUM2> binedges, bool allow_overflow=false) {
370  return _binIndex(val, binedges, allow_overflow);
371  }
372 
381  template <typename NUM, typename CONTAINER>
382  inline typename std::enable_if<std::is_arithmetic<NUM>::value && std::is_arithmetic<typename CONTAINER::value_type>::value, int>::type
383  binIndex(NUM val, const CONTAINER& binedges, bool allow_overflow=false) {
384  return _binIndex(val, binedges, allow_overflow);
385  }
386 
388 
389 
391 
392 
395  template <typename NUM>
396  inline typename std::enable_if<std::is_arithmetic<NUM>::value, NUM>::type
397  median(const vector<NUM>& sample) {
398  if (sample.empty()) throw RangeError("Can't compute median of an empty set");
399  vector<NUM> tmp = sample;
400  std::sort(tmp.begin(), tmp.end());
401  const size_t imid = tmp.size()/2; // len1->idx0, len2->idx1, len3->idx1, len4->idx2, ...
402  if (sample.size() % 2 == 0) return (tmp.at(imid-1) + tmp.at(imid)) / 2.0;
403  else return tmp.at(imid);
404  }
405 
406 
409  template <typename NUM>
410  inline typename std::enable_if<std::is_arithmetic<NUM>::value, double>::type
411  mean(const vector<NUM>& sample) {
412  if (sample.empty()) throw RangeError("Can't compute mean of an empty set");
413  double mean = 0.0;
414  for (size_t i = 0; i < sample.size(); ++i) {
415  mean += sample[i];
416  }
417  return mean/sample.size();
418  }
419 
420  // Calculate the error on the mean, assuming Poissonian errors
422  template <typename NUM>
423  inline typename std::enable_if<std::is_arithmetic<NUM>::value, double>::type
424  mean_err(const vector<NUM>& sample) {
425  if (sample.empty()) throw RangeError("Can't compute mean_err of an empty set");
426  double mean_e = 0.0;
427  for (size_t i = 0; i < sample.size(); ++i) {
428  mean_e += sqrt(sample[i]);
429  }
430  return mean_e/sample.size();
431  }
432 
433 
436  template <typename NUM>
437  inline typename std::enable_if<std::is_arithmetic<NUM>::value, double>::type
438  covariance(const vector<NUM>& sample1, const vector<NUM>& sample2) {
439  if (sample1.empty() || sample2.empty()) throw RangeError("Can't compute covariance of an empty set");
440  if (sample1.size() != sample2.size()) throw RangeError("Sizes of samples must be equal for covariance calculation");
441  const double mean1 = mean(sample1);
442  const double mean2 = mean(sample2);
443  const size_t N = sample1.size();
444  double cov = 0.0;
445  for (size_t i = 0; i < N; i++) {
446  const double cov_i = (sample1[i] - mean1)*(sample2[i] - mean2);
447  cov += cov_i;
448  }
449  if (N > 1) return cov/(N-1);
450  else return 0.0;
451  }
452 
455  template <typename NUM>
456  inline typename std::enable_if<std::is_arithmetic<NUM>::value, double>::type
457  covariance_err(const vector<NUM>& sample1, const vector<NUM>& sample2) {
458  if (sample1.empty() || sample2.empty()) throw RangeError("Can't compute covariance_err of an empty set");
459  if (sample1.size() != sample2.size()) throw RangeError("Sizes of samples must be equal for covariance_err calculation");
460  const double mean1 = mean(sample1);
461  const double mean2 = mean(sample2);
462  const double mean1_e = mean_err(sample1);
463  const double mean2_e = mean_err(sample2);
464  const size_t N = sample1.size();
465  double cov_e = 0.0;
466  for (size_t i = 0; i < N; i++) {
467  const double cov_i = (sqrt(sample1[i]) - mean1_e)*(sample2[i] - mean2) +
468  (sample1[i] - mean1)*(sqrt(sample2[i]) - mean2_e);
469  cov_e += cov_i;
470  }
471  if (N > 1) return cov_e/(N-1);
472  else return 0.0;
473  }
474 
475 
478  template <typename NUM>
479  inline typename std::enable_if<std::is_arithmetic<NUM>::value, double>::type
480  correlation(const vector<NUM>& sample1, const vector<NUM>& sample2) {
481  const double cov = covariance(sample1, sample2);
482  const double var1 = covariance(sample1, sample1);
483  const double var2 = covariance(sample2, sample2);
484  const double correlation = cov/sqrt(var1*var2);
485  const double corr_strength = correlation*sqrt(var2/var1);
486  return corr_strength;
487  }
488 
491  template <typename NUM>
492  inline typename std::enable_if<std::is_arithmetic<NUM>::value, double>::type
493  correlation_err(const vector<NUM>& sample1, const vector<NUM>& sample2) {
494  const double cov = covariance(sample1, sample2);
495  const double var1 = covariance(sample1, sample1);
496  const double var2 = covariance(sample2, sample2);
497  const double cov_e = covariance_err(sample1, sample2);
498  const double var1_e = covariance_err(sample1, sample1);
499  const double var2_e = covariance_err(sample2, sample2);
500 
501  // Calculate the correlation
502  const double correlation = cov/sqrt(var1*var2);
503  // Calculate the error on the correlation
504  const double correlation_err = cov_e/sqrt(var1*var2) -
505  cov/(2*pow(3./2., var1*var2)) * (var1_e * var2 + var1 * var2_e);
506 
507  // Calculate the error on the correlation strength
508  const double corr_strength_err = correlation_err*sqrt(var2/var1) +
509  correlation/(2*sqrt(var2/var1)) * (var2_e/var1 - var2*var1_e/pow(2, var2));
510 
511  return corr_strength_err;
512  }
513 
515 
516 
518 
519 
524  inline double _mapAngleM2PITo2Pi(double angle) {
525  double rtn = fmod(angle, TWOPI);
526  if (isZero(rtn)) return 0;
527  assert(rtn >= -TWOPI && rtn <= TWOPI);
528  return rtn;
529  }
530 
532  inline double mapAngleMPiToPi(double angle) {
533  double rtn = _mapAngleM2PITo2Pi(angle);
534  if (isZero(rtn)) return 0;
535  if (rtn > PI) rtn -= TWOPI;
536  if (rtn <= -PI) rtn += TWOPI;
537  assert(rtn > -PI && rtn <= PI);
538  return rtn;
539  }
540 
542  inline double mapAngle0To2Pi(double angle) {
543  double rtn = _mapAngleM2PITo2Pi(angle);
544  if (isZero(rtn)) return 0;
545  if (rtn < 0) rtn += TWOPI;
546  if (rtn == TWOPI) rtn = 0;
547  assert(rtn >= 0 && rtn < TWOPI);
548  return rtn;
549  }
550 
552  inline double mapAngle0ToPi(double angle) {
553  double rtn = fabs(mapAngleMPiToPi(angle));
554  if (isZero(rtn)) return 0;
555  assert(rtn > 0 && rtn <= PI);
556  return rtn;
557  }
558 
560  inline double mapAngle(double angle, PhiMapping mapping) {
561  switch (mapping) {
562  case MINUSPI_PLUSPI:
563  return mapAngleMPiToPi(angle);
564  case ZERO_2PI:
565  return mapAngle0To2Pi(angle);
566  case ZERO_PI:
567  return mapAngle0To2Pi(angle);
568  default:
569  throw Rivet::UserError("The specified phi mapping scheme is not implemented");
570  }
571  }
572 
574 
575 
577 
578 
582  inline double deltaPhi(double phi1, double phi2, bool sign=false) {
583  const double x = mapAngleMPiToPi(phi1 - phi2);
584  return sign ? x : fabs(x);
585  }
586 
590  inline double deltaEta(double eta1, double eta2, bool sign=false) {
591  const double x = eta1 - eta2;
592  return sign ? x : fabs(x);
593  }
594 
598  inline double deltaRap(double y1, double y2, bool sign=false) {
599  const double x = y1 - y2;
600  return sign? x : fabs(x);
601  }
602 
605  inline double deltaR2(double rap1, double phi1, double rap2, double phi2) {
606  const double dphi = deltaPhi(phi1, phi2);
607  return sqr(rap1-rap2) + sqr(dphi);
608  }
609 
612  inline double deltaR(double rap1, double phi1, double rap2, double phi2) {
613  return sqrt(deltaR2(rap1, phi1, rap2, phi2));
614  }
615 
617  inline double rapidity(double E, double pz) {
618  if (isZero(E - pz)) {
619  throw std::runtime_error("Divergent positive rapidity");
620  return DBL_MAX;
621  }
622  if (isZero(E + pz)) {
623  throw std::runtime_error("Divergent negative rapidity");
624  return -DBL_MAX;
625  }
626  return 0.5*log((E+pz)/(E-pz));
627  }
628 
630 
631 
634  inline double mT(double pT1, double pT2, double dphi) {
635  return sqrt(2*pT1*pT2 * (1 - cos(dphi)) );
636  }
637 
638 
639 }
640 
641 
642 #endif
Definition: MC_Cent_pPb.hh:10
std::enable_if< std::is_floating_point< NUM >::value, bool >::type notNaN(NUM val)
Check if a number is non-NaN.
Definition: MathUtils.hh:43
std::enable_if< std::is_arithmetic< NUM1 >::value &&std::is_arithmetic< NUM2 >::value, int >::type binIndex(NUM1 val, std::initializer_list< NUM2 > binedges, bool allow_overflow=false)
Return the bin index of the given value, val, given a vector of bin edges.
Definition: MathUtils.hh:369
double rapidity(double E, double pz)
Calculate a rapidity value from the supplied energy E and longitudinal momentum pz.
Definition: MathUtils.hh:617
double mapAngleMPiToPi(double angle)
Map an angle into the range (-PI, PI].
Definition: MathUtils.hh:532
double safediv(double num, double den, double fail=0.0)
Definition: MathUtils.hh:228
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.
Definition: MathUtils.hh:163
static const double PI
Definition: MathConstants.hh:13
Error specialisation for where the problem is between the chair and the computer. ...
Definition: Exceptions.hh:55
std::enable_if< std::is_floating_point< NUM >::value, bool >::type isNaN(NUM val)
Check if a number is NaN.
Definition: MathUtils.hh:38
double mapAngle(double angle, PhiMapping mapping)
Map an angle into the enum-specified range.
Definition: MathUtils.hh:560
std::enable_if< std::is_arithmetic< NUM >::value, NUM >::type add_quad(NUM a, NUM b)
Named number-type addition in quadrature operation.
Definition: MathUtils.hh:210
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.
Definition: MathUtils.hh:282
double cdfBW(double x, double mu, double gamma)
CDF for the Breit-Wigner distribution.
Definition: MathUtils.hh:258
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.
Definition: MathUtils.hh:303
double deltaEta(double eta1, double eta2, bool sign=false)
Definition: MathUtils.hh:590
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.
Definition: MathUtils.hh:183
PhiMapping
Enum for range of to be mapped into.
Definition: MathConstants.hh:49
std::enable_if< std::is_arithmetic< NUM >::value, double >::type covariance(const vector< NUM > &sample1, const vector< NUM > &sample2)
Definition: MathUtils.hh:438
double deltaPhi(double phi1, double phi2, bool sign=false)
Calculate the difference between two angles in radians.
Definition: MathUtils.hh:582
std::enable_if< std::is_arithmetic< NUM >::value, double >::type mean_err(const vector< NUM > &sample)
Definition: MathUtils.hh:424
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.
Definition: MathUtils.hh:112
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.
Definition: MathUtils.hh:173
double mT(double pT1, double pT2, double dphi)
Definition: MathUtils.hh:634
double invcdfBW(double p, double mu, double gamma)
Inverse CDF for the Breit-Wigner distribution.
Definition: MathUtils.hh:265
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.
Definition: MathUtils.hh:54
static const double TWOPI
A pre-defined value of .
Definition: MathConstants.hh:16
double deltaRap(double y1, double y2, bool sign=false)
Definition: MathUtils.hh:598
double deltaR2(double rap1, double phi1, double rap2, double phi2)
Definition: MathUtils.hh:605
double deltaR(double rap1, double phi1, double rap2, double phi2)
Definition: MathUtils.hh:612
RangeBoundary
Definition: MathUtils.hh:104
double mapAngle0To2Pi(double angle)
Map an angle into the range [0, 2PI).
Definition: MathUtils.hh:542
double mapAngle0ToPi(double angle)
Map an angle into the range [0, PI].
Definition: MathUtils.hh:552
std::enable_if< std::is_arithmetic< NUM >::value, double >::type covariance_err(const vector< NUM > &sample1, const vector< NUM > &sample2)
Definition: MathUtils.hh:457
std::enable_if< std::is_floating_point< NUM >::value, bool >::type isZero(NUM val, double tolerance=1e-8)
Compare a number to zero.
Definition: MathUtils.hh:21
double angle(const Vector2 &a, const Vector2 &b)
Angle (in radians) between two 2-vectors.
Definition: Vector2.hh:175
std::enable_if< std::is_arithmetic< NUM >::value, double >::type correlation_err(const vector< NUM > &sample1, const vector< NUM > &sample2)
Definition: MathUtils.hh:493
std::enable_if< std::is_arithmetic< NUM >::value, NUM >::type median(const vector< NUM > &sample)
Definition: MathUtils.hh:397
std::enable_if< std::is_arithmetic< NUM >::value, double >::type mean(const vector< NUM > &sample)
Definition: MathUtils.hh:411
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.
Definition: MathUtils.hh:79
std::enable_if< std::is_arithmetic< NUM >::value, NUM >::type sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.hh:198
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.
Definition: MathUtils.hh:235
Error for e.g. use of invalid bin ranges.
Definition: Exceptions.hh:22
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 incl...
Definition: MathUtils.hh:332
std::enable_if< std::is_arithmetic< NUM >::value, int >::type sign(NUM val)
Find the sign of a number.
Definition: MathUtils.hh:245
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.
Definition: MathUtils.hh:132
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.
Definition: MathUtils.hh:90
std::enable_if< std::is_arithmetic< NUM >::value, double >::type correlation(const vector< NUM > &sample1, const vector< NUM > &sample2)
Definition: MathUtils.hh:480