ComPWA
Common Partial-Wave-Analysis Framework
MinuitResult.cpp
Go to the documentation of this file.
1 // Copyright (c) 2014, 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 #include "MinuitResult.hpp"
6 
7 #include "Core/Logging.hpp"
8 
9 #include "Minuit2/FunctionMinimum.h"
10 #include "Minuit2/MnUserParameters.h"
11 
12 #include <boost/archive/xml_iarchive.hpp>
13 #include <boost/archive/xml_oarchive.hpp>
14 
15 namespace ComPWA {
16 namespace Optimizer {
17 namespace Minuit2 {
18 
19 std::vector<double>
20 getGlobalCorrelations(const ROOT::Minuit2::MnUserParameterState &minState) {
21  std::vector<double> GlobalCC;
22  if (minState.HasGlobalCC()) {
23  GlobalCC = minState.GlobalCC().GlobalCC();
24  } else {
25  auto NumFreeParameter = minState.Parameters().Trafo().VariableParameters();
26  GlobalCC = std::vector<double>(NumFreeParameter, 0);
27  LOG(ERROR)
28  << "getGlobalCorrelations() | no valid global correlation available!";
29  }
30  return GlobalCC;
31 }
32 
34  const ROOT::Minuit2::FunctionMinimum &FMin)
35  : FitResult(Result), CovPosDef(FMin.HasPosDefCovar()),
36  HasValidParameters(FMin.HasValidParameters()),
37  HasValidCov(FMin.HasValidCovariance()),
38  HasAccCov(FMin.HasAccurateCovar()),
39  HasReachedCallLimit(FMin.HasReachedCallLimit()),
40  EdmAboveMax(FMin.IsAboveMaxEdm()), HesseFailed(FMin.HesseFailed()),
41  ErrorDef(FMin.Up()), NFcn(FMin.NFcn()), Edm(FMin.Edm()),
42  GlobalCC(getGlobalCorrelations(FMin.UserState())) {}
43 
44 std::ostream &operator<<(std::ostream &os, const MinuitResult &Result) {
45  const FitResult &BaseResult = Result;
46  os << BaseResult;
47 
48  os << "--------------MINUIT2 FIT INFOS----------------\n";
49  if (!Result.IsValid)
50  os << " *** MINIMUM NOT VALID! ***\n";
51  os << "Estimated distance to minimum: " << Result.Edm << "\n";
52  if (Result.EdmAboveMax)
53  os << " *** EDM IS ABOVE MAXIMUM! ***\n";
54  os << "Error definition: " << Result.ErrorDef << "\n";
55  os << "Number of calls: " << Result.NFcn << "\n";
56  if (Result.HasReachedCallLimit)
57  os << " *** LIMIT OF MAX CALLS REACHED! ***\n";
58  if (!Result.HasValidParameters)
59  os << " *** NO VALID SET OF PARAMETERS! ***\n";
60  if (!Result.HasValidCov)
61  os << " *** COVARIANCE MATRIX NOT VALID! ***\n";
62  if (!Result.HasAccCov)
63  os << " *** COVARIANCE MATRIX NOT ACCURATE! ***\n";
64  if (!Result.CovPosDef)
65  os << " *** COVARIANCE MATRIX NOT POSITIVE DEFINITE! ***\n";
66  if (Result.HesseFailed)
67  os << " *** HESSE FAILED! ***\n";
68  os << "-----------------------------------------------\n";
69  return os;
70 }
71 
72 void MinuitResult::write(std::string filename) const {
73  std::ofstream ofs(filename);
74  boost::archive::xml_oarchive oa(ofs);
75  oa << boost::serialization::make_nvp("MinuitResult", *this);
76 }
77 
78 MinuitResult load(std::string filename) {
79  MinuitResult Result;
80  std::ifstream ifs(filename);
81  assert(ifs.good());
82  boost::archive::xml_iarchive ia(ifs);
83  ia >> boost::serialization::make_nvp("MinuitResult", Result);
84  return Result;
85 }
86 
87 } // namespace Minuit2
88 } // namespace Optimizer
89 } // namespace ComPWA
std::vector< double > getGlobalCorrelations(const ROOT::Minuit2::MnUserParameterState &minState)
friend std::ostream & operator<<(std::ostream &os, const MinuitResult &Result)
Data structure which resembles a general fit result.
Definition: FitResult.hpp:19
void write(std::string filename) const
MinuitResult load(std::string filename)