// @(#)root/minuit2:$Id$
// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
 *                                                                    *
 **********************************************************************/

#ifndef ROOT_Minuit2_MnApplication
#define ROOT_Minuit2_MnApplication

#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnStrategy.h"

namespace ROOT {

   namespace Minuit2 {



class FunctionMinimum;
class MinuitParameter;
class MnMachinePrecision;
class ModularFunctionMinimizer;
class FCNBase;
class FCNGradientBase;

//___________________________________________________________________________
/**
    application interface class for minimizers (migrad, simplex, Minimize,
    Scan)
    User normally instantiates the derived class like ROOT::Minuit2::MnMigrad
    for using Migrad for minimization
 */

class MnApplication {

public:


   /// constructor from non-gradient functions
   MnApplication(const FCNBase& fcn, const MnUserParameterState& state, const MnStrategy& stra, unsigned int nfcn = 0);

   /// constructor from gradient function
   MnApplication(const FCNGradientBase& fcn, const MnUserParameterState& state, const MnStrategy& stra, unsigned int nfcn = 0);

   virtual ~MnApplication() { }

   /**
      Minimize the function
      @param maxfcn : max number of function calls (if = 0) default is used which is set to
                     200 + 100 * npar + 5 * npar**2
      @param tolerance : value used for terminating iteration procedure.
             For example, MIGRAD will stop iterating when edm (expected distance from minimum) will be:
             edm < tolerance * 10**-3
             Default value of tolerance used is 0.1
   */
   virtual FunctionMinimum operator()(unsigned int maxfcn = 0, double tolerance = 0.1);

   virtual const ModularFunctionMinimizer& Minimizer() const = 0;

   const MnMachinePrecision& Precision() const {return fState.Precision();}
   const MnUserParameterState& State() const {return fState;}
   const MnUserParameters& Parameters() const {return fState.Parameters();}
   const MnUserCovariance& Covariance() const {return fState.Covariance();}
   virtual const FCNBase& Fcnbase() const {return fFCN;}
   const MnStrategy& Strategy() const {return fStrategy;}
   unsigned int NumOfCalls() const {return fNumCall;}

protected:

   const FCNBase& fFCN;
   MnUserParameterState fState;
   MnStrategy fStrategy;
   unsigned int fNumCall;
   bool fUseGrad;

public:

// facade: forward interface of MnUserParameters and MnUserTransformation
// via MnUserParameterState

   //access to parameters (row-wise)
   const std::vector<ROOT::Minuit2::MinuitParameter>& MinuitParameters() const;
   //access to parameters and errors in column-wise representation
   std::vector<double> Params() const;
   std::vector<double> Errors() const;

   //access to single Parameter
   const MinuitParameter& Parameter(unsigned int i) const;

   //add free Parameter
   void Add(const char* Name, double val, double err);
   //add limited Parameter
   void Add(const char* Name, double val, double err, double , double);
   //add const Parameter
   void Add(const char*, double);

   //interaction via external number of Parameter
   void Fix(unsigned int);
   void Release(unsigned int);
   void SetValue(unsigned int, double);
   void SetError(unsigned int, double);
   void SetLimits(unsigned int, double, double);
   void RemoveLimits(unsigned int);

   double Value(unsigned int) const;
   double Error(unsigned int) const;

   //interaction via Name of Parameter
   void Fix(const char*);
   void Release(const char*);
   void SetValue(const char*, double);
   void SetError(const char*, double);
   void SetLimits(const char*, double, double);
   void RemoveLimits(const char*);
   void SetPrecision(double);

   double Value(const char*) const;
   double Error(const char*) const;

   //convert Name into external number of Parameter
   unsigned int Index(const char*) const;
   //convert external number into Name of Parameter
   const char* Name(unsigned int) const;

   // transformation internal <-> external
   double Int2ext(unsigned int, double) const;
   double Ext2int(unsigned int, double) const;
   unsigned int IntOfExt(unsigned int) const;
   unsigned int ExtOfInt(unsigned int) const;
   unsigned int VariableParameters() const;

};

  }  // namespace Minuit2

}  // namespace ROOT

#endif  // ROOT_Minuit2_MnApplication
 MnApplication.h:1
 MnApplication.h:2
 MnApplication.h:3
 MnApplication.h:4
 MnApplication.h:5
 MnApplication.h:6
 MnApplication.h:7
 MnApplication.h:8
 MnApplication.h:9
 MnApplication.h:10
 MnApplication.h:11
 MnApplication.h:12
 MnApplication.h:13
 MnApplication.h:14
 MnApplication.h:15
 MnApplication.h:16
 MnApplication.h:17
 MnApplication.h:18
 MnApplication.h:19
 MnApplication.h:20
 MnApplication.h:21
 MnApplication.h:22
 MnApplication.h:23
 MnApplication.h:24
 MnApplication.h:25
 MnApplication.h:26
 MnApplication.h:27
 MnApplication.h:28
 MnApplication.h:29
 MnApplication.h:30
 MnApplication.h:31
 MnApplication.h:32
 MnApplication.h:33
 MnApplication.h:34
 MnApplication.h:35
 MnApplication.h:36
 MnApplication.h:37
 MnApplication.h:38
 MnApplication.h:39
 MnApplication.h:40
 MnApplication.h:41
 MnApplication.h:42
 MnApplication.h:43
 MnApplication.h:44
 MnApplication.h:45
 MnApplication.h:46
 MnApplication.h:47
 MnApplication.h:48
 MnApplication.h:49
 MnApplication.h:50
 MnApplication.h:51
 MnApplication.h:52
 MnApplication.h:53
 MnApplication.h:54
 MnApplication.h:55
 MnApplication.h:56
 MnApplication.h:57
 MnApplication.h:58
 MnApplication.h:59
 MnApplication.h:60
 MnApplication.h:61
 MnApplication.h:62
 MnApplication.h:63
 MnApplication.h:64
 MnApplication.h:65
 MnApplication.h:66
 MnApplication.h:67
 MnApplication.h:68
 MnApplication.h:69
 MnApplication.h:70
 MnApplication.h:71
 MnApplication.h:72
 MnApplication.h:73
 MnApplication.h:74
 MnApplication.h:75
 MnApplication.h:76
 MnApplication.h:77
 MnApplication.h:78
 MnApplication.h:79
 MnApplication.h:80
 MnApplication.h:81
 MnApplication.h:82
 MnApplication.h:83
 MnApplication.h:84
 MnApplication.h:85
 MnApplication.h:86
 MnApplication.h:87
 MnApplication.h:88
 MnApplication.h:89
 MnApplication.h:90
 MnApplication.h:91
 MnApplication.h:92
 MnApplication.h:93
 MnApplication.h:94
 MnApplication.h:95
 MnApplication.h:96
 MnApplication.h:97
 MnApplication.h:98
 MnApplication.h:99
 MnApplication.h:100
 MnApplication.h:101
 MnApplication.h:102
 MnApplication.h:103
 MnApplication.h:104
 MnApplication.h:105
 MnApplication.h:106
 MnApplication.h:107
 MnApplication.h:108
 MnApplication.h:109
 MnApplication.h:110
 MnApplication.h:111
 MnApplication.h:112
 MnApplication.h:113
 MnApplication.h:114
 MnApplication.h:115
 MnApplication.h:116
 MnApplication.h:117
 MnApplication.h:118
 MnApplication.h:119
 MnApplication.h:120
 MnApplication.h:121
 MnApplication.h:122
 MnApplication.h:123
 MnApplication.h:124
 MnApplication.h:125
 MnApplication.h:126
 MnApplication.h:127
 MnApplication.h:128
 MnApplication.h:129
 MnApplication.h:130
 MnApplication.h:131
 MnApplication.h:132
 MnApplication.h:133
 MnApplication.h:134
 MnApplication.h:135
 MnApplication.h:136
 MnApplication.h:137
 MnApplication.h:138
 MnApplication.h:139
 MnApplication.h:140
 MnApplication.h:141