1 #ifndef PhysicsTools_Utilities_RootMinuitCommands_h
2 #define PhysicsTools_Utilities_RootMinuitCommands_h
14 #include<boost/tokenizer.hpp>
34 if(
i != 0) cout <<
",";
40 if(
i != 0) cout <<
",";
47 template<
class Function>
84 typedef boost::tokenizer<boost::char_separator<char> >
tokenizer;
91 const char *
begin = str.c_str();
93 double val = strtod(begin, &end);
97 <<
"RootMinuitCommands: invalid double value: "
103 typename std::map<std::string, size_t>::const_iterator
p =
parIndices_.find(name);
106 <<
"RootMinuit: can't find parameter " << name <<
"\n";
107 return pars_[p->second].second;
110 std::ostringstream
out;
111 out <<
"RootMinuitCommands config. error, line " <<
lineNumber_<<
": ";
115 const typename tokenizer::iterator &
end)
const {
124 template<
typename Function>
139 std::ifstream *
file = fileInPath();
142 <<
"RootMinuitCommands: can't open file: " << fileName
143 <<
" in path: " <<
path <<
"\n";
145 cout <<
">>> configuration file: " << fileName << endl;
148 bool commands =
false;
151 if(
line.size()==0)
continue;
153 if(!(last >=
'0' && last <=
'z'))
line.erase(
line.end() - 1);
154 boost::char_separator<char>
sep(
" ");
156 tokenizer::iterator
i = tokens.begin(),
e = tokens.end();
157 if(tokens.begin()==tokens.end())
continue;
158 if(*(i->begin()) !=
'#') {
163 <<
"please, declare all parameter before all other minuit commands.\n";
164 string name = nextToken(i,
e);
166 par.
val = string2double(nextToken(i,
e));
167 par.
err = string2double(nextToken(i,
e));
168 par.
min = string2double(nextToken(i,
e));
169 par.
max = string2double(nextToken(i,
e));
170 tokenizer::iterator
j =
i; ++
j;
172 string fixed = nextToken(i,
e);
175 else if(fixed ==
"free")
180 <<
"fix parameter option unknown: " << *i <<
"\n"
181 <<
"valid options are: fixed, free.\n";
185 pars_.push_back(std::make_pair(name, par));
186 size_t s = parIndices_.size();
187 parIndices_[
name] =
s;
191 <<
" [" << par.
min <<
", " << par.
max <<
"],"
192 <<
" err: " << par.
err
198 string arg = nextToken(i,
e);
200 commands_.push_back(com);
204 }
else if(*i ==
kSet) {
208 string arg = nextToken(i,
e);
210 com.
doubleArgs.push_back(string2double(nextToken(i,
e)));
211 commands_.push_back(com);
219 commands_.push_back(com);
226 <<
"unkonwn command:: " << *i <<
"\n";
232 cout <<
">>> end configuration" << endl;
235 template<
typename Function>
238 typename vector<command>::const_iterator
c = commands_.begin(),
end = commands_.end();
239 for(;
c !=
end; ++
c) {
241 cout <<
">>> minuit command: ";
251 else if(
c->name ==
kFix)
255 else if(
c->name ==
kSet)
double min(const std::string &name)
void init(const char *fileName)
std::string errorHeader() const
const std::string & name() const
boost::tokenizer< boost::char_separator< char > > tokenizer
std::vector< std::string > stringArgs
void printFitResults(std::ostream &cout=std::cout)
void setParameter(const std::string &name, double val)
void fixParameter(const std::string &name)
double par(const std::string &name)
void run(RootMinuit< Function > &minuit) const
std::vector< command > commands_
std::vector< double > doubleArgs
std::string nextToken(typename tokenizer::iterator &i, const typename tokenizer::iterator &end) const
bool fixed(const std::string &name)
void addParameter(const std::string &name, boost::shared_ptr< double > val, double err, double min, double max)
std::vector< std::pair< std::string, parameter_t > > parameterVector_t
tuple path
else: Piece not in the list, fine.
void print(std::ostream &cout) const
double string2double(const std::string &str) const
std::map< std::string, size_t > parIndices_
double max(const std::string &name)
void add(RootMinuit< Function > &minuit, funct::Parameter &p) const
const parameter_t & parameter(const std::string &name) const
double err(const std::string &name)
RootMinuitCommand command
RootMinuit< Function > minuit
void releaseParameter(const std::string &name)
RootMinuitCommands(const char *fileName, bool verbose=true)
RootMinuitCommands(bool verbose=true)