Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
FumiliStandardChi2FCN.h
Go to the documentation of this file.
1// @(#)root/minuit2:$Id$
2// Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT *
7 * *
8 **********************************************************************/
9
10#ifndef ROOT_Minuit2_FumiliStandardChi2FCN
11#define ROOT_Minuit2_FumiliStandardChi2FCN
12
15
16#include <ROOT/RSpan.hxx>
17
18#include <cassert>
19#include <vector>
20#include <cmath>
21
22namespace ROOT {
23
24namespace Minuit2 {
25
26/**
27
28Class implementing the standard chi square function, which
29is the sum of the squares of the figures-of-merit calculated for each measurement
30point, the individual figures-of-merit being: (the Value predicted by the
31model-measured Value)/standard deviation.
32
33@author Andras Zsenei and Lorenzo Moneta, Creation date: 31 Aug 2004
34
35@see FumiliChi2FCN
36
37@ingroup Minuit
38
39\todo nice formula for the documentation...
40
41*/
42
44
45public:
46 /**
47
48 Constructor which initializes chi square function for one-dimensional model function
49
50 @param modelFCN the model function used for describing the data.
51
52 @param meas vector containing the measured values.
53
54 @param pos vector containing the x values corresponding to the
55 measurements
56
57 @param mvar vector containing the variances corresponding to each
58 measurement (where the variance equals the standard deviation squared).
59 If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW)
60
61 */
62
63 FumiliStandardChi2FCN(const ParametricFunction &modelFCN, std::span<const double> meas,
64 std::span<const double> pos, std::span<const double> mvar)
65 { // this->fModelFCN = &modelFunction;
66 this->SetModelFunction(modelFCN);
67
68 assert(meas.size() == pos.size());
69 assert(meas.size() == mvar.size());
70 fMeasurements.assign(meas.begin(), meas.end());
71 std::vector<double> x(1);
72 unsigned int n = mvar.size();
73 fPositions.reserve(n);
74 // correct for variance == 0
75 fInvErrors.resize(n);
76 for (unsigned int i = 0; i < n; ++i) {
77 x[0] = pos[i];
78 fPositions.push_back(x);
79 // PAW/ROOT hack : use 1 for 0 entries bins
80 if (mvar[i] == 0)
81 fInvErrors[i] = 1;
82 else
83 fInvErrors[i] = 1.0 / std::sqrt(mvar[i]);
84 }
85 }
86
87 /**
88
89 Constructor which initializes the multi-dimensional model function.
90
91 @param modelFCN the model function used for describing the data.
92
93 @param meas vector containing the measured values.
94
95 @param pos vector containing the x values corresponding to the
96 measurements
97
98 @param mvar vector containing the variances corresponding to each
99 measurement (where the variance equals the standard deviation squared).
100 If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW)
101
102 */
103
104 FumiliStandardChi2FCN(const ParametricFunction &modelFCN, std::span<const double> meas,
105 std::span<const std::vector<double>> pos, std::span<const double> mvar)
106 { // this->fModelFCN = &modelFunction;
107 this->SetModelFunction(modelFCN);
108
109 assert(meas.size() == pos.size());
110 assert(meas.size() == mvar.size());
111 fMeasurements.assign(meas.begin(), meas.end());
112 fPositions.assign(pos.begin(), pos.end());
113 // correct for variance == 0
114 unsigned int n = mvar.size();
115 fInvErrors.resize(n);
116 for (unsigned int i = 0; i < n; ++i) {
117 // PAW/ROOT hack : use 1 for 0 entries bins
118 if (mvar[i] == 0)
119 fInvErrors[i] = 1;
120 else
121 fInvErrors[i] = 1.0 / std::sqrt(mvar[i]);
122 }
123 }
124
125 /**
126
127 Evaluates the model function for the different measurement points and
128 the Parameter values supplied, calculates a figure-of-merit for each
129 measurement and returns a vector containing the result of this
130 evaluation. The figure-of-merit is (Value predicted by the model
131 function-measured Value)/standard deviation.
132
133 @param par vector of Parameter values to feed to the model function.
134
135 @return A vector containing the figures-of-merit for the model function evaluated
136 for each set of measurements.
137
138 \todo What to do when the variances are 0???!! (right now just pushes back 0...)
139
140 */
141
142 std::vector<double> Elements(std::vector<double> const &par) const override;
143
144 /**
145
146 Accessor to the position of the measurement (x coordinate).
147
148 @param Index Index of the measuerement the position of which to return.
149
150 @return the position of the measurement.
151
152 */
153
154 const std::vector<double> &GetMeasurement(int Index) const override;
155
156 /**
157
158 Accessor to the number of measurements used for calculating
159 the chi-square.
160
161 @return the number of measurements.
162
163 */
164
165 int GetNumberOfMeasurements() const override;
166
167 /**
168
169 Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p
170 The result is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and
171 FumiliFCNBase::Hessian methods
172
173 @param par vector of parameters
174
175 **/
176
177 void EvaluateAll(std::vector<double> const &par) override;
178
179private:
180 std::vector<double> fMeasurements;
181 // support multi dim coordinates
182 std::vector<std::vector<double>> fPositions;
183 std::vector<double> fInvErrors;
184};
185
186} // namespace Minuit2
187
188} // namespace ROOT
189
190#endif // ROOT_Minuit2_FumiliStandardChi2FCN
Extension of the FCNBase for the Fumili method.
void SetModelFunction(const ParametricFunction &modelFCN)
Sets the model function for the data (for example gaussian+linear for a peak)
Class implementing the standard chi square function, which is the sum of the squares of the figures-o...
const std::vector< double > & GetMeasurement(int Index) const override
Accessor to the position of the measurement (x coordinate).
FumiliStandardChi2FCN(const ParametricFunction &modelFCN, std::span< const double > meas, std::span< const std::vector< double > > pos, std::span< const double > mvar)
Constructor which initializes the multi-dimensional model function.
std::vector< double > Elements(std::vector< double > const &par) const override
Evaluates the model function for the different measurement points and the Parameter values supplied,...
int GetNumberOfMeasurements() const override
Accessor to the number of measurements used for calculating the chi-square.
std::vector< std::vector< double > > fPositions
FumiliStandardChi2FCN(const ParametricFunction &modelFCN, std::span< const double > meas, std::span< const double > pos, std::span< const double > mvar)
Constructor which initializes chi square function for one-dimensional model function.
void EvaluateAll(std::vector< double > const &par) override
Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p ...
Function which has parameters.
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...