To fit a model to some data you first have to instantiate the
myfitter::Fitter
class, which is declared in
myfitter/fitter.hpp. Each Fitter
object contains an
object of type myfitter::InputFunction
(defined in
myfitter/inputfunction.hpp), which can be accessed through
the method
InputFunction& Fitter::input_function()
The experimental inputs are specified by adding objects of type
InputComponent
to the input_function()
member of the Fitter
class. This is done with the method
int InputFunction::add(const InputComponent&)
The return value does (currently) not serve any purpose. An object of
type InputComponent
represents a term in the input function
D (see
[arXiv:1207.1446v2] for
details) and stores default values for the measured observables
(x_0 in the notation of
[arXiv:1207.1446v2]). The
most common types of input components are defined in the header
myfitter/inputcomponents.hpp. Here is an example:
#include <myfitter/fitter.hpp> #include <myfitter/inputcomponents.hpp> using namespace myfitter; ... int main() { MyModel mymodel; // initialise mymodel ... Fitter fitter(MyModel::NOBS); fitter.input_function().add( GaussianIC(MyModel::O_MYSECONDOBS, 3.0, 1.2, 0.4, 0.6)); ...
The constructor of the Fitter
class takes an integer value as
argument, which specifies the number of observables. Only models which
provide that exact number of observables (as returned by
Model::nobservables()
) can be fitted with the created
Fitter
object. The last line adds a Gaussian contribution with
systematic errors to the input function. Specifically, it states that
the observables associated with the index
MyModel::O_MYSECONDOBS
(see MyModel
example) has a measured value of 3.0 with a Gaussian
statistical error of 1.2 and systematic errors of +0.4
and -0.6. In a scientific text, this might be written as
3.0\pm 1.2 (stat.) ^+0.4_-0.6 (syst.). When you
perform the actual fit you can still change the central values of the
observables. The methods Fitter::local_fit
and
Fitter::global_fit
(see Minimising the chi-square Function)
have optional arguments which let you override the default values
stored in the input_function()
member. However, the (different
types of) errors can only be specified by passing correctly
initialised InputComponent
objects to the
InputFunction::add
method.
The same observable may contribute to several terms in the input
function. For instance, following the last line of the previous
example, you may add a second gaussian input for O_MYSECONDOBS
:
fitter.input_function().add( GaussianIC(MyModel::O_MYSECONDOBS, 10.0, 0.1, 0.02, 0.03));
The contributions of the two terms to the input function will simply
be added. However, the InputFunction
object allows only one
central value for each observable. The line above will therefore
replace the previous central value of 3.0 with 10.0, so that the
gaussian contributions from both terms will be computed with a
central value of 10.0. Generally, you should avoid adding multiple
gaussian input components for the same observable to your input
function. If you have several measurements for the same observable you
should instead combine the central values and errors correctly and
only add one input component for the combination. However, for
non-gaussian inputs or non-linear constraints (see Non-linear Constraints) this combination is not necessarily possible and it is
for this reason only that myFitter allows multiple inputs for the
same observable.
The header myfitter/inputcomponents.hpp provides the
following subclasses of InputComponent
:
GaussianIC
GaussianIC(int iobs, double value, double error, double syst_plus=0., double syst_minus=0.)
creates an input component for observable iobs with central
value value, Gaussian error error and systematic errors
syst_plus and syst_minus. The values of error,
syst_plus and syst_minus should all be positive. If the
last two arguments are omitted, the default value 0 is used.
AsymmetricGaussianIC
AsymmetricGaussianIC(int iobs, double value, double error_plus, double error_minus, double syst_plus=0., double syst_minus=0.)
creates an input component for observable iobs with central
value value, asymmetric Gaussian errors error_plus and
error_minus and systematic errors syst_plus and
syst_minus. The values of error_plus, error_minus,
syst_plus and syst_minus should all be positive. If the
last two arguments are omitted, the default value 0 is used.
CorrelatedGaussianIC
CorrelatedGaussianIC(int n)
creates an “empty” input component for n observables. Note
that n is the number of observables provided by the model
(i.e. the same number that is passed to the Fitter
constructor) and not the number of observables contributing to
the input component. To initialise a CorrelatedGaussianIC
object, you first have to specify the contributing observables and
their central values and errors with the add()
method and then
set the elements of the correlation matrix with the cor()
method. Here is an example:
CorrelatedGaussianIC ic(MyModel::NOBS); ic.add(MyModel::O_MYFIRSTOBS, 2.3, 0.4); ic.add(MyModel::O_MYSECONDOBS, 5.6, 0.7); ic.cor(MyModel::O_MYFIRSTOBS, MyModel::O_MYSECONDOBS, 0.23);
This means that the two observables associated with the integers
MyModel::O_MYFIRSTOBS
and MyModel::O_MYSECONDOBS
(see MyModel
example) have measured values of
2.3 and 5.6, standard deviations of 0.4 and
0.7 and a correlation of 0.23. Note that only
off-diagonal elements of the correlation matrix in one triangle have
to be set. To add this input component to the input function
of a Fitter
instance fitter
, call
fitter.input_function().add(ic);
All the information of the ic
object is copied by the
InputFunction::add()
method and the lc
object
is no longer needed afterwards.