Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FunctionMinimum.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_FunctionMinimum
11#define ROOT_Minuit2_FunctionMinimum
12
13#include "Minuit2/MinimumSeed.h"
17
18#include <vector>
19#include <memory>
20#include <cmath>
21
22#ifdef G__DICTIONARY
23typedef ROOT::Minuit2::MinimumState MinimumState;
24#endif
25
26namespace ROOT {
27
28namespace Minuit2 {
29
30//______________________________________________________________________________________________
31/**
32 class holding the full result of the minimization;
33 both internal and external (MnUserParameterState) representation available
34 for the parameters at the Minimum
35 */
36
38
39public:
40 enum Status {
44 };
45
46public:
47 /// Constructor from only MinimumSeed. Minimum is only from seed result not the full minimization
48 FunctionMinimum(const MinimumSeed &seed, double up)
49 : FunctionMinimum(seed,
50 std::vector<MinimumState>(1, MinimumState(seed.Parameters(), seed.Error(), seed.Gradient(),
51 seed.Parameters().Fval(), seed.NFcn())),
52 up)
53 {
54 }
55
56 /// Constructor at the end of a minimization from seed and vector of states
57 FunctionMinimum(const MinimumSeed &seed, const std::vector<MinimumState> &states, double up, Status status = MnValid)
58 : fPtr{new Data{seed, states, up, status == MnAboveMaxEdm, status == MnReachedCallLimit, {}}}
59 {
60 }
61
62 /// add latest minimization state (for example add Hesse result after Migrad)
63 void Add(const MinimumState &state, Status status = MnValid)
64 {
65 fPtr->fStates.push_back(state);
66 // LM : update also the user state
67 fPtr->fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
68 // reset maxedm flag. If new state has edm over max other method must be used
69 fPtr->fAboveMaxEdm = status == MnAboveMaxEdm;
70 fPtr->fReachedCallLimit = status == MnReachedCallLimit;
71 }
72
73 const MinimumSeed &Seed() const { return fPtr->fSeed; }
74 const std::vector<MinimumState> &States() const { return fPtr->fStates; }
75
76 // user representation of state at Minimum
78 {
79 if (!fPtr->fUserState.IsValid())
80 fPtr->fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
81 return fPtr->fUserState;
82 }
83 const MnUserParameters &UserParameters() const { return UserState().Parameters(); }
84 const MnUserCovariance &UserCovariance() const { return UserState().Covariance(); }
85
86 // forward interface of last state
87 const MinimumState &State() const { return States().back(); }
88 const MinimumParameters &Parameters() const { return States().back().Parameters(); }
89 const MinimumError &Error() const { return States().back().Error(); }
90 const FunctionGradient &Grad() const { return States().back().Gradient(); }
91 double Fval() const { return States().back().Fval(); }
92 double Edm() const { return States().back().Edm(); }
93 int NFcn() const { return States().back().NFcn(); }
94
95 double Up() const { return fPtr->fErrorDef; }
96 bool IsValid() const { return State().IsValid() && !IsAboveMaxEdm() && !HasReachedCallLimit(); }
97 bool HasValidParameters() const { return State().Parameters().IsValid(); }
98 bool HasValidCovariance() const { return State().Error().IsValid(); }
99 bool HasAccurateCovar() const { return State().Error().IsAccurate(); }
100 bool HasPosDefCovar() const { return State().Error().IsPosDef(); }
101 bool HasMadePosDefCovar() const { return State().Error().IsMadePosDef(); }
102 bool HesseFailed() const { return State().Error().HesseFailed(); }
103 bool HasCovariance() const { return State().Error().IsAvailable(); }
104 bool IsAboveMaxEdm() const { return fPtr->fAboveMaxEdm || std::isnan(Edm()); }
105 bool HasReachedCallLimit() const { return fPtr->fReachedCallLimit; }
106
107 void SetErrorDef(double up)
108 {
109 fPtr->fErrorDef = up;
110 // update user state for new value of up (scaling of errors)
111 fPtr->fUserState = MnUserParameterState(State(), up, Seed().Trafo());
112 }
113
114private:
115 struct Data {
117 std::vector<MinimumState> fStates;
118 double fErrorDef;
122 };
123
124 std::shared_ptr<Data> fPtr;
125};
126
127} // namespace Minuit2
128
129} // namespace ROOT
130
131#endif // ROOT_Minuit2_FunctionMinimum
class holding the full result of the minimization; both internal and external (MnUserParameterState) ...
const std::vector< MinimumState > & States() const
FunctionMinimum(const MinimumSeed &seed, const std::vector< MinimumState > &states, double up, Status status=MnValid)
Constructor at the end of a minimization from seed and vector of states.
void Add(const MinimumState &state, Status status=MnValid)
add latest minimization state (for example add Hesse result after Migrad)
const MinimumParameters & Parameters() const
const MinimumError & Error() const
const FunctionGradient & Grad() const
std::shared_ptr< Data > fPtr
const MnUserParameterState & UserState() const
const MnUserCovariance & UserCovariance() const
const MinimumState & State() const
const MnUserParameters & UserParameters() const
FunctionMinimum(const MinimumSeed &seed, double up)
Constructor from only MinimumSeed. Minimum is only from seed result not the full minimization.
const MinimumSeed & Seed() const
MinimumError keeps the inv.
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
class which holds the external user and/or internal Minuit representation of the parameters and error...
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
const std::vector< ROOT::Minuit2::MinuitParameter > & Parameters() const
access to parameters (row-wise)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
std::vector< MinimumState > fStates