CMS 3D CMS Logo

Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes

fit::RootMinuitCommands< Function > Class Template Reference

#include <RootMinuitCommands.h>

List of all members.

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 (const char *fileName, bool verbose=true)
 RootMinuitCommands (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.

                                            :
      verbose_(verbose) {
    }
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]
template<class Function >
double fit::RootMinuitCommands< Function >::err ( const std::string &  name) [inline]
template<class Function >
std::string fit::RootMinuitCommands< Function >::errorHeader ( ) const [inline, private]

Definition at line 109 of file RootMinuitCommands.h.

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

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

                                  {
      std::ostringstream out;
      out << "RootMinuitCommands config. error, line " << lineNumber_<< ": ";
      return out.str();
    }
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().

                                      {
      return parameter(name).fixed;
    }   
template<typename Function >
void fit::RootMinuitCommands< Function >::init ( const char *  fileName)

Definition at line 125 of file RootMinuitCommands.h.

References cmsCodeRulesChecker::arg, launcher::cmssw_base, cmsBenchmark::cmssw_release_base, edm::errors::Configuration, gather_cfg::cout, fit::RootMinuitCommand::doubleArgs, fit::parameter_t::err, 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, Gflash::par, path(), fit::RootMinuitCommand::print(), asciidump::s, fit::RootMinuitCommand::stringArgs, EcalElecEmulTccFlatFileProducerFromTPG_cfg::tokens, and fit::parameter_t::val.

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

                                                               {
    using namespace std;
    string cmssw_release_base = getenv("CMSSW_RELEASE_BASE");
    string cmssw_base = getenv("CMSSW_BASE");
    string path = "."; 
    if(!cmssw_release_base.empty()) {
      path += ':';
      path += (cmssw_release_base + "/src");
    }
    if(!cmssw_base.empty()) {
      path += ':';
      path += (cmssw_base + "/src");
    }
    FileInPath fileInPath(path, fileName);
    ifstream * file = fileInPath();
    if(file==0 || !file->is_open())
      throw edm::Exception(edm::errors::Configuration)
        << "RootMinuitCommands: can't open file: " << fileName 
        << " in path: " << path << "\n";
    if (verbose_) 
      cout << ">>> configuration file: " << fileName << endl;
    string line;
    lineNumber_ = 0;
    bool commands = false;
    while(getline(*file, line)) {
      ++lineNumber_;
      if(line.size()==0) continue;
      char last = *line.rbegin();
      if(!(last >= '0' && last <= 'z')) line.erase(line.end() - 1);
      boost::char_separator<char> sep(" ");
      tokenizer tokens(line, sep);
      tokenizer::iterator i = tokens.begin(), e = tokens.end();
      if(tokens.begin()==tokens.end()) continue;
      if(*(i->begin()) != '#') {
        if(*i == kParameter) {
          if(commands)
            throw edm::Exception(edm::errors::Configuration)
              << errorHeader() 
              << "please, declare all parameter before all other minuit commands.\n";
          string name = nextToken(i, e);
          parameter_t par;
          par.val = string2double(nextToken(i, e));
          par.err = string2double(nextToken(i, e));
          par.min = string2double(nextToken(i, e));
          par.max = string2double(nextToken(i, e));
          tokenizer::iterator j = i; ++j;
          if(j != e) {
            string fixed = nextToken(i, e);
            if(fixed == "fixed") 
              par.fixed = true;
            else if(fixed == "free")
              par.fixed = false;
            else
              throw edm::Exception(edm::errors::Configuration)
                << errorHeader()
                << "fix parameter option unknown: " << *i << "\n"
                << "valid options are: fixed, free.\n";
          } else {
            par.fixed = false;
          }
          pars_.push_back(std::make_pair(name, par));
          size_t s = parIndices_.size();
          parIndices_[name] = s;
          if(verbose_)
            cout << ">>> " << kParameter << " " << name 
                 << " " << par.val 
                 << " [" << par.min << ", " << par.max << "],"
                 << " err: " << par.err
                 << endl;
        } else if(*i == kFix || *i == kRelease) {
          commands = true;
          command com;
          com.name = *i;
          string arg = nextToken(i, e);
          com.stringArgs.push_back(arg);
          commands_.push_back(com);
          if(verbose_) {
            cout << ">>> "; com.print(cout); cout << endl;
          }
        } else if(*i == kSet) {
          commands = true;
          command com;
          com.name = *i;
          string arg = nextToken(i, e);
          com.stringArgs.push_back(arg);
          com.doubleArgs.push_back(string2double(nextToken(i, e)));
          commands_.push_back(com);
          if(verbose_) {
            cout << ">>> "; com.print(cout); cout << endl;
          }
        } else if(*i == kMinimize || *i == kMigrad || *i == kPrintAll) {
          commands = true;
          command com;
          com.name = *i;
          commands_.push_back(com);
          if(verbose_) {
            cout << ">>> "; com.print(cout); cout << endl;
          }
        } else {
          throw edm::Exception(edm::errors::Configuration)
            << errorHeader()
            << "unkonwn command:: " << *i << "\n";
          
        }
      }
    }
    if (verbose_) 
      cout << ">>> end configuration" << endl;
  }
template<class Function >
double fit::RootMinuitCommands< Function >::max ( const std::string &  name) [inline]
template<class Function >
double fit::RootMinuitCommands< Function >::min ( const std::string &  name) [inline]
template<class Function >
std::string fit::RootMinuitCommands< Function >::nextToken ( typename tokenizer::iterator &  i,
const typename tokenizer::iterator &  end 
) const [inline, private]

Definition at line 114 of file RootMinuitCommands.h.

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

                                                                        {
      ++i;
      if(i == end)
        throw edm::Exception(edm::errors::Configuration)
          << errorHeader() << "missing parameter\n";
      return *i;
    }
template<class Function >
double fit::RootMinuitCommands< Function >::par ( const std::string &  name) [inline]
template<class Function >
const parameter_t& fit::RootMinuitCommands< Function >::parameter ( const std::string &  name) const [inline, private]
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().

                                                                           {
    using namespace std;
    typename vector<command>::const_iterator c = commands_.begin(), end = commands_.end();
    for(; c != end; ++c) {
      if(verbose_) {
        cout << ">>> minuit command: ";
        c->print(cout);
        cout << endl;
      }
      if(c->name == kMinimize)
        minuit.minimize();
      else if(c->name == kMigrad)
        minuit.migrad();
      else if(c->name == kPrintAll)
        minuit.printFitResults();
      else if(c->name == kFix) 
        minuit.fixParameter(c->stringArgs[0]);
      else if(c->name == kRelease) 
        minuit.releaseParameter(c->stringArgs[0]);
      else if(c->name == kSet)
        minuit.setParameter(c->stringArgs[0], c->doubleArgs[0]);
    }
  }
template<class Function >
double fit::RootMinuitCommands< Function >::string2double ( const std::string &  str) const [inline, private]

Definition at line 90 of file RootMinuitCommands.h.

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

                                                      {
      const char * begin = str.c_str();
      char * end;
      double val = strtod(begin, &end);
      size_t s = end - begin;
      if(s < str.size()) {
        throw edm::Exception(edm::errors::Configuration)
          << "RootMinuitCommands: invalid double value: " 
          << str  << "\n";
      }
      return val;
    }

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.