LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
QuadExpr.cxx
Go to the documentation of this file.
2 
3 #include <cstdlib>
4 #include <iostream>
5 #include <ostream>
6 #include <string>
7 
9 {
10  QuadExpr ret(0);
11  ret.b = 1;
12  return ret;
13 }
14 
16 {
17  a += e.a;
18  b += e.b;
19  c += e.c;
20  return *this;
21 }
22 
24 {
25  QuadExpr ret = *this;
26  ret += e;
27  return ret;
28 }
29 
31 {
32  a -= e.a;
33  b -= e.b;
34  c -= e.c;
35  return *this;
36 }
37 
39 {
40  QuadExpr ret = *this;
41  ret -= e;
42  return ret;
43 }
44 
46 {
47  if ((b != 0 && e.a != 0) || (a != 0 && e.b != 0) || (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:30
QuadExpr operator*(const QuadExpr &e) const
Definition: QuadExpr.cxx:45
QuadExpr & operator+=(const QuadExpr &e)
Definition: QuadExpr.cxx:15
double Linear() const
Definition: QuadExpr.h:15
double a
Definition: QuadExpr.h:33
std::ostream & operator<<(std::ostream &os, const QuadExpr &e)
Definition: QuadExpr.cxx:72
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
QuadExpr operator+(const QuadExpr &e) const
Definition: QuadExpr.cxx:23
Float_t e
Definition: plot.C:35
double Quadratic() const
Definition: QuadExpr.h:14