CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

fit::RootMinuit< Function > Class Template Reference

#include <RootMinuit.h>

List of all members.

Public Member Functions

void addParameter (const std::string &name, boost::shared_ptr< double > val, double err, double min, double max)
void addParameter (const funct::Parameter &par, double err, double min, double max)
void fixParameter (const std::string &name)
template<unsigned int N>
void getErrorMatrix (ROOT::Math::SMatrix< double, N, N, ROOT::Math::MatRepSym< double, N > > &err)
double getParameter (const std::string &name, double &err)
double getParameter (const std::string &name)
double getParameterError (const std::string &name, double &val)
double getParameterError (const std::string &name)
double migrad ()
double minimize ()
double minValue ()
int numberOfFreeParameters ()
int numberOfParameters ()
void printFitResults (std::ostream &cout=std::cout)
void printParameters (std::ostream &cout=std::cout)
void releaseParameter (const std::string &name)
 RootMinuit (Function f, bool verbose=false)
void setParameter (const std::string &name, double val)
void setParameters ()

Private Member Functions

void init ()
size_t parameterIndex (const std::string &name) const

Static Private Member Functions

static void fcn_ (int &, double *, double &f, double *par, int)

Private Attributes

bool initialized_
std::auto_ptr< TMinuit > minuit_
double minValue_
std::map< std::string, size_t > parIndices_
parameterVector_t parMap_
std::vector< boost::shared_ptr
< double > > 
pars_
bool verbose_

Static Private Attributes

static Function f_
static std::vector
< boost::shared_ptr< double > > * 
fPars_ = 0

Detailed Description

template<class Function>
class fit::RootMinuit< Function >

Definition at line 21 of file RootMinuit.h.


Constructor & Destructor Documentation

template<class Function>
fit::RootMinuit< Function >::RootMinuit ( Function  f,
bool  verbose = false 
) [inline]

Definition at line 23 of file RootMinuit.h.

References f, and fit::RootMinuit< Function >::f_.

                                                 : 
      initialized_(false), minValue_(0), verbose_(verbose) { 
      f_ = f;
    }

Member Function Documentation

template<class Function>
void fit::RootMinuit< Function >::addParameter ( const std::string &  name,
boost::shared_ptr< double >  val,
double  err,
double  min,
double  max 
) [inline]
template<class Function>
void DropBoxMetadata::Parameters::addParameter ( const funct::Parameter par,
double  err,
double  min,
double  max 
) [inline]

Definition at line 43 of file RootMinuit.h.

References fit::RootMinuit< Function >::addParameter(), max(), min, and funct::Parameter::name().

                                                                                      {
      return addParameter(par.name(), par, err, min, max);
    }
template<class Function>
static void fit::RootMinuit< Function >::fcn_ ( int &  ,
double *  ,
double &  f,
double *  par,
int   
) [inline, static, private]

Definition at line 189 of file RootMinuit.h.

References fit::RootMinuit< Function >::f_, fit::RootMinuit< Function >::fPars_, i, and findQualityFiles::size.

Referenced by fit::RootMinuit< Function >::init().

                                                                   {
      size_t size = fPars_->size();
      for(size_t i = 0; i < size; ++i) 
        *((*fPars_)[i]) = par[i];
      f = RootMinuitFuncEvaluator<Function>::evaluate(f_);
    }
template<class Function>
void fit::RootMinuit< Function >::fixParameter ( const std::string &  name) [inline]
template<class Function>
template<unsigned int N>
void fit::RootMinuit< Function >::getErrorMatrix ( ROOT::Math::SMatrix< double, N, N, ROOT::Math::MatRepSym< double, N > > &  err) [inline]

Definition at line 71 of file RootMinuit.h.

References edm::errors::Configuration, alignCSCRings::e, Exception, i, fit::RootMinuit< Function >::init(), j, fit::RootMinuit< Function >::minuit_, N, fit::RootMinuit< Function >::numberOfParameters(), and fit::RootMinuit< Function >::setParameters().

                                                                                            {
      init();
      if(N != numberOfParameters())
        throw edm::Exception(edm::errors::Configuration)
          << "RootMinuit: can't call getErrorMatrix passing an SMatrix of dimension " << N
          << " while the number of parameters is " << numberOfParameters() << "\n";
      double * e = new double[N*N];
      minuit_->mnemat(e, numberOfParameters());
      for(size_t i = 0; i < N; ++i) {
        for(size_t j = 0; j <= i; ++j) {
          err(i, j) = e[i + N*j];
        }
      }
      delete [] e;
      setParameters();
    }
template<class Function>
string DropBoxMetadata::Parameters::getParameter ( const std::string &  name) [inline]

Definition at line 52 of file RootMinuit.h.

References fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().

                                                {
      double val, err;
      init();
      minuit_->GetParameter(parameterIndex(name), val, err);
      return val;
    }
template<class Function>
double fit::RootMinuit< Function >::getParameter ( const std::string &  name,
double &  err 
) [inline]

Definition at line 46 of file RootMinuit.h.

References fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().

                                                              {
      double val;
      init();
      minuit_->GetParameter(parameterIndex(name), val, err);
      return val;
    }
template<class Function>
double fit::RootMinuit< Function >::getParameterError ( const std::string &  name,
double &  val 
) [inline]
template<class Function>
double fit::RootMinuit< Function >::getParameterError ( const std::string &  name) [inline]

Definition at line 64 of file RootMinuit.h.

References fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::parameterIndex().

                                                     {
      double val, err;
      init();
      minuit_->GetParameter(parameterIndex(name), val, err);
      return err;
    }
template<class Function>
void fit::RootMinuit< Function >::init ( void  ) [inline, private]

Definition at line 202 of file RootMinuit.h.

References fitWZ::arglist, edm::errors::Configuration, end, fit::parameter_t::err, Exception, fit::RootMinuit< Function >::fcn_(), fit::RootMinuit< Function >::fPars_, i, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuit< Function >::minuit_, mergeVDriftHistosByStation::name, AlCaHLTBitMon_ParallelJobs::p, fit::RootMinuit< Function >::parMap_, fit::RootMinuit< Function >::pars_, AlCaHLTBitMon_QueryRunRegistry::string, fit::parameter_t::val, and fit::RootMinuit< Function >::verbose_.

Referenced by fit::RootMinuit< Function >::getErrorMatrix(), fit::RootMinuit< Function >::getParameter(), fit::RootMinuit< Function >::getParameterError(), fit::RootMinuit< Function >::migrad(), fit::RootMinuit< Function >::minimize(), fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::numberOfFreeParameters(), and fit::RootMinuit< Function >::numberOfParameters().

                {
      if(initialized_) return;
      minuit_.reset(new TMinuit(parMap_.size()));
      double arglist[10];
      int ierflg = 0;      
      if (! verbose_) {
        arglist[0] = -1;
        minuit_->mnexcm("SET PRINT", arglist, 1, ierflg); 
        if (ierflg != 0) 
          throw edm::Exception(edm::errors::Configuration)
            << "RootMinuit: error in calling SET PRINT\n";
      }     
      arglist[0] = 1;
      minuit_->mnexcm("SET ERR", arglist, 1, ierflg);
      if (ierflg != 0) 
        throw edm::Exception(edm::errors::Configuration)
          << "RootMinuit: error in calling SET ERR\n";

      size_t i = 0;
      typename parameterVector_t::const_iterator p = parMap_.begin(), end = parMap_.end();
      for(; p != end; ++p, ++i) {
        const std::string & name = p->first;
        const parameter_t & par = p->second;
        minuit_->mnparm(i, name, par.val, par.err, par.min, par.max, ierflg);
        if(ierflg != 0)
          throw edm::Exception(edm::errors::Configuration)
            << "RootMinuit: error in setting parameter " << i 
            << " value = " << par.val << " error = " << par.err
            << " range = [" << par.min << ", " << par.max << "]\n";
      }
      initialized_ = true;
      for(i = 0, p = parMap_.begin(); p != end; ++p, ++i)
        if(p->second.fixed)
          minuit_->FixParameter(i);
      fPars_= & pars_; 
      minuit_->SetFCN(fcn_);
    }
template<class Function>
double fit::RootMinuit< Function >::migrad ( ) [inline]

Definition at line 146 of file RootMinuit.h.

References fitWZ::arglist, dtNoiseDBValidation_cfg::cerr, fit::RootMinuit< Function >::init(), m, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::setParameters(), and fit::RootMinuit< Function >::verbose_.

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

                    {
      init();
      double arglist[10];
      arglist[0] = 5000;
      arglist[1] = 0.1;
      int ierflag;
      minuit_->mnexcm("MIGRAD", arglist, 2, ierflag);
      if ( ierflag != 0 ) std::cerr << "ERROR in migrad!!" << std::endl;
      if(verbose_) minuit_->mnmatu(1); //Prints the covariance matrix
      double m = minValue();
      if(verbose_) minuit_->mnprin(3, m);
      setParameters();
      return m;
    }
template<class Function>
double fit::RootMinuit< Function >::minimize ( ) [inline]

Definition at line 132 of file RootMinuit.h.

References fitWZ::arglist, dtNoiseDBValidation_cfg::cerr, fit::RootMinuit< Function >::init(), m, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::setParameters(), and fit::RootMinuit< Function >::verbose_.

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

                      {
      init();
      double arglist[10];
      arglist[0] = 5000;
      arglist[1] = 0.1;
      int ierflag;
      minuit_->mnexcm("MINIMIZE", arglist, 2, ierflag);
      if ( ierflag != 0 ) std::cerr << "ERROR in minimize!!" << std::endl;
      if(verbose_) minuit_->mnmatu(1); //Prints the covariance matrix
      double m = minValue();
      if(verbose_) minuit_->mnprin(3, m);
      setParameters();
      return m;
    }
template<class Function>
double fit::RootMinuit< Function >::minValue ( ) [inline]

Definition at line 160 of file RootMinuit.h.

References fit::RootMinuit< Function >::init(), fit::RootMinuit< Function >::minuit_, and fit::RootMinuit< Function >::minValue_.

Referenced by fit::RootMinuit< Function >::migrad(), fit::RootMinuit< Function >::minimize(), and fit::RootMinuit< Function >::printFitResults().

                      {
      init();
      int ierflag;
      double edm, errdef;
      int nvpar, nparx;
      minuit_->mnstat(minValue_, edm, errdef, nvpar, nparx, ierflag);
      return minValue_;
    }
template<class Function>
int fit::RootMinuit< Function >::numberOfFreeParameters ( ) [inline]

Definition at line 128 of file RootMinuit.h.

References fit::RootMinuit< Function >::init(), and fit::RootMinuit< Function >::minuit_.

Referenced by fit::RootMinuit< Function >::printFitResults().

                                 { 
      init();
      return minuit_->GetNumFreePars();
    }
template<class Function>
int fit::RootMinuit< Function >::numberOfParameters ( ) [inline]

Definition at line 124 of file RootMinuit.h.

References fit::RootMinuit< Function >::init(), and fit::RootMinuit< Function >::minuit_.

Referenced by fit::RootMinuit< Function >::getErrorMatrix().

                             { 
      init();
      return minuit_->GetNumPars();
    }
template<class Function>
size_t fit::RootMinuit< Function >::parameterIndex ( const std::string &  name) const [inline, private]
template<class Function>
void fit::RootMinuit< Function >::printFitResults ( std::ostream &  cout = std::cout) [inline]
template<class Function>
void fit::RootMinuit< Function >::printParameters ( std::ostream &  cout = std::cout) [inline]

Definition at line 168 of file RootMinuit.h.

References gather_cfg::cout, end, fit::RootMinuit< Function >::getParameterError(), i, fit::RootMinuit< Function >::parIndices_, and fit::RootMinuit< Function >::pars_.

Referenced by fit::RootMinuit< Function >::printFitResults().

                                                     {
      std::map<std::string, size_t>::const_iterator i = parIndices_.begin(), end = parIndices_.end();
      for(; i != end; ++i) {
        cout << i->first << " = " << *pars_[i->second] 
             << " +/- " << getParameterError(i->first) << std::endl;
      }
    }
template<class Function>
void fit::RootMinuit< Function >::releaseParameter ( const std::string &  name) [inline]
template<class Function>
void fit::RootMinuit< Function >::setParameter ( const std::string &  name,
double  val 
) [inline]

Definition at line 101 of file RootMinuit.h.

References edm::errors::Configuration, fit::parameter_t::err, Exception, i, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parameterIndex(), fit::RootMinuit< Function >::parMap_, and fit::parameter_t::val.

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

                                                          {
      size_t i = parameterIndex(name);
      parameter_t & par = parMap_[i].second;
      par.val = val;
      if(initialized_) {
        int ierflg = 0;      
        minuit_->mnparm(i, name, par.val, par.err, par.min, par.max, ierflg);
        if(ierflg != 0)
          throw edm::Exception(edm::errors::Configuration)
            << "RootMinuit: error in setting parameter " << i 
            << " value = " << par.val << " error = " << par.err
            << " range = [" << par.min << ", " << par.max << "]\n";
      }
    }
template<class Function>
void fit::RootMinuit< Function >::setParameters ( ) [inline]

Definition at line 115 of file RootMinuit.h.

References end, i, getHLTprescales::index, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parIndices_, and fit::RootMinuit< Function >::pars_.

Referenced by fit::RootMinuit< Function >::getErrorMatrix(), fit::RootMinuit< Function >::migrad(), and fit::RootMinuit< Function >::minimize().

                         {
      std::map<std::string, size_t>::const_iterator i = parIndices_.begin(), end = parIndices_.end();
      double val, err;
      for(; i != end; ++i) {
        size_t index = i->second;
        minuit_->GetParameter(index, val, err);
        *pars_[index] = val;
      }
    }

Member Data Documentation

template<class Function>
Function fit::RootMinuit< Function >::f_ [static, private]
template<class Function>
std::vector< boost::shared_ptr< double > > * fit::RootMinuit< Function >::fPars_ = 0 [static, private]
template<class Function>
bool fit::RootMinuit< Function >::initialized_ [private]
template<class Function>
std::auto_ptr<TMinuit> fit::RootMinuit< Function >::minuit_ [private]
template<class Function>
double fit::RootMinuit< Function >::minValue_ [private]

Definition at line 183 of file RootMinuit.h.

Referenced by fit::RootMinuit< Function >::minValue().

template<class Function>
std::map<std::string, size_t> fit::RootMinuit< Function >::parIndices_ [private]
template<class Function>
parameterVector_t fit::RootMinuit< Function >::parMap_ [private]
template<class Function>
std::vector<boost::shared_ptr<double> > fit::RootMinuit< Function >::pars_ [private]
template<class Function>
bool fit::RootMinuit< Function >::verbose_ [private]