LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 <ostream>
7 
8 class QuadExpr
9 {
10 public:
11  QuadExpr(double v) : a(0), b(0), c(v) {}
12  // Named constructor for independent variable
13  static QuadExpr X();
14 
15  double Quadratic() const {return a;}
16  double Linear() const {return b;}
17  double Constant() const {return c;}
18 
19  double Eval(double x) const;
20 
21  QuadExpr& operator+=(const QuadExpr& e);
22  QuadExpr& operator-=(const QuadExpr& e);
23  QuadExpr& operator*=(const QuadExpr& e);
24 
25  QuadExpr operator+(const QuadExpr& e) const;
26  QuadExpr operator-(const QuadExpr& e) const;
27  QuadExpr operator*(const QuadExpr& e) const;
28 
29  QuadExpr operator+(double v) const {return (*this)+QuadExpr(v);}
30  QuadExpr operator-(double v) const {return (*this)-QuadExpr(v);}
31  QuadExpr operator*(double v) const {return (*this)*QuadExpr(v);}
32 
33 protected:
34  double a, b, c; // a*x^2 + b*x + c
35 };
36 
37 inline QuadExpr operator+(double v, const QuadExpr& e){return e+v;}
38 inline QuadExpr operator-(double v, const QuadExpr& e){return QuadExpr(v)-e;}
39 inline QuadExpr operator*(double v, const QuadExpr& e){return e*v;}
40 
41 std::ostream& operator<<(std::ostream&, const QuadExpr&);
42 
43 #endif
Float_t x
Definition: compare.C:6
QuadExpr & operator-=(const QuadExpr &e)
Definition: QuadExpr.cxx:28
QuadExpr operator*(double v) const
Definition: QuadExpr.h:31
QuadExpr(double v)
Definition: QuadExpr.h:11
QuadExpr operator*(const QuadExpr &e) const
Definition: QuadExpr.cxx:43
QuadExpr operator-(double v) const
Definition: QuadExpr.h:30
QuadExpr & operator+=(const QuadExpr &e)
Definition: QuadExpr.cxx:13
double Linear() const
Definition: QuadExpr.h:16
QuadExpr operator+(double v) const
Definition: QuadExpr.h:29
double a
Definition: QuadExpr.h:34
double c
Definition: QuadExpr.h:34
QuadExpr operator-(const QuadExpr &e) const
Definition: QuadExpr.cxx:36
double b
Definition: QuadExpr.h:34
QuadExpr & operator*=(const QuadExpr &e)
Definition: QuadExpr.cxx:61
static QuadExpr X()
Definition: QuadExpr.cxx:6
double Constant() const
Definition: QuadExpr.h:17
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:21
Float_t e
Definition: plot.C:34
double Quadratic() const
Definition: QuadExpr.h:15