Fitter.cxx
Go to the documentation of this file.
1 
12 #include "Fitter.h"
13 
14 #include "StatedFCN.h"
15 
16 #include <climits>
17 #include <cstdlib>
18 #include <stdexcept>
19 
20 using std::string;
21 using std::vector;
22 
23 using namespace hippodraw;
24 
26 Fitter ( const char * name )
27  : m_name ( name ),
28  m_fcn ( 0 ),
29  m_max_iterations ( 100 )
30 {
31 }
32 
34 Fitter ( const Fitter & fitter )
35  : m_name ( fitter.m_name ),
36  m_max_iterations ( fitter.m_max_iterations )
37 {
38  if ( fitter.m_fcn != 0 ) m_fcn = fitter.m_fcn -> clone ();
39 }
40 
43 {
44  if ( m_fcn != 0 ) delete m_fcn;
45 }
46 
47 void
49 copyFrom ( const Fitter * fitter )
50 {
51  m_fcn -> copyFrom ( fitter -> m_fcn );
52 }
53 
54 const std::string &
56 name () const
57 {
58  return m_name;
59 }
60 
61 void
63 setFCN ( StatedFCN * fcn )
64 {
65  if ( m_fcn != 0 ) delete m_fcn;
66 
67  m_fcn = fcn;
68 }
69 
70 StatedFCN *
73 {
74  return m_fcn;
75 }
76 
77 bool
79 isCompatible ( const FunctionBase * function ) const
80 {
81  bool yes = false;
82  if ( m_fcn != 0 ) {
83  yes = m_fcn -> isCompatible ( function );
84  }
85  return yes;
86 }
87 
88 void
90 setFunction ( FunctionBase * function )
91 {
92  if ( m_fcn != 0 ) {
93  m_fcn -> setFunction ( function );
94  }
95 }
96 
97 void
99 setDataSource ( const DataSource * source )
100 {
101  if ( m_fcn != 0 ) {
102  m_fcn -> setDataSource ( source );
103  m_fcn -> setUseErrors ();
104  }
105 }
106 
107 void
108 Fitter::
109 setUseErrors ( bool yes )
110 {
111  if ( m_fcn != 0 ) {
112  m_fcn -> setUseErrors ( yes );
113  }
114 }
115 
116 bool
117 Fitter::
118 getUseErrors () const
119 {
120  bool yes = false;
121  if ( m_fcn != 0 ) {
122  yes = m_fcn -> getUseErrors ();
123  }
124 
125  return yes;
126 }
127 
128 bool
129 Fitter::
131 {
132  bool yes = true;
133  if ( m_fcn != 0 ) {
134  yes = m_fcn -> needsIntegrated ();
135  }
136  return yes;
137 }
138 
139 void
140 Fitter::
141 fillFreeParameters ( std::vector < double > & free_parms) const
142 {
143  return m_fcn -> fillFreeParameters ( free_parms );
144 }
145 
146 void
147 Fitter::
148 setFixedFlags ( const std::vector < int > & flags )
149 {
150  m_fcn -> setFixedFlags ( flags );
151 }
152 
153 const vector < int > &
154 Fitter::
155 getFixedFlags ( ) const
156 {
157  return m_fcn -> getFixedFlags ();
158 }
159 
160 void
161 Fitter::
162 setLimits ( unsigned int, double, double )
163 {
164  string what ( "The " );
165  what += m_name;
166  what += " minimizer does not support limits on parameters";
167  throw std::runtime_error ( what );
168 }
169 
170 unsigned int
171 Fitter::
172 getParameterIndex ( const std::string & name )
173 {
174  unsigned int index = UINT_MAX;
175  const vector < string > & names = m_fcn -> getParmNames ();
176  unsigned int size = names.size();
177  for ( unsigned int i = 0; i < size; i++ ) {
178  const string & pname = names [i];
179  if ( pname == name ) {
180  index = i;
181  break;
182  }
183  }
184  if ( index == UINT_MAX ) {
185  string what ( "No parameter named `" );
186  what += name;
187  what += "' for this function.";
188  throw std::runtime_error ( what );
189  }
190 
191  return index;
192 }
193 
194 void
195 Fitter::
196 setLimits ( const std::string & name, double lower, double upper )
197 {
198  unsigned int index = getParameterIndex ( name );
199  setLimits ( index, lower, upper );
200 }
201 
202 void
203 Fitter::
204 setStepSize ( unsigned int, double )
205 {
206  string what ( "This " );
207  what += m_name;
208  what += " minimizer does not support setting step size.";
209  throw std::runtime_error ( what );
210 }
211 
212 void
213 Fitter::
214 setStepSize ( const std::string & name, double size )
215 {
216  unsigned int index = getParameterIndex ( name );
217  setStepSize ( index, size );
218 }
219 
220 double
222 {
223  return m_fcn -> objectiveValue ();
224 }
225 
226 int
227 Fitter::
229 {
230  return m_fcn -> degreesOfFreedom();
231 }
232 
233 int
234 Fitter::
235 calcCovariance ( std::vector < std::vector < double > > & )
236 {
237  return EXIT_FAILURE;
238 }
239 
240 void
241 Fitter::
243 {
244  m_fcn -> setFitCut ( cut );
245 }
246 
247 void
248 Fitter::
249 setFitRange ( bool yes )
250 {
251  m_fcn -> setFitRange ( yes );
252 }

Generated for HippoDraw Class Library by doxygen