CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
fit::RootMinuitCommands< Function > Class Template Reference

#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 (bool verbose=true)
 
 RootMinuitCommands (const char *fileName, 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_tparameter (const std::string &name) const
 
double string2double (const std::string &str) const
 

Private Attributes

std::vector< commandcommands_
 
unsigned int lineNumber_
 
std::map< std::string, size_t > parIndices_
 
parameterVector_t pars_
 
bool verbose_
 

Detailed Description

template<class Function>
class fit::RootMinuitCommands< Function >

Definition at line 50 of file RootMinuitCommands.h.

Member Typedef Documentation

◆ command

template<class Function >
typedef RootMinuitCommand fit::RootMinuitCommands< Function >::command

Definition at line 53 of file RootMinuitCommands.h.

◆ minuit

template<class Function >
typedef RootMinuit<Function> fit::RootMinuitCommands< Function >::minuit

Definition at line 52 of file RootMinuitCommands.h.

◆ tokenizer

template<class Function >
typedef boost::tokenizer<boost::char_separator<char> > fit::RootMinuitCommands< Function >::tokenizer
private

Definition at line 72 of file RootMinuitCommands.h.

Constructor & Destructor Documentation

◆ RootMinuitCommands() [1/2]

template<class Function >
fit::RootMinuitCommands< Function >::RootMinuitCommands ( bool  verbose = true)
inline

Definition at line 54 of file RootMinuitCommands.h.

◆ RootMinuitCommands() [2/2]

template<class Function >
fit::RootMinuitCommands< Function >::RootMinuitCommands ( const char *  fileName,
bool  verbose = true 
)
inline

Member Function Documentation

◆ add()

template<class Function >
void fit::RootMinuitCommands< Function >::add ( RootMinuit< Function > &  minuit,
funct::Parameter p 
) const
inline

◆ err()

template<class Function >
double fit::RootMinuitCommands< Function >::err ( const std::string &  name)
inline

◆ errorHeader()

template<class Function >
std::string fit::RootMinuitCommands< Function >::errorHeader ( ) const
inlineprivate

Definition at line 94 of file RootMinuitCommands.h.

References fit::RootMinuitCommands< Function >::lineNumber_, and MillePedeFileConverter_cfg::out.

Referenced by fit::RootMinuitCommands< Function >::nextToken().

94  {
95  std::ostringstream out;
96  out << "RootMinuitCommands config. error, line " << lineNumber_ << ": ";
97  return out.str();
98  }

◆ fixed()

template<class Function >
bool fit::RootMinuitCommands< Function >::fixed ( const std::string &  name)
inline

◆ init()

template<typename Function >
void fit::RootMinuitCommands< Function >::init ( const char *  fileName)

Definition at line 108 of file RootMinuitCommands.h.

References tkAlTrackRefitSequence_cff::commands, edm::errors::Configuration, gather_cfg::cout, ztail::d, fit::RootMinuitCommand::doubleArgs, MillePedeFileConverter_cfg::e, fit::parameter_t::err, Exception, f, geometryDiff::file, MillePedeFileConverter_cfg::fileName, fit::parameter_t::fixed, alignBH_cfg::fixed, mps_fire::i, dqmiolumiharvest::j, join(), kFix, kMigrad, kMinimize, kParameter, kPrintAll, kRelease, kSet, dqmdumpme::last, mps_splice::line, fit::parameter_t::max, fit::parameter_t::min, eostools::move(), fit::RootMinuitCommand::name, mergeVDriftHistosByStation::name, fit::RootMinuitCommand::print(), alignCSCRings::s, fit::RootMinuitCommand::stringArgs, and fit::parameter_t::val.

Referenced by fit::RootMinuitCommands< Function >::RootMinuitCommands().

108  {
109  using namespace std;
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");
117  }
118  if (!cmssw_base.empty()) {
119  directories.emplace_back(cmssw_base + "/src");
120  }
121  ifstream file;
122  for (auto const& d : directories) {
123  std::ifstream f{d + "/" + fileName};
124  if (f.good()) {
125  file = std::move(f);
126  break;
127  }
128  }
129  if (!file.is_open()) {
131  << "RootMinuitCommands: can't open file: " << fileName
132  << " in path: " << boost::algorithm::join(directories, ":") << "\n";
133  }
134  if (verbose_)
135  cout << ">>> configuration file: " << fileName << endl;
136  string line;
137  lineNumber_ = 0;
138  bool commands = false;
139  while (getline(file, line)) {
140  ++lineNumber_;
141  if (line.empty())
142  continue;
143  char last = *line.rbegin();
144  if (!(last >= '0' && last <= 'z'))
145  line.erase(line.end() - 1);
146  boost::char_separator<char> sep(" ");
147  tokenizer tokens(line, sep);
148  tokenizer::iterator i = tokens.begin(), e = tokens.end();
149  if (tokens.begin() == tokens.end())
150  continue;
151  if (*(i->begin()) != '#') {
152  if (*i == kParameter) {
153  if (commands)
155  << errorHeader() << "please, declare all parameter before all other minuit commands.\n";
156  string name = nextToken(i, e);
157  parameter_t par;
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;
163  ++j;
164  if (j != e) {
165  string fixed = nextToken(i, e);
166  if (fixed == "fixed")
167  par.fixed = true;
168  else if (fixed == "free")
169  par.fixed = false;
170  else
172  << errorHeader() << "fix parameter option unknown: " << *i << "\n"
173  << "valid options are: fixed, free.\n";
174  } else {
175  par.fixed = false;
176  }
177  pars_.push_back(std::make_pair(name, par));
178  size_t s = parIndices_.size();
179  parIndices_[name] = s;
180  if (verbose_)
181  cout << ">>> " << kParameter << " " << name << " " << par.val << " [" << par.min << ", " << par.max << "],"
182  << " err: " << par.err << endl;
183  } else if (*i == kFix || *i == kRelease) {
184  commands = true;
185  command com;
186  com.name = *i;
187  string arg = nextToken(i, e);
188  com.stringArgs.push_back(arg);
189  commands_.push_back(com);
190  if (verbose_) {
191  cout << ">>> ";
192  com.print(cout);
193  cout << endl;
194  }
195  } else if (*i == kSet) {
196  commands = true;
197  command com;
198  com.name = *i;
199  string arg = nextToken(i, e);
200  com.stringArgs.push_back(arg);
201  com.doubleArgs.push_back(string2double(nextToken(i, e)));
202  commands_.push_back(com);
203  if (verbose_) {
204  cout << ">>> ";
205  com.print(cout);
206  cout << endl;
207  }
208  } else if (*i == kMinimize || *i == kMigrad || *i == kPrintAll) {
209  commands = true;
210  command com;
211  com.name = *i;
212  commands_.push_back(com);
213  if (verbose_) {
214  cout << ">>> ";
215  com.print(cout);
216  cout << endl;
217  }
218  } else {
219  throw edm::Exception(edm::errors::Configuration) << errorHeader() << "unkonwn command:: " << *i << "\n";
220  }
221  }
222  }
223  if (verbose_)
224  cout << ">>> end configuration" << endl;
225  }
boost::tokenizer< boost::char_separator< char > > tokenizer
double par(const std::string &name)
std::string nextToken(typename tokenizer::iterator &i, const typename tokenizer::iterator &end) const
std::vector< command > commands_
A arg
Definition: Factorize.h:31
bool fixed(const std::string &name)
const char * kSet
const char * kParameter
const char * kFix
double f[11][100]
const char * kPrintAll
d
Definition: ztail.py:151
std::map< std::string, size_t > parIndices_
static std::string join(char **cmd)
Definition: RemoteFile.cc:21
const char * kMigrad
const char * kRelease
RootMinuitCommand command
std::string errorHeader() const
const char * kMinimize
double string2double(const std::string &str) const
def move(src, dest)
Definition: eostools.py:511

◆ max()

template<class Function >
double fit::RootMinuitCommands< Function >::max ( const std::string &  name)
inline

◆ min()

template<class Function >
double fit::RootMinuitCommands< Function >::min ( const std::string &  name)
inline

◆ nextToken()

template<class Function >
std::string fit::RootMinuitCommands< Function >::nextToken ( typename tokenizer::iterator &  i,
const typename tokenizer::iterator &  end 
) const
inlineprivate

Definition at line 99 of file RootMinuitCommands.h.

References edm::errors::Configuration, fit::RootMinuitCommands< Function >::errorHeader(), Exception, and mps_fire::i.

99  {
100  ++i;
101  if (i == end)
102  throw edm::Exception(edm::errors::Configuration) << errorHeader() << "missing parameter\n";
103  return *i;
104  }
std::string errorHeader() const

◆ par()

template<class Function >
double fit::RootMinuitCommands< Function >::par ( const std::string &  name)
inline

◆ parameter()

template<class Function >
const parameter_t& fit::RootMinuitCommands< Function >::parameter ( const std::string &  name) const
inlineprivate

◆ run()

template<typename Function >
void fit::RootMinuitCommands< Function >::run ( RootMinuit< Function > &  minuit) const

Definition at line 228 of file RootMinuitCommands.h.

References DummyCfis::c, gather_cfg::cout, 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().

228  {
229  using namespace std;
230  typename vector<command>::const_iterator c = commands_.begin(), end = commands_.end();
231  for (; c != end; ++c) {
232  if (verbose_) {
233  cout << ">>> minuit command: ";
234  c->print(cout);
235  cout << endl;
236  }
237  if (c->name == kMinimize)
238  minuit.minimize();
239  else if (c->name == kMigrad)
240  minuit.migrad();
241  else if (c->name == kPrintAll)
242  minuit.printFitResults();
243  else if (c->name == kFix)
244  minuit.fixParameter(c->stringArgs[0]);
245  else if (c->name == kRelease)
246  minuit.releaseParameter(c->stringArgs[0]);
247  else if (c->name == kSet)
248  minuit.setParameter(c->stringArgs[0], c->doubleArgs[0]);
249  }
250  }
std::vector< command > commands_
const char * kSet
const char * kFix
const char * kPrintAll
const char * kMigrad
const char * kRelease
RootMinuit< Function > minuit
const char * kMinimize

◆ string2double()

template<class Function >
double fit::RootMinuitCommands< Function >::string2double ( const std::string &  str) const
inlineprivate

Definition at line 78 of file RootMinuitCommands.h.

References edm::errors::Configuration, Exception, alignCSCRings::s, str, and heppy_batch::val.

78  {
79  const char* begin = str.c_str();
80  char* end;
81  double val = strtod(begin, &end);
82  size_t s = end - begin;
83  if (s < str.size()) {
84  throw edm::Exception(edm::errors::Configuration) << "RootMinuitCommands: invalid double value: " << str << "\n";
85  }
86  return val;
87  }
#define str(s)

Member Data Documentation

◆ commands_

template<class Function >
std::vector<command> fit::RootMinuitCommands< Function >::commands_
private

Definition at line 77 of file RootMinuitCommands.h.

◆ lineNumber_

template<class Function >
unsigned int fit::RootMinuitCommands< Function >::lineNumber_
private

◆ parIndices_

template<class Function >
std::map<std::string, size_t> fit::RootMinuitCommands< Function >::parIndices_
private

Definition at line 76 of file RootMinuitCommands.h.

Referenced by fit::RootMinuitCommands< Function >::parameter().

◆ pars_

template<class Function >
parameterVector_t fit::RootMinuitCommands< Function >::pars_
private

Definition at line 75 of file RootMinuitCommands.h.

Referenced by fit::RootMinuitCommands< Function >::parameter().

◆ verbose_

template<class Function >
bool fit::RootMinuitCommands< Function >::verbose_
private

Definition at line 73 of file RootMinuitCommands.h.