00001 00012 #include "Fitter.h" 00013 00014 #include "StatedFCN.h" 00015 00016 #include <stdexcept> 00017 00018 using std::string; 00019 using std::vector; 00020 00021 using namespace hippodraw; 00022 00023 Fitter:: 00024 Fitter ( const char * name ) 00025 : m_name ( name ), 00026 m_fcn ( 0 ), 00027 m_max_iterations ( 100 ) 00028 { 00029 } 00030 00031 Fitter:: 00032 Fitter ( const Fitter & fitter ) 00033 : m_name ( fitter.m_name ), 00034 m_max_iterations ( fitter.m_max_iterations ) 00035 { 00036 if ( fitter.m_fcn != 0 ) m_fcn = fitter.m_fcn -> clone (); 00037 } 00038 00039 Fitter:: 00040 ~Fitter () 00041 { 00042 if ( m_fcn != 0 ) delete m_fcn; 00043 } 00044 00045 void 00046 Fitter:: 00047 copyFrom ( const Fitter * fitter ) 00048 { 00049 m_fcn -> copyFrom ( fitter -> m_fcn ); 00050 } 00051 00052 const std::string & 00053 Fitter:: 00054 name () const 00055 { 00056 return m_name; 00057 } 00058 00059 void 00060 Fitter:: 00061 setFCN ( StatedFCN * fcn ) 00062 { 00063 if ( m_fcn != 0 ) delete m_fcn; 00064 00065 m_fcn = fcn; 00066 } 00067 00068 StatedFCN * 00069 Fitter:: 00070 getFCN () 00071 { 00072 return m_fcn; 00073 } 00074 00075 bool 00076 Fitter:: 00077 isCompatible ( const FunctionBase * function ) const 00078 { 00079 bool yes = false; 00080 if ( m_fcn != 0 ) { 00081 yes = m_fcn -> isCompatible ( function ); 00082 } 00083 return yes; 00084 } 00085 00086 void 00087 Fitter:: 00088 setFunction ( FunctionBase * function ) 00089 { 00090 if ( m_fcn != 0 ) { 00091 m_fcn -> setFunction ( function ); 00092 } 00093 } 00094 00095 void 00096 Fitter:: 00097 setDataSource ( const DataSource * source ) 00098 { 00099 if ( m_fcn != 0 ) { 00100 m_fcn -> setDataSource ( source ); 00101 m_fcn -> setUseErrors (); 00102 } 00103 } 00104 00105 void 00106 Fitter:: 00107 setUseErrors ( bool yes ) 00108 { 00109 if ( m_fcn != 0 ) { 00110 m_fcn -> setUseErrors ( yes ); 00111 } 00112 } 00113 00114 bool 00115 Fitter:: 00116 getUseErrors () const 00117 { 00118 bool yes = false; 00119 if ( m_fcn != 0 ) { 00120 yes = m_fcn -> getUseErrors (); 00121 } 00122 00123 return yes; 00124 } 00125 00126 bool 00127 Fitter:: 00128 needsIntegrated () const 00129 { 00130 bool yes = true; 00131 if ( m_fcn != 0 ) { 00132 yes = m_fcn -> needsIntegrated (); 00133 } 00134 return yes; 00135 } 00136 00137 void 00138 Fitter:: 00139 fillFreeParameters ( std::vector < double > & free_parms) const 00140 { 00141 return m_fcn -> fillFreeParameters ( free_parms ); 00142 } 00143 00144 void 00145 Fitter:: 00146 setFixedFlags ( const std::vector < int > & flags ) 00147 { 00148 m_fcn -> setFixedFlags ( flags ); 00149 } 00150 00151 const vector < int > & 00152 Fitter:: 00153 getFixedFlags ( ) const 00154 { 00155 return m_fcn -> getFixedFlags (); 00156 } 00157 00158 void 00159 Fitter:: 00160 setLimits ( unsigned int, double, double ) 00161 { 00162 string what ( "The " ); 00163 what += m_name; 00164 what += " minimizer does not support limits on parameters"; 00165 throw std::runtime_error ( what ); 00166 } 00167 00168 unsigned int 00169 Fitter:: 00170 getParameterIndex ( const std::string & name ) 00171 { 00172 unsigned int index = UINT_MAX; 00173 const vector < string > & names = m_fcn -> getParmNames (); 00174 unsigned int size = names.size(); 00175 for ( unsigned int i = 0; i < size; i++ ) { 00176 const string & pname = names [i]; 00177 if ( pname == name ) { 00178 index = i; 00179 break; 00180 } 00181 } 00182 if ( index == UINT_MAX ) { 00183 string what ( "No parameter named `" ); 00184 what += name; 00185 what += "' for this function."; 00186 throw std::runtime_error ( what ); 00187 } 00188 00189 return index; 00190 } 00191 00192 void 00193 Fitter:: 00194 setLimits ( const std::string & name, double lower, double upper ) 00195 { 00196 unsigned int index = getParameterIndex ( name ); 00197 setLimits ( index, lower, upper ); 00198 } 00199 00200 void 00201 Fitter:: 00202 setStepSize ( unsigned int, double ) 00203 { 00204 string what ( "This " ); 00205 what += m_name; 00206 what += " minimizer does not support setting step size."; 00207 throw std::runtime_error ( what ); 00208 } 00209 00210 void 00211 Fitter:: 00212 setStepSize ( const std::string & name, double size ) 00213 { 00214 unsigned int index = getParameterIndex ( name ); 00215 setStepSize ( index, size ); 00216 } 00217 00218 double 00219 Fitter::objectiveValue () const 00220 { 00221 return m_fcn -> objectiveValue (); 00222 } 00223 00224 int 00225 Fitter:: 00226 calcDegreesOfFreedom () const 00227 { 00228 return m_fcn -> degreesOfFreedom(); 00229 } 00230 00231 int 00232 Fitter:: 00233 calcCovariance ( std::vector < std::vector < double > > & ) 00234 { 00235 return EXIT_FAILURE; 00236 } 00237 00238 void 00239 Fitter:: 00240 setFitCut ( TupleCut * cut ) 00241 { 00242 m_fcn -> setFitCut ( cut ); 00243 } 00244 00245 void 00246 Fitter:: 00247 setFitRange ( bool yes ) 00248 { 00249 m_fcn -> setFitRange ( yes ); 00250 }