Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:12

0001 // @(#)root/minuit2:$Id$
0002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005
0003 
0004 /**********************************************************************
0005  *                                                                    *
0006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
0007  *                                                                    *
0008  **********************************************************************/
0009 
0010 #ifndef ROOT_Minuit2_MinimumState
0011 #define ROOT_Minuit2_MinimumState
0012 
0013 #include "Minuit2/MinimumParameters.h"
0014 #include "Minuit2/MinimumError.h"
0015 #include "Minuit2/FunctionGradient.h"
0016 
0017 #include <memory>
0018 
0019 namespace ROOT {
0020 
0021 namespace Minuit2 {
0022 
0023 /** MinimumState keeps the information (position, Gradient, 2nd deriv, etc)
0024     after one minimization step (usually in MinimumBuilder).
0025  */
0026 
0027 class MinimumState {
0028 
0029 public:
0030    /// Invalid state.
0031    MinimumState(unsigned int n) : MinimumState(MinimumParameters(n, 0.0), MinimumError(n), FunctionGradient(n), 0.0, 0)
0032    {
0033    }
0034 
0035    /// Constructor without parameter values, but with function value, edm and nfcn.
0036    /// This constructor will result in a state that is flagged as not valid
0037    MinimumState(double fval, double edm, int nfcn)
0038       : MinimumState(MinimumParameters(0, fval), MinimumError(0), FunctionGradient(0), edm, nfcn)
0039    {
0040    }
0041 
0042    /// Constructor with only parameter values, edm and nfcn, but without errors (covariance).
0043    /// The resulting state it will be considered valid, since it contains the parameter values,
0044    /// although it has not the error matrix (MinimumError) and  HasCovariance() returns false.
0045    MinimumState(const MinimumParameters &states, double edm, int nfcn)
0046       : MinimumState(states, MinimumError(states.Vec().size()), FunctionGradient(states.Vec().size()), edm, nfcn)
0047    {
0048    }
0049 
0050    /// Constructor with parameters values, errors and gradient
0051    MinimumState(const MinimumParameters &states, const MinimumError &err, const FunctionGradient &grad, double edm,
0052                 int nfcn)
0053       : fPtr{new Data{states, err, grad, edm, nfcn}}
0054    {
0055    }
0056 
0057    const MinimumParameters &Parameters() const { return fPtr->fParameters; }
0058    const MnAlgebraicVector &Vec() const { return Parameters().Vec(); }
0059    int size() const { return Vec().size(); }
0060 
0061    const MinimumError &Error() const { return fPtr->fError; }
0062    const FunctionGradient &Gradient() const { return fPtr->fGradient; }
0063    double Fval() const { return Parameters().Fval(); }
0064    double Edm() const { return fPtr->fEDM; }
0065    int NFcn() const { return fPtr->fNFcn; }
0066 
0067    bool IsValid() const
0068    {
0069       if (HasParameters() && HasCovariance())
0070          return Parameters().IsValid() && Error().IsValid();
0071       else if (HasParameters())
0072          return Parameters().IsValid();
0073       else
0074          return false;
0075    }
0076 
0077    bool HasParameters() const { return Parameters().IsValid(); }
0078    bool HasCovariance() const { return Error().IsAvailable(); }
0079 
0080 private:
0081    struct Data {
0082       MinimumParameters fParameters;
0083       MinimumError fError;
0084       FunctionGradient fGradient;
0085       double fEDM;
0086       int fNFcn;
0087    };
0088 
0089    std::shared_ptr<Data> fPtr;
0090 };
0091 
0092 } // namespace Minuit2
0093 
0094 } // namespace ROOT
0095 
0096 #endif // ROOT_Minuit2_MinimumState