Logo ROOT  
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 #include "Minuit2/FumiliChi2FCN.h"
15 #include <cassert>
16 #include <vector>
17 #include <cmath>
18 
19 namespace ROOT {
20 
21 namespace Minuit2 {
22 
23 /**
24 
25 Class implementing the standard chi square function, which
26 is the sum of the squares of the figures-of-merit calculated for each measurement
27 point, the individual figures-of-merit being: (the Value predicted by the
28 model-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 
42 public:
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;
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  virtual const std::vector<double> &GetMeasurement(int Index) const;
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  virtual int GetNumberOfMeasurements() const;
165 
166  /**
167 
168  Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p
169  The resul 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  virtual void EvaluateAll(const std::vector<double> &par);
177 
178 private:
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
n
const Int_t n
Definition: legend1.C:16
ROOT::Minuit2::FumiliStandardChi2FCN::EvaluateAll
virtual void EvaluateAll(const std::vector< double > &par)
Evaluate function Value, Gradient and Hessian using Fumili approximation, for values of parameters p ...
Definition: FumiliStandardChi2FCN.cxx:57
ROOT::Minuit2::FumiliStandardChi2FCN::fMeasurements
std::vector< double > fMeasurements
Definition: FumiliStandardChi2FCN.h:179
ROOT::Minuit2::ParametricFunction
Function which has parameters.
Definition: ParametricFunction.h:43
ROOT::Minuit2::FumiliChi2FCN
Extension of the FCNBase for the Fumili method.
Definition: FumiliChi2FCN.h:49
x
Double_t x[n]
Definition: legend1.C:17
ROOT::Minuit2::FumiliStandardChi2FCN::FumiliStandardChi2FCN
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.
Definition: FumiliStandardChi2FCN.h:60
FumiliChi2FCN.h
ROOT::Minuit2::FumiliStandardChi2FCN::fInvErrors
std::vector< double > fInvErrors
Definition: FumiliStandardChi2FCN.h:182
ROOT::Minuit2::FumiliStandardChi2FCN::GetMeasurement
virtual const std::vector< double > & GetMeasurement(int Index) const
Accessor to the position of the measurement (x coordinate).
Definition: FumiliStandardChi2FCN.cxx:45
ROOT::Minuit2::FumiliStandardChi2FCN::fPositions
std::vector< std::vector< double > > fPositions
Definition: FumiliStandardChi2FCN.h:181
sqrt
double sqrt(double)
ROOT::Minuit2::FumiliChi2FCN::SetModelFunction
void SetModelFunction(const ParametricFunction &modelFCN)
Sets the model function for the data (for example gaussian+linear for a peak)
Definition: FumiliChi2FCN.h:64
ROOT::Minuit2::FumiliStandardChi2FCN::Elements
std::vector< double > Elements(const std::vector< double > &par) const
Evaluates the model function for the different measurement points and the Parameter values supplied,...
Definition: FumiliStandardChi2FCN.cxx:19
ROOT::Minuit2::FumiliStandardChi2FCN::FumiliStandardChi2FCN
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.
Definition: FumiliStandardChi2FCN.h:101
ROOT::Minuit2::FumiliStandardChi2FCN
Class implementing the standard chi square function, which is the sum of the squares of the figures-o...
Definition: FumiliStandardChi2FCN.h:40
ROOT::Minuit2::FumiliStandardChi2FCN::~FumiliStandardChi2FCN
~FumiliStandardChi2FCN()
Definition: FumiliStandardChi2FCN.h:122
ParametricFunction.h
RooFit::Index
RooCmdArg Index(RooCategory &icat)
Definition: RooGlobalFunc.cxx:98
ROOT
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: EExecutionPolicy.hxx:4
ROOT::Minuit2::FumiliStandardChi2FCN::GetNumberOfMeasurements
virtual int GetNumberOfMeasurements() const
Accessor to the number of measurements used for calculating the chi-square.
Definition: FumiliStandardChi2FCN.cxx:51