FumiliChi2FCN.h

Go to the documentation of this file.
00001 // @(#)root/minuit2:$Id: FumiliChi2FCN.h 34992 2010-08-25 10:36:11Z moneta $
00002 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei   2003-2005  
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2005 LCG ROOT Math team,  CERN/PH-SFT                *
00007  *                                                                    *
00008  **********************************************************************/
00009 
00010 #ifndef ROOT_Minuit2_FumiliChi2FCN
00011 #define ROOT_Minuit2_FumiliChi2FCN
00012 
00013 #include "FumiliFCNBase.h"
00014 #include <vector>
00015 #include "Minuit2/ParametricFunction.h"
00016 
00017 namespace ROOT {
00018 
00019    namespace Minuit2 {
00020 
00021 
00022 
00023 /** 
00024 
00025 Extension of the FCNBase for the Fumili method. Fumili applies only to 
00026 minimization problems used for fitting. The method is based on a 
00027 linearization of the model function negleting second derivatives. 
00028 User needs to provide the model function. The figure-of-merit describing
00029 the difference between the model function and the actual measurements in
00030 the case of chi-square is the sum of the squares of the figures-of-merit
00031 calculated for each measurement point, which is implemented by the 
00032 operator() member function. The user still has to implement the calculation
00033 of the individual figures-of-merit (which in the majority of the cases
00034 will be the (measured Value - the Value predicted by the model)/standard deviation
00035 implemeted by the FumiliStandardChi2FCN;
00036 however this form can become more complicated (see for an example Numerical Recipes'
00037 section on "Straight-Line Data with Errors in Both Coordinates")).
00038 
00039 
00040 @author Andras Zsenei and Lorenzo Moneta, Creation date: 24 Aug 2004
00041 
00042 @see <A HREF="http://www.cern.ch/winkler/minuit/tutorial/mntutorial.pdf">MINUIT Tutorial</A> on function minimization, section 5
00043 
00044 @see FumiliStandardChi2FCN
00045 
00046 @ingroup Minuit
00047 
00048 */
00049 
00050 
00051 
00052 class FumiliChi2FCN : public FumiliFCNBase {
00053 
00054 public:
00055 
00056   FumiliChi2FCN() {}
00057 
00058   virtual ~FumiliChi2FCN() {}
00059 
00060 
00061 
00062   /**
00063 
00064   Sets the model function for the data (for example gaussian+linear for a peak)
00065 
00066   @param modelFunction a reference to the model function.
00067 
00068   */
00069 
00070   void SetModelFunction(const ParametricFunction& modelFCN) { fModelFunction = &modelFCN; }
00071 
00072 
00073 
00074   /**
00075 
00076   Returns the model function used for the data.
00077 
00078   @return Returns a pointer to the model function.
00079 
00080   */
00081 
00082   const ParametricFunction *  ModelFunction() const { return fModelFunction; }
00083 
00084 
00085 
00086   /**
00087      
00088   Evaluates the model function for the different measurement points and 
00089   the Parameter values supplied, calculates a figure-of-merit for each
00090   measurement and returns a vector containing the result of this
00091   evaluation.
00092 
00093   @param par vector of Parameter values to feed to the model function.
00094 
00095   @return A vector containing the figures-of-merit for the model function evaluated 
00096   for each set of measurements.
00097 
00098   */
00099 
00100   virtual std::vector<double> Elements(const std::vector<double>& par) const = 0;
00101 
00102 
00103 
00104   /**
00105      
00106   Accessor to the parameters of a given measurement. For example in the
00107   case of a chi-square fit with a one-dimensional Gaussian, the Parameter 
00108   characterizing the measurement will be the position. It is the Parameter
00109   that is feeded to the model function.
00110 
00111   @param Index Index of the measueremnt the parameters of which to return
00112   @return A reference to a vector containing the values characterizing a measurement
00113 
00114   */
00115 
00116   virtual const std::vector<double> &  GetMeasurement(int Index) const = 0;
00117 
00118 
00119   /**
00120 
00121   Accessor to the number of measurements used for calculating the 
00122   present figure of merit.
00123 
00124   @return the number of measurements
00125 
00126   */
00127 
00128   virtual int GetNumberOfMeasurements() const = 0;
00129 
00130 
00131 
00132   /**
00133  
00134   Calculates the sum of Elements squared, ie the chi-square. The user must 
00135   implement in a class which inherits from FumiliChi2FCN the member function
00136   Elements() which will supply the Elements for the sum.
00137 
00138 
00139   @param par vector containing the Parameter values for the model function
00140   
00141   @return The sum of Elements squared
00142 
00143   @see FumiliFCNBase#elements
00144 
00145   */
00146   
00147   double operator()(const std::vector<double>& par) const {
00148 
00149     double chiSquare = 0.0; 
00150     std::vector<double> vecElements =  Elements(par);
00151     unsigned int vecElementsSize = vecElements.size();
00152 
00153     for (unsigned int i = 0; i < vecElementsSize; ++i) 
00154       chiSquare += vecElements[i]*vecElements[i]; 
00155 
00156     return chiSquare; 
00157   }
00158   
00159 
00160 
00161   /**
00162      
00163   !!!!!!!!!!!! to be commented
00164 
00165   */
00166 
00167   virtual double Up() const { return 1.0; } 
00168 
00169  private: 
00170 
00171   // A pointer to the model function which describes the data
00172   const ParametricFunction *fModelFunction;
00173 
00174    
00175 
00176 };
00177 
00178   }  // namespace Minuit2
00179 
00180 }  // namespace ROOT
00181 
00182 #endif  // ROOT_Minuit2_FumiliChi2FCN

Generated on Tue Jul 5 14:25:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1