1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2025-04-05 09:35:54 +01:00

New function fitSample to make XYSampleData::fit more modular:

Eg application: In fit scans, one may only want central fit for the uncorr fit to speed up process.
This commit is contained in:
AndrewYongZhenNing 2021-09-22 12:38:54 +01:00
parent 9c5ade4989
commit 28aff209c4
2 changed files with 48 additions and 27 deletions

View File

@ -294,9 +294,40 @@ const XYStatData & XYSampleData::getData(void)
}
// fit /////////////////////////////////////////////////////////////////////////
void XYSampleData::fitSample(std::vector<Minimizer *> &minimizer,
const std::vector<const DoubleModel *> &v,
SampleFitResult &result,
FitResult &sampleResult,
DVec &init,
Index s)
{
double pValue = 0;
setDataToSample(s);
if (s == central)
{
sampleResult = data_.fit(minimizer, init, v);
init = sampleResult.segment(0, init.size());
pValue = sampleResult.getPValue();
checkPValue(pValue);
}
else
{
sampleResult = data_.fit(*(minimizer.back()), init, v);
}
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);
}
}
SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
const DVec &init,
const std::vector<const DoubleModel *> &v)
const std::vector<const DoubleModel *> &v,
bool centralSample)
{
computeVarMat();
@ -307,29 +338,16 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
result.resize(nSample_);
result.chi2_.resize(nSample_);
result.model_.resize(v.size());
double chi2PerDof;
FOR_STAT_ARRAY(result, s)
if(centralSample)
{
setDataToSample(s);
if (s == central)
{
sampleResult = data_.fit(minimizer, initCopy, v);
initCopy = sampleResult.segment(0, initCopy.size());
chi2PerDof = sampleResult.getChi2PerDof();
checkChi2PerDof(chi2PerDof);
}
else
{
sampleResult = data_.fit(*(minimizer.back()), initCopy, v);
chi2PerDof = sampleResult.getChi2PerDof();
}
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);
}
fitSample(minimizer, v, result, sampleResult, initCopy, central);
}
else
{
FOR_STAT_ARRAY(result, s)
{
fitSample(minimizer, v, result, sampleResult, initCopy, s);
}
}
result.nPar_ = sampleResult.getNPar();
result.nDof_ = sampleResult.nDof_;
@ -340,11 +358,12 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
SampleFitResult XYSampleData::fit(Minimizer &minimizer,
const DVec &init,
const std::vector<const DoubleModel *> &v)
const std::vector<const DoubleModel *> &v,
bool centralSample)
{
vector<Minimizer *> mv{&minimizer};
return fit(mv, init, v);
return fit(mv, init, v, centralSample);
}
// residuals ///////////////////////////////////////////////////////////////////

View File

@ -102,10 +102,12 @@ public:
// get internal XYStatData
const XYStatData & getData(void);
// fit
void fitSample(std::vector<Minimizer *> &minimizer, const std::vector<const DoubleModel *> &v,
SampleFitResult &result, FitResult &sampleResult, DVec &init, Index s);
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
const std::vector<const DoubleModel *> &v);
const std::vector<const DoubleModel *> &v, bool centralSample = false);
SampleFitResult fit(Minimizer &minimizer, const DVec &init,
const std::vector<const DoubleModel *> &v);
const std::vector<const DoubleModel *> &v, bool centralSample = false);
template <typename... Ts>
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
const DoubleModel &model, const Ts... models);