1 #ifndef PhysicsTools_Utilities_RootMinuitCommands_h 2 #define PhysicsTools_Utilities_RootMinuitCommands_h 14 #include<boost/tokenizer.hpp> 32 if(stringArgs.size() > 0) {
33 for(
size_t i = 0;
i != stringArgs.size(); ++
i) {
34 if(
i != 0) cout <<
",";
35 cout <<
" \"" << stringArgs[
i] <<
"\"";
38 if(doubleArgs.size() > 0) {
39 for(
size_t i = 0;
i != doubleArgs.size(); ++
i) {
40 if(
i != 0) cout <<
",";
41 cout <<
" " << doubleArgs[
i];
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);
104 if(p == parIndices_.end())
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 {
119 << errorHeader() <<
"missing parameter\n";
124 template<
typename Function>
130 if(!cmssw_release_base.empty()) {
132 path += (cmssw_release_base +
"/src");
134 if(!cmssw_base.empty()) {
136 path += (cmssw_base +
"/src");
139 std::ifstream *
file = fileInPath();
140 if(file==0 || !file->is_open())
142 <<
"RootMinuitCommands: can't open file: " << fileName
143 <<
" in path: " << path <<
"\n";
145 cout <<
">>> configuration file: " << fileName << endl;
149 while(getline(*file, line)) {
151 if(line.size()==0)
continue;
152 char last = *line.rbegin();
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)
256 minuit.
setParameter(c->stringArgs[0], c->doubleArgs[0]);
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
commands
min number of hits for refit layers to remove
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)