|
||||
File indexing completed on 2025-01-18 10:10:23
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_FumiliStandardChi2FCN 0011 #define ROOT_Minuit2_FumiliStandardChi2FCN 0012 0013 #include "Minuit2/FumiliChi2FCN.h" 0014 #include "Minuit2/ParametricFunction.h" 0015 #include <cassert> 0016 #include <vector> 0017 #include <cmath> 0018 0019 namespace ROOT { 0020 0021 namespace Minuit2 { 0022 0023 /** 0024 0025 Class implementing the standard chi square function, which 0026 is the sum of the squares of the figures-of-merit calculated for each measurement 0027 point, the individual figures-of-merit being: (the Value predicted by the 0028 model-measured Value)/standard deviation. 0029 0030 @author Andras Zsenei and Lorenzo Moneta, Creation date: 31 Aug 2004 0031 0032 @see FumiliChi2FCN 0033 0034 @ingroup Minuit 0035 0036 \todo nice formula for the documentation... 0037 0038 */ 0039 0040 class FumiliStandardChi2FCN : public FumiliChi2FCN { 0041 0042 public: 0043 /** 0044 0045 Constructor which initializes chi square function for one-dimensional model function 0046 0047 @param modelFCN the model function used for describing the data. 0048 0049 @param meas vector containing the measured values. 0050 0051 @param pos vector containing the x values corresponding to the 0052 measurements 0053 0054 @param mvar vector containing the variances corresponding to each 0055 measurement (where the variance equals the standard deviation squared). 0056 If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW) 0057 0058 */ 0059 0060 FumiliStandardChi2FCN(const ParametricFunction &modelFCN, const std::vector<double> &meas, 0061 const std::vector<double> &pos, const std::vector<double> &mvar) 0062 { // this->fModelFCN = &modelFunction; 0063 this->SetModelFunction(modelFCN); 0064 0065 assert(meas.size() == pos.size()); 0066 assert(meas.size() == mvar.size()); 0067 fMeasurements = meas; 0068 std::vector<double> x(1); 0069 unsigned int n = mvar.size(); 0070 fPositions.reserve(n); 0071 // correct for variance == 0 0072 fInvErrors.resize(n); 0073 for (unsigned int i = 0; i < n; ++i) { 0074 x[0] = pos[i]; 0075 fPositions.push_back(x); 0076 // PAW/ROOT hack : use 1 for 0 entries bins 0077 if (mvar[i] == 0) 0078 fInvErrors[i] = 1; 0079 else 0080 fInvErrors[i] = 1.0 / std::sqrt(mvar[i]); 0081 } 0082 } 0083 0084 /** 0085 0086 Constructor which initializes the multi-dimensional model function. 0087 0088 @param modelFCN the model function used for describing the data. 0089 0090 @param meas vector containing the measured values. 0091 0092 @param pos vector containing the x values corresponding to the 0093 measurements 0094 0095 @param mvar vector containing the variances corresponding to each 0096 measurement (where the variance equals the standard deviation squared). 0097 If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW) 0098 0099 */ 0100 0101 FumiliStandardChi2FCN(const ParametricFunction &modelFCN, const std::vector<double> &meas, 0102 const std::vector<std::vector<double>> &pos, const std::vector<double> &mvar) 0103 { // this->fModelFCN = &modelFunction; 0104 this->SetModelFunction(modelFCN); 0105 0106 assert(meas.size() == pos.size()); 0107 assert(meas.size() == mvar.size()); 0108 fMeasurements = meas; 0109 fPositions = pos; 0110 // correct for variance == 0 0111 unsigned int n = mvar.size(); 0112 fInvErrors.resize(n); 0113 for (unsigned int i = 0; i < n; ++i) { 0114 // PAW/ROOT hack : use 1 for 0 entries bins 0115 if (mvar[i] == 0) 0116 fInvErrors[i] = 1; 0117 else 0118 fInvErrors[i] = 1.0 / std::sqrt(mvar[i]); 0119 } 0120 } 0121 0122 ~FumiliStandardChi2FCN() override {} 0123 0124 /** 0125 0126 Evaluates the model function for the different measurement points and 0127 the Parameter values supplied, calculates a figure-of-merit for each 0128 measurement and returns a vector containing the result of this 0129 evaluation. The figure-of-merit is (Value predicted by the model 0130 function-measured Value)/standard deviation. 0131 0132 @param par vector of Parameter values to feed to the model function. 0133 0134 @return A vector containing the figures-of-merit for the model function evaluated 0135 for each set of measurements. 0136 0137 \todo What to do when the variances are 0???!! (right now just pushes back 0...) 0138 0139 */ 0140 0141 std::vector<double> Elements(const std::vector<double> &par) const override; 0142 0143 /** 0144 0145 Accessor to the position of the measurement (x coordinate). 0146 0147 @param Index Index of the measuerement the position of which to return. 0148 0149 @return the position of the measurement. 0150 0151 */ 0152 0153 const std::vector<double> &GetMeasurement(int Index) const override; 0154 0155 /** 0156 0157 Accessor to the number of measurements used for calculating 0158 the chi-square. 0159 0160 @return the number of measurements. 0161 0162 */ 0163 0164 int GetNumberOfMeasurements() const override; 0165 0166 /** 0167 0168 Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p 0169 The result is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and 0170 FumiliFCNBase::Hessian methods 0171 0172 @param par vector of parameters 0173 0174 **/ 0175 0176 void EvaluateAll(const std::vector<double> &par) override; 0177 0178 private: 0179 std::vector<double> fMeasurements; 0180 // support multi dim coordinates 0181 std::vector<std::vector<double>> fPositions; 0182 std::vector<double> fInvErrors; 0183 }; 0184 0185 } // namespace Minuit2 0186 0187 } // namespace ROOT 0188 0189 #endif // ROOT_Minuit2_FumiliStandardChi2FCN
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |