mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
New methods in XYSampleData class to skip fits that are non-converging/large chi2PerDof.
This is tracked by boolean goodFit_.
This commit is contained in:
parent
1b12f2ca2d
commit
9e8d534635
@ -234,6 +234,21 @@ DVec XYSampleData::getYError(const Index j)
|
|||||||
return data_.getYError(j);
|
return data_.getYError(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool XYSampleData::checkFit()
|
||||||
|
{
|
||||||
|
return goodFit_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XYSampleData::checkChi2PerDof(double Chi2PerDof)
|
||||||
|
{
|
||||||
|
if(Chi2PerDof >= 2 or Chi2PerDof < 0 or isnan(Chi2PerDof))
|
||||||
|
{
|
||||||
|
goodFit_ = false;
|
||||||
|
cerr << "chi2PerDof = " << Chi2PerDof << ". Aborting fit now." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// get total fit variance matrix and its pseudo-inverse ////////////////////////
|
// get total fit variance matrix and its pseudo-inverse ////////////////////////
|
||||||
const DMat & XYSampleData::getFitVarMat(void)
|
const DMat & XYSampleData::getFitVarMat(void)
|
||||||
{
|
{
|
||||||
@ -292,24 +307,34 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
|
|||||||
result.resize(nSample_);
|
result.resize(nSample_);
|
||||||
result.chi2_.resize(nSample_);
|
result.chi2_.resize(nSample_);
|
||||||
result.model_.resize(v.size());
|
result.model_.resize(v.size());
|
||||||
|
double chi2PerDof;
|
||||||
|
goodFit_ = true;
|
||||||
FOR_STAT_ARRAY(result, s)
|
FOR_STAT_ARRAY(result, s)
|
||||||
{
|
{
|
||||||
setDataToSample(s);
|
if(goodFit_)
|
||||||
if (s == central)
|
|
||||||
{
|
{
|
||||||
sampleResult = data_.fit(minimizer, initCopy, v);
|
setDataToSample(s);
|
||||||
initCopy = sampleResult.segment(0, initCopy.size());
|
if (s == central)
|
||||||
}
|
{
|
||||||
else
|
sampleResult = data_.fit(minimizer, initCopy, v);
|
||||||
{
|
initCopy = sampleResult.segment(0, initCopy.size());
|
||||||
sampleResult = data_.fit(*(minimizer.back()), initCopy, v);
|
chi2PerDof = sampleResult.getChi2PerDof();
|
||||||
}
|
checkChi2PerDof(chi2PerDof);
|
||||||
result[s] = sampleResult;
|
}
|
||||||
result.chi2_[s] = sampleResult.getChi2();
|
else
|
||||||
for (unsigned int j = 0; j < v.size(); ++j)
|
{
|
||||||
{
|
sampleResult = data_.fit(*(minimizer.back()), initCopy, v);
|
||||||
result.model_[j].resize(nSample_);
|
chi2PerDof = sampleResult.getChi2PerDof();
|
||||||
result.model_[j][s] = sampleResult.getModel(j);
|
checkChi2PerDof(chi2PerDof);
|
||||||
|
}
|
||||||
|
result[s] = sampleResult;
|
||||||
|
result.chi2_[s] = sampleResult.getChi2();
|
||||||
|
for (unsigned int j = 0; j < v.size(); ++j)
|
||||||
|
{
|
||||||
|
result.model_[j].resize(nSample_);
|
||||||
|
result.model_[j][s] = sampleResult.getModel(j);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.nPar_ = sampleResult.getNPar();
|
result.nPar_ = sampleResult.getNPar();
|
||||||
|
@ -91,6 +91,8 @@ public:
|
|||||||
const DMat & getXYVar(const Index i, const Index j);
|
const DMat & getXYVar(const Index i, const Index j);
|
||||||
DVec getXError(const Index i);
|
DVec getXError(const Index i);
|
||||||
DVec getYError(const Index j);
|
DVec getYError(const Index j);
|
||||||
|
bool checkFit(); // check fit candidate based on chi2PerDof
|
||||||
|
void checkChi2PerDof(double Chi2PerDof);
|
||||||
// get total fit variance matrix and its pseudo-inverse
|
// get total fit variance matrix and its pseudo-inverse
|
||||||
const DMat & getFitVarMat(void);
|
const DMat & getFitVarMat(void);
|
||||||
const DMat & getFitVarMatPInv(void);
|
const DMat & getFitVarMatPInv(void);
|
||||||
@ -133,6 +135,7 @@ private:
|
|||||||
Index nSample_, dataSample_{central};
|
Index nSample_, dataSample_{central};
|
||||||
bool initData_{true}, computeVarMat_{true};
|
bool initData_{true}, computeVarMat_{true};
|
||||||
bool initXMap_{true};
|
bool initXMap_{true};
|
||||||
|
bool goodFit_{true}; // used to break minimisation if central sample chi2PerDof is bad
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
Loading…
x
Reference in New Issue
Block a user