#include <PhysicsTools/Utilities/interface/RootMinuit.h>
Public Member Functions | |
void | addParameter (const funct::Parameter &par, double err, double min, double max) |
void | addParameter (const std::string &name, boost::shared_ptr< double > val, double err, double min, double max) |
void | fixParameter (const std::string &name) |
template<unsigned int N> | |
void | getErrorMatrix (ROOT::Math::SMatrix< double, N, N, ROOT::Math::MatRepSym< double, N > > &err) |
double | getParameter (const std::string &name) |
double | getParameter (const std::string &name, double &err) |
double | getParameterError (const std::string &name) |
double | getParameterError (const std::string &name, double &val) |
double | migrad () |
double | minimize () |
double | minValue () |
int | numberOfFreeParameters () |
int | numberOfParameters () |
void | printFitResults (std::ostream &cout=std::cout) |
void | printParameters (std::ostream &cout=std::cout) |
void | releaseParameter (const std::string &name) |
RootMinuit (Function f, bool verbose=false) | |
void | setParameter (const std::string &name, double val) |
void | setParameters () |
Private Member Functions | |
void | init () |
size_t | parameterIndex (const std::string &name) const |
Static Private Member Functions | |
static void | fcn_ (int &, double *, double &f, double *par, int) |
Private Attributes | |
bool | initialized_ |
std::auto_ptr< TMinuit > | minuit_ |
double | minValue_ |
std::map< std::string, size_t > | parIndices_ |
parameterVector_t | parMap_ |
std::vector< boost::shared_ptr < double > > | pars_ |
bool | verbose_ |
Static Private Attributes | |
static Function | f_ |
static std::vector < boost::shared_ptr< double > > * | fPars_ = 0 |
Definition at line 21 of file RootMinuit.h.
fit::RootMinuit< Function >::RootMinuit | ( | Function | f, | |
bool | verbose = false | |||
) | [inline] |
void fit::RootMinuit< Function >::addParameter | ( | const funct::Parameter & | par, | |
double | err, | |||
double | min, | |||
double | max | |||
) | [inline] |
Definition at line 43 of file RootMinuit.h.
References fit::RootMinuit< Function >::addParameter(), and funct::Parameter::name().
00043 { 00044 return addParameter(par.name(), par, err, min, max); 00045 }
void fit::RootMinuit< Function >::addParameter | ( | const std::string & | name, | |
boost::shared_ptr< double > | val, | |||
double | err, | |||
double | min, | |||
double | max | |||
) | [inline] |
Definition at line 27 of file RootMinuit.h.
References edm::errors::Configuration, fit::parameter_t::err, fit::parameter_t::fixed, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuit< Function >::parIndices_, fit::RootMinuit< Function >::parMap_, fit::RootMinuit< Function >::pars_, s, and fit::parameter_t::val.
Referenced by fit::RootMinuit< Function >::addParameter().
00027 { 00028 if(initialized_) 00029 throw edm::Exception(edm::errors::Configuration) 00030 << "RootMinuit: can't add parameter " << name 00031 << " after minuit initialization\n"; 00032 pars_.push_back(val); 00033 parameter_t par; 00034 par.val = *val; 00035 par.err = err; 00036 par.min = min; 00037 par.max = max; 00038 par.fixed = false; 00039 parMap_.push_back(std::make_pair(name, par)); 00040 size_t s = parIndices_.size(); 00041 parIndices_[name] = s; 00042 }
static void fit::RootMinuit< Function >::fcn_ | ( | int & | , | |
double * | , | |||
double & | f, | |||
double * | par, | |||
int | ||||
) | [inline, static, private] |
Definition at line 193 of file RootMinuit.h.
References fit::RootMinuit< Function >::f_, fit::RootMinuit< Function >::fPars_, i, and size.
Referenced by fit::RootMinuit< Function >::init().
00193 { 00194 size_t size = fPars_->size(); 00195 for(size_t i = 0; i < size; ++i) 00196 *((*fPars_)[i]) = par[i]; 00197 f = f_(); 00198 }
void fit::RootMinuit< Function >::fixParameter | ( | const std::string & | name | ) | [inline] |
Definition at line 87 of file RootMinuit.h.
References i, fit::RootMinuit< Function >::initialized_, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parameterIndex(), and fit::RootMinuit< Function >::parMap_.
Referenced by fit::RootMinuitCommands< Function >::run().
00087 { 00088 size_t i = parameterIndex(name); 00089 parMap_[i].second.fixed = true; 00090 if(initialized_) { 00091 minuit_->FixParameter(i); 00092 } 00093 }
void fit::RootMinuit< Function >::getErrorMatrix | ( | ROOT::Math::SMatrix< double, N, N, ROOT::Math::MatRepSym< double, N > > & | err | ) | [inline] |
Definition at line 71 of file RootMinuit.h.
References edm::errors::Configuration, e, err, i, fit::RootMinuit< Function >::init(), j, fit::RootMinuit< Function >::minuit_, N, fit::RootMinuit< Function >::numberOfParameters(), and fit::RootMinuit< Function >::setParameters().
00071 { 00072 init(); 00073 if(N != numberOfParameters()) 00074 throw edm::Exception(edm::errors::Configuration) 00075 << "RootMinuit: can't call getErrorMatrix passing an SMatrix of dimension " << N 00076 << " while the number of parameters is " << numberOfParameters() << "\n"; 00077 double * e = new double[N*N]; 00078 minuit_->mnemat(e, numberOfParameters()); 00079 for(size_t i = 0; i < N; ++i) { 00080 for(size_t j = 0; j <= i; ++j) { 00081 err(i, j) = e[i + N*j]; 00082 } 00083 } 00084 delete [] e; 00085 setParameters(); 00086 }
double fit::RootMinuit< Function >::getParameter | ( | const std::string & | name | ) | [inline] |
Definition at line 52 of file RootMinuit.h.
References err, fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().
00052 { 00053 double val, err; 00054 init(); 00055 minuit_->GetParameter(parameterIndex(name), val, err); 00056 return val; 00057 }
double fit::RootMinuit< Function >::getParameter | ( | const std::string & | name, | |
double & | err | |||
) | [inline] |
Definition at line 46 of file RootMinuit.h.
References fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().
00046 { 00047 double val; 00048 init(); 00049 minuit_->GetParameter(parameterIndex(name), val, err); 00050 return val; 00051 }
double fit::RootMinuit< Function >::getParameterError | ( | const std::string & | name | ) | [inline] |
Definition at line 64 of file RootMinuit.h.
References err, fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().
00064 { 00065 double val, err; 00066 init(); 00067 minuit_->GetParameter(parameterIndex(name), val, err); 00068 return err; 00069 }
double fit::RootMinuit< Function >::getParameterError | ( | const std::string & | name, | |
double & | val | |||
) | [inline] |
Definition at line 58 of file RootMinuit.h.
References err, fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().
Referenced by fit::RootMinuit< Function >::printParameters().
00058 { 00059 double err; 00060 init(); 00061 minuit_->GetParameter(parameterIndex(name), val, err); 00062 return err; 00063 }
void fit::RootMinuit< Function >::init | ( | void | ) | [inline, private] |
Definition at line 206 of file RootMinuit.h.
References edm::errors::Configuration, end, fit::parameter_t::err, fit::RootMinuit< Function >::fcn_(), fit::RootMinuit< Function >::fPars_, i, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuit< Function >::minuit_, name, p, fit::RootMinuit< Function >::parMap_, fit::RootMinuit< Function >::pars_, fit::parameter_t::val, and fit::RootMinuit< Function >::verbose_.
Referenced by fit::RootMinuit< Function >::getErrorMatrix(), fit::RootMinuit< Function >::getParameter(), fit::RootMinuit< Function >::getParameterError(), fit::RootMinuit< Function >::migrad(), fit::RootMinuit< Function >::minimize(), fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::numberOfFreeParameters(), and fit::RootMinuit< Function >::numberOfParameters().
00206 { 00207 if(initialized_) return; 00208 minuit_.reset(new TMinuit(parMap_.size())); 00209 double arglist[10]; 00210 int ierflg = 0; 00211 if (! verbose_) { 00212 arglist[0] = -1; 00213 minuit_->mnexcm("SET PRINT", arglist, 1, ierflg); 00214 if (ierflg != 0) 00215 throw edm::Exception(edm::errors::Configuration) 00216 << "RootMinuit: error in calling SET PRINT\n"; 00217 } 00218 arglist[0] = 1; 00219 minuit_->mnexcm("SET ERR", arglist, 1, ierflg); 00220 if (ierflg != 0) 00221 throw edm::Exception(edm::errors::Configuration) 00222 << "RootMinuit: error in calling SET ERR\n"; 00223 00224 size_t i = 0; 00225 typename parameterVector_t::const_iterator p = parMap_.begin(), end = parMap_.end(); 00226 for(; p != end; ++p, ++i) { 00227 const std::string & name = p->first; 00228 const parameter_t & par = p->second; 00229 minuit_->mnparm(i, name, par.val, par.err, par.min, par.max, ierflg); 00230 if(ierflg != 0) 00231 throw edm::Exception(edm::errors::Configuration) 00232 << "RootMinuit: error in setting parameter " << i 00233 << " value = " << par.val << " error = " << par.err 00234 << " range = [" << par.min << ", " << par.max << "]\n"; 00235 } 00236 initialized_ = true; 00237 for(i = 0, p = parMap_.begin(); p != end; ++p, ++i) 00238 if(p->second.fixed) 00239 minuit_->FixParameter(i); 00240 fPars_= & pars_; 00241 minuit_->SetFCN(fcn_); 00242 }
double fit::RootMinuit< Function >::migrad | ( | ) | [inline] |
Definition at line 146 of file RootMinuit.h.
References TestMuL1L2Filter_cff::cerr, lat::endl(), fit::RootMinuit< Function >::init(), m, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::setParameters(), and fit::RootMinuit< Function >::verbose_.
Referenced by fit::RootMinuitCommands< Function >::run().
00146 { 00147 init(); 00148 double arglist[10]; 00149 arglist[0] = 5000; 00150 arglist[1] = 0.1; 00151 int ierflag; 00152 minuit_->mnexcm("MIGRAD", arglist, 2, ierflag); 00153 if ( ierflag != 0 ) std::cerr << "ERROR in migrad!!" << std::endl; 00154 if(verbose_) minuit_->mnmatu(1); //Prints the covariance matrix 00155 double m = minValue(); 00156 if(verbose_) minuit_->mnprin(3, m); 00157 setParameters(); 00158 return m; 00159 }
double fit::RootMinuit< Function >::minimize | ( | ) | [inline] |
Definition at line 132 of file RootMinuit.h.
References TestMuL1L2Filter_cff::cerr, lat::endl(), fit::RootMinuit< Function >::init(), m, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::setParameters(), and fit::RootMinuit< Function >::verbose_.
Referenced by fit::RootMinuitCommands< Function >::run().
00132 { 00133 init(); 00134 double arglist[10]; 00135 arglist[0] = 5000; 00136 arglist[1] = 0.1; 00137 int ierflag; 00138 minuit_->mnexcm("MINIMIZE", arglist, 2, ierflag); 00139 if ( ierflag != 0 ) std::cerr << "ERROR in minimize!!" << std::endl; 00140 if(verbose_) minuit_->mnmatu(1); //Prints the covariance matrix 00141 double m = minValue(); 00142 if(verbose_) minuit_->mnprin(3, m); 00143 setParameters(); 00144 return m; 00145 }
double fit::RootMinuit< Function >::minValue | ( | void | ) | [inline] |
Definition at line 160 of file RootMinuit.h.
References fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::minValue_.
Referenced by fit::RootMinuit< Function >::migrad(), fit::RootMinuit< Function >::minimize(), and fit::RootMinuit< Function >::printFitResults().
00160 { 00161 init(); 00162 int ierflag; 00163 double edm, errdef; 00164 int nvpar, nparx; 00165 minuit_->mnstat(minValue_, edm, errdef, nvpar, nparx, ierflag); 00166 return minValue_; 00167 }
int fit::RootMinuit< Function >::numberOfFreeParameters | ( | ) | [inline] |
Definition at line 128 of file RootMinuit.h.
References fit::RootMinuit< Function >::init(), and fit::RootMinuit< Function >::minuit_.
Referenced by fit::RootMinuit< Function >::printFitResults().
int fit::RootMinuit< Function >::numberOfParameters | ( | ) | [inline] |
Definition at line 124 of file RootMinuit.h.
References fit::RootMinuit< Function >::init(), and fit::RootMinuit< Function >::minuit_.
Referenced by fit::RootMinuit< Function >::getErrorMatrix().
size_t fit::RootMinuit< Function >::parameterIndex | ( | const std::string & | name | ) | const [inline, private] |
Definition at line 199 of file RootMinuit.h.
References edm::errors::Configuration, p, and fit::RootMinuit< Function >::parIndices_.
Referenced by fit::RootMinuit< Function >::fixParameter(), fit::RootMinuit< Function >::getParameter(), fit::RootMinuit< Function >::getParameterError(), fit::RootMinuit< Function >::releaseParameter(), and fit::RootMinuit< Function >::setParameter().
00199 { 00200 typename std::map<std::string, size_t>::const_iterator p = parIndices_.find(name); 00201 if(p == parIndices_.end()) 00202 throw edm::Exception(edm::errors::Configuration) 00203 << "RootMinuit: can't find parameter " << name << "\n"; 00204 return p->second; 00205 }
void fit::RootMinuit< Function >::printFitResults | ( | std::ostream & | cout = std::cout |
) | [inline] |
Definition at line 175 of file RootMinuit.h.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), fit::RootMinuit< Function >::f_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::numberOfFreeParameters(), and fit::RootMinuit< Function >::printParameters().
Referenced by fit::RootMinuitCommands< Function >::run().
00175 { 00176 double amin = minValue(); 00177 int ndof = f_.degreesOfFreedom() - numberOfFreeParameters(); 00178 cout << "chi-squared/n.d.o.f. = " << amin << "/" << ndof << " = " << amin/ndof 00179 << "; prob: " << TMath::Prob(amin, ndof) 00180 << std::endl; 00181 printParameters(cout); 00182 }
void fit::RootMinuit< Function >::printParameters | ( | std::ostream & | cout = std::cout |
) | [inline] |
Definition at line 168 of file RootMinuit.h.
References GenMuonPlsPt100GeV_cfg::cout, end, lat::endl(), fit::RootMinuit< Function >::getParameterError(), i, fit::RootMinuit< Function >::parIndices_, and fit::RootMinuit< Function >::pars_.
Referenced by fit::RootMinuit< Function >::printFitResults().
00168 { 00169 std::map<std::string, size_t>::const_iterator i = parIndices_.begin(), end = parIndices_.end(); 00170 for(; i != end; ++i) { 00171 cout << i->first << " = " << *pars_[i->second] 00172 << " +/- " << getParameterError(i->first) << std::endl; 00173 } 00174 }
void fit::RootMinuit< Function >::releaseParameter | ( | const std::string & | name | ) | [inline] |
Definition at line 94 of file RootMinuit.h.
References i, fit::RootMinuit< Function >::initialized_, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parameterIndex(), and fit::RootMinuit< Function >::parMap_.
Referenced by fit::RootMinuitCommands< Function >::run().
00094 { 00095 size_t i = parameterIndex(name); 00096 parMap_[i].second.fixed = false; 00097 if(initialized_) { 00098 minuit_->Release(i); 00099 } 00100 }
void fit::RootMinuit< Function >::setParameter | ( | const std::string & | name, | |
double | val | |||
) | [inline] |
Definition at line 101 of file RootMinuit.h.
References edm::errors::Configuration, fit::parameter_t::err, i, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parameterIndex(), fit::RootMinuit< Function >::parMap_, and fit::parameter_t::val.
Referenced by fit::RootMinuitCommands< Function >::run().
00101 { 00102 size_t i = parameterIndex(name); 00103 parameter_t & par = parMap_[i].second; 00104 par.val = val; 00105 if(initialized_) { 00106 int ierflg = 0; 00107 minuit_->mnparm(i, name, par.val, par.err, par.min, par.max, ierflg); 00108 if(ierflg != 0) 00109 throw edm::Exception(edm::errors::Configuration) 00110 << "RootMinuit: error in setting parameter " << i 00111 << " value = " << par.val << " error = " << par.err 00112 << " range = [" << par.min << ", " << par.max << "]\n"; 00113 } 00114 }
void fit::RootMinuit< Function >::setParameters | ( | ) | [inline] |
Definition at line 115 of file RootMinuit.h.
References end, err, i, index, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parIndices_, and fit::RootMinuit< Function >::pars_.
Referenced by fit::RootMinuit< Function >::getErrorMatrix(), fit::RootMinuit< Function >::migrad(), and fit::RootMinuit< Function >::minimize().
00115 { 00116 std::map<std::string, size_t>::const_iterator i = parIndices_.begin(), end = parIndices_.end(); 00117 double val, err; 00118 for(; i != end; ++i) { 00119 size_t index = i->second; 00120 minuit_->GetParameter(index, val, err); 00121 *pars_[index] = val; 00122 } 00123 }
Function fit::RootMinuit< Function >::f_ [inline, static, private] |
Definition at line 192 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::fcn_(), fit::RootMinuit< Function >::printFitResults(), and fit::RootMinuit< Function >::RootMinuit().
std::vector< boost::shared_ptr< double > > * fit::RootMinuit< Function >::fPars_ = 0 [inline, static, private] |
Definition at line 190 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::fcn_(), and fit::RootMinuit< Function >::init().
bool fit::RootMinuit< Function >::initialized_ [private] |
Definition at line 186 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::addParameter(), fit::RootMinuit< Function >::fixParameter(), fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::releaseParameter(), and fit::RootMinuit< Function >::setParameter().
std::auto_ptr<TMinuit> fit::RootMinuit< Function >::minuit_ [private] |
Definition at line 188 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::fixParameter(), fit::RootMinuit< Function >::getErrorMatrix(), fit::RootMinuit< Function >::getParameter(), fit::RootMinuit< Function >::getParameterError(), fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::migrad(), fit::RootMinuit< Function >::minimize(), fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::numberOfFreeParameters(), fit::RootMinuit< Function >::numberOfParameters(), fit::RootMinuit< Function >::releaseParameter(), fit::RootMinuit< Function >::setParameter(), and fit::RootMinuit< Function >::setParameters().
double fit::RootMinuit< Function >::minValue_ [private] |
std::map<std::string, size_t> fit::RootMinuit< Function >::parIndices_ [private] |
Definition at line 185 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::addParameter(), fit::RootMinuit< Function >::parameterIndex(), fit::RootMinuit< Function >::printParameters(), and fit::RootMinuit< Function >::setParameters().
parameterVector_t fit::RootMinuit< Function >::parMap_ [private] |
Definition at line 184 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::addParameter(), fit::RootMinuit< Function >::fixParameter(), fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::releaseParameter(), and fit::RootMinuit< Function >::setParameter().
std::vector<boost::shared_ptr<double> > fit::RootMinuit< Function >::pars_ [private] |
Definition at line 189 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::addParameter(), fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::printParameters(), and fit::RootMinuit< Function >::setParameters().
bool fit::RootMinuit< Function >::verbose_ [private] |
Definition at line 191 of file RootMinuit.h.
Referenced by fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::migrad(), and fit::RootMinuit< Function >::minimize().