mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-11 03:20:46 +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:
parent
9c5ade4989
commit
28aff209c4
@ -294,9 +294,40 @@ const XYStatData & XYSampleData::getData(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fit /////////////////////////////////////////////////////////////////////////
|
// 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,
|
SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
|
||||||
const DVec &init,
|
const DVec &init,
|
||||||
const std::vector<const DoubleModel *> &v)
|
const std::vector<const DoubleModel *> &v,
|
||||||
|
bool centralSample)
|
||||||
{
|
{
|
||||||
computeVarMat();
|
computeVarMat();
|
||||||
|
|
||||||
@ -307,29 +338,16 @@ 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;
|
if(centralSample)
|
||||||
FOR_STAT_ARRAY(result, s)
|
|
||||||
{
|
{
|
||||||
setDataToSample(s);
|
fitSample(minimizer, v, result, sampleResult, initCopy, central);
|
||||||
if (s == central)
|
}
|
||||||
{
|
else
|
||||||
sampleResult = data_.fit(minimizer, initCopy, v);
|
{
|
||||||
initCopy = sampleResult.segment(0, initCopy.size());
|
FOR_STAT_ARRAY(result, s)
|
||||||
chi2PerDof = sampleResult.getChi2PerDof();
|
{
|
||||||
checkChi2PerDof(chi2PerDof);
|
fitSample(minimizer, v, result, sampleResult, initCopy, s);
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
result.nPar_ = sampleResult.getNPar();
|
result.nPar_ = sampleResult.getNPar();
|
||||||
result.nDof_ = sampleResult.nDof_;
|
result.nDof_ = sampleResult.nDof_;
|
||||||
@ -340,11 +358,12 @@ SampleFitResult XYSampleData::fit(std::vector<Minimizer *> &minimizer,
|
|||||||
|
|
||||||
SampleFitResult XYSampleData::fit(Minimizer &minimizer,
|
SampleFitResult XYSampleData::fit(Minimizer &minimizer,
|
||||||
const DVec &init,
|
const DVec &init,
|
||||||
const std::vector<const DoubleModel *> &v)
|
const std::vector<const DoubleModel *> &v,
|
||||||
|
bool centralSample)
|
||||||
{
|
{
|
||||||
vector<Minimizer *> mv{&minimizer};
|
vector<Minimizer *> mv{&minimizer};
|
||||||
|
|
||||||
return fit(mv, init, v);
|
return fit(mv, init, v, centralSample);
|
||||||
}
|
}
|
||||||
|
|
||||||
// residuals ///////////////////////////////////////////////////////////////////
|
// residuals ///////////////////////////////////////////////////////////////////
|
||||||
|
@ -102,10 +102,12 @@ public:
|
|||||||
// get internal XYStatData
|
// get internal XYStatData
|
||||||
const XYStatData & getData(void);
|
const XYStatData & getData(void);
|
||||||
// fit
|
// 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,
|
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,
|
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>
|
template <typename... Ts>
|
||||||
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
|
SampleFitResult fit(std::vector<Minimizer *> &minimizer, const DVec &init,
|
||||||
const DoubleModel &model, const Ts... models);
|
const DoubleModel &model, const Ts... models);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user