// @(#)root/mathcore:$Id$
// Author: L. Moneta Thu Aug 16 15:40:28 2007

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2007  LCG ROOT Math Team, CERN/PH-SFT                *
 *                                                                    *
 *                                                                    *
 **********************************************************************/

// Header file for class FitMethodFunction

#ifndef ROOT_Math_FitMethodFunction
#define ROOT_Math_FitMethodFunction

#ifndef ROOT_Math_IFunction
#include "Math/IFunction.h"
#endif

// #ifndef ROOT_Math_IParamFunctionfwd
// #include "Math/IParamFunctionfwd.h"
// #endif

namespace ROOT {

   namespace Math {

//______________________________________________________________________________________
/**
   FitMethodFunction class
   Interface for objective functions (like chi2 and likelihood used in the fit)
   In addition to normal function interface provide interface for calculating each
   data contrinution to the function which is required by some algorithm (like Fumili)

   @ingroup  FitMethodFunc
*/
template<class FunctionType>
class BasicFitMethodFunction : public FunctionType {

public:


   typedef  typename FunctionType::BaseFunc BaseFunction;

   /// enumeration specyfing the possible fit method types
   enum Type_t { kUndefined , kLeastSquare, kLogLikelihood };


   BasicFitMethodFunction(int dim, int npoint) :
      fNDim(dim),
      fNPoints(npoint),
      fNCalls(0)
   {}

   /**
      Virtual Destructor (no operations)
   */
   virtual ~BasicFitMethodFunction ()  {}

   /**
      Number of dimension (parameters) . From IGenMultiFunction interface
    */
   virtual unsigned int NDim() const { return fNDim; }

   /**
      method returning the data i-th contribution to the fit objective function
      For example the residual for the least square functions or the pdf element for the
      likelihood functions.
      Estimating eventually also the gradient of the data element if the passed pointer  is not null
    */
   virtual double DataElement(const double *x, unsigned int i, double *g = 0) const = 0;


   /**
      return the number of data points used in evaluating the function
    */
   virtual unsigned int NPoints() const { return fNPoints; }

   /**
      return the type of method, override if needed
    */
   virtual Type_t Type() const { return kUndefined; }

   /**
      return the total number of function calls (overrided if needed)
    */
   virtual unsigned int NCalls() const { return fNCalls; }

   /**
      update number of calls
    */
   virtual void UpdateNCalls() const { fNCalls++; }

   /**
      reset number of function calls
    */
   virtual void ResetNCalls() { fNCalls = 0; }



public:


protected:


private:

   unsigned int fNDim;      // function dimension
   unsigned int fNPoints;   // size of the data
   mutable unsigned int fNCalls; // number of function calls


};

      // define the normal and gradient function
      typedef BasicFitMethodFunction<ROOT::Math::IMultiGenFunction>  FitMethodFunction;
      typedef BasicFitMethodFunction<ROOT::Math::IMultiGradFunction> FitMethodGradFunction;


      // useful template definition to use these interface in
      // generic programming
      // (comment them out since they are not used anymore)
/*
      template<class FunType>
      struct ParamFunctionTrait {
         typedef  IParamMultiFunction PFType;
      };

      // specialization for the gradient param functions
      template<>
      struct ParamFunctionTrait<ROOT::Math::IMultiGradFunction>  {
         typedef  IParamMultiGradFunction PFType;
      };
*/


   } // end namespace Math

} // end namespace ROOT






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