Logo ROOT   6.08/07
Reference Guide
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 
13 
14 #include "Minuit2/FumiliChi2FCN.h"
16 #include <assert.h>
17 #include <vector>
18 #include <cmath>
19 
20 namespace ROOT {
21 
22  namespace Minuit2 {
23 
24 
25 
26 /**
27 
28 Class implementing the standard chi square function, which
29 is the sum of the squares of the figures-of-merit calculated for each measurement
30 point, the individual figures-of-merit being: (the Value predicted by the
31 model-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 
45 public:
46 
47 
48  /**
49 
50  Constructor which initializes chi square function for one-dimensional model function
51 
52  @param modelFCN the model function used for describing the data.
53 
54  @param meas vector containing the measured values.
55 
56  @param pos vector containing the x values corresponding to the
57  measurements
58 
59  @param mvar vector containing the variances corresponding to each
60  measurement (where the variance equals the standard deviation squared).
61  If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW)
62 
63  */
64 
65  FumiliStandardChi2FCN(const ParametricFunction& modelFCN, const std::vector<double>& meas,
66  const std::vector<double>& pos,
67  const std::vector<double>& mvar)
68  { //this->fModelFCN = &modelFunction;
69  this->SetModelFunction(modelFCN);
70 
71  assert(meas.size() == pos.size());
72  assert(meas.size() == mvar.size());
73  fMeasurements = meas;
74  std::vector<double> x(1);
75  unsigned int n = mvar.size();
76  fPositions.reserve( n);
77  // correct for variance == 0
78  fInvErrors.resize(n);
79  for (unsigned int i = 0; i < n; ++i)
80  {
81  x[0] = pos[i];
82  fPositions.push_back(x);
83  // PAW/ROOT hack : use 1 for 0 entries bins
84  if (mvar[i] == 0)
85  fInvErrors[i] = 1;
86  else
87  fInvErrors[i] = 1.0/std::sqrt(mvar[i]);
88  }
89 
90  }
91 
92 
93  /**
94 
95  Constructor which initializes the multi-dimensional model function.
96 
97  @param modelFCN the model function used for describing the data.
98 
99  @param meas vector containing the measured values.
100 
101  @param pos vector containing the x values corresponding to the
102  measurements
103 
104  @param mvar vector containing the variances corresponding to each
105  measurement (where the variance equals the standard deviation squared).
106  If the variances are zero, a Value of 1 is used (as it is done in ROOT/PAW)
107 
108  */
109 
110  FumiliStandardChi2FCN(const ParametricFunction& modelFCN, const std::vector<double>& meas,
111  const std::vector<std::vector<double> >& pos,
112  const std::vector<double>& mvar)
113  { //this->fModelFCN = &modelFunction;
114  this->SetModelFunction(modelFCN);
115 
116  assert(meas.size() == pos.size());
117  assert(meas.size() == mvar.size());
118  fMeasurements = meas;
119  fPositions = pos;
120  // correct for variance == 0
121  unsigned int n = mvar.size();
122  fInvErrors.resize(n);
123  for (unsigned int i = 0; i < n; ++i)
124  {
125  // PAW/ROOT hack : use 1 for 0 entries bins
126  if (mvar[i] == 0)
127  fInvErrors[i] = 1;
128  else
129  fInvErrors[i] = 1.0/std::sqrt(mvar[i]);
130  }
131 
132  }
133 
134 
135 
136 
138 
139 
140 
141 
142 
143  /**
144 
145  Evaluates the model function for the different measurement points and
146  the Parameter values supplied, calculates a figure-of-merit for each
147  measurement and returns a vector containing the result of this
148  evaluation. The figure-of-merit is (Value predicted by the model
149  function-measured Value)/standard deviation.
150 
151  @param par vector of Parameter values to feed to the model function.
152 
153  @return A vector containing the figures-of-merit for the model function evaluated
154  for each set of measurements.
155 
156  \todo What to do when the variances are 0???!! (right now just pushes back 0...)
157 
158  */
159 
160  std::vector<double> Elements(const std::vector<double>& par) const;
161 
162 
163 
164  /**
165 
166  Accessor to the position of the measurement (x coordinate).
167 
168  @param Index Index of the measuerement the position of which to return.
169 
170  @return the position of the measurement.
171 
172  */
173 
174  virtual const std::vector<double> & GetMeasurement(int Index) const;
175 
176 
177  /**
178 
179  Accessor to the number of measurements used for calculating
180  the chi-square.
181 
182  @return the number of measurements.
183 
184  */
185 
186  virtual int GetNumberOfMeasurements() const;
187 
188 
189  /**
190 
191  Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p
192  The resul is cached inside and is return from the FumiliFCNBase::Value , FumiliFCNBase::Gradient and
193  FumiliFCNBase::Hessian methods
194 
195  @param par vector of parameters
196 
197  **/
198 
199  virtual void EvaluateAll( const std::vector<double> & par );
200 
201 
202  private:
203 
204 
205  std::vector<double> fMeasurements;
206  // support multi dim coordinates
207  std::vector<std::vector<double> > fPositions;
208  std::vector<double> fInvErrors;
209 };
210 
211  } // namespace Minuit2
212 
213 } // namespace ROOT
214 
215 #endif // ROOT_Minuit2_FumiliStandardChi2FCN
virtual const std::vector< double > & GetMeasurement(int Index) const
Accessor to the position of the measurement (x coordinate).
double par[1]
Definition: unuranDistr.cxx:38
std::vector< std::vector< double > > fPositions
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
std::vector< double > Elements(const std::vector< double > &par) const
Evaluates the model function for the different measurement points and the Parameter values supplied...
double sqrt(double)
virtual int GetNumberOfMeasurements() const
Accessor to the number of measurements used for calculating the chi-square.
Double_t x[n]
Definition: legend1.C:17
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.
virtual void EvaluateAll(const std::vector< double > &par)
Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p ...
Class implementing the standard chi square function, which is the sum of the squares of the figures-o...
Extension of the FCNBase for the Fumili method.
Definition: FumiliChi2FCN.h:52
Function which has parameters.
RooCmdArg Index(RooCategory &icat)
void SetModelFunction(const ParametricFunction &modelFCN)
Sets the model function for the data (for example gaussian+linear for a peak)
Definition: FumiliChi2FCN.h:70
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.
const Int_t n
Definition: legend1.C:16