//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      Sim/Residual/ChiSquaredModule.h
//! @brief     Defines class ChiSquaredModule.
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#ifndef BORNAGAIN_SIM_RESIDUAL_CHISQUAREDMODULE_H
#define BORNAGAIN_SIM_RESIDUAL_CHISQUAREDMODULE_H

#include "Base/Type/Cloneable.h"
#include <memory>

class IntensityFunction;
class VarianceFunction;

//! Calculation of chi2 between two data sets.

class ChiSquaredModule : public Cloneable {
public:
    ChiSquaredModule();
    ChiSquaredModule(const ChiSquaredModule& other);
    ~ChiSquaredModule() override;

#ifndef SWIG
    ChiSquaredModule* clone() const override;
#endif // SWIG

    //! Returns variance function.
    const VarianceFunction* varianceFunction() const;

    //! Sets variance function.
    void setVarianceFunction(const VarianceFunction& variance_function);

    //! Returns data rescaler.
    const IntensityFunction* intensityFunction() const;

    //! Sets data rescaler.
    void setIntensityFunction(const IntensityFunction& intensity_function);

    double residual(double a, double b);

private:
    std::unique_ptr<VarianceFunction> m_variance_function;
    std::unique_ptr<IntensityFunction> m_intensity_function;
};

#endif // BORNAGAIN_SIM_RESIDUAL_CHISQUAREDMODULE_H
