1#ifndef __JROOT__JROOTFIT__
2#define __JROOT__JROOTFIT__
18#include "TGraphErrors.h"
19#include "TGraph2DErrors.h"
35namespace JPP {
using namespace JROOT; }
62 return range_type(pAxis->GetXmin(), pAxis->GetXmax());
79 for (Int_t i = 0; i != nx; ++i) {
107 return getRange(g2.GetN(), g2.GetX());
119 return getRange(g2.GetN(), g2.GetY());
152 return std::numeric_limits<double>::min();
162 inline double getRho(
const double z)
const
176 inline double getPsi(
const double z)
const
209 const double error) :
221 inline double getRho(
const double z)
const
235 inline double getPsi(
const double z)
const
338 m_2d(
const double x,
const double y,
const T& v) :
375 m_3d(
const double x,
const double y,
const double z,
const T& v) :
466 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
468 const double x = h1.GetXaxis()->GetBinCenter(ix);
469 const size_t count = h1.GetBinContent(ix);
488 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
490 const double x = h1.GetXaxis()->GetBinCenter(ix);
491 const double value = h1.GetBinContent(ix);
492 const double error = h1.GetBinError (ix);
494 if (X(x) && error > 0.0) {
511 for (Int_t i = 0; i !=
g1.GetN(); ++i) {
513 const double x =
g1.GetX()[i];
514 const double value =
g1.GetY()[i];
515 const double error =
g1.GetEY()[i];
517 if (X(x) && error > 0.0) {
605 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
606 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
608 const double x = h2.GetXaxis()->GetBinCenter(ix);
609 const double y = h2.GetYaxis()->GetBinCenter(iy);
610 const size_t count = h2.GetBinContent(ix,iy);
632 for (Int_t ix = 1; ix <= h2.GetXaxis()->GetNbins(); ++ix) {
633 for (Int_t iy = 1; iy <= h2.GetYaxis()->GetNbins(); ++iy) {
635 const double x = h2.GetXaxis()->GetBinCenter(ix);
636 const double y = h2.GetYaxis()->GetBinCenter(iy);
637 const double value = h2.GetBinContent(ix,iy);
638 const double error = h2.GetBinError (ix,iy);
640 if (X(x) && Y(y) && error > 0.0) {
660 for (Int_t i = 0; i != g2.GetN(); ++i) {
662 const double x = g2.GetX()[i];
663 const double y = g2.GetY()[i];
664 const double value = g2.GetZ()[i];
665 const double error = g2.GetEZ()[i];
667 if (X(x) && Y(y) && error > 0.0) {
734 for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
735 for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
736 for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
738 const double x = h3.GetXaxis()->GetBinCenter(ix);
739 const double y = h3.GetYaxis()->GetBinCenter(iy);
740 const double z = h3.GetZaxis()->GetBinCenter(iz);
741 const size_t count = h3.GetBinContent(ix,iy,iz);
743 if (X(x) && Y(y) && Z(z)) {
766 for (Int_t ix = 1; ix <= h3.GetXaxis()->GetNbins(); ++ix) {
767 for (Int_t iy = 1; iy <= h3.GetYaxis()->GetNbins(); ++iy) {
768 for (Int_t iz = 1; iz <= h3.GetZaxis()->GetNbins(); ++iz) {
770 const double x = h3.GetXaxis()->GetBinCenter(ix);
771 const double y = h3.GetYaxis()->GetBinCenter(iy);
772 const double z = h3.GetZaxis()->GetBinCenter(iz);
773 const double value = h3.GetBinContent(ix,iy,iz);
774 const double error = h3.GetBinError (ix,iy,iz);
776 if (X(x) && Y(y) && Z(z) && error > 0.0) {
798 template<
class JF1_t>
799 JF1(
const char*
const name,
815 template<
class JF1_t>
838 setParameters(
this, parameters);
840 return this->getValue(x[0]);
860 template<
class JF2_t>
861 JF2(
const char*
const name,
881 template<
class JF2_t>
904 setParameters(
this, parameters);
906 return this->getValue(x[0], x[1]);
927 template<
class JF3_t>
928 JF3(
const char*
const name,
952 template<
class JF3_t>
975 setParameters(
this, parameters);
977 return this->getValue(x[0], x[1], x[2]);
1002 std::set<size_t>(indices)
1014 for (
size_t i = 0; i != T::parameters.size(); ++i) {
1015 if (std::find(parameters.begin(), parameters.end(), T::parameters[i]) != parameters.end()) {
1026 template<
class JFs_t>
1066 return JFs_t::parameters.size();
1121 return (this->
value)[i];
1132 return (this->
error)[i];
1143 using namespace std;
1145 out <<
"chi2/NDF " <<
FIXED(7,3) << this->
getChi2() <<
"/" << this->
getNDF() << endl;
1150 out << setw(2) << i <<
' '
1161 template<
class JFs_t>
1217 (*this)(*h1, f1, type, ls, X);
1219 h1->GetListOfFunctions()->Add(
new JF1(
"f1",
1259 (*this)(*
g1, f1, ls, X);
1261 g1->GetListOfFunctions()->Add(
new JF1(
"f1",
1313 (*this)(*h2, f2, type, ls, X, Y);
1315 h2->GetListOfFunctions()->Add(
new JF2(
"f2",
1360 (*this)(*g2, f2, ls, X, Y);
1362 g2->GetListOfFunctions()->Add(
new JF2(
"f2",
1419 (*this)(*h3,
f3, type, ls, X, Y, Z);
1421 h3->GetListOfFunctions()->Add(
new JF3(
"f3",
1455 for (
size_t i = 0; i != JFs_t::parameters.size(); ++i) {
1456 if (ls.count(i) == 0) {
1457 this->
parameters.push_back(JFs_t::parameters[i]);
1462 this->
npx = data.size();
1486 const double y = fs.getValue(mp.
x);
1506 const double y = fs.getValue(mp.
x, mp.
y);
1526 const double y = fs.getValue(mp.
x, mp.
y, mp.
z);
1544 template<
class JFs_t>
1559 template<
class T,
class JF1_t>
1581 template<
class T,
class JF1_t>
1600 template<
class JF1_t>
1619 template<
class JF1_t>
1641 template<
class T,
class JF2_t>
1665 template<
class T,
class JF2_t>
1686 template<
class JF2_t>
1707 template<
class JF2_t>
1732 template<
class T,
class JF3_t>
1758 template<
class T,
class JF3_t>
Maximum likelihood estimator (M-estimators).
Auxiliary methods for mathematics.
double f3(const double x, const double y, const double z)
3D function.
Double_t g1(const Double_t x)
Function.
Auxiliary class to define a range between two values.
Fit method based on the Levenberg-Marquardt method.
std::vector< parameter_type > parameters
fit parameters
int numberOfIterations
number of iterations
Base class for result of ROOT Fit.
JRootfit_t()
Default constructor.
void print(std::ostream &out) const
Print result.
const JFs_t & getFunction() const
Get function.
int getNDF() const
Get number of degrees of freedom.
size_t getNumberOfParameters() const
Get number of parameters.
double getChi2() const
Get chi2.
double getValue(size_t i) const
Get value of parameter at given index.
double getError(size_t i) const
Get error of parameter at given index.
size_t getNumberOfFreeParameters() const
Get number of free parameters.
size_t getN() const
Get number of data points.
size_t npx
number of data points
static JRootfit Fit
Global fit object.
const result_type & operator()(const TGraphErrors &g1, const JFs_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
const result_type & operator()(TH3 *h3, const JFs_t &f3, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Fit.
const result_type & operator()(TH1 *h1, const JFs_t &f1, const T &type, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
const result_type & operator()(TGraphErrors *g1, const JFs_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
const result_type & operator()(const TH3 &h3, const JFs_t &f3, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Fit.
size_t getNumberOfFreeParameters()
const result_type & operator()(TH2 *h2, const JFs_t &f2, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
const result_type & operator()(const TH2 &h2, const JFs_t &f2, const T &type, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
const result_type & operator()(const TGraph2DErrors &g2, const JFs_t &f2, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
const result_type & operator()(TGraph2DErrors *g2, const JFs_t &f2, const index_list &ls=index_list(), const range_type &X=range_type(), const range_type &Y=range_type())
Fit.
const struct JROOT::JRootfit::function_type fit
const result_type & operator()(const TH1 &h1, const JFs_t &f1, const T &type, const index_list &ls=index_list(), const range_type &X=range_type())
Fit.
JRootfit_t< JFs_t > result_type
const result_type & eval(const JFs_t &fs, const index_list &ls, const data_type< T > &data)
Evaluate fit.
JRootfit()
Default constructor.
JMEstimator * getMEstimator(const int type)
Get M-Estimator.
constexpr size_t getNumberOfParameters()
Get number of parameters.
void setParameters(JF1_t *f1, const double *values)
Set values of all parameters.
double poisson(const size_t n, const double mu)
Poisson probability density distribution.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
range_type getRangeX(const TGraph2D &g2)
Get range of given graph.
range_type getRangeY(const TGraph2D &g2)
Get range of given graph.
JTOOLS::JRange< double > range_type
Type definiton of abscissa range.
JRootfit_t< JF1_t > Fit(const TH1 &h1, const JF1_t &f1, const index_list &ls=index_list(), const range_type &X=range_type())
Global fit fuction.
range_type getRange(TAxis *pAxis)
Get range of given axis.
Auxiliary data structure for floating point format specification.
Data structure for return value of fit function.
JModel_t gradient
partial derivatives of chi2
Interface for maximum likelihood estimator (M-estimator).
double operator()(const double *x, const double *parameters)
ROOT compatible function call.
helper(const JF1_t &f1)
Constructor.
Wrapper data structure to build ROOT 1D function.
JF1(const char *const name, const JF1_t &f1, const range_type &X)
Constructor.
double operator()(const double *x, const double *parameters)
ROOT compatible function call.
helper(const JF2_t &f2)
Constructor.
Wrapper data structure to build ROOT 2D function.
JF2(const char *const name, const JF2_t &f2, const range_type &X, const range_type &Y)
Constructor.
helper(const JF3_t &f3)
Constructor.
double operator()(const double *x, const double *parameters)
ROOT compatible function call.
Wrapper data structure to build ROOT 3D function.
JF3(const char *const name, const JF3_t &f3, const range_type &X, const range_type &Y, const range_type &Z)
Constructor.
Auxiliary data structure for fit functions.
JGandalf< JFs_t >::result_type result_type
const result_type & operator()(const JFs_t &fs, const m_1d< T > &mp) const
Fit function.
const result_type & operator()(const JFs_t &fs, const m_2d< T > &mp) const
Fit function.
const result_type & operator()(const JFs_t &fs, const m_3d< T > &mp) const
Fit function.
void unpack(const TGraphErrors &g1, const range_type &X=range_type())
Unpack 1D-graph.
data_type(const TH1 &h1, const range_type &X=range_type())
Unpack constructor.
void unpack(const TH1 &h1, const range_type &X=range_type())
Unpack 1D-histogram.
data_type(const TGraphErrors &g1, const range_type &X=range_type())
Unpack constructor.
data_type()
Default constructor.
void unpack(const TGraph2DErrors &g2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack 2D-graph.
void unpack(const TH2 &h2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack 2D-histogram.
data_type(const TGraph2DErrors &g2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack constructor.
data_type()
Default constructor.
data_type(const TH2 &h2, const range_type &X=range_type(), const range_type &Y=range_type())
Unpack constructor.
data_type()
Default constructor.
data_type(const TH3 &h3, const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Unpack constructor.
void unpack(const TH3 &h3, const range_type &X=range_type(), const range_type &Y=range_type(), const range_type &Z=range_type())
Unpack 3D-histogram.
Template definition of data structure for set of data points.
void unpack(const TH1 &h1, const range_type &X)
Unpack 1D-histogram.
Auxiliary data structure for list of fixed parameters.
index_list(const std::initializer_list< size_t > &indices)
Constructor.
index_list()
Default constructor.
index_list(const std::initializer_list< double T::* > ¶meters)
Conversion constructor.
m_1d()
Default constructor.
m_1d(const double x, const T &v)
Constructor.
m_2d(const double x, const double y, const T &v)
Constructor.
m_2d()
Default constructor.
m_3d(const double x, const double y, const double z, const T &v)
Constructor.
m_3d()
Default constructor.
Data point for counting measurement.
double getPsi(const double z) const
Get derivative of chi2.
double getRho(const double z) const
Get chi2.
static double epsilon()
Minimal value for numerical computations.
m_count()
Default constructor.
m_count(const size_t count)
Constructor.
Data point for value with error.
static const estimator_type & getMEstimator()
Get M-estimator.
double getRho(const double z) const
Get chi2.
static estimator_type & get_mestimator()
Get M-estimator.
m_value(const double value, const double error)
Constructor.
m_value()
Default constructor.
std::shared_ptr< JMEstimator > estimator_type
double getPsi(const double z) const
Get derivative of chi2.
static const void setMEstimator(int type)
Set M-estimator.