MathUtil.h
Go to the documentation of this file.
1 #ifndef MATHUTIL_H
2 #define MATHUTIL_H
3 
4 //////////////////////////////////////////////////////////////////////////
5 // //
6 // \file MathUtil.h //
7 // //
8 // Simple mathematical functions, initially to present the abuse of //
9 // pow() //
10 // <bckhouse@caltech.edu> //
11 // //
12 //////////////////////////////////////////////////////////////////////////
13 
14 #include <cmath>
15 #include <vector>
16 
17 namespace util{
18 
19  /// \name Simple mathematical functions
20  //@{
21 
22  /// More efficient square function than pow(x,2)
23  template<class T> inline T sqr(T x){return x*x;}
24 
25  /// More efficient cube function than pow(x,3)
26  template<class T> inline T cube(T x){return x*x*x;}
27 
28  /// 2D Euclidean distance
29  inline double pythag(double x, double y)
30  {
31  return sqrt(sqr(x)+sqr(y));
32  }
33 
34  /// 3D Euclidean distance
35  inline double pythag(double x, double y, double z)
36  {
37  return sqrt(sqr(x)+sqr(y)+sqr(z));
38  }
39 
40  /// \brief Simplified version of \ref LinFit
41  ///
42  /// All weights are assumed 1. In the absence of ability to weight, the
43  /// returned chi-square doesn't mean much and is omitted.
44  void LinFitUnweighted(const std::vector<double>& x,
45  const std::vector<double>& y,
46  double& m, double &c);
47 
48  /// \brief Find the best-fit line to a collection of points in 2-D by
49  /// minimizing the squared vertical distance from the points to the line.
50  ///
51  /// \param x - input vector of x coordinates
52  /// \param y - input vector of y coordinates
53  /// \param w - input vector of weights for the points
54  /// \param m - output gradient of the fit line
55  /// \param c - output y-intercept of the fit line
56  /// \return The chi^2 value defined by chi^2 = sum_i[w_i d^2_i]
57  double LinFit(const std::vector<double>& x,
58  const std::vector<double>& y,
59  const std::vector<double>& w,
60  double& m, double &c);
61 
62  //@}
63 
64 } // end namespace
65 
66 #endif // MATHUTIL_H
Filter events based on their run/event numbers.
T sqrt(T number)
Definition: d0nt_math.hpp:156
T cube(T x)
More efficient cube function than pow(x,3)
Definition: MathUtil.h:26
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
z
Definition: test.py:28
void LinFitUnweighted(const std::vector< double > &x, const std::vector< double > &y, double &m, double &c)
Simplified version of LinFit.
Definition: MathUtil.cxx:8
double pythag(double x, double y)
2D Euclidean distance
Definition: MathUtil.h:29
double LinFit(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &w, double &m, double &c)
Find the best-fit line to a collection of points in 2-D by minimizing the squared vertical distance f...
Definition: MathUtil.cxx:36
double T
Definition: Xdiff_gwt.C:5
Float_t w
Definition: plot.C:20