Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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; } // why *2 ?
49
50 const MnAlgebraicSymMatrix &InvHessian() const { return fPtr->fMatrix; }
51
52 // calculate invert of matrix. Used to compute Hessian by inverting matrix
54 {
55 return InvertMatrix(fPtr->fMatrix);
56 }
57
58 static MnAlgebraicSymMatrix InvertMatrix(const MnAlgebraicSymMatrix & matrix, int & ifail) {
59 // calculate inverse of given matrix
60 MnAlgebraicSymMatrix tmp(matrix);
61 ifail = ROOT::Minuit2::Invert(tmp);
62 if (ifail != 0) {
63 MnPrint print("MinimumError::Invert");
64 print.Warn("Inversion fails; return diagonal matrix");
65 for (unsigned int i = 0; i < matrix.Nrow(); ++i)
66 for (unsigned int j = 0; j <= i; j++)
67 tmp(i, j) = i == j ? 1. / matrix(i, i) : 0;
68 }
69 return tmp;
70 }
72 int ifail = 0;
73 return InvertMatrix(matrix, ifail);
74 }
75
76 double Dcovar() const { return fPtr->fDCovar; }
77 Status GetStatus() const { return fPtr->fStatus; }
78
79 bool IsValid() const { return IsAvailable() && (IsPosDef() || IsMadePosDef() || IsNotPosDef()); }
80 bool IsAccurate() const { return IsPosDef() && Dcovar() < 0.1; }
81
82 bool IsPosDef() const { return GetStatus() == MnPosDef; }
83 bool IsMadePosDef() const { return GetStatus() == MnMadePosDef; }
84 bool IsNotPosDef() const { return GetStatus() == MnNotPosDef; }
85 bool HesseFailed() const { return GetStatus() == MnHesseFailed; }
86 bool InvertFailed() const { return GetStatus() == MnInvertFailed; }
87 bool HasReachedCallLimit() const { return GetStatus() == MnReachedCallLimit; }
88 bool IsAvailable() const { return GetStatus() != MnUnset; }
89
90private:
91 struct Data {
93 double fDCovar;
95 };
96
97 std::shared_ptr<Data> fPtr;
98};
99
100} // namespace Minuit2
101
102} // namespace ROOT
103
104#endif // ROOT_Minuit2_MinimumError
Class describing a symmetric matrix of size n.
Definition LASymMatrix.h:45
unsigned int Nrow() const
MinimumError keeps the inv.
static MnAlgebraicSymMatrix InvertMatrix(const MnAlgebraicSymMatrix &matrix, int &ifail)
MinimumError(const MnAlgebraicSymMatrix &mat, Status status)
MinimumError(unsigned int n)
const MnAlgebraicSymMatrix & InvHessian() const
MnAlgebraicSymMatrix Matrix() const
MnAlgebraicSymMatrix Hessian() const
std::shared_ptr< Data > fPtr
static MnAlgebraicSymMatrix InvertMatrix(const MnAlgebraicSymMatrix &matrix)
MinimumError(const MnAlgebraicSymMatrix &mat, double dcov)
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:135
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.