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#include <cassert>
16#include <vector>
17#include <cmath>
18
19namespace ROOT {
20
21namespace Minuit2 {
22
23/**
24
25Class implementing the standard chi square function, which
26is the sum of the squares of the figures-of-merit calculated for each measurement
27point, the individual figures-of-merit being: (the Value predicted by the
28model-measured Value)/standard deviation.
29
30@author Andras Zsenei and Lorenzo Moneta, Creation date: 31 Aug 2004
31
32@see FumiliChi2FCN
33
34@ingroup Minuit
35
36\todo nice formula for the documentation...
37
38*/
39
41
42public:
43 /**
44
45 Constructor which initializes chi square function for one-dimensional model function
46
47 @param modelFCN the model function used for describing the data.
48
49 @param meas vector containing the measured values.
50
51 @param pos vector containing the x values corresponding to the
52 measurements
53
54 @param mvar vector containing the variances corresponding to each
55 measurement (where the variance equals the standard deviation squared).
56 If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW)
57
58 */
59
60 FumiliStandardChi2FCN(const ParametricFunction &modelFCN, const std::vector<double> &meas,
61 const std::vector<double> &pos, const std::vector<double> &mvar)
62 { // this->fModelFCN = &modelFunction;
63 this->SetModelFunction(modelFCN);
64
65 assert(meas.size() == pos.size());
66 assert(meas.size() == mvar.size());
67 fMeasurements = meas;
68 std::vector<double> x(1);
69 unsigned int n = mvar.size();
70 fPositions.reserve(n);
71 // correct for variance == 0
72 fInvErrors.resize(n);
73 for (unsigned int i = 0; i < n; ++i) {
74 x[0] = pos[i];
75 fPositions.push_back(x);
76 // PAW/ROOT hack : use 1 for 0 entries bins
77 if (mvar[i] == 0)
78 fInvErrors[i] = 1;
79 else
80 fInvErrors[i] = 1.0 / std::sqrt(mvar[i]);
81 }
82 }
83
84 /**
85
86 Constructor which initializes the multi-dimensional model function.
87
88 @param modelFCN the model function used for describing the data.
89
90 @param meas vector containing the measured values.
91
92 @param pos vector containing the x values corresponding to the
93 measurements
94
95 @param mvar vector containing the variances corresponding to each
96 measurement (where the variance equals the standard deviation squared).
97 If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW)
98
99 */
100
101 FumiliStandardChi2FCN(const ParametricFunction &modelFCN, const std::vector<double> &meas,
102 const std::vector<std::vector<double>> &pos, const std::vector<double> &mvar)
103 { // this->fModelFCN = &modelFunction;
104 this->SetModelFunction(modelFCN);
105
106 assert(meas.size() == pos.size());
107 assert(meas.size() == mvar.size());
108 fMeasurements = meas;
109 fPositions = pos;
110 // correct for variance == 0
111 unsigned int n = mvar.size();
112 fInvErrors.resize(n);
113 for (unsigned int i = 0; i < n; ++i) {
114 // PAW/ROOT hack : use 1 for 0 entries bins
115 if (mvar[i] == 0)
116 fInvErrors[i] = 1;
117 else
118 fInvErrors[i] = 1.0 / std::sqrt(mvar[i]);
119 }
120 }
121
123
124 /**
125
126 Evaluates the model function for the different measurement points and
127 the Parameter values supplied, calculates a figure-of-merit for each
128 measurement and returns a vector containing the result of this
129 evaluation. The figure-of-merit is (Value predicted by the model
130 function-measured Value)/standard deviation.
131
132 @param par vector of Parameter values to feed to the model function.
133
134 @return A vector containing the figures-of-merit for the model function evaluated
135 for each set of measurements.
136
137 \todo What to do when the variances are 0???!! (right now just pushes back 0...)
138
139 */
140
141 std::vector<double> Elements(const std::vector<double> &par) const override;
142
143 /**
144
145 Accessor to the position of the measurement (x coordinate).
146
147 @param Index Index of the measuerement the position of which to return.
148
149 @return the position of the measurement.
150
151 */
152
153 const std::vector<double> &GetMeasurement(int Index) const override;
154
155 /**
156
157 Accessor to the number of measurements used for calculating
158 the chi-square.
159
160 @return the number of measurements.
161
162 */
163
164 int GetNumberOfMeasurements() const override;
165
166 /**
167
168 Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p
169 The result is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and
170 FumiliFCNBase::Hessian methods
171
172 @param par vector of parameters
173
174 **/
175
176 void EvaluateAll(const std::vector<double> &par) override;
177
178private:
179 std::vector<double> fMeasurements;
180 // support multi dim coordinates
181 std::vector<std::vector<double>> fPositions;
182 std::vector<double> fInvErrors;
183};
184
185} // namespace Minuit2
186
187} // namespace ROOT
188
189#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, const std::vector< double > &meas, const std::vector< double > &pos, const std::vector< double > &mvar)
Constructor which initializes chi square function for one-dimensional model function.
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, const std::vector< double > &meas, const std::vector< std::vector< double > > &pos, const std::vector< double > &mvar)
Constructor which initializes the multi-dimensional model function.
std::vector< double > Elements(const std::vector< double > &par) const override
Evaluates the model function for the different measurement points and the Parameter values supplied,...
void EvaluateAll(const std::vector< double > &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
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.