CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 48 of file RootMinuitCommands.h.

Member Typedef Documentation

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

Definition at line 51 of file RootMinuitCommands.h.

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

Definition at line 50 of file RootMinuitCommands.h.

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

Definition at line 84 of file RootMinuitCommands.h.

Constructor & Destructor Documentation

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

Definition at line 52 of file RootMinuitCommands.h.

52  :
53  verbose_(verbose) {
54  }
template<class Function >
fit::RootMinuitCommands< Function >::RootMinuitCommands ( const char *  fileName,
bool  verbose = true 
)
inline

Member Function Documentation

template<class Function >
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().

75  {
76  const std::string & name = p.name();
77  const parameter_t & par = parameter(name);
78  minuit.addParameter(p, par.err, par.min, par.max);
79  if(par.fixed) minuit.fixParameter(name);
80  }
const std::string & name() const
Definition: Parameter.h:13
double par(const std::string &name)
const parameter_t & parameter(const std::string &name) const
RootMinuit< Function > minuit
template<class Function >
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().

63  {
64  return parameter(name).err;
65  }
const parameter_t & parameter(const std::string &name) const
template<class Function >
std::string fit::RootMinuitCommands< Function >::errorHeader ( ) const
inlineprivate

Definition at line 109 of file RootMinuitCommands.h.

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

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

109  {
110  std::ostringstream out;
111  out << "RootMinuitCommands config. error, line " << lineNumber_<< ": ";
112  return out.str();
113  }
tuple out
Definition: dbtoconf.py:99
template<class Function >
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().

72  {
73  return parameter(name).fixed;
74  }
const parameter_t & parameter(const std::string &name) const
template<typename Function >
void fit::RootMinuitCommands< Function >::init ( const char *  fileName)

Definition at line 125 of file RootMinuitCommands.h.

References launcher::cmssw_base, cmsBenchmark::cmssw_release_base, edm::errors::Configuration, gather_cfg::cout, fit::RootMinuitCommand::doubleArgs, alignCSCRings::e, fit::parameter_t::err, edm::hlt::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, scaleCards::path, fit::RootMinuitCommand::print(), alignCSCRings::s, fit::RootMinuitCommand::stringArgs, and fit::parameter_t::val.

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

125  {
126  using namespace std;
127  string cmssw_release_base = getenv("CMSSW_RELEASE_BASE");
128  string cmssw_base = getenv("CMSSW_BASE");
129  string path = ".";
130  if(!cmssw_release_base.empty()) {
131  path += ':';
132  path += (cmssw_release_base + "/src");
133  }
134  if(!cmssw_base.empty()) {
135  path += ':';
136  path += (cmssw_base + "/src");
137  }
138  FileInPath fileInPath(path, fileName);
139  ifstream * file = fileInPath();
140  if(file==0 || !file->is_open())
142  << "RootMinuitCommands: can't open file: " << fileName
143  << " in path: " << path << "\n";
144  if (verbose_)
145  cout << ">>> configuration file: " << fileName << endl;
146  string line;
147  lineNumber_ = 0;
148  bool commands = false;
149  while(getline(*file, line)) {
150  ++lineNumber_;
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(" ");
155  tokenizer tokens(line, sep);
156  tokenizer::iterator i = tokens.begin(), e = tokens.end();
157  if(tokens.begin()==tokens.end()) continue;
158  if(*(i->begin()) != '#') {
159  if(*i == kParameter) {
160  if(commands)
162  << errorHeader()
163  << "please, declare all parameter before all other minuit commands.\n";
164  string name = nextToken(i, e);
165  parameter_t par;
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;
171  if(j != e) {
172  string fixed = nextToken(i, e);
173  if(fixed == "fixed")
174  par.fixed = true;
175  else if(fixed == "free")
176  par.fixed = false;
177  else
179  << errorHeader()
180  << "fix parameter option unknown: " << *i << "\n"
181  << "valid options are: fixed, free.\n";
182  } else {
183  par.fixed = false;
184  }
185  pars_.push_back(std::make_pair(name, par));
186  size_t s = parIndices_.size();
187  parIndices_[name] = s;
188  if(verbose_)
189  cout << ">>> " << kParameter << " " << name
190  << " " << par.val
191  << " [" << par.min << ", " << par.max << "],"
192  << " err: " << par.err
193  << endl;
194  } else if(*i == kFix || *i == kRelease) {
195  commands = true;
196  command com;
197  com.name = *i;
198  string arg = nextToken(i, e);
199  com.stringArgs.push_back(arg);
200  commands_.push_back(com);
201  if(verbose_) {
202  cout << ">>> "; com.print(cout); cout << endl;
203  }
204  } else if(*i == kSet) {
205  commands = true;
206  command com;
207  com.name = *i;
208  string arg = nextToken(i, e);
209  com.stringArgs.push_back(arg);
210  com.doubleArgs.push_back(string2double(nextToken(i, e)));
211  commands_.push_back(com);
212  if(verbose_) {
213  cout << ">>> "; com.print(cout); cout << endl;
214  }
215  } else if(*i == kMinimize || *i == kMigrad || *i == kPrintAll) {
216  commands = true;
217  command com;
218  com.name = *i;
219  commands_.push_back(com);
220  if(verbose_) {
221  cout << ">>> "; com.print(cout); cout << endl;
222  }
223  } else {
225  << errorHeader()
226  << "unkonwn command:: " << *i << "\n";
227 
228  }
229  }
230  }
231  if (verbose_)
232  cout << ">>> end configuration" << endl;
233  }
int i
Definition: DBlmapReader.cc:9
std::string errorHeader() const
boost::tokenizer< boost::char_separator< char > > tokenizer
double par(const std::string &name)
std::vector< command > commands_
A arg
Definition: Factorize.h:36
std::string nextToken(typename tokenizer::iterator &i, const typename tokenizer::iterator &end) const
bool fixed(const std::string &name)
const char * kSet
const char * kParameter
list path
Definition: scaleCards.py:51
const char * kFix
int j
Definition: DBlmapReader.cc:9
const char * kPrintAll
double string2double(const std::string &str) const
std::map< std::string, size_t > parIndices_
const char * kMigrad
list cmssw_release_base
Definition: cmsBenchmark.py:61
const char * kRelease
RootMinuitCommand command
tuple cout
Definition: gather_cfg.py:121
const char * kMinimize
list cmssw_base
Definition: launcher.py:19
template<class Function >
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().

69  {
70  return parameter(name).max;
71  }
const parameter_t & parameter(const std::string &name) const
template<class Function >
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().

66  {
67  return parameter(name).min;
68  }
const parameter_t & parameter(const std::string &name) const
template<class Function >
std::string fit::RootMinuitCommands< Function >::nextToken ( typename tokenizer::iterator &  i,
const typename tokenizer::iterator &  end 
) const
inlineprivate

Definition at line 114 of file RootMinuitCommands.h.

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

115  {
116  ++i;
117  if(i == end)
119  << errorHeader() << "missing parameter\n";
120  return *i;
121  }
int i
Definition: DBlmapReader.cc:9
std::string errorHeader() const
#define end
Definition: vmac.h:38
template<class Function >
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().

60  {
61  return parameter(name).val;
62  }
const parameter_t & parameter(const std::string &name) const
template<class Function >
const parameter_t& fit::RootMinuitCommands< Function >::parameter ( const std::string &  name) const
inlineprivate
template<typename Function >
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().

236  {
237  using namespace std;
238  typename vector<command>::const_iterator c = commands_.begin(), end = commands_.end();
239  for(; c != end; ++c) {
240  if(verbose_) {
241  cout << ">>> minuit command: ";
242  c->print(cout);
243  cout << endl;
244  }
245  if(c->name == kMinimize)
246  minuit.minimize();
247  else if(c->name == kMigrad)
248  minuit.migrad();
249  else if(c->name == kPrintAll)
250  minuit.printFitResults();
251  else if(c->name == kFix)
252  minuit.fixParameter(c->stringArgs[0]);
253  else if(c->name == kRelease)
254  minuit.releaseParameter(c->stringArgs[0]);
255  else if(c->name == kSet)
256  minuit.setParameter(c->stringArgs[0], c->doubleArgs[0]);
257  }
258  }
std::vector< command > commands_
const char * kSet
const char * kFix
const char * kPrintAll
#define end
Definition: vmac.h:38
const char * kMigrad
const char * kRelease
tuple cout
Definition: gather_cfg.py:121
RootMinuit< Function > minuit
const char * kMinimize
template<class Function >
double fit::RootMinuitCommands< Function >::string2double ( const std::string &  str) const
inlineprivate

Definition at line 90 of file RootMinuitCommands.h.

References begin, edm::errors::Configuration, end, edm::hlt::Exception, and alignCSCRings::s.

90  {
91  const char * begin = str.c_str();
92  char * end;
93  double val = strtod(begin, &end);
94  size_t s = end - begin;
95  if(s < str.size()) {
97  << "RootMinuitCommands: invalid double value: "
98  << str << "\n";
99  }
100  return val;
101  }
#define end
Definition: vmac.h:38
#define begin
Definition: vmac.h:31

Member Data Documentation

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

Definition at line 89 of file RootMinuitCommands.h.

template<class Function >
unsigned int fit::RootMinuitCommands< Function >::lineNumber_
private
template<class Function >
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().

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

Definition at line 87 of file RootMinuitCommands.h.

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

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

Definition at line 85 of file RootMinuitCommands.h.