Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
17#include <memory>
18
19namespace ROOT {
20
21namespace Minuit2 {
22
23/** MinimumError keeps the inv. 2nd derivative (inv. Hessian) used for
24 calculating the Parameter step size (-V*g) and for the covariance Update
25 (ErrorUpdator). The covariance matrix is equal to twice the inv. Hessian.
26 */
28
29public:
39
40public:
41 MinimumError(unsigned int n) : fPtr{new Data{{n}, {0}, 1.0, MnUnset}} {}
42
43 MinimumError(const MnAlgebraicSymMatrix &mat, double dcov) : fPtr{new Data{mat, {0}, dcov, MnPosDef}} {}
44
46
47 MinimumError(const MnAlgebraicSymMatrix &mat, Status status) : fPtr{new Data{mat, {0}, 1.0, status}} {}
48
49 MnAlgebraicSymMatrix Matrix() const { return 2. * fPtr->fMatrix; } // why *2 ?
50
51 const MnAlgebraicSymMatrix &InvHessian() const { return fPtr->fMatrix; }
52
53 // calculate invert of matrix. Used to compute Hessian by inverting matrix
55 {
56 if (fPtr->fHessian.size() == 0)
57 fPtr->fHessian = InvertMatrix(fPtr->fMatrix);
58 return fPtr->fHessian;
59 }
60
62 // calculate inverse of given matrix
65 if (ifail != 0) {
66 MnPrint print("MinimumError::Invert");
67 print.Warn("Inversion fails; return diagonal matrix");
68 for (unsigned int i = 0; i < matrix.Nrow(); ++i)
69 for (unsigned int j = 0; j <= i; j++)
70 tmp(i, j) = i == j ? 1. / matrix(i, i) : 0;
71 }
72 return tmp;
73 }
75 int ifail = 0;
76 return InvertMatrix(matrix, ifail);
77 }
78
79 double Dcovar() const { return fPtr->fDCovar; }
80 Status GetStatus() const { return fPtr->fStatus; }
81
82 bool IsValid() const { return IsAvailable() && (IsPosDef() || IsMadePosDef() || IsNotPosDef()); }
83 bool IsAccurate() const { return IsPosDef() && Dcovar() < 0.1; }
84
85 bool IsPosDef() const { return GetStatus() == MnPosDef; }
86 bool IsMadePosDef() const { return GetStatus() == MnMadePosDef; }
87 bool IsNotPosDef() const { return GetStatus() == MnNotPosDef; }
88 bool HesseFailed() const { return GetStatus() == MnHesseFailed; }
89 bool InvertFailed() const { return GetStatus() == MnInvertFailed; }
90 bool HasReachedCallLimit() const { return GetStatus() == MnReachedCallLimit; }
91 bool IsAvailable() const { return GetStatus() != MnUnset; }
92
93private:
94 struct Data {
96 MnAlgebraicSymMatrix fHessian; // optional stored also Hessian (used in Fumili)
97 double fDCovar;
99 };
100
101 std::shared_ptr<Data> fPtr;
102};
103
104} // namespace Minuit2
105
106} // namespace ROOT
107
108#endif // ROOT_Minuit2_MinimumError
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Class describing a symmetric matrix of size n.
Definition MnMatrix.h:438
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
const MnAlgebraicSymMatrix & Hessian() const
MnAlgebraicSymMatrix Matrix() const
std::shared_ptr< Data > fPtr
static MnAlgebraicSymMatrix InvertMatrix(const MnAlgebraicSymMatrix &matrix)
MinimumError(const MnAlgebraicSymMatrix &mat, const MnAlgebraicSymMatrix &hess, double dcov)
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:123
const Int_t n
Definition legend1.C:16
int Invert(LASymMatrix &)
Definition MnMatrix.cxx:296
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
MnAlgebraicSymMatrix fHessian