1 #ifndef PhisycsTools_Utilities_RootMinuit_h 2 #define PhisycsTools_Utilities_RootMinuit_h 12 #include "Math/SMatrix.h" 20 template <
class Function>
29 <<
"RootMinuit: can't add parameter " <<
name <<
" after minuit initialization\n";
68 template <
unsigned int N>
73 <<
"RootMinuit: can't call getErrorMatrix passing an SMatrix of dimension " <<
N 75 double *
e =
new double[
N *
N];
77 for (
size_t i = 0;
i <
N; ++
i) {
78 for (
size_t j = 0;
j <=
i; ++
j) {
108 <<
"RootMinuit: error in setting parameter " <<
i <<
" value = " << par.
val <<
" error = " << par.
err 109 <<
" range = [" << par.
min <<
", " << par.
max <<
"]\n";
115 for (;
i != end; ++
i) {
127 return minuit_->GetNumFreePars();
135 minuit_->mnexcm(
"MINIMIZE", arglist, 2, ierflag);
137 std::cerr <<
"ERROR in minimize!!" << std::endl;
152 minuit_->mnexcm(
"MIGRAD", arglist, 2, ierflag);
154 std::cerr <<
"ERROR in migrad!!" << std::endl;
173 for (;
i != end; ++
i) {
188 std::vector<std::shared_ptr<double> >
pars_;
189 static std::vector<std::shared_ptr<double> > *
fPars_;
192 static void fcn_(
int &,
double *,
double &
f,
double *par,
int) {
194 for (
size_t i = 0;
i <
size; ++
i)
199 typename std::map<std::string, size_t>::const_iterator
p =
parIndices_.find(
name);
212 minuit_->mnexcm(
"SET PRINT", arglist, 1, ierflg);
217 minuit_->mnexcm(
"SET ERR", arglist, 1, ierflg);
222 typename parameterVector_t::const_iterator
p =
parMap_.begin(), end =
parMap_.end();
223 for (;
p != end; ++
p, ++
i) {
229 <<
"RootMinuit: error in setting parameter " <<
i <<
" value = " << par.
val <<
" error = " << par.
err 230 <<
" range = [" << par.
min <<
", " << par.
max <<
"]\n";
241 template <
class Function>
244 template <
class Function>
double getParameterError(const std::string &name)
void printParameters(std::ostream &cout=std::cout)
std::vector< std::shared_ptr< double > > pars_
void getErrorMatrix(ROOT::Math::SMatrix< double, N, N, ROOT::Math::MatRepSym< double, N > > &err)
void printFitResults(std::ostream &cout=std::cout)
size_t parameterIndex(const std::string &name) const
void setParameter(const std::string &name, double val)
std::map< std::string, size_t > parIndices_
const std::string & name() const
double getParameterError(const std::string &name, double &val)
void fixParameter(const std::string &name)
static void print(double amin, unsigned int numberOfFreeParameters, const Function &f)
RootMinuit(const Function &f, bool verbose=false)
std::vector< std::pair< std::string, parameter_t > > parameterVector_t
int numberOfFreeParameters()
double getParameter(const std::string &name)
std::unique_ptr< TMinuit > minuit_
double getParameter(const std::string &name, double &err)
void addParameter(const funct::Parameter &par, double err, double min, double max)
static void fcn_(int &, double *, double &f, double *par, int)
parameterVector_t parMap_
static std::vector< std::shared_ptr< double > > * fPars_
static double evaluate(const Function &f)
void releaseParameter(const std::string &name)
void addParameter(const std::string &name, std::shared_ptr< double > val, double err, double min, double max)