LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
QuadExpr.cxx
Go to the documentation of this file.
1 #include "QuadExpr.h"
2 
3 #include <cstdlib>
4 #include <iostream>
5 
7 {
8  QuadExpr ret(0);
9  ret.b = 1;
10  return ret;
11 }
12 
14 {
15  a += e.a;
16  b += e.b;
17  c += e.c;
18  return *this;
19 }
20 
22 {
23  QuadExpr ret = *this;
24  ret += e;
25  return ret;
26 }
27 
29 {
30  a -= e.a;
31  b -= e.b;
32  c -= e.c;
33  return *this;
34 }
35 
37 {
38  QuadExpr ret = *this;
39  ret -= e;
40  return ret;
41 }
42 
44 {
45  if((b != 0 && e.a != 0) ||
46  (a != 0 && e.b != 0) ||
47  (a != 0 && e.a != 0)){
48  std::cout << "(" << *this << ") * (" << e << ")"
49  << " does not result in a quadratic expression." << std::endl;
50  abort();
51  }
52 
53  QuadExpr ret(0);
54  ret.c = c*e.c;
55  ret.b = c*e.b + b*e.c;
56  ret.a = c*e.a + a*e.c + b*e.b;
57 
58  return ret;
59 }
60 
62 {
63  *this = *this * e;
64  return *this;
65 }
66 
67 double QuadExpr::Eval(double x) const
68 {
69  return a*x*x + b*x + c;
70 }
71 
72 std::ostream& operator<<(std::ostream& os, const QuadExpr& e)
73 {
74  os << e.Quadratic() << "*x^2 + " << e.Linear() << "*x + " << e.Constant();
75  return os;
76 }
Float_t x
Definition: compare.C:6
QuadExpr & operator-=(const QuadExpr &e)
Definition: QuadExpr.cxx:28
QuadExpr operator*(const QuadExpr &e) const
Definition: QuadExpr.cxx:43
QuadExpr & operator+=(const QuadExpr &e)
Definition: QuadExpr.cxx:13
double Linear() const
Definition: QuadExpr.h:16
double a
Definition: QuadExpr.h:34
std::ostream & operator<<(std::ostream &os, const QuadExpr &e)
Definition: QuadExpr.cxx:72
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
QuadExpr operator+(const QuadExpr &e) const
Definition: QuadExpr.cxx:21
Float_t e
Definition: plot.C:34
double Quadratic() const
Definition: QuadExpr.h:15