Jpp  master_rocky-43-ge265d140c
the software that should make you happy
JPower.hh
Go to the documentation of this file.
1 #ifndef __JMATH__JPOWER__
2 #define __JMATH__JPOWER__
3 
4 #include <istream>
5 #include <ostream>
6 #include <cmath>
7 
8 
9 /**
10  * \author mdejong
11  */
12 
13 namespace JMATH {}
14 namespace JPP { using namespace JMATH; }
15 
16 namespace JMATH {
17 
18  /**
19  * Power law function object.
20  *
21  * Evaluation of function, derivative and integral values.
22  */
23  class JPower {
24  public:
25  /**
26  * Constructor.
27  *
28  * \param alpha spectral index
29  * \param factor multiplication factor
30  */
31  JPower(const double alpha,
32  const double factor = 1.0)
33  {
34  this->alpha = alpha;
35  this->factor = factor;
36  }
37 
38 
39  /**
40  * Function value.
41  *
42  * \param x abscissa value
43  * \return function value
44  */
45  double getValue(const double x) const
46  {
47  return factor * pow(x, alpha);
48  }
49 
50 
51  /**
52  * Derivative value.
53  *
54  * \param x abscissa value
55  * \return derivative value
56  */
57  double getDerivative(const double x) const
58  {
59  return factor * alpha * pow(x, alpha - 1);
60  }
61 
62 
63  /**
64  * Integral value.
65  *
66  * \param x abscissa value
67  * \return integral value
68  */
69  double getIntegral(const double x) const
70  {
71  if (alpha != -1.0)
72  return factor * pow(x, alpha + 1) / (alpha + 1);
73  else
74  return factor * log(x);
75  }
76 
77 
78  /**
79  * Function value.
80  *
81  * \param x abscissa value
82  * \return function value
83  */
84  double operator()(const double x) const
85  {
86  return getValue(x);
87  }
88 
89 
90  /**
91  * Read power from input.
92  *
93  * \param in input stream
94  * \param object power
95  * \return input stream
96  */
97  friend inline std::istream& operator>>(std::istream& in, JPower& object)
98  {
99  in >> object.alpha >> object.factor;
100 
101  return in;
102  }
103 
104 
105  /**
106  * Write power to output.
107  *
108  * \param out output stream
109  * \param object trigonometric
110  * \return output stream
111  */
112  friend inline std::ostream& operator<<(std::ostream& out, const JPower& object)
113  {
114  return out << object.alpha << ' ' << object.factor;
115  }
116 
117  protected:
118  double alpha;
119  double factor;
120  };
121 }
122 
123 #endif
Power law function object.
Definition: JPower.hh:23
double getDerivative(const double x) const
Derivative value.
Definition: JPower.hh:57
double factor
Definition: JPower.hh:119
double operator()(const double x) const
Function value.
Definition: JPower.hh:84
double getValue(const double x) const
Function value.
Definition: JPower.hh:45
double getIntegral(const double x) const
Integral value.
Definition: JPower.hh:69
friend std::istream & operator>>(std::istream &in, JPower &object)
Read power from input.
Definition: JPower.hh:97
double alpha
Definition: JPower.hh:118
JPower(const double alpha, const double factor=1.0)
Constructor.
Definition: JPower.hh:31
friend std::ostream & operator<<(std::ostream &out, const JPower &object)
Write power to output.
Definition: JPower.hh:112
Auxiliary classes and methods for mathematical operations.
Definition: JEigen3D.hh:88
T pow(const T &x, const double y)
Power .
Definition: JMath.hh:97
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).