CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
fit::RootMinuit< Function > Class Template Reference

#include <RootMinuit.h>

Public Member Functions

void addParameter (const funct::Parameter &par, double err, double min, double max)
 
void addParameter (const std::string &name, std::shared_ptr< double > val, 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 getParameter (const std::string &name, double &err)
 
double getParameterError (const std::string &name)
 
double getParameterError (const std::string &name, double &val)
 
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 (const 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::unique_ptr< TMinuit > minuit_
 
double minValue_
 
std::map< std::string, size_t > parIndices_
 
parameterVector_t parMap_
 
std::vector< std::shared_ptr< double > > pars_
 
bool verbose_
 

Static Private Attributes

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

Detailed Description

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

Definition at line 21 of file RootMinuit.h.

Constructor & Destructor Documentation

◆ RootMinuit()

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

Definition at line 23 of file RootMinuit.h.

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

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

Member Function Documentation

◆ addParameter() [1/2]

template<class Function>
void fit::RootMinuit< Function >::addParameter ( const funct::Parameter par,
double  err,
double  min,
double  max 
)
inline

◆ addParameter() [2/2]

template<class Function>
void fit::RootMinuit< Function >::addParameter ( const std::string &  name,
std::shared_ptr< double >  val,
double  err,
double  min,
double  max 
)
inline

Definition at line 26 of file RootMinuit.h.

26  {
27  if (initialized_)
29  << "RootMinuit: can't add parameter " << name << " after minuit initialization\n";
30  pars_.push_back(val);
31  parameter_t par;
32  par.val = *val;
33  par.err = err;
34  par.min = min;
35  par.max = max;
36  par.fixed = false;
37  parMap_.push_back(std::make_pair(name, par));
38  size_t s = parIndices_.size();
39  parIndices_[name] = s;
40  }

References edm::errors::Configuration, fit::parameter_t::err, submitPVResolutionJobs::err, Exception, fit::parameter_t::fixed, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, SiStripPI::max, fit::parameter_t::min, min(), Skims_PA_cff::name, fit::RootMinuit< Function >::parIndices_, fit::RootMinuit< Function >::parMap_, fit::RootMinuit< Function >::pars_, alignCSCRings::s, fit::parameter_t::val, and heppy_batch::val.

Referenced by metTools.AddMETCollection::__init__(), trackTools.MakeAODTrackCandidates::__init__(), coreTools.RunOnData::__init__(), runJetUncertainties.RunJetUncertainties::__init__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__init__(), cmsswVersionTools.PickRelValInputFiles::__init__(), coreTools.RemoveMCMatching::__init__(), trackTools.MakePATTrackCandidates::__init__(), trigTools.SwitchOnTrigger::__init__(), trigTools.SwitchOnTriggerStandAlone::__init__(), tauTools.AddTauCollection::__init__(), trackTools.MakeTrackCandidates::__init__(), trigTools.SwitchOnTriggerMatching::__init__(), trigTools.SwitchOnTriggerMatchingStandAlone::__init__(), trigTools.SwitchOnTriggerMatchEmbedding::__init__(), jetTools.AddJetCollection::__init__(), jetTools.SwitchJetCollection::__init__(), jetTools.UpdateJetCollection::__init__(), jetTools.AddJetID::__init__(), jetTools.SetTagInfos::__init__(), fit::RootMinuitCommands< Function >::add(), and fit::RootMinuit< Function >::addParameter().

◆ fcn_()

template<class Function>
static void fit::RootMinuit< Function >::fcn_ ( int &  ,
double *  ,
double &  f,
double *  par,
int   
)
inlinestaticprivate

Definition at line 192 of file RootMinuit.h.

192  {
193  size_t size = fPars_->size();
194  for (size_t i = 0; i < size; ++i)
195  *((*fPars_)[i]) = par[i];
197  }

References fit::RootMinuitFuncEvaluator< Function >::evaluate(), f, fit::RootMinuit< Function >::f_, fit::RootMinuit< Function >::fPars_, mps_fire::i, and findQualityFiles::size.

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

◆ fixParameter()

template<class Function>
void fit::RootMinuit< Function >::fixParameter ( const std::string &  name)
inline

◆ getErrorMatrix()

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 69 of file RootMinuit.h.

69  {
70  init();
71  if (N != numberOfParameters())
73  << "RootMinuit: can't call getErrorMatrix passing an SMatrix of dimension " << N
74  << " while the number of parameters is " << numberOfParameters() << "\n";
75  double *e = new double[N * N];
76  minuit_->mnemat(e, numberOfParameters());
77  for (size_t i = 0; i < N; ++i) {
78  for (size_t j = 0; j <= i; ++j) {
79  err(i, j) = e[i + N * j];
80  }
81  }
82  delete[] e;
83  setParameters();
84  }

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

◆ getParameter() [1/2]

template<class Function>
double fit::RootMinuit< Function >::getParameter ( const std::string &  name)
inline

◆ getParameter() [2/2]

template<class Function>
double fit::RootMinuit< Function >::getParameter ( const std::string &  name,
double &  err 
)
inline

◆ getParameterError() [1/2]

template<class Function>
double fit::RootMinuit< Function >::getParameterError ( const std::string &  name)
inline

◆ getParameterError() [2/2]

template<class Function>
double fit::RootMinuit< Function >::getParameterError ( const std::string &  name,
double &  val 
)
inline

◆ init()

template<class Function>
void fit::RootMinuit< Function >::init ( void  )
inlineprivate

Definition at line 204 of file RootMinuit.h.

204  {
205  if (initialized_)
206  return;
207  minuit_.reset(new TMinuit(parMap_.size()));
208  double arglist[10];
209  int ierflg = 0;
210  if (!verbose_) {
211  arglist[0] = -1;
212  minuit_->mnexcm("SET PRINT", arglist, 1, ierflg);
213  if (ierflg != 0)
214  throw edm::Exception(edm::errors::Configuration) << "RootMinuit: error in calling SET PRINT\n";
215  }
216  arglist[0] = 1;
217  minuit_->mnexcm("SET ERR", arglist, 1, ierflg);
218  if (ierflg != 0)
219  throw edm::Exception(edm::errors::Configuration) << "RootMinuit: error in calling SET ERR\n";
220 
221  size_t i = 0;
222  typename parameterVector_t::const_iterator p = parMap_.begin(), end = parMap_.end();
223  for (; p != end; ++p, ++i) {
224  const std::string &name = p->first;
225  const parameter_t &par = p->second;
226  minuit_->mnparm(i, name, par.val, par.err, par.min, par.max, ierflg);
227  if (ierflg != 0)
229  << "RootMinuit: error in setting parameter " << i << " value = " << par.val << " error = " << par.err
230  << " range = [" << par.min << ", " << par.max << "]\n";
231  }
232  initialized_ = true;
233  for (i = 0, p = parMap_.begin(); p != end; ++p, ++i)
234  if (p->second.fixed)
235  minuit_->FixParameter(i);
236  fPars_ = &pars_;
237  minuit_->SetFCN(fcn_);
238  }

References edm::errors::Configuration, mps_fire::end, fit::parameter_t::err, Exception, fit::RootMinuit< Function >::fcn_(), fit::RootMinuit< Function >::fPars_, mps_fire::i, fit::RootMinuit< Function >::initialized_, fit::parameter_t::max, fit::parameter_t::min, fit::RootMinuit< Function >::minuit_, Skims_PA_cff::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().

◆ migrad()

template<class Function>
double fit::RootMinuit< Function >::migrad ( )
inline

Definition at line 146 of file RootMinuit.h.

146  {
147  init();
148  double arglist[10];
149  arglist[0] = 5000;
150  arglist[1] = 0.1;
151  int ierflag;
152  minuit_->mnexcm("MIGRAD", arglist, 2, ierflag);
153  if (ierflag != 0)
154  std::cerr << "ERROR in migrad!!" << std::endl;
155  if (verbose_)
156  minuit_->mnmatu(1); //Prints the covariance matrix
157  double m = minValue();
158  if (verbose_)
159  minuit_->mnprin(3, m);
160  setParameters();
161  return m;
162  }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, fit::RootMinuit< Function >::init(), visualization-live-secondInstance_cfg::m, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::setParameters(), and fit::RootMinuit< Function >::verbose_.

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

◆ minimize()

template<class Function>
double fit::RootMinuit< Function >::minimize ( )
inline

Definition at line 129 of file RootMinuit.h.

129  {
130  init();
131  double arglist[10];
132  arglist[0] = 5000;
133  arglist[1] = 0.1;
134  int ierflag;
135  minuit_->mnexcm("MINIMIZE", arglist, 2, ierflag);
136  if (ierflag != 0)
137  std::cerr << "ERROR in minimize!!" << std::endl;
138  if (verbose_)
139  minuit_->mnmatu(1); //Prints the covariance matrix
140  double m = minValue();
141  if (verbose_)
142  minuit_->mnprin(3, m);
143  setParameters();
144  return m;
145  }

References EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0::cerr, fit::RootMinuit< Function >::init(), visualization-live-secondInstance_cfg::m, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::minValue(), fit::RootMinuit< Function >::setParameters(), and fit::RootMinuit< Function >::verbose_.

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

◆ minValue()

template<class Function>
double fit::RootMinuit< Function >::minValue ( )
inline

Definition at line 163 of file RootMinuit.h.

163  {
164  init();
165  int ierflag;
166  double edm, errdef;
167  int nvpar, nparx;
168  minuit_->mnstat(minValue_, edm, errdef, nvpar, nparx, ierflag);
169  return minValue_;
170  }

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

◆ numberOfFreeParameters()

template<class Function>
int fit::RootMinuit< Function >::numberOfFreeParameters ( )
inline

Definition at line 125 of file RootMinuit.h.

125  {
126  init();
127  return minuit_->GetNumFreePars();
128  }

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

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

◆ numberOfParameters()

template<class Function>
int fit::RootMinuit< Function >::numberOfParameters ( )
inline

Definition at line 121 of file RootMinuit.h.

121  {
122  init();
123  return minuit_->GetNumPars();
124  }

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

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

◆ parameterIndex()

template<class Function>
size_t fit::RootMinuit< Function >::parameterIndex ( const std::string &  name) const
inlineprivate

◆ printFitResults()

template<class Function>
void fit::RootMinuit< Function >::printFitResults ( std::ostream &  cout = std::cout)
inline

◆ printParameters()

template<class Function>
void fit::RootMinuit< Function >::printParameters ( std::ostream &  cout = std::cout)
inline

Definition at line 171 of file RootMinuit.h.

171  {
172  std::map<std::string, size_t>::const_iterator i = parIndices_.begin(), end = parIndices_.end();
173  for (; i != end; ++i) {
174  cout << i->first << " = " << *pars_[i->second] << " +/- " << getParameterError(i->first) << std::endl;
175  }
176  }

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

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

◆ releaseParameter()

template<class Function>
void fit::RootMinuit< Function >::releaseParameter ( const std::string &  name)
inline

◆ setParameter()

template<class Function>
void fit::RootMinuit< Function >::setParameter ( const std::string &  name,
double  val 
)
inline

Definition at line 99 of file RootMinuit.h.

99  {
100  size_t i = parameterIndex(name);
101  parameter_t &par = parMap_[i].second;
102  par.val = val;
103  if (initialized_) {
104  int ierflg = 0;
105  minuit_->mnparm(i, name, par.val, par.err, par.min, par.max, ierflg);
106  if (ierflg != 0)
108  << "RootMinuit: error in setting parameter " << i << " value = " << par.val << " error = " << par.err
109  << " range = [" << par.min << ", " << par.max << "]\n";
110  }
111  }

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

Referenced by coreTools.RunOnData::__call__(), trackTools.MakeAODTrackCandidates::__call__(), runJetUncertainties.RunJetUncertainties::__call__(), metTools.AddMETCollection::__call__(), cmsswVersionTools.PickRelValInputFiles::__call__(), coreTools.RemoveMCMatching::__call__(), trackTools.MakePATTrackCandidates::__call__(), trigTools.SwitchOnTrigger::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::__call__(), trigTools.SwitchOnTriggerStandAlone::__call__(), tauTools.AddTauCollection::__call__(), trackTools.MakeTrackCandidates::__call__(), trigTools.SwitchOnTriggerMatching::__call__(), trigTools.SwitchOnTriggerMatchingStandAlone::__call__(), trigTools.SwitchOnTriggerMatchEmbedding::__call__(), jetTools.AddJetCollection::__call__(), jetTools.SwitchJetCollection::__call__(), jetTools.UpdateJetCollection::__call__(), jetTools.AddJetID::__call__(), jetTools.SetTagInfos::__call__(), runMETCorrectionsAndUncertainties.RunMETCorrectionsAndUncertainties::jetConfiguration(), and fit::RootMinuitCommands< Function >::run().

◆ setParameters()

template<class Function>
void fit::RootMinuit< Function >::setParameters ( )
inline

Definition at line 112 of file RootMinuit.h.

112  {
113  std::map<std::string, size_t>::const_iterator i = parIndices_.begin(), end = parIndices_.end();
114  double val, err;
115  for (; i != end; ++i) {
116  size_t index = i->second;
117  minuit_->GetParameter(index, val, err);
118  *pars_[index] = val;
119  }
120  }

References mps_fire::end, submitPVResolutionJobs::err, mps_fire::i, fit::RootMinuit< Function >::minuit_, fit::RootMinuit< Function >::parIndices_, fit::RootMinuit< Function >::pars_, and heppy_batch::val.

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

Member Data Documentation

◆ f_

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

◆ fPars_

template<class Function>
std::vector< std::shared_ptr< double > > * fit::RootMinuit< Function >::fPars_ = nullptr
staticprivate

◆ initialized_

template<class Function>
bool fit::RootMinuit< Function >::initialized_
private

◆ minuit_

template<class Function>
std::unique_ptr<TMinuit> fit::RootMinuit< Function >::minuit_
private

◆ minValue_

template<class Function>
double fit::RootMinuit< Function >::minValue_
private

Definition at line 186 of file RootMinuit.h.

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

◆ parIndices_

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

◆ parMap_

template<class Function>
parameterVector_t fit::RootMinuit< Function >::parMap_
private

◆ pars_

template<class Function>
std::vector<std::shared_ptr<double> > fit::RootMinuit< Function >::pars_
private

◆ verbose_

template<class Function>
bool fit::RootMinuit< Function >::verbose_
private
funct::Parameter::name
const std::string & name() const
Definition: Parameter.h:12
fit::RootMinuit::setParameters
void setParameters()
Definition: RootMinuit.h:112
mps_fire.i
i
Definition: mps_fire.py:428
fit::RootMinuit::addParameter
void addParameter(const std::string &name, std::shared_ptr< double > val, double err, double min, double max)
Definition: RootMinuit.h:26
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
min
T min(T a, T b)
Definition: MathUtil.h:58
fit::RootMinuit::parameterIndex
size_t parameterIndex(const std::string &name) const
Definition: RootMinuit.h:198
edm
HLT enums.
Definition: AlignableModifier.h:19
fit::RootMinuit::getParameterError
double getParameterError(const std::string &name, double &val)
Definition: RootMinuit.h:56
gather_cfg.cout
cout
Definition: gather_cfg.py:144
fit::RootMinuit::printParameters
void printParameters(std::ostream &cout=std::cout)
Definition: RootMinuit.h:171
fit::RootMinuit::pars_
std::vector< std::shared_ptr< double > > pars_
Definition: RootMinuit.h:188
edm::Exception
Definition: EDMException.h:77
fit::RootMinuit::parIndices_
std::map< std::string, size_t > parIndices_
Definition: RootMinuit.h:184
alignCSCRings.s
s
Definition: alignCSCRings.py:92
fit::RootMinuit::init
void init()
Definition: RootMinuit.h:204
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
mps_fire.end
end
Definition: mps_fire.py:242
N
#define N
Definition: blowfish.cc:9
verbose
static constexpr int verbose
Definition: HLTExoticaSubAnalysis.cc:25
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
fit::RootMinuit::minuit_
std::unique_ptr< TMinuit > minuit_
Definition: RootMinuit.h:187
fit::RootMinuit::numberOfFreeParameters
int numberOfFreeParameters()
Definition: RootMinuit.h:125
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
fit::RootMinuit::initialized_
bool initialized_
Definition: RootMinuit.h:185
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fit::RootMinuitFuncEvaluator::evaluate
static double evaluate(const Function &f)
Definition: RootMinuitFuncEvaluator.h:7
heppy_batch.val
val
Definition: heppy_batch.py:351
fit::RootMinuitResultPrinter::print
static void print(double amin, unsigned int numberOfFreeParameters, const Function &f)
Definition: RootMinuitResultPrinter.h:9
fit::RootMinuit::fPars_
static std::vector< std::shared_ptr< double > > * fPars_
Definition: RootMinuit.h:189
Exception
Definition: hltDiff.cc:245
fit::RootMinuit::verbose_
bool verbose_
Definition: RootMinuit.h:190
fit::RootMinuit::numberOfParameters
int numberOfParameters()
Definition: RootMinuit.h:121
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
fit::RootMinuit::minValue_
double minValue_
Definition: RootMinuit.h:186
fit::RootMinuit::f_
static Function f_
Definition: RootMinuit.h:191
fit::RootMinuit::minValue
double minValue()
Definition: RootMinuit.h:163
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
edm::errors::Configuration
Definition: EDMException.h:36
fit::RootMinuit::fcn_
static void fcn_(int &, double *, double &f, double *par, int)
Definition: RootMinuit.h:192
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
fit::RootMinuit::parMap_
parameterVector_t parMap_
Definition: RootMinuit.h:183