Logo ROOT   6.13/01
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 
27 //extern StackAllocator gStackAllocator;
28 
29 /** result of the minimization;
30  both internal and external (MnUserParameterState) representation available
31  For the parameters at the Minimum
32  */
33 
35 
36 public:
37 
39  class MnAboveMaxEdm {};
40 
41 public:
42 
43  /// constructor from only MinimumSeed. Minimum is only from seed result not the full minimization
44  BasicFunctionMinimum(const MinimumSeed& seed, double up) : fSeed(seed), fStates(std::vector<MinimumState>(1, MinimumState(seed.Parameters(), seed.Error(), seed.Gradient(), seed.Parameters().Fval(), seed.NFcn()))), fErrorDef(up), fAboveMaxEdm(false), fReachedCallLimit(false), fUserState(MnUserParameterState()) {}
45 
46  /// constructor at the end of a successfull minimization from seed and vector of states
47  BasicFunctionMinimum(const MinimumSeed& seed, const std::vector<MinimumState>& states, double up) : fSeed(seed), fStates(states), fErrorDef(up), fAboveMaxEdm(false), fReachedCallLimit(false), fUserState(MnUserParameterState()) {}
48 
49  /// constructor at the end of a failed minimization due to exceeding function call limit
50  BasicFunctionMinimum(const MinimumSeed& seed, const std::vector<MinimumState>& states, double up, MnReachedCallLimit) : fSeed(seed), fStates(states), fErrorDef(up), fAboveMaxEdm(false), fReachedCallLimit(true), fUserState(MnUserParameterState()) {}
51 
52  /// constructor at the end of a failed minimization due to edm above maximum value
53  BasicFunctionMinimum(const MinimumSeed& seed, const std::vector<MinimumState>& states, double up, MnAboveMaxEdm) : fSeed(seed), fStates(states), fErrorDef(up), fAboveMaxEdm(true), fReachedCallLimit(false), fUserState(MnUserParameterState()) {}
54 
55  /// copy constructor
57 
59  fSeed = min.fSeed;
60  fStates = min.fStates;
61  fErrorDef = min.fErrorDef;
64  fUserState = min.fUserState;
65  return *this;
66  }
67 
69 
70  /// add latest minimization state (for example add Hesse result after Migrad)
71  void Add(const MinimumState& state ) {
72  fStates.push_back(state);
73  // LM : update also the user state
74  fUserState = MnUserParameterState(State(), Up(), Seed().Trafo());
75  // reset maxedm flag. If new state has edm over max other method must be used
76  fAboveMaxEdm = false;
77  }
78 
79  ///Add a new state and flag that edm is above maximum
80  void Add(const MinimumState& state, MnAboveMaxEdm) {
81  Add(state);
82  fAboveMaxEdm = true;
83  }
84 
85  const MinimumSeed& Seed() const {return fSeed;}
86  const std::vector<MinimumState>& States() const {return fStates;}
87 
88 // user representation of state at Minimum
90  if(!fUserState.IsValid())
92  return fUserState;
93  }
95  if(!fUserState.IsValid())
97  return fUserState.Parameters();
98  }
100  if(!fUserState.IsValid())
102  return fUserState.Covariance();
103  }
104 
105  void* operator new(size_t nbytes) {
106  return StackAllocatorHolder::Get().Allocate(nbytes);
107  }
108 
109  void operator delete(void* p, size_t /*nbytes */) {
111  }
112 
113  // forward interface of last state
114  const MinimumState& State() const {return fStates.back();}
115  const MinimumParameters& Parameters() const {return fStates.back().Parameters();}
116  const MinimumError& Error() const {return fStates.back().Error();}
117  const FunctionGradient& Grad() const {return fStates.back().Gradient();}
118  double Fval() const {return fStates.back().Fval();}
119  double Edm() const {return fStates.back().Edm();}
120  int NFcn() const {return fStates.back().NFcn();}
121 
122  double Up() const {return fErrorDef;}
123  bool IsValid() const {
124  return State().IsValid() && !IsAboveMaxEdm() && !HasReachedCallLimit();
125  }
126  bool HasValidParameters() const {return State().Parameters().IsValid();}
127  bool HasValidCovariance() const {return State().Error().IsValid();}
128  bool HasAccurateCovar() const {return State().Error().IsAccurate();}
129  bool HasPosDefCovar() const {return State().Error().IsPosDef();}
130  bool HasMadePosDefCovar() const {return State().Error().IsMadePosDef();}
131  bool HesseFailed() const {return State().Error().HesseFailed();}
132  bool HasCovariance() const {return State().Error().IsAvailable();}
133  bool IsAboveMaxEdm() const {return fAboveMaxEdm;}
134  bool HasReachedCallLimit() const {return fReachedCallLimit;}
135 
136  void SetErrorDef( double up) {
137  fErrorDef = up;
138  // update user state for new valeu of up (scaling of errors)
139  fUserState = MnUserParameterState(State(), up, Seed().Trafo());
140  }
141 
142 private:
143 
145  std::vector<MinimumState> fStates;
146  double fErrorDef;
150 };
151 
152  } // namespace Minuit2
153 
154 } // namespace ROOT
155 
156 #endif // ROOT_Minuit2_BasicFunctionMinimum
void Add(const MinimumState &state)
add latest minimization state (for example add Hesse result after Migrad)
const MnUserParameterState & UserState() const
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 ...
Namespace for new ROOT classes and functions.
Definition: TFoamSampler.h:19
const MnUserTransformation & Trafo() const
Definition: MinimumSeed.h:50
MinimumSeed contains the starting values for the minimization produced by the SeedGenerator.
Definition: MinimumSeed.h:31
BasicFunctionMinimum(const BasicFunctionMinimum &min)
copy constructor
BasicFunctionMinimum & operator=(const BasicFunctionMinimum &min)
STL namespace.
const FunctionGradient & Grad() const
const MinimumState & State() const
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
void * Allocate(size_t nBytes)
const MnUserCovariance & UserCovariance() const
result of the minimization; both internal and external (MnUserParameterState) representation availabl...
const MinimumError & Error() const
std::vector< MinimumState > fStates
void Add(const MinimumState &state, MnAboveMaxEdm)
Add a new state and flag that edm is above maximum.
class which holds the external user and/or internal Minuit representation of the parameters and error...
const MinimumSeed & Seed() const
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 ...
API class for the user interaction with the parameters; serves as input to the minimizer as well as o...
const MnUserCovariance & Covariance() const
const std::vector< MinimumState > & States() const
const MnUserParameters & Parameters() const
const MinimumError & Error() const
Definition: MinimumState.h:62
const MinimumParameters & Parameters() const
Definition: MinimumState.h:58
const MinimumParameters & Parameters() const
MinimumError keeps the inv.
Definition: MinimumError.h:26
const MnUserParameters & UserParameters() const
MinimumState keeps the information (position, Gradient, 2nd deriv, etc) after one minimization step (...
Definition: MinimumState.h:29
BasicFunctionMinimum(const MinimumSeed &seed, double up)
constructor from only MinimumSeed. Minimum is only from seed result not the full minimization ...
static StackAllocator & Get()
Class containing the covariance matrix data represented as a vector of size n*(n+1)/2 Used to hide in...