GooFit  v2.1.3
Params.cpp
Go to the documentation of this file.
1 #include <goofit/PDFs/GooPdf.h>
2 #include <goofit/PdfBase.h>
3 #include <goofit/Variable.h>
5 
6 namespace GooFit {
7 
9  : pdf_(&pdf) {
11 
12  for(Variable &var : vars_) {
13  bool added;
14  if(var.IsFixed()) {
15  added = Add(var.getName(), var.getValue());
16  } else if(var.getLowerLimit() == var.getUpperLimit()) {
17  added = Add(var.getName(), var.getValue(), var.getError());
18  } else {
19  added = Add(var.getName(), var.getValue(), var.getError(), var.getLowerLimit(), var.getUpperLimit());
20  }
21 
22  if(!added)
23  throw std::runtime_error("The name " + var.getName() + " appears more than once!");
24 
25  var.setFitterIndex(Index(var.getName()));
26  }
27 }
28 
29 void Params::SetGooFitParams(const Minuit2::MnUserParameterState &input) {
30  for(Variable &var : vars_) {
31  int counter = var.getFitterIndex();
32  var.setValue(input.Value(counter));
33  var.setError(input.Error(counter));
34  SetValue(counter, var.getValue());
35  SetError(counter, var.getError());
36  }
37 }
38 
39 std::vector<double> Params::make_minuit_vector() const {
40  std::vector<double> minuitPars(max_fitter_index(vars_) + 1);
41  for(const Variable &var : vars_) {
42  minuitPars.at(var.getFitterIndex()) = var.getValue();
43  }
44  return minuitPars;
45 }
46 
47 void Params::from_minuit_vector(const std::vector<double> &values, bool force_changed) {
48  std::vector<double> gooPars(max_index(vars_) + 1);
49 
50  for(Variable &var : vars_) {
51  var.setChanged(force_changed ? true : var.getValue() != values.at(var.getFitterIndex()));
52  gooPars.at(var.getIndex()) = values.at(var.getFitterIndex()) - var.getBlind(Variable::Key());
53  }
54 
55  if(do_record_)
56  recorded_.push_back(values);
57 
58  pdf_->copyParams(gooPars);
59 }
60 
61 } // namespace GooFit
std::vector< Variable > vars_
Definition: Params.h:22
std::vector< double > make_minuit_vector() const
Make a parameter array with the current variable values.
Definition: Params.cpp:39
int max_fitter_index(const std::vector< Variable > &vars)
Get the max fitter index of a variable from a list.
Definition: Variable.cpp:28
void from_minuit_vector(const std::vector< double > &values, bool force_changed=false)
Set from a minuit vector. Optional force_changed to force complete recalculation. ...
Definition: Params.cpp:47
int max_index(const std::vector< Variable > &vars)
Get the max index of a variable from a list.
Definition: Variable.cpp:8
PdfBase * pdf_
Definition: Params.h:23
void SetGooFitParams(const Minuit2::MnUserParameterState &input)
Read the values back into GooFit.
Definition: Params.cpp:29
__host__ void copyParams(const std::vector< double > &pars) const
std::vector< std::vector< double > > recorded_
Definition: Params.h:27
This provides a key for some special classes to access blind info (passkey)
Definition: Variable.h:154
Params(PdfBase &pdf)
Definition: Params.cpp:8
bool do_record_
Definition: Params.h:26
virtual __host__ std::vector< Variable > getParameters() const
Definition: PdfBase.cpp:81