Logo ROOT  
Reference Guide
BasicFunctionMinimum.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_BasicFunctionMinimum
11 #define ROOT_Minuit2_BasicFunctionMinimum
12 
13 #include "Minuit2/MinimumSeed.h"
14 #include "Minuit2/MinimumState.h"
17 
18 #include "Minuit2/StackAllocator.h"
19 
20 #include <vector>
21 
22 namespace ROOT {
23 
24 namespace Minuit2 {
25 
26 // extern StackAllocator gStackAllocator;
27 
28 /** result of the minimization;
29  both internal and external (MnUserParameterState) representation available
30  For the parameters at the Minimum
31  */
32 
34 
35 public:
37  };
38  class MnAboveMaxEdm {
39  };
40 
41 public:
42  /// Constructor from only MinimumSeed. Minimum is only from seed result not the full minimization
43  BasicFunctionMinimum(const MinimumSeed &seed, double up)
44  : fSeed(seed), fStates(std::vector<MinimumState>(1, MinimumState(seed.Parameters(), seed.Error(), seed.Gradient(),
45  seed.Parameters().Fval(), seed.NFcn()))),
47  {
48  }
49 
50  /// Constructor at the end of a successfull minimization from seed and vector of states
51  BasicFunctionMinimum(const MinimumSeed &seed, const std::vector<MinimumState> &states, double up)
52  : fSeed(seed), fStates(states), fErrorDef(up), fAboveMaxEdm(false), fReachedCallLimit(false),
54  {
55  }
56 
57  /// Constructor at the end of a failed minimization due to exceeding function call limit
58  BasicFunctionMinimum(const MinimumSeed &seed, const std::vector<MinimumState> &states, double up, MnReachedCallLimit)
59  : fSeed(seed), fStates(states), fErrorDef(up), fAboveMaxEdm(false), fReachedCallLimit(true),
61  {
62  }
63 
64  /// Constructor at the end of a failed minimization due to edm above maximum value
65  BasicFunctionMinimum(const MinimumSeed &seed, const std::vector<MinimumState> &states, double up, MnAboveMaxEdm)
66  : fSeed(seed), fStates(states), fErrorDef(up), fAboveMaxEdm(true), fReachedCallLimit(false),
68  {
69  }
70 
71  /// Copy constructor
75  {
76  }
77 
79  {
80  fSeed = min.fSeed;
81  fStates = min.fStates;
82  fErrorDef = min.fErrorDef;
85  fUserState = min.fUserState;
86  return *this;
87  }
88 
90 
91  /// add latest minimization state (for example add Hesse result after Migrad)
92  void Add(const MinimumState &state)
93  {
94  fStates.push_back(state);
95  // LM : update also the user state
96  fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
97  // reset maxedm flag. If new state has edm over max other method must be used
98  fAboveMaxEdm = false;
99  }
100 
101  /// Add a new state and flag that edm is above maximum
102  void Add(const MinimumState &state, MnAboveMaxEdm)
103  {
104  Add(state);
105  fAboveMaxEdm = true;
106  }
107 
108  const MinimumSeed &Seed() const { return fSeed; }
109  const std::vector<MinimumState> &States() const { return fStates; }
110 
111  // user representation of state at Minimum
113  {
114  if (!fUserState.IsValid())
115  fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
116  return fUserState;
117  }
119  {
120  if (!fUserState.IsValid())
121  fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
122  return fUserState.Parameters();
123  }
125  {
126  if (!fUserState.IsValid())
127  fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
128  return fUserState.Covariance();
129  }
130 
131  void *operator new(size_t nbytes) { return StackAllocatorHolder::Get().Allocate(nbytes); }
132 
133  void operator delete(void *p, size_t /*nbytes */) { StackAllocatorHolder::Get().Deallocate(p); }
134 
135  // forward interface of last state
136  const MinimumState &State() const { return fStates.back(); }
137  const MinimumParameters &Parameters() const { return fStates.back().Parameters(); }
138  const MinimumError &Error() const { return fStates.back().Error(); }
139  const FunctionGradient &Grad() const { return fStates.back().Gradient(); }
140  double Fval() const { return fStates.back().Fval(); }
141  double Edm() const { return fStates.back().Edm(); }
142  int NFcn() const { return fStates.back().NFcn(); }
143 
144  double Up() const { return fErrorDef; }
145  bool IsValid() const { return State().IsValid() && !IsAboveMaxEdm() && !HasReachedCallLimit(); }
146  bool HasValidParameters() const { return State().Parameters().IsValid(); }
147  bool HasValidCovariance() const { return State().Error().IsValid(); }
148  bool HasAccurateCovar() const { return State().Error().IsAccurate(); }
149  bool HasPosDefCovar() const { return State().Error().IsPosDef(); }
150  bool HasMadePosDefCovar() const { return State().Error().IsMadePosDef(); }
151  bool HesseFailed() const { return State().Error().HesseFailed(); }
152  bool HasCovariance() const { return State().Error().IsAvailable(); }
153  bool IsAboveMaxEdm() const { return fAboveMaxEdm; }
154  bool HasReachedCallLimit() const { return fReachedCallLimit; }
155 
156  void SetErrorDef(double up)
157  {
158  fErrorDef = up;
159  // update user state for new valeu of up (scaling of errors)
160  fUserState = MnUserParameterState(State(), up, Seed().Trafo());
161  }
162 
163 private:
165  std::vector<MinimumState> fStates;
166  double fErrorDef;
170 };
171 
172 } // namespace Minuit2
173 
174 } // namespace ROOT
175 
176 #endif // ROOT_Minuit2_BasicFunctionMinimum
ROOT::Minuit2::BasicFunctionMinimum::fReachedCallLimit
bool fReachedCallLimit
Definition: BasicFunctionMinimum.h:168
ROOT::Minuit2::BasicFunctionMinimum::HasPosDefCovar
bool HasPosDefCovar() const
Definition: BasicFunctionMinimum.h:149
ROOT::Minuit2::BasicFunctionMinimum::BasicFunctionMinimum
BasicFunctionMinimum(const MinimumSeed &seed, const std::vector< MinimumState > &states, double up, MnReachedCallLimit)
Constructor at the end of a failed minimization due to exceeding function call limit.
Definition: BasicFunctionMinimum.h:58
ROOT::Minuit2::BasicFunctionMinimum::Edm
double Edm() const
Definition: BasicFunctionMinimum.h:141
ROOT::Minuit2::BasicFunctionMinimum::fUserState
MnUserParameterState fUserState
Definition: BasicFunctionMinimum.h:169
ROOT::Minuit2::MinimumState
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
ROOT::Minuit2::BasicFunctionMinimum::Fval
double Fval() const
Definition: BasicFunctionMinimum.h:140
ROOT::Minuit2::BasicFunctionMinimum::Error
const MinimumError & Error() const
Definition: BasicFunctionMinimum.h:138
ROOT::Minuit2::BasicFunctionMinimum::Add
void Add(const MinimumState &state, MnAboveMaxEdm)
Add a new state and flag that edm is above maximum.
Definition: BasicFunctionMinimum.h:102
ROOT::Minuit2::BasicFunctionMinimum::HasReachedCallLimit
bool HasReachedCallLimit() const
Definition: BasicFunctionMinimum.h:154
ROOT::Minuit2::BasicFunctionMinimum::HesseFailed
bool HesseFailed() const
Definition: BasicFunctionMinimum.h:151
ROOT::Minuit2::MinimumState::IsValid
bool IsValid() const
Definition: MinimumState.h:60
ROOT::Minuit2::BasicFunctionMinimum::BasicFunctionMinimum
BasicFunctionMinimum(const MinimumSeed &seed, const std::vector< MinimumState > &states, double up, MnAboveMaxEdm)
Constructor at the end of a failed minimization due to edm above maximum value.
Definition: BasicFunctionMinimum.h:65
MnUserTransformation.h
MinimumSeed.h
ROOT::Minuit2::BasicFunctionMinimum::HasAccurateCovar
bool HasAccurateCovar() const
Definition: BasicFunctionMinimum.h:148
ROOT::Minuit2::BasicFunctionMinimum::~BasicFunctionMinimum
~BasicFunctionMinimum()
Definition: BasicFunctionMinimum.h:89
ROOT::Minuit2::StackAllocator::Deallocate
void Deallocate(void *p)
Definition: StackAllocator.h:103
ROOT::Minuit2::BasicFunctionMinimum::operator=
BasicFunctionMinimum & operator=(const BasicFunctionMinimum &min)
Definition: BasicFunctionMinimum.h:78
MnUserParameterState.h
ROOT::Minuit2::MinimumError::IsValid
bool IsValid() const
Definition: MinimumError.h:67
ROOT::Minuit2::FunctionGradient
Definition: FunctionGradient.h:21
ROOT::Minuit2::MnUserCovariance
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...
Definition: MnUserCovariance.h:26
ROOT::Minuit2::BasicFunctionMinimum::BasicFunctionMinimum
BasicFunctionMinimum(const MinimumSeed &seed, const std::vector< MinimumState > &states, double up)
Constructor at the end of a successfull minimization from seed and vector of states.
Definition: BasicFunctionMinimum.h:51
ROOT::Minuit2::BasicFunctionMinimum::HasCovariance
bool HasCovariance() const
Definition: BasicFunctionMinimum.h:152
ROOT::Minuit2::BasicFunctionMinimum
result of the minimization; both internal and external (MnUserParameterState) representation availabl...
Definition: BasicFunctionMinimum.h:33
ROOT::Minuit2::BasicFunctionMinimum::States
const std::vector< MinimumState > & States() const
Definition: BasicFunctionMinimum.h:109
ROOT::Minuit2::MnUserParameterState::IsValid
bool IsValid() const
Definition: MnUserParameterState.h:106
ROOT::Minuit2::BasicFunctionMinimum::State
const MinimumState & State() const
Definition: BasicFunctionMinimum.h:136
ROOT::Minuit2::BasicFunctionMinimum::HasMadePosDefCovar
bool HasMadePosDefCovar() const
Definition: BasicFunctionMinimum.h:150
ROOT::Minuit2::BasicFunctionMinimum::UserState
const MnUserParameterState & UserState() const
Definition: BasicFunctionMinimum.h:112
ROOT::Minuit2::BasicFunctionMinimum::NFcn
int NFcn() const
Definition: BasicFunctionMinimum.h:142
ROOT::Minuit2::MinimumError::HesseFailed
bool HesseFailed() const
Definition: MinimumError.h:70
ROOT::Minuit2::BasicFunctionMinimum::fAboveMaxEdm
bool fAboveMaxEdm
Definition: BasicFunctionMinimum.h:167
ROOT::Minuit2::BasicFunctionMinimum::fErrorDef
double fErrorDef
Definition: BasicFunctionMinimum.h:166
ROOT::Minuit2::BasicFunctionMinimum::UserParameters
const MnUserParameters & UserParameters() const
Definition: BasicFunctionMinimum.h:118
ROOT::Minuit2::MinimumParameters
Definition: MinimumParameters.h:21
ROOT::Minuit2::MinimumState::Error
const MinimumError & Error() const
Definition: MinimumState.h:54
ROOT::Minuit2::BasicFunctionMinimum::fStates
std::vector< MinimumState > fStates
Definition: BasicFunctionMinimum.h:165
ROOT::Minuit2::MnUserParameters
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
Definition: MnUserParameters.h:36
ROOT::Minuit2::BasicFunctionMinimum::BasicFunctionMinimum
BasicFunctionMinimum(const MinimumSeed &seed, double up)
Constructor from only MinimumSeed. Minimum is only from seed result not the full minimization.
Definition: BasicFunctionMinimum.h:43
ROOT::Minuit2::BasicFunctionMinimum::Grad
const FunctionGradient & Grad() const
Definition: BasicFunctionMinimum.h:139
StackAllocator.h
ROOT::Minuit2::StackAllocator::Allocate
void * Allocate(size_t nBytes)
Definition: StackAllocator.h:71
ROOT::Minuit2::BasicFunctionMinimum::Add
void Add(const MinimumState &state)
add latest minimization state (for example add Hesse result after Migrad)
Definition: BasicFunctionMinimum.h:92
ROOT::Minuit2::MinimumParameters::IsValid
bool IsValid() const
Definition: MinimumParameters.h:41
ROOT::Minuit2::BasicFunctionMinimum::IsValid
bool IsValid() const
Definition: BasicFunctionMinimum.h:145
ROOT::Minuit2::StackAllocatorHolder::Get
static StackAllocator & Get()
Definition: StackAllocator.h:223
ROOT::Minuit2::BasicFunctionMinimum::SetErrorDef
void SetErrorDef(double up)
Definition: BasicFunctionMinimum.h:156
ROOT::Minuit2::BasicFunctionMinimum::UserCovariance
const MnUserCovariance & UserCovariance() const
Definition: BasicFunctionMinimum.h:124
ROOT::Minuit2::BasicFunctionMinimum::Parameters
const MinimumParameters & Parameters() const
Definition: BasicFunctionMinimum.h:137
ROOT::Minuit2::MnUserParameterState
class which holds the external user and/or internal Minuit representation of the parameters and error...
Definition: MnUserParameterState.h:33
ROOT::Minuit2::BasicFunctionMinimum::MnAboveMaxEdm
Definition: BasicFunctionMinimum.h:38
ROOT::Minuit2::MinimumError
MinimumError keeps the inv.
Definition: MinimumError.h:26
ROOT::Minuit2::MinimumState::Parameters
const MinimumParameters & Parameters() const
Definition: MinimumState.h:50
ROOT::Minuit2::MnUserParameterState::Parameters
const MnUserParameters & Parameters() const
Definition: MnUserParameterState.h:89
ROOT::Minuit2::BasicFunctionMinimum::BasicFunctionMinimum
BasicFunctionMinimum(const BasicFunctionMinimum &min)
Copy constructor.
Definition: BasicFunctionMinimum.h:72
ROOT::Minuit2::BasicFunctionMinimum::IsAboveMaxEdm
bool IsAboveMaxEdm() const
Definition: BasicFunctionMinimum.h:153
ROOT::Minuit2::MinimumError::IsMadePosDef
bool IsMadePosDef() const
Definition: MinimumError.h:69
ROOT::Minuit2::BasicFunctionMinimum::HasValidCovariance
bool HasValidCovariance() const
Definition: BasicFunctionMinimum.h:147
ROOT::Minuit2::BasicFunctionMinimum::Up
double Up() const
Definition: BasicFunctionMinimum.h:144
ROOT::Minuit2::BasicFunctionMinimum::fSeed
MinimumSeed fSeed
Definition: BasicFunctionMinimum.h:164
ROOT::Minuit2::BasicFunctionMinimum::MnReachedCallLimit
Definition: BasicFunctionMinimum.h:36
ROOT::Minuit2::MinimumError::IsAvailable
bool IsAvailable() const
Definition: MinimumError.h:72
ROOT::Minuit2::MnUserParameterState::Covariance
const MnUserCovariance & Covariance() const
Definition: MnUserParameterState.h:90
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::MinimumError::IsPosDef
bool IsPosDef() const
Definition: MinimumError.h:68
MinimumState.h
ROOT::Minuit2::MinimumSeed
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
Definition: MinimumSeed.h:31
ROOT::Minuit2::BasicFunctionMinimum::Seed
const MinimumSeed & Seed() const
Definition: BasicFunctionMinimum.h:108
ROOT::Minuit2::BasicFunctionMinimum::HasValidParameters
bool HasValidParameters() const
Definition: BasicFunctionMinimum.h:146
ROOT::Minuit2::MinimumError::IsAccurate
bool IsAccurate() const
Definition: MinimumError.h:66