2014-03-03 12:41:48 +00:00
|
|
|
/*
|
|
|
|
* XYData.hpp, part of LatAnalyze 3
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 - 2014 Antonin Portelli
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* LatAnalyze 3 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with LatAnalyze 3. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_XYData_hpp_
|
|
|
|
#define Latan_XYData_hpp_
|
|
|
|
|
2014-03-13 18:51:01 +00:00
|
|
|
#include <LatAnalyze/Global.hpp>
|
|
|
|
#include <LatAnalyze/Chi2Function.hpp>
|
|
|
|
#include <LatAnalyze/FitInterface.hpp>
|
|
|
|
#include <LatAnalyze/Function.hpp>
|
|
|
|
#include <LatAnalyze/Mat.hpp>
|
|
|
|
#include <LatAnalyze/Minimizer.hpp>
|
|
|
|
#include <LatAnalyze/Model.hpp>
|
2014-03-03 17:01:07 +00:00
|
|
|
#include <vector>
|
2014-03-03 12:41:48 +00:00
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
BEGIN_LATAN_NAMESPACE
|
2014-03-03 12:41:48 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* object for fit result *
|
|
|
|
******************************************************************************/
|
|
|
|
class FitResult: public DVec
|
|
|
|
{
|
|
|
|
friend class XYStatData;
|
|
|
|
public:
|
|
|
|
// constructors
|
2014-03-03 14:21:37 +00:00
|
|
|
FitResult(void) = default;
|
2014-03-17 15:00:59 +00:00
|
|
|
EIGEN_EXPR_CTOR(FitResult, FitResult, Base, MatExpr)
|
2014-03-03 12:41:48 +00:00
|
|
|
// destructor
|
|
|
|
virtual ~FitResult(void) = default;
|
|
|
|
// access
|
2014-03-03 17:01:07 +00:00
|
|
|
double getChi2(void) const;
|
|
|
|
double getChi2PerDof(void) const;
|
2014-09-18 17:15:56 +01:00
|
|
|
double getNDof(void) const;
|
2014-03-03 17:01:07 +00:00
|
|
|
const DoubleFunction & getModel(const Index j = 0) const;
|
2014-03-03 12:41:48 +00:00
|
|
|
private:
|
2014-03-03 17:01:07 +00:00
|
|
|
double chi2_{0.0};
|
|
|
|
Index nDof_{0};
|
|
|
|
std::vector<DoubleFunction> model_;
|
2014-03-03 12:41:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* object for X vs. Y statistical data *
|
|
|
|
******************************************************************************/
|
2014-03-12 19:15:40 +00:00
|
|
|
class XYStatData: public FitInterface
|
2014-03-03 12:41:48 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
xx = 0,
|
|
|
|
yy = 1,
|
|
|
|
yx = 2
|
|
|
|
};
|
|
|
|
public:
|
|
|
|
// constructors
|
|
|
|
XYStatData(void);
|
|
|
|
XYStatData(const Index nData, const Index nXDim, const Index nYDim);
|
|
|
|
// destructor
|
|
|
|
virtual ~XYStatData(void) = default;
|
|
|
|
// access
|
|
|
|
void resize(const Index nData, const Index xDim,
|
|
|
|
const Index yDim);
|
2014-04-03 09:03:46 +01:00
|
|
|
void reinitChi2(const bool doReinit = true);
|
2015-02-23 18:11:37 +00:00
|
|
|
Block<MatBase<double>> x(const PlaceHolder ph1 = _,
|
|
|
|
const PlaceHolder ph2 = _);
|
|
|
|
ConstBlock<MatBase<double>> x(const PlaceHolder ph1 = _,
|
|
|
|
const PlaceHolder ph2 = _) const;
|
|
|
|
Block<MatBase<double>> x(const Index i, const PlaceHolder ph2 = _);
|
|
|
|
ConstBlock<MatBase<double>> x(const Index i,
|
|
|
|
const PlaceHolder ph2 = _) const;
|
|
|
|
Block<MatBase<double>> x(const PlaceHolder ph1, const Index k);
|
|
|
|
ConstBlock<MatBase<double>> x(const PlaceHolder ph1,
|
|
|
|
const Index k) const;
|
|
|
|
double & x(const Index i, const Index k);
|
|
|
|
const double & x(const Index i, const Index k) const;
|
|
|
|
Block<MatBase<double>> y(const PlaceHolder ph1 = _,
|
|
|
|
const PlaceHolder ph2 = _);
|
|
|
|
ConstBlock<MatBase<double>> y(const PlaceHolder ph1 = _,
|
|
|
|
const PlaceHolder ph2 = _) const;
|
|
|
|
Block<MatBase<double>> y(const Index i, const PlaceHolder ph2 = _);
|
|
|
|
ConstBlock<MatBase<double>> y(const Index i,
|
|
|
|
const PlaceHolder ph2 = _) const;
|
|
|
|
Block<MatBase<double>> y(const PlaceHolder ph1, const Index k);
|
|
|
|
ConstBlock<MatBase<double>> y(const PlaceHolder ph1,
|
|
|
|
const Index k) const;
|
|
|
|
double & y(const Index i, const Index k);
|
|
|
|
const double & y(const Index i, const Index k) const;
|
|
|
|
Block<MatBase<double>> xxVar(const Index i1, const Index i2);
|
|
|
|
ConstBlock<MatBase<double>> xxVar(const Index i1, const Index i2) const;
|
|
|
|
Block<MatBase<double>> yyVar(const Index j1, const Index j2);
|
|
|
|
ConstBlock<MatBase<double>> yyVar(const Index j1, const Index j2) const;
|
|
|
|
Block<MatBase<double>> yxVar(const Index j, const Index i);
|
|
|
|
ConstBlock<MatBase<double>> yxVar(const Index j, const Index i) const;
|
2014-03-03 12:41:48 +00:00
|
|
|
// fit
|
2014-04-03 09:03:46 +01:00
|
|
|
FitResult fit(Minimizer &minimizer, const DVec &init,
|
|
|
|
const std::vector<const DoubleModel *> &modelVector);
|
|
|
|
template <typename... Ts>
|
|
|
|
FitResult fit(Minimizer &minimizer, const DVec &init,
|
|
|
|
const DoubleModel &model, const Ts... models);
|
2014-03-12 19:17:15 +00:00
|
|
|
|
2014-03-03 12:41:48 +00:00
|
|
|
private:
|
2014-03-03 14:21:37 +00:00
|
|
|
DMat x_, y_;
|
|
|
|
Mat<DMat> var_[3];
|
|
|
|
IVec isXExact_, isFitPoint_;
|
|
|
|
Chi2Function chi2_;
|
2014-04-03 09:03:46 +01:00
|
|
|
bool reinitChi2_{true};
|
2014-03-03 12:41:48 +00:00
|
|
|
};
|
|
|
|
|
2014-04-03 09:03:46 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* XYStatData template implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
template <typename... Ts>
|
|
|
|
FitResult XYStatData::fit(Minimizer &minimizer, const DVec &init,
|
|
|
|
const DoubleModel &model, const Ts... models)
|
|
|
|
{
|
|
|
|
static_assert(static_or<std::is_assignable<DoubleModel &, Ts>::value...>::value,
|
|
|
|
"model arguments are not compatible with DoubleModel &");
|
|
|
|
|
|
|
|
std::vector<const DoubleModel *> modelVector{&model, &models...};
|
|
|
|
|
|
|
|
return fit(minimizer, init, modelVector);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-28 17:15:05 +00:00
|
|
|
END_LATAN_NAMESPACE
|
2014-03-03 12:41:48 +00:00
|
|
|
|
|
|
|
#endif // Latan_XYData_hpp_
|