#include <RootMinuitCommands.h>
Public Types | |
typedef RootMinuitCommand | command |
typedef RootMinuit< Function > | minuit |
Public Member Functions | |
void | add (RootMinuit< Function > &minuit, funct::Parameter &p) const |
double | err (const std::string &name) |
bool | fixed (const std::string &name) |
void | init (const char *fileName) |
double | max (const std::string &name) |
double | min (const std::string &name) |
double | par (const std::string &name) |
RootMinuitCommands (const char *fileName, bool verbose=true) | |
RootMinuitCommands (bool verbose=true) | |
void | run (RootMinuit< Function > &minuit) const |
Private Types | |
typedef boost::tokenizer < boost::char_separator< char > > | tokenizer |
Private Member Functions | |
std::string | errorHeader () const |
std::string | nextToken (typename tokenizer::iterator &i, const typename tokenizer::iterator &end) const |
const parameter_t & | parameter (const std::string &name) const |
double | string2double (const std::string &str) const |
Private Attributes | |
std::vector< command > | commands_ |
unsigned int | lineNumber_ |
std::map< std::string, size_t > | parIndices_ |
parameterVector_t | pars_ |
bool | verbose_ |
Definition at line 48 of file RootMinuitCommands.h.
typedef RootMinuitCommand fit::RootMinuitCommands< Function >::command |
Definition at line 51 of file RootMinuitCommands.h.
typedef RootMinuit<Function> fit::RootMinuitCommands< Function >::minuit |
Definition at line 50 of file RootMinuitCommands.h.
typedef boost::tokenizer<boost::char_separator<char> > fit::RootMinuitCommands< Function >::tokenizer [private] |
Definition at line 84 of file RootMinuitCommands.h.
fit::RootMinuitCommands< Function >::RootMinuitCommands | ( | bool | verbose = true | ) | [inline] |
Definition at line 52 of file RootMinuitCommands.h.
fit::RootMinuitCommands< Function >::RootMinuitCommands | ( | const char * | fileName, |
bool | verbose = true |
||
) | [inline] |
Definition at line 55 of file RootMinuitCommands.h.
References fit::RootMinuitCommands< Function >::init().
void fit::RootMinuitCommands< Function >::add | ( | RootMinuit< Function > & | minuit, |
funct::Parameter & | p | ||
) | const [inline] |
Definition at line 75 of file RootMinuitCommands.h.
References fit::RootMinuit< Function >::addParameter(), fit::parameter_t::err, fit::parameter_t::fixed, fit::RootMinuit< Function >::fixParameter(), fit::parameter_t::max, fit::parameter_t::min, funct::Parameter::name(), mergeVDriftHistosByStation::name, fit::RootMinuitCommands< Function >::par(), and fit::RootMinuitCommands< Function >::parameter().
double fit::RootMinuitCommands< Function >::err | ( | const std::string & | name | ) | [inline] |
Definition at line 63 of file RootMinuitCommands.h.
References fit::parameter_t::err, and fit::RootMinuitCommands< Function >::parameter().
std::string fit::RootMinuitCommands< Function >::errorHeader | ( | ) | const [inline, private] |
Definition at line 109 of file RootMinuitCommands.h.
References fit::RootMinuitCommands< Function >::lineNumber_, and dbtoconf::out.
Referenced by fit::RootMinuitCommands< Function >::nextToken().
{ std::ostringstream out; out << "RootMinuitCommands config. error, line " << lineNumber_<< ": "; return out.str(); }
bool fit::RootMinuitCommands< Function >::fixed | ( | const std::string & | name | ) | [inline] |
Definition at line 72 of file RootMinuitCommands.h.
References fit::parameter_t::fixed, and fit::RootMinuitCommands< Function >::parameter().
void fit::RootMinuitCommands< Function >::init | ( | const char * | fileName | ) |
Definition at line 125 of file RootMinuitCommands.h.
References cmsCodeRulesChecker::arg, launcher::cmssw_base, cmsBenchmark::cmssw_release_base, edm::errors::Configuration, gather_cfg::cout, fit::RootMinuitCommand::doubleArgs, fit::parameter_t::err, Exception, mergeVDriftHistosByStation::file, fit::parameter_t::fixed, i, j, kFix, kMigrad, kMinimize, kParameter, kPrintAll, kRelease, kSet, prof2calltree::last, geometryCSVtoXML::line, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuitCommand::name, mergeVDriftHistosByStation::name, Gflash::par, path(), fit::RootMinuitCommand::print(), asciidump::s, fit::RootMinuitCommand::stringArgs, EcalElecEmulTccFlatFileProducerFromTPG_cfg::tokens, and fit::parameter_t::val.
Referenced by fit::RootMinuitCommands< Function >::RootMinuitCommands().
{ using namespace std; string cmssw_release_base = getenv("CMSSW_RELEASE_BASE"); string cmssw_base = getenv("CMSSW_BASE"); string path = "."; if(!cmssw_release_base.empty()) { path += ':'; path += (cmssw_release_base + "/src"); } if(!cmssw_base.empty()) { path += ':'; path += (cmssw_base + "/src"); } FileInPath fileInPath(path, fileName); ifstream * file = fileInPath(); if(file==0 || !file->is_open()) throw edm::Exception(edm::errors::Configuration) << "RootMinuitCommands: can't open file: " << fileName << " in path: " << path << "\n"; if (verbose_) cout << ">>> configuration file: " << fileName << endl; string line; lineNumber_ = 0; bool commands = false; while(getline(*file, line)) { ++lineNumber_; if(line.size()==0) continue; char last = *line.rbegin(); if(!(last >= '0' && last <= 'z')) line.erase(line.end() - 1); boost::char_separator<char> sep(" "); tokenizer tokens(line, sep); tokenizer::iterator i = tokens.begin(), e = tokens.end(); if(tokens.begin()==tokens.end()) continue; if(*(i->begin()) != '#') { if(*i == kParameter) { if(commands) throw edm::Exception(edm::errors::Configuration) << errorHeader() << "please, declare all parameter before all other minuit commands.\n"; string name = nextToken(i, e); parameter_t par; par.val = string2double(nextToken(i, e)); par.err = string2double(nextToken(i, e)); par.min = string2double(nextToken(i, e)); par.max = string2double(nextToken(i, e)); tokenizer::iterator j = i; ++j; if(j != e) { string fixed = nextToken(i, e); if(fixed == "fixed") par.fixed = true; else if(fixed == "free") par.fixed = false; else throw edm::Exception(edm::errors::Configuration) << errorHeader() << "fix parameter option unknown: " << *i << "\n" << "valid options are: fixed, free.\n"; } else { par.fixed = false; } pars_.push_back(std::make_pair(name, par)); size_t s = parIndices_.size(); parIndices_[name] = s; if(verbose_) cout << ">>> " << kParameter << " " << name << " " << par.val << " [" << par.min << ", " << par.max << "]," << " err: " << par.err << endl; } else if(*i == kFix || *i == kRelease) { commands = true; command com; com.name = *i; string arg = nextToken(i, e); com.stringArgs.push_back(arg); commands_.push_back(com); if(verbose_) { cout << ">>> "; com.print(cout); cout << endl; } } else if(*i == kSet) { commands = true; command com; com.name = *i; string arg = nextToken(i, e); com.stringArgs.push_back(arg); com.doubleArgs.push_back(string2double(nextToken(i, e))); commands_.push_back(com); if(verbose_) { cout << ">>> "; com.print(cout); cout << endl; } } else if(*i == kMinimize || *i == kMigrad || *i == kPrintAll) { commands = true; command com; com.name = *i; commands_.push_back(com); if(verbose_) { cout << ">>> "; com.print(cout); cout << endl; } } else { throw edm::Exception(edm::errors::Configuration) << errorHeader() << "unkonwn command:: " << *i << "\n"; } } } if (verbose_) cout << ">>> end configuration" << endl; }
double fit::RootMinuitCommands< Function >::max | ( | const std::string & | name | ) | [inline] |
Definition at line 69 of file RootMinuitCommands.h.
References fit::parameter_t::max, and fit::RootMinuitCommands< Function >::parameter().
double fit::RootMinuitCommands< Function >::min | ( | const std::string & | name | ) | [inline] |
Definition at line 66 of file RootMinuitCommands.h.
References fit::parameter_t::min, and fit::RootMinuitCommands< Function >::parameter().
std::string fit::RootMinuitCommands< Function >::nextToken | ( | typename tokenizer::iterator & | i, |
const typename tokenizer::iterator & | end | ||
) | const [inline, private] |
Definition at line 114 of file RootMinuitCommands.h.
References edm::errors::Configuration, fit::RootMinuitCommands< Function >::errorHeader(), Exception, and i.
{ ++i; if(i == end) throw edm::Exception(edm::errors::Configuration) << errorHeader() << "missing parameter\n"; return *i; }
double fit::RootMinuitCommands< Function >::par | ( | const std::string & | name | ) | [inline] |
Definition at line 60 of file RootMinuitCommands.h.
References fit::RootMinuitCommands< Function >::parameter(), and fit::parameter_t::val.
Referenced by fit::RootMinuitCommands< Function >::add().
const parameter_t& fit::RootMinuitCommands< Function >::parameter | ( | const std::string & | name | ) | const [inline, private] |
Definition at line 102 of file RootMinuitCommands.h.
References edm::errors::Configuration, L1TEmulatorMonitor_cff::p, fit::RootMinuitCommands< Function >::parIndices_, and fit::RootMinuitCommands< Function >::pars_.
Referenced by fit::RootMinuitCommands< Function >::add(), fit::RootMinuitCommands< Function >::err(), fit::RootMinuitCommands< Function >::fixed(), fit::RootMinuitCommands< Function >::max(), fit::RootMinuitCommands< Function >::min(), and fit::RootMinuitCommands< Function >::par().
{ typename std::map<std::string, size_t>::const_iterator p = parIndices_.find(name); if(p == parIndices_.end()) throw edm::Exception(edm::errors::Configuration) << "RootMinuit: can't find parameter " << name << "\n"; return pars_[p->second].second; }
void fit::RootMinuitCommands< Function >::run | ( | RootMinuit< Function > & | minuit | ) | const |
Definition at line 236 of file RootMinuitCommands.h.
References trackerHits::c, gather_cfg::cout, end, fit::RootMinuit< Function >::fixParameter(), kFix, kMigrad, kMinimize, kPrintAll, kRelease, kSet, fit::RootMinuit< Function >::migrad(), fit::RootMinuit< Function >::minimize(), fit::RootMinuit< Function >::printFitResults(), fit::RootMinuit< Function >::releaseParameter(), and fit::RootMinuit< Function >::setParameter().
{ using namespace std; typename vector<command>::const_iterator c = commands_.begin(), end = commands_.end(); for(; c != end; ++c) { if(verbose_) { cout << ">>> minuit command: "; c->print(cout); cout << endl; } if(c->name == kMinimize) minuit.minimize(); else if(c->name == kMigrad) minuit.migrad(); else if(c->name == kPrintAll) minuit.printFitResults(); else if(c->name == kFix) minuit.fixParameter(c->stringArgs[0]); else if(c->name == kRelease) minuit.releaseParameter(c->stringArgs[0]); else if(c->name == kSet) minuit.setParameter(c->stringArgs[0], c->doubleArgs[0]); } }
double fit::RootMinuitCommands< Function >::string2double | ( | const std::string & | str | ) | const [inline, private] |
Definition at line 90 of file RootMinuitCommands.h.
References begin, edm::errors::Configuration, end, Exception, and asciidump::s.
{ const char * begin = str.c_str(); char * end; double val = strtod(begin, &end); size_t s = end - begin; if(s < str.size()) { throw edm::Exception(edm::errors::Configuration) << "RootMinuitCommands: invalid double value: " << str << "\n"; } return val; }
std::vector<command> fit::RootMinuitCommands< Function >::commands_ [private] |
Definition at line 89 of file RootMinuitCommands.h.
unsigned int fit::RootMinuitCommands< Function >::lineNumber_ [private] |
Definition at line 86 of file RootMinuitCommands.h.
Referenced by fit::RootMinuitCommands< Function >::errorHeader().
std::map<std::string, size_t> fit::RootMinuitCommands< Function >::parIndices_ [private] |
Definition at line 88 of file RootMinuitCommands.h.
Referenced by fit::RootMinuitCommands< Function >::parameter().
parameterVector_t fit::RootMinuitCommands< Function >::pars_ [private] |
Definition at line 87 of file RootMinuitCommands.h.
Referenced by fit::RootMinuitCommands< Function >::parameter().
bool fit::RootMinuitCommands< Function >::verbose_ [private] |
Definition at line 85 of file RootMinuitCommands.h.