/usr/include/root/Fit/Chi2FCN.h is in libroot-math-mathcore-dev 5.34.14-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | // @(#)root/mathcore:$Id$
// Author: L. Moneta Tue Sep 5 09:13:32 2006
/**********************************************************************
* *
* Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
* *
* *
**********************************************************************/
// Header file for class Chi2FCN
#ifndef ROOT_Fit_Chi2FCN
#define ROOT_Fit_Chi2FCN
#ifndef ROOT_Math_FitMethodFunction
#include "Math/FitMethodFunction.h"
#endif
#ifndef ROOT_Math_IParamFunction
#include "Math/IParamFunction.h"
#endif
#ifndef ROOT_Fit_BinData
#include "Fit/BinData.h"
#endif
#ifndef ROOT_Fit_FitUtil
#include "Fit/FitUtil.h"
#endif
//#define ROOT_FIT_PARALLEL
#ifdef ROOT_FIT_PARALLEL
#ifndef ROOT_Fit_FitUtilParallel
#include "Fit/FitUtilParallel.h"
#endif
#endif
/**
@defgroup FitMethodFunc Fit Method Classes
Classes describing Fit Method functions
@ingroup Fit
*/
namespace ROOT {
namespace Fit {
//___________________________________________________________________________________
/**
Chi2FCN class for binnned fits using the least square methods
@ingroup FitMethodFunc
*/
template<class FunType>
class Chi2FCN : public ::ROOT::Math::BasicFitMethodFunction<FunType> {
public:
typedef ::ROOT::Math::BasicFitMethodFunction<FunType> BaseObjFunction;
typedef typename BaseObjFunction::BaseFunction BaseFunction;
//typedef typename ::ROOT::Math::ParamFunctionTrait<FunType>::PFType IModelFunction;
typedef ::ROOT::Math::IParamMultiFunction IModelFunction;
typedef typename BaseObjFunction::Type_t Type_t;
/**
Constructor from data set (binned ) and model function
*/
Chi2FCN (const BinData & data, const IModelFunction & func) :
BaseObjFunction(func.NPar(), data.Size() ),
fData(data),
fFunc(func),
fNEffPoints(0),
fGrad ( std::vector<double> ( func.NPar() ) )
{ }
/**
Destructor (no operations)
*/
virtual ~Chi2FCN () {}
#ifdef LATER
private:
// usually copying is non trivial, so we make this unaccessible
/**
Copy constructor
*/
Chi2FCN(const Chi2FCN &);
/**
Assignment operator
*/
Chi2FCN & operator = (const Chi2FCN & rhs);
#endif
public:
virtual BaseFunction * Clone() const {
// clone the function
Chi2FCN * fcn = new Chi2FCN(fData,fFunc);
return fcn;
}
using BaseObjFunction::operator();
// effective points used in the fit (exclude the rejected one)
virtual unsigned int NFitPoints() const { return fNEffPoints; }
/// i-th chi-square residual
virtual double DataElement(const double * x, unsigned int i, double * g) const {
if (i==0) this->UpdateNCalls();
return FitUtil::EvaluateChi2Residual(fFunc, fData, x, i, g);
}
// need to be virtual to be instantiated
virtual void Gradient(const double *x, double *g) const {
// evaluate the chi2 gradient
FitUtil::EvaluateChi2Gradient(fFunc, fData, x, g, fNEffPoints);
}
/// get type of fit method function
virtual typename BaseObjFunction::Type_t Type() const { return BaseObjFunction::kLeastSquare; }
/// access to const reference to the data
virtual const BinData & Data() const { return fData; }
/// access to const reference to the model function
virtual const IModelFunction & ModelFunction() const { return fFunc; }
protected:
/// set number of fit points (need to be called in const methods, make it const)
virtual void SetNFitPoints(unsigned int n) const { fNEffPoints = n; }
private:
/**
Evaluation of the function (required by interface)
*/
virtual double DoEval (const double * x) const {
this->UpdateNCalls();
#ifdef ROOT_FIT_PARALLEL
return FitUtilParallel::EvaluateChi2(fFunc, fData, x, fNEffPoints);
#else
if (!fData.HaveCoordErrors() )
return FitUtil::EvaluateChi2(fFunc, fData, x, fNEffPoints);
else
return FitUtil::EvaluateChi2Effective(fFunc, fData, x, fNEffPoints);
#endif
}
// for derivatives
virtual double DoDerivative(const double * x, unsigned int icoord ) const {
Gradient(x, &fGrad[0]);
return fGrad[icoord];
}
const BinData & fData;
const IModelFunction & fFunc;
mutable unsigned int fNEffPoints; // number of effective points used in the fit
mutable std::vector<double> fGrad; // for derivatives
};
// define useful typedef's
typedef Chi2FCN<ROOT::Math::IMultiGenFunction> Chi2Function;
typedef Chi2FCN<ROOT::Math::IMultiGradFunction> Chi2GradFunction;
} // end namespace Fit
} // end namespace ROOT
#endif /* ROOT_Fit_Chi2FCN */
|