GooFit  v2.1.3
Public Member Functions | List of all members
GooFit::Minuit1 Class Reference

#include <FitManagerMinuit1.h>

Inheritance diagram for GooFit::Minuit1:

Public Member Functions

 Minuit1 (PdfBase *pdfPointer)
 
Int_t Eval (Int_t npar, Double_t *grad, Double_t &fval, Double_t *par, Int_t flag) override
 Fit function for Minuit. More...
 
std::vector< VariablegetVaraibles () const
 

Detailed Description

Definition at line 11 of file FitManagerMinuit1.h.

Constructor & Destructor Documentation

◆ Minuit1()

GooFit::Minuit1::Minuit1 ( PdfBase pdfPointer)

Definition at line 13 of file FitManagerMinuit1.cpp.

References GooFit::PdfBase::copyParams().

14  : TMinuit(max_index(pdfPointer->getParameters()) + 1)
15  , pdfPointer(pdfPointer)
16  , vars(pdfPointer->getParameters()) {
17  int counter = 0;
18 
19  for(Variable &var : vars) {
20  var.setFitterIndex(counter);
21 
22  Int_t err = DefineParameter(
23  counter, var.getName().c_str(), var.getValue(), var.getError(), var.getLowerLimit(), var.getUpperLimit());
24 
25  if(GetNumPars() != counter + 1)
27  "Error when implementing param {} (possibly invalid error/lowerlimit/upperlimit values)!",
28  var.getName());
29 
30  if(err != 0)
31  throw GooFit::GeneralError("Was not able to implement param {} (error {})", var.getName(), err);
32 
33  if(var.IsFixed())
34  FixParameter(counter);
35 
36  counter++;
37  }
38 
39  pdfPointer->copyParams();
40 }
Thrown when a general error is encountered.
Definition: Error.h:10
int max_index(const std::vector< Variable > &vars)
Get the max index of a variable from a list.
Definition: Variable.cpp:8
__host__ void copyParams(const std::vector< double > &pars) const
virtual __host__ std::vector< Variable > getParameters() const
Definition: PdfBase.cpp:81

Member Function Documentation

◆ Eval()

Int_t GooFit::Minuit1::Eval ( Int_t  npar,
Double_t *  grad,
Double_t &  fval,
Double_t *  par,
Int_t  flag 
)
override

Fit function for Minuit.

Definition at line 42 of file FitManagerMinuit1.cpp.

References GooFit::PdfBase::calculateNLL(), GooFit::PdfBase::copyParams(), GOOFIT_TRACE, GOOFIT_WARN, GooFit::host_callnumber, and GooFit::max_index().

42  {
43  std::vector<double> pars{fp, fp + GetNumPars()};
44 
45  std::vector<double> gooPars;
46  gooPars.resize(max_index(vars) + 1);
47 
48  for(Variable &var : vars) {
49  if(std::isnan(pars.at(var.getFitterIndex())))
50  GOOFIT_WARN("Variable {} at {} is NaN", var.getName(), var.getIndex());
51 
52  var.setChanged(var.getValue() != pars.at(var.getFitterIndex()));
53  var.setValue(pars.at(var.getFitterIndex()));
54  gooPars.at(var.getIndex()) = var.getValue() - var.getBlind(Variable::Key());
55  }
56 
57  pdfPointer->copyParams(gooPars);
58 
59  GOOFIT_TRACE("Calculating NLL");
60  fun = pdfPointer->calculateNLL();
62  return 0;
63 }
virtual __host__ double calculateNLL() const =0
#define GOOFIT_TRACE(...)
Definition: Log.h:126
int max_index(const std::vector< Variable > &vars)
Get the max index of a variable from a list.
Definition: Variable.cpp:8
#define GOOFIT_WARN(...)
Definition: Log.h:46
__host__ void copyParams(const std::vector< double > &pars) const
int host_callnumber
Definition: PdfBase.cpp:33

◆ getVaraibles()

std::vector<Variable> GooFit::Minuit1::getVaraibles ( ) const
inline

Definition at line 27 of file FitManagerMinuit1.h.

27 { return vars; };

The documentation for this class was generated from the following files: