Logo ROOT  
Reference Guide
MinimumError.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#ifndef ROOT_Minuit2_MinimumError
11#define ROOT_Minuit2_MinimumError
12
13#include "Minuit2/MnConfig.h"
14#include "Minuit2/MnMatrix.h"
15#include "Minuit2/MnPrint.h"
16#include "Minuit2/LaSum.h"
17
18#include <memory>
19
20namespace ROOT {
21
22namespace Minuit2 {
23
24/** MinimumError keeps the inv. 2nd derivative (inv. Hessian) used for
25 calculating the Parameter step size (-V*g) and for the covariance Update
26 (ErrorUpdator). The covariance matrix is equal to twice the inv. Hessian.
27 */
29
30public:
31 enum Status {
39 };
40
41public:
42 MinimumError(unsigned int n) : fPtr{new Data{{n}, 1.0, MnUnset}} {}
43
44 MinimumError(const MnAlgebraicSymMatrix &mat, double dcov) : fPtr{new Data{mat, dcov, MnPosDef}} {}
45
46 MinimumError(const MnAlgebraicSymMatrix &mat, Status status) : fPtr{new Data{mat, 1.0, status}} {}
47
48 MnAlgebraicSymMatrix Matrix() const { return 2. * fPtr->fMatrix; }
49
50 const MnAlgebraicSymMatrix &InvHessian() const { return fPtr->fMatrix; }
51
53 {
54 // calculate Heassian: inverse of error matrix
55 MnAlgebraicSymMatrix tmp(fPtr->fMatrix);
56 if (Invert(tmp) != 0) {
57 MnPrint print("MinimumError::Hessian");
58 print.Warn("Inversion fails; return diagonal matrix");
59 for (unsigned int i = 0; i < fPtr->fMatrix.Nrow(); ++i)
60 for (unsigned int j = 0; j <= i; j++)
61 tmp(i, j) = i == j ? 1. / fPtr->fMatrix(i, i) : 0;
62 }
63 return tmp;
64 }
65
66 double Dcovar() const { return fPtr->fDCovar; }
67 Status GetStatus() const { return fPtr->fStatus; }
68
69 bool IsValid() const { return IsAvailable() && (IsPosDef() || IsMadePosDef()); }
70 bool IsAccurate() const { return IsPosDef() && Dcovar() < 0.1; }
71
72 bool IsPosDef() const { return GetStatus() == MnPosDef; }
73 bool IsMadePosDef() const { return GetStatus() == MnMadePosDef; }
74 bool HesseFailed() const { return GetStatus() == MnHesseFailed; }
75 bool InvertFailed() const { return GetStatus() == MnInvertFailed; }
76 bool HasReachedCallLimit() const { return GetStatus() == MnReachedCallLimit; }
77 bool IsAvailable() const { return GetStatus() != MnUnset; }
78
79private:
80 struct Data {
82 double fDCovar;
84 };
85
86 std::shared_ptr<Data> fPtr;
87};
88
89} // namespace Minuit2
90
91} // namespace ROOT
92
93#endif // ROOT_Minuit2_MinimumError
Class describing a symmetric matrix of size n.
Definition: LASymMatrix.h:45
MinimumError keeps the inv.
Definition: MinimumError.h:28
bool HasReachedCallLimit() const
Definition: MinimumError.h:76
MinimumError(const MnAlgebraicSymMatrix &mat, Status status)
Definition: MinimumError.h:46
MinimumError(unsigned int n)
Definition: MinimumError.h:42
const MnAlgebraicSymMatrix & InvHessian() const
Definition: MinimumError.h:50
MnAlgebraicSymMatrix Matrix() const
Definition: MinimumError.h:48
MnAlgebraicSymMatrix Hessian() const
Definition: MinimumError.h:52
std::shared_ptr< Data > fPtr
Definition: MinimumError.h:86
MinimumError(const MnAlgebraicSymMatrix &mat, double dcov)
Definition: MinimumError.h:44
Force the covariance matrix to be positive defined by adding extra terms in the diagonal.
Definition: MnPosDef.h:25
void Warn(const Ts &... args)
Definition: MnPrint.h:126
const Int_t n
Definition: legend1.C:16
int Invert(LASymMatrix &)
Definition: LaInverse.cxx:21
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
MnAlgebraicSymMatrix fMatrix
Definition: MinimumError.h:81