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.

54 : verbose_(verbose) {}

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

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

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

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

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

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  }

References runTheMatrix::cmssw_base, tkAlTrackRefitSequence_cff::commands, edm::errors::Configuration, gather_cfg::cout, ztail::d, fit::RootMinuitCommand::doubleArgs, MillePedeFileConverter_cfg::e, fit::parameter_t::err, Exception, f, FrontierConditions_GlobalTag_cff::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(), Skims_PA_cff::name, fit::RootMinuitCommand::name, fit::RootMinuitCommand::print(), alignCSCRings::s, fit::RootMinuitCommand::stringArgs, and fit::parameter_t::val.

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

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

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

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

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

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  }

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

◆ string2double()

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

Definition at line 78 of file RootMinuitCommands.h.

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  }

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

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.

kMigrad
const char * kMigrad
Definition: RootMinuitCommands.h:21
mps_fire.i
i
Definition: mps_fire.py:355
kSet
const char * kSet
Definition: RootMinuitCommands.h:19
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
fit::RootMinuitCommands::tokenizer
boost::tokenizer< boost::char_separator< char > > tokenizer
Definition: RootMinuitCommands.h:72
fit::RootMinuitCommands::pars_
parameterVector_t pars_
Definition: RootMinuitCommands.h:75
kParameter
const char * kParameter
Definition: RootMinuitCommands.h:16
fit::RootMinuitCommands::parameter
const parameter_t & parameter(const std::string &name) const
Definition: RootMinuitCommands.h:88
tkAlTrackRefitSequence_cff.commands
commands
Definition: tkAlTrackRefitSequence_cff.py:14
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
fit::parameter_t::val
double val
Definition: ParameterMap.h:9
gather_cfg.cout
cout
Definition: gather_cfg.py:144
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
kMinimize
const char * kMinimize
Definition: RootMinuitCommands.h:20
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
runTheMatrix.cmssw_base
cmssw_base
Definition: runTheMatrix.py:296
end
#define end
Definition: vmac.h:39
edm::Exception
Definition: EDMException.h:77
fit::RootMinuitCommands::minuit
RootMinuit< Function > minuit
Definition: RootMinuitCommands.h:52
alignCSCRings.s
s
Definition: alignCSCRings.py:92
dqmdumpme.last
last
Definition: dqmdumpme.py:56
fit::RootMinuitCommands::commands_
std::vector< command > commands_
Definition: RootMinuitCommands.h:77
fit::parameter_t::max
double max
Definition: ParameterMap.h:9
fit::RootMinuitCommands::nextToken
std::string nextToken(typename tokenizer::iterator &i, const typename tokenizer::iterator &end) const
Definition: RootMinuitCommands.h:99
str
#define str(s)
Definition: TestProcessor.cc:48
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
fit::RootMinuitCommands::lineNumber_
unsigned int lineNumber_
Definition: RootMinuitCommands.h:74
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fit::RootMinuitCommands::fixed
bool fixed(const std::string &name)
Definition: RootMinuitCommands.h:61
fit::RootMinuitCommands::parIndices_
std::map< std::string, size_t > parIndices_
Definition: RootMinuitCommands.h:76
kRelease
const char * kRelease
Definition: RootMinuitCommands.h:18
fit::RootMinuitCommands::par
double par(const std::string &name)
Definition: RootMinuitCommands.h:57
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
fit::RootMinuitCommands::init
void init(const char *fileName)
Definition: RootMinuitCommands.h:108
fit::RootMinuitCommands::string2double
double string2double(const std::string &str) const
Definition: RootMinuitCommands.h:78
fit::parameter_t::err
double err
Definition: ParameterMap.h:9
fit::RootMinuitCommands::command
RootMinuitCommand command
Definition: RootMinuitCommands.h:53
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
fit::RootMinuitCommand::name
std::string name
Definition: RootMinuitCommands.h:27
kFix
const char * kFix
Definition: RootMinuitCommands.h:17
Exception
Definition: hltDiff.cc:246
kPrintAll
const char * kPrintAll
Definition: RootMinuitCommands.h:22
fit::parameter_t::min
double min
Definition: ParameterMap.h:9
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
fit::parameter_t::fixed
bool fixed
Definition: ParameterMap.h:10
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
funct::arg
A arg
Definition: Factorize.h:36
ztail.d
d
Definition: ztail.py:151
fit::RootMinuitCommands::verbose_
bool verbose_
Definition: RootMinuitCommands.h:73
fit::RootMinuitCommands::errorHeader
std::string errorHeader() const
Definition: RootMinuitCommands.h:94
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
mps_splice.line
line
Definition: mps_splice.py:76
edm::errors::Configuration
Definition: EDMException.h:36
begin
#define begin
Definition: vmac.h:32
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37