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 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.

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(), fit::RootMinuitCommand::name, findQualityFiles::run, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by counter.Counter::register().

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.

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 MillePedeFileConverter_cfg::out.

109  {
110  std::ostringstream out;
111  out << "RootMinuitCommands config. error, line " << lineNumber_<< ": ";
112  return out.str();
113  }
template<class Function >
bool fit::RootMinuitCommands< Function >::fixed ( const std::string &  name)
inline

Definition at line 72 of file RootMinuitCommands.h.

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 cmsBenchmark::cmssw_base, cmsBenchmark::cmssw_release_base, TrackerTrackHitFilter_cff::commands, edm::errors::Configuration, gather_cfg::cout, edmIntegrityCheck::d, fit::RootMinuitCommand::doubleArgs, MillePedeFileConverter_cfg::e, fit::parameter_t::err, Exception, f, FrontierConditions_GlobalTag_cff::file, fit::parameter_t::fixed, alignBH_cfg::fixed, mps_fire::i, join(), kFix, kMigrad, kMinimize, kParameter, kPrintAll, kRelease, kSet, plotBeamSpotDB::last, mps_splice::line, fit::parameter_t::max, fit::parameter_t::min, eostools::move(), fit::RootMinuitCommand::name, fit::RootMinuitCommand::print(), alignCSCRings::s, fit::RootMinuitCommand::stringArgs, and fit::parameter_t::val.

125  {
126  using namespace std;
127  string cmssw_release_base = getenv("CMSSW_RELEASE_BASE");
128  string cmssw_base = getenv("CMSSW_BASE");
129  vector<string> directories;
130  directories.reserve(3);
131  directories.emplace_back(".");
132  if(!cmssw_release_base.empty()) {
133  directories.emplace_back(cmssw_release_base + "/src");
134  }
135  if(!cmssw_base.empty()) {
136  directories.emplace_back(cmssw_base + "/src");
137  }
138  ifstream file;
139  for(auto const& d: directories) {
140  std::ifstream f{ d+"/"+fileName };
141  if(f.good()) {
142  file = std::move(f);
143  break;
144  }
145  }
146  if(!file.is_open()) {
148  << "RootMinuitCommands: can't open file: " << fileName
149  << " in path: " << boost::algorithm::join(directories,":") << "\n";
150  }
151  if (verbose_)
152  cout << ">>> configuration file: " << fileName << endl;
153  string line;
154  lineNumber_ = 0;
155  bool commands = false;
156  while(getline(file, line)) {
157  ++lineNumber_;
158  if(line.size()==0) continue;
159  char last = *line.rbegin();
160  if(!(last >= '0' && last <= 'z')) line.erase(line.end() - 1);
161  boost::char_separator<char> sep(" ");
162  tokenizer tokens(line, sep);
163  tokenizer::iterator i = tokens.begin(), e = tokens.end();
164  if(tokens.begin()==tokens.end()) continue;
165  if(*(i->begin()) != '#') {
166  if(*i == kParameter) {
167  if(commands)
169  << errorHeader()
170  << "please, declare all parameter before all other minuit commands.\n";
171  string name = nextToken(i, e);
172  parameter_t par;
173  par.val = string2double(nextToken(i, e));
174  par.err = string2double(nextToken(i, e));
175  par.min = string2double(nextToken(i, e));
176  par.max = string2double(nextToken(i, e));
177  tokenizer::iterator j = i; ++j;
178  if(j != e) {
179  string fixed = nextToken(i, e);
180  if(fixed == "fixed")
181  par.fixed = true;
182  else if(fixed == "free")
183  par.fixed = false;
184  else
186  << errorHeader()
187  << "fix parameter option unknown: " << *i << "\n"
188  << "valid options are: fixed, free.\n";
189  } else {
190  par.fixed = false;
191  }
192  pars_.push_back(std::make_pair(name, par));
193  size_t s = parIndices_.size();
194  parIndices_[name] = s;
195  if(verbose_)
196  cout << ">>> " << kParameter << " " << name
197  << " " << par.val
198  << " [" << par.min << ", " << par.max << "],"
199  << " err: " << par.err
200  << endl;
201  } else if(*i == kFix || *i == kRelease) {
202  commands = true;
203  command com;
204  com.name = *i;
205  string arg = nextToken(i, e);
206  com.stringArgs.push_back(arg);
207  commands_.push_back(com);
208  if(verbose_) {
209  cout << ">>> "; com.print(cout); cout << endl;
210  }
211  } else if(*i == kSet) {
212  commands = true;
213  command com;
214  com.name = *i;
215  string arg = nextToken(i, e);
216  com.stringArgs.push_back(arg);
217  com.doubleArgs.push_back(string2double(nextToken(i, e)));
218  commands_.push_back(com);
219  if(verbose_) {
220  cout << ">>> "; com.print(cout); cout << endl;
221  }
222  } else if(*i == kMinimize || *i == kMigrad || *i == kPrintAll) {
223  commands = true;
224  command com;
225  com.name = *i;
226  commands_.push_back(com);
227  if(verbose_) {
228  cout << ">>> "; com.print(cout); cout << endl;
229  }
230  } else {
232  << errorHeader()
233  << "unkonwn command:: " << *i << "\n";
234 
235  }
236  }
237  }
238  if (verbose_)
239  cout << ">>> end configuration" << endl;
240  }
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:37
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
const char * kFix
commands
min number of hits for refit layers to remove
double f[11][100]
const char * kPrintAll
double string2double(const std::string &str) const
std::map< std::string, size_t > parIndices_
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
const char * kMigrad
const char * kRelease
RootMinuitCommand command
const char * kMinimize
def move(src, dest)
Definition: eostools.py:511
template<class Function >
double fit::RootMinuitCommands< Function >::max ( const std::string &  name)
inline

Definition at line 69 of file RootMinuitCommands.h.

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.

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, Exception, and mps_fire::i.

115  {
116  ++i;
117  if(i == end)
119  << errorHeader() << "missing parameter\n";
120  return *i;
121  }
std::string errorHeader() const
#define end
Definition: vmac.h:39
template<class Function >
double fit::RootMinuitCommands< Function >::par ( const std::string &  name)
inline

Definition at line 60 of file RootMinuitCommands.h.

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

Definition at line 102 of file RootMinuitCommands.h.

References edm::errors::Configuration, and AlCaHLTBitMon_ParallelJobs::p.

102  {
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;
108  }
std::map< std::string, size_t > parIndices_
template<typename Function >
void fit::RootMinuitCommands< Function >::run ( RootMinuit< Function > &  minuit) const

Definition at line 243 of file RootMinuitCommands.h.

References EnergyCorrector::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().

243  {
244  using namespace std;
245  typename vector<command>::const_iterator c = commands_.begin(), end = commands_.end();
246  for(; c != end; ++c) {
247  if(verbose_) {
248  cout << ">>> minuit command: ";
249  c->print(cout);
250  cout << endl;
251  }
252  if(c->name == kMinimize)
253  minuit.minimize();
254  else if(c->name == kMigrad)
255  minuit.migrad();
256  else if(c->name == kPrintAll)
257  minuit.printFitResults();
258  else if(c->name == kFix)
259  minuit.fixParameter(c->stringArgs[0]);
260  else if(c->name == kRelease)
261  minuit.releaseParameter(c->stringArgs[0]);
262  else if(c->name == kSet)
263  minuit.setParameter(c->stringArgs[0], c->doubleArgs[0]);
264  }
265  }
std::vector< command > commands_
const char * kSet
const char * kFix
const char * kPrintAll
#define end
Definition: vmac.h:39
const char * kMigrad
const char * kRelease
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, Exception, alignCSCRings::s, and heppy_batch::val.

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:39
#define begin
Definition: vmac.h:32
#define str(s)

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

Definition at line 86 of file RootMinuitCommands.h.

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

Definition at line 88 of file RootMinuitCommands.h.

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

Definition at line 87 of file RootMinuitCommands.h.

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

Definition at line 85 of file RootMinuitCommands.h.