BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ChiSquaredModule.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Device/Instrument/ChiSquaredModule.cpp
6 //! @brief Implements class ChiSquaredModule.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
16 #include "Base/Utils/Assert.h"
19 #include <cmath>
20 #include <limits>
21 
22 double ChiSquaredModule::residual(double a, double b, double weight)
23 {
24  double value_simu = a;
25  double value_real = b;
26 
27  if (mp_intensity_function) {
28  value_simu = mp_intensity_function->evaluate(value_simu);
29  value_real = mp_intensity_function->evaluate(value_real);
30  }
31 
32  double variance = m_variance_function->variance(value_real, value_simu);
33  double normalize = variance <= 0 ? std::numeric_limits<double>::min() : std::sqrt(variance);
34 
35  return std::sqrt(weight) * (value_simu - value_real) / normalize;
36 }
Defines the macro ASSERT.
Defines class ChiSquaredModule.
Defines and implements the interface class IIntensityFunction and its child classes IntensityFunction...
Defines IVarianceFunction classes.