GooFit  v2.1.3
FitManagerMinuit2.cpp
Go to the documentation of this file.
2 
3 #include <goofit/Color.h>
4 
5 #include <Minuit2/FunctionMinimum.h>
6 #include <Minuit2/MnMigrad.h>
7 #include <Minuit2/MnPrint.h>
8 #include <Minuit2/MnUserParameterState.h>
9 #include <Minuit2/MnUserParameters.h>
10 
11 #include <CLI/Timer.hpp>
12 
13 namespace GooFit {
14 
16  : upar_(*dat)
17  , fcn_(upar_) {}
18 
19 Minuit2::FunctionMinimum FitManagerMinuit2::fit() {
20  auto val = Minuit2::MnPrint::Level();
21  Minuit2::MnPrint::SetLevel(verbosity);
22 
23  // Setting global call number to 0
24  host_callnumber = 0;
25 
26  CLI::Timer timer{"The minimization took"};
27 
28  Minuit2::MnMigrad migrad{fcn_, upar_};
29 
30  // Do the minimization
31  if(verbosity > 0)
32  std::cout << GooFit::gray << GooFit::bold;
33 
34  CLI::Timer avetimer{"Average time per call"};
35  Minuit2::FunctionMinimum min = migrad(maxfcn_);
36 
37  // Print nice output
38  if(verbosity > 0) {
39  std::cout << GooFit::reset << (min.IsValid() ? GooFit::green : GooFit::red);
40  std::cout << min << GooFit::reset;
41  std::cout << GooFit::magenta << timer.to_string() << GooFit::reset << std::endl;
42  std::cout << (avetimer / min.NFcn()).to_string() << std::endl;
43  }
44 
45  if(min.IsValid()) {
46  retval_ = FitErrors::Valid;
47  } else {
48  if(verbosity > 0) {
49  std::cout << GooFit::red;
50  std::cout << "HesseFailed: " << min.HesseFailed() << std::endl;
51  std::cout << "HasCovariance: " << min.HasCovariance() << std::endl;
52  std::cout << "HasValidCovariance: " << min.HasValidCovariance() << std::endl;
53  std::cout << "HasValidParameters: " << min.HasValidParameters() << std::endl;
54  std::cout << "IsAboveMaxEdm: " << min.IsAboveMaxEdm() << std::endl;
55  std::cout << "HasReachedCallLimit: " << min.HasReachedCallLimit() << std::endl;
56  std::cout << "HasAccurateCovar: " << min.HasAccurateCovar() << std::endl;
57  std::cout << "HasPosDefCovar : " << min.HasPosDefCovar() << std::endl;
58  std::cout << "HasMadePosDefCovar : " << min.HasMadePosDefCovar() << std::endl;
59  std::cout << GooFit::reset;
60  }
61 
62  retval_ = FitErrors::InValid;
63  }
64 
65  // Set the parameters in GooFit to the new values
66  upar_.SetGooFitParams(min.UserState());
67 
68  Minuit2::MnPrint::SetLevel(val);
69  return min;
70 }
71 
72 } // namespace GooFit
constexpr rang::style const bold
Definition: Color.h:17
constexpr rang::fg const red
Definition: Color.h:9
constexpr rang::style const reset
Definition: Color.h:16
constexpr rang::fg const gray
Definition: Color.h:15
constexpr rang::fg const magenta
Definition: Color.h:13
ROOT::Minuit2::FunctionMinimum fit()
This runs the fit.
constexpr rang::fg const green
Definition: Color.h:10
int host_callnumber
Definition: PdfBase.cpp:33