StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PowerLawFit.h
1 #include "LinearFit.h"
2 
3 template<typename Number>
4 class PowerLawFit : public LinearFit<Number>
5 {
6  public:
7  typedef map<Number, Number> Points;
8 
9  PowerLawFit();
10  PowerLawFit(Points * points);
11  PowerLawFit(const PowerLawFit & fit);
12  virtual ~PowerLawFit();
13  const PowerLawFit & operator=(const PowerLawFit & fit);
14  virtual void fit();
15  virtual void fit(Points * points);
16  const Number getExponent() const;
17  const Number getCoefficient() const;
18 
19  protected:
21  Points * _data;
23  Points _logData;
25  Number _exponent;
27  Number _coeff;
28 
29 };
30 
31 template<typename Number>
33  : LinearFit<Number>(),_data(0),_exponent(0),_coeff(0)
34 {}
35 
36 template<typename Number>
37 PowerLawFit<Number>::PowerLawFit(Points * points)
38  : LinearFit<Number>(),_data(points),_exponent(0),_coeff(0)
39 {
40 }
41 
42 template<typename Number>
44  : LinearFit<Number>(fit), _data(fit._data),_exponent(fit._exponent),_coeff(fit._coeff)
45 {}
46 
47 template<typename Number>
49 {}
50 
51 template<typename Number>
53 {
55  _data = fit._data;
56  _exponent = fit._exponent;
57  _coeff = fit._coeff;
58  return *this;
59 }
60 
61 template<typename Number>
63 {
64  typename Points::const_iterator i;
65  _logData.clear();
66  double x,y;
67  for (i=_data->begin();i!=_data->end();i++)
68  {
69  x = ::log(i->first);
70  y = ::log(i->second);
71  _logData[x]=y;
72  }
73  this->_points = &_logData;
75  _coeff = exp(this->_b);
76  _exponent = this->_a;
77 }
78 
79 template<typename Number>
80 void PowerLawFit<Number>::fit(Points * points)
81 {
82  _data = points;
83  fit();
84 }
85 
86 template<typename Number>
87 const Number PowerLawFit<Number>::getExponent() const
88 {
89  return _exponent;
90 }
91 
92 template<typename Number>
93 const Number PowerLawFit<Number>::getCoefficient() const
94 {
95  return _coeff;
96 }
Points * _data
Points provided on input.
Definition: PowerLawFit.h:21
Points _logData
Transient (for internal use) array used to hold the log 0f _data.
Definition: PowerLawFit.h:23
Number _coeff
Multiplicative Coefficient of the power law.
Definition: PowerLawFit.h:27
Number _exponent
Exponent of the power law.
Definition: PowerLawFit.h:25