ComPWA
Common Partial-Wave-Analysis Framework
MinuitFcn.hpp
Go to the documentation of this file.
1 // Copyright (c) 2013, 2017 The ComPWA Team.
2 // This file is part of the ComPWA framework, check
3 // https://github.com/ComPWA/ComPWA/license.txt for details.
4 
5 #ifndef OPTIMIZER_MINUIT2_MINUITFCN_HPP_
6 #define OPTIMIZER_MINUIT2_MINUITFCN_HPP_
7 
9 
10 #include "Minuit2/FCNBase.h"
11 
12 #include <iomanip>
13 #include <map>
14 #include <sstream>
15 
16 namespace ROOT {
17 namespace Minuit2 {
18 
24 class MinuitFcn : public FCNBase {
25 
26 public:
27  MinuitFcn(ComPWA::Estimator::Estimator<double> &estimator)
28  : Estimator(estimator){};
29  virtual ~MinuitFcn() = default;
30 
31  double operator()(const std::vector<double> &x) const {
32  Estimator.updateParametersFrom(x);
33 
34  // Start timing
35  std::chrono::steady_clock::time_point StartTime =
36  std::chrono::steady_clock::now();
37  double result = Estimator.evaluate();
38  std::chrono::steady_clock::time_point EndTime =
39  std::chrono::steady_clock::now();
40 
41  LOG(DEBUG) << "MinuitFcn: Estimator = " << std::setprecision(10) << result
42  << std::setprecision(4) << " Time: "
43  << std::chrono::duration_cast<std::chrono::milliseconds>(
44  EndTime - StartTime)
45  .count()
46  << "ms";
47  LOG(DEBUG) << "Parameters: " << [&]() {
48  std::ostringstream params;
49  for (auto var : x) {
50  params << var << " ";
51  }
52  return params.str();
53  }();
54 
55  return result;
56  };
57 
58  double Up() const {
59  return 0.5; // TODO: Setter, LH 0.5, Chi2 1.
60  };
61 
62 private:
64 };
65 
66 } // namespace Minuit2
67 } // namespace ROOT
68 
69 #endif