Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:31:44

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_FumiliMaximumLikelihoodFCN
0011 #define ROOT_Minuit2_FumiliMaximumLikelihoodFCN
0012 
0013 #include "FumiliFCNBase.h"
0014 #include "Minuit2/ParametricFunction.h"
0015 #include "Math/Util.h"
0016 #include <vector>
0017 #include <cassert>
0018 
0019 namespace ROOT {
0020 
0021 namespace Minuit2 {
0022 
0023 /**
0024 
0025 Extension of the FCNBase for the Fumili method. Fumili applies only to
0026 minimization problems used for fitting. The method is based on a
0027 linearization of the model function negleting second derivatives.
0028 User needs to provide the model function. In this cased the function
0029 to be minimized is the sum of the logarithms of the model function
0030 for the different measurements times -1.
0031 
0032 
0033 @author Andras Zsenei and Lorenzo Moneta, Creation date: 3 Sep 2004
0034 
0035 @see <A HREF="http://www.cern.ch/winkler/minuit/tutorial/mntutorial.pdf">MINUIT Tutorial</A> on function minimization,
0036 section 5
0037 
0038 @see FumiliStandardMaximumLikelihoodFCN
0039 
0040 @ingroup Minuit
0041 
0042 \todo Insert a nice latex formula...
0043 
0044 */
0045 
0046 class FumiliMaximumLikelihoodFCN : public FumiliFCNBase {
0047 
0048 public:
0049    FumiliMaximumLikelihoodFCN() {}
0050 
0051    /**
0052 
0053    Sets the model function for the data (for example gaussian+linear for a peak)
0054 
0055    @param modelFCN a reference to the model function.
0056 
0057    */
0058 
0059    void SetModelFunction(const ParametricFunction &modelFCN) { fModelFunction = &modelFCN; }
0060 
0061    /**
0062 
0063    Returns the model function used for the data.
0064 
0065    @return Returns a pointer to the model function.
0066 
0067    */
0068 
0069    const ParametricFunction *ModelFunction() const { return fModelFunction; }
0070 
0071    /**
0072 
0073    Evaluates the model function for the different measurement points and
0074    the Parameter values supplied, calculates a figure-of-merit for each
0075    measurement and returns a vector containing the result of this
0076    evaluation.
0077 
0078    @param par vector of Parameter values to feed to the model function.
0079 
0080    @return A vector containing the figures-of-merit for the model function evaluated
0081    for each set of measurements.
0082 
0083    */
0084 
0085    virtual std::vector<double> Elements(std::vector<double> const &par) const = 0;
0086 
0087    /**
0088 
0089    Accessor to the parameters of a given measurement. For example in the
0090    case of a chi-square fit with a one-dimensional Gaussian, the Parameter
0091    characterizing the measurement will be the position. It is the Parameter
0092    that is passed to the model function.
0093 
0094    @param Index Index of the measueremnt the parameters of which to return
0095    @return A vector containing the values characterizing a measurement
0096 
0097    */
0098 
0099    virtual const std::vector<double> &GetMeasurement(int Index) const = 0;
0100 
0101    /**
0102 
0103    Accessor to the number of measurements used for calculating the
0104    present figure of merit.
0105 
0106    @return the number of measurements
0107 
0108    */
0109 
0110    virtual int GetNumberOfMeasurements() const = 0;
0111 
0112    /**
0113 
0114    Calculates the function for the maximum likelihood method. The user must
0115    implement in a class which inherits from FumiliChi2FCN the member function
0116    Elements() which will supply the Elements for the sum.
0117 
0118 
0119    @param par vector containing the Parameter values for the model function
0120 
0121    @return The sum of the natural logarithm of the Elements multiplied by -1
0122 
0123    @see FumiliFCNBase#elements
0124 
0125    */
0126 
0127    double operator()(std::vector<double> const &par) const override
0128    {
0129 
0130       double sumoflogs = 0.0;
0131       std::vector<double> vecElements = Elements(par);
0132       unsigned int vecElementsSize = vecElements.size();
0133 
0134       for (unsigned int i = 0; i < vecElementsSize; ++i) {
0135          double tmp = vecElements[i];
0136          // for max likelihood probability have to be positive
0137          assert(tmp >= 0);
0138          sumoflogs -= ROOT::Math::Util::EvalLog(tmp);
0139          // std::cout << " i " << tmp << " likelihood " << sumoflogs << std::endl;
0140       }
0141 
0142       return sumoflogs;
0143    }
0144 
0145    /**
0146 
0147    !!!!!!!!!!!! to be commented
0148 
0149    */
0150 
0151    double Up() const override { return 0.5; }
0152 
0153 private:
0154    // A pointer to the model function which describes the data
0155    const ParametricFunction *fModelFunction;
0156 };
0157 
0158 } // namespace Minuit2
0159 
0160 } // namespace ROOT
0161 
0162 #endif // ROOT_Minuit2_FumiliMaximumLikelihoodFCN