|
|
Go to the documentation of this file. 1 #ifndef PhysicsTools_Utilities_RootMinuitCommands_h
2 #define PhysicsTools_Utilities_RootMinuitCommands_h
13 #include <boost/tokenizer.hpp>
14 #include <boost/algorithm/string/join.hpp>
49 template <
class Function>
72 typedef boost::tokenizer<boost::char_separator<char> >
tokenizer;
89 typename std::map<std::string, size_t>::const_iterator
p =
parIndices_.find(
name);
92 return pars_[
p->second].second;
95 std::ostringstream
out;
96 out <<
"RootMinuitCommands config. error, line " <<
lineNumber_ <<
": ";
107 template <
typename Function>
110 string cmssw_release_base = std::getenv(
"CMSSW_RELEASE_BASE");
111 string cmssw_base = std::getenv(
"CMSSW_BASE");
112 vector<string> directories;
113 directories.reserve(3);
114 directories.emplace_back(
".");
115 if (!cmssw_release_base.empty()) {
116 directories.emplace_back(cmssw_release_base +
"/src");
119 directories.emplace_back(
cmssw_base +
"/src");
122 for (
auto const&
d : directories) {
129 if (!
file.is_open()) {
131 <<
"RootMinuitCommands: can't open file: " <<
fileName
146 boost::char_separator<char> sep(
" ");
148 tokenizer::iterator
i = tokens.begin(),
e = tokens.end();
149 if (tokens.begin() == tokens.end())
151 if (*(
i->begin()) !=
'#') {
155 << errorHeader() <<
"please, declare all parameter before all other minuit commands.\n";
156 string name = nextToken(
i,
e);
158 par.
val = string2double(nextToken(
i,
e));
159 par.
err = string2double(nextToken(
i,
e));
160 par.
min = string2double(nextToken(
i,
e));
161 par.
max = string2double(nextToken(
i,
e));
162 tokenizer::iterator
j =
i;
165 string fixed = nextToken(
i,
e);
166 if (
fixed ==
"fixed")
168 else if (
fixed ==
"free")
172 << errorHeader() <<
"fix parameter option unknown: " << *
i <<
"\n"
173 <<
"valid options are: fixed, free.\n";
177 pars_.push_back(std::make_pair(
name, par));
178 size_t s = parIndices_.size();
179 parIndices_[
name] =
s;
182 <<
" err: " << par.
err << endl;
187 string arg = nextToken(
i,
e);
189 commands_.push_back(com);
195 }
else if (*
i ==
kSet) {
199 string arg = nextToken(
i,
e);
201 com.
doubleArgs.push_back(string2double(nextToken(
i,
e)));
202 commands_.push_back(com);
212 commands_.push_back(com);
224 cout <<
">>> end configuration" << endl;
227 template <
typename Function>
230 typename vector<command>::const_iterator
c = commands_.begin(),
end = commands_.end();
231 for (;
c !=
end; ++
c) {
233 cout <<
">>> minuit command: ";
243 else if (
c->name ==
kFix)
247 else if (
c->name ==
kSet)
RootMinuitCommands(const char *fileName, bool verbose=true)
void setParameter(const std::string &name, double val)
void addParameter(const std::string &name, std::shared_ptr< double > val, double err, double min, double max)
boost::tokenizer< boost::char_separator< char > > tokenizer
const parameter_t & parameter(const std::string &name) const
std::vector< double > doubleArgs
static std::string join(char **cmd)
RootMinuitCommands(bool verbose=true)
double min(const std::string &name)
void print(std::ostream &cout) const
RootMinuit< Function > minuit
std::vector< command > commands_
void fixParameter(const std::string &name)
std::string nextToken(typename tokenizer::iterator &i, const typename tokenizer::iterator &end) const
double max(const std::string &name)
static constexpr int verbose
bool fixed(const std::string &name)
std::map< std::string, size_t > parIndices_
double par(const std::string &name)
void add(RootMinuit< Function > &minuit, funct::Parameter &p) const
void run(RootMinuit< Function > &minuit) const
void init(const char *fileName)
double string2double(const std::string &str) const
RootMinuitCommand command
std::string errorHeader() const
double err(const std::string &name)
std::vector< std::pair< std::string, parameter_t > > parameterVector_t
void releaseParameter(const std::string &name)
void printFitResults(std::ostream &cout=std::cout)
std::vector< std::string > stringArgs