LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
QuadExpr.h
Go to the documentation of this file.
1 // Christopher Backhouse - bckhouse@fnal.gov
2 
3 #ifndef QUADEXPR_H
4 #define QUADEXPR_H
5 
6 #include <iosfwd>
7 
8 class QuadExpr {
9 public:
10  QuadExpr(double v) : a(0), b(0), c(v) {}
11  // Named constructor for independent variable
12  static QuadExpr X();
13 
14  double Quadratic() const { return a; }
15  double Linear() const { return b; }
16  double Constant() const { return c; }
17 
18  double Eval(double x) const;
19 
20  QuadExpr& operator+=(const QuadExpr& e);
21  QuadExpr& operator-=(const QuadExpr& e);
22  QuadExpr& operator*=(const QuadExpr& e);
23 
24  QuadExpr operator+(const QuadExpr& e) const;
25  QuadExpr operator-(const QuadExpr& e) const;
26  QuadExpr operator*(const QuadExpr& e) const;
27 
28  QuadExpr operator+(double v) const { return (*this) + QuadExpr(v); }
29  QuadExpr operator-(double v) const { return (*this) - QuadExpr(v); }
30  QuadExpr operator*(double v) const { return (*this) * QuadExpr(v); }
31 
32 protected:
33  double a, b, c; // a*x^2 + b*x + c
34 };
35 
36 inline QuadExpr operator+(double v, const QuadExpr& e)
37 {
38  return e + v;
39 }
40 inline QuadExpr operator-(double v, const QuadExpr& e)
41 {
42  return QuadExpr(v) - e;
43 }
44 inline QuadExpr operator*(double v, const QuadExpr& e)
45 {
46  return e * v;
47 }
48 
49 std::ostream& operator<<(std::ostream&, const QuadExpr&);
50 
51 #endif
Float_t x
Definition: compare.C:6
QuadExpr & operator-=(const QuadExpr &e)
Definition: QuadExpr.cxx:30
QuadExpr operator*(double v) const
Definition: QuadExpr.h:30
QuadExpr(double v)
Definition: QuadExpr.h:10
QuadExpr operator*(const QuadExpr &e) const
Definition: QuadExpr.cxx:45
QuadExpr operator-(double v) const
Definition: QuadExpr.h:29
QuadExpr & operator+=(const QuadExpr &e)
Definition: QuadExpr.cxx:15
double Linear() const
Definition: QuadExpr.h:15
QuadExpr operator+(double v) const
Definition: QuadExpr.h:28
double a
Definition: QuadExpr.h:33
double c
Definition: QuadExpr.h:33
QuadExpr operator-(const QuadExpr &e) const
Definition: QuadExpr.cxx:38
double b
Definition: QuadExpr.h:33
QuadExpr & operator*=(const QuadExpr &e)
Definition: QuadExpr.cxx:61
static QuadExpr X()
Definition: QuadExpr.cxx:8
double Constant() const
Definition: QuadExpr.h:16
double Eval(double x) const
Definition: QuadExpr.cxx:67
std::ostream & operator<<(std::ostream &, const QuadExpr &)
Definition: QuadExpr.cxx:72
QuadExpr operator+(const QuadExpr &e) const
Definition: QuadExpr.cxx:23
Float_t e
Definition: plot.C:35
double Quadratic() const
Definition: QuadExpr.h:14