added info if fit does not converge

This commit is contained in:
nemu 2009-02-26 07:49:43 +00:00
parent 41630d0945
commit acb5eda314
5 changed files with 51 additions and 18 deletions

View File

@ -63,6 +63,19 @@ using namespace std;
PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, bool chisq_only) :
fChisqOnly(chisq_only), fRunInfo(runInfo)
{
/*
PRunData *data=runListCollection->GetSingleHisto(0);
fstream fout( "__test.dat", ios_base::out );
fout << data->fDataTimeStart << endl;
fout << data->fDataTimeStep << endl;
fout << "------" << endl;
fout << data->fValue.size() << endl;
fout << "------" << endl;
for (unsigned int i=0; i<data->fValue.size(); i++) {
fout << data->fValue[i] << ", " << data->fError[i] << endl;
}
fout.close();
*/
fUseChi2 = true; // chi^2 is the default
fParams = *(runInfo->GetMsrParamList());
@ -141,7 +154,7 @@ bool PFitter::DoFit()
else
cout << endl << "Maximum Likelihood fit will be executed" << endl;
bool status;
bool status = true;
// init positive errors to default false, if minos is called, it will be set true there
for (unsigned int i=0; i<fParams.size(); i++) {
fRunInfo->SetMsrParamPosErrorPresent(i, false);
@ -212,6 +225,16 @@ bool PFitter::DoFit()
exit(0);
break;
}
// check if command has been successful
if (!status)
break;
}
if (IsValid()) {
fRunInfo->GetMsrStatistic()->fValid = true;
} else {
fRunInfo->GetMsrStatistic()->fValid = false;
}
return true;
@ -411,6 +434,7 @@ bool PFitter::ExecuteMigrad()
fRunInfo->SetMsrParamPosErrorPresent(i, false);
}
*/
fIsValid = false;
return false;
}
@ -482,6 +506,7 @@ bool PFitter::ExecuteMinimize()
fRunInfo->SetMsrParamPosErrorPresent(i, false);
}
*/
fIsValid = false;
return false;
}
@ -539,7 +564,7 @@ bool PFitter::ExecuteMinos()
// check if minimum was valid
if (!fFcnMin->IsValid()) {
cout << endl << "**ERROR**: MINOS cannot started since the previews minimization faild :-(";
cout << endl << "**ERROR**: MINOS cannot started since the previews minimization failed :-(";
cout << endl;
return false;
}
@ -841,6 +866,7 @@ bool PFitter::ExecuteSimplex()
ROOT::Minuit2::FunctionMinimum min = simplex(maxfcn, tolerance);
if (!min.IsValid()) {
cout << endl << "**WARNING**: PFitter::ExecuteSimplex(): Fit did not converge, sorry ...";
fIsValid = false;
return false;
}

View File

@ -60,6 +60,7 @@ PMsrHandler::PMsrHandler(char *fileName)
fTitle = "";
fStatistic.fValid = false;
fStatistic.fChisq = true;
fStatistic.fMin = -1.0;
fStatistic.fNdf = 0;
@ -799,21 +800,26 @@ int PMsrHandler::WriteMsrLogFile()
fStatistic.fStatLines.clear();
// create the new statistics block
PMsrLineStructure line;
if (fStatistic.fChisq) { // chi^2
line.fLine = " chisq = ";
line.fLine += fStatistic.fMin;
line.fLine += ", NDF = ";
line.fLine += fStatistic.fNdf;
line.fLine += ", chisq/NDF = ";
line.fLine += fStatistic.fMin / fStatistic.fNdf;
cout << endl << line.fLine.Data() << endl;
if (fStatistic.fValid) { // valid fit result
if (fStatistic.fChisq) { // chi^2
line.fLine = " chisq = ";
line.fLine += fStatistic.fMin;
line.fLine += ", NDF = ";
line.fLine += fStatistic.fNdf;
line.fLine += ", chisq/NDF = ";
line.fLine += fStatistic.fMin / fStatistic.fNdf;
cout << endl << line.fLine.Data() << endl;
} else {
line.fLine = " maxLH = ";
line.fLine += fStatistic.fMin;
line.fLine += ", NDF = ";
line.fLine += fStatistic.fNdf;
line.fLine += ", maxLH/NDF = ";
line.fLine += fStatistic.fMin / fStatistic.fNdf;
cout << endl << line.fLine.Data() << endl;
}
} else {
line.fLine = " maxLH = ";
line.fLine += fStatistic.fMin;
line.fLine += ", NDF = ";
line.fLine += fStatistic.fNdf;
line.fLine += ", maxLH/NDF = ";
line.fLine += fStatistic.fMin / fStatistic.fNdf;
line.fLine = "*** FIT DID NOT CONVERGE ***";
cout << endl << line.fLine.Data() << endl;
}
fStatistic.fStatLines.push_back(line);

View File

@ -141,7 +141,7 @@ double PRunSingleHisto::CalcChiSquare(const std::vector<double>& par)
time = fData.fDataTimeStart + (double)i*fData.fDataTimeStep;
if ((time>=fFitStartTime) && (time<=fFitStopTime)) {
diff = fData.fValue[i] -
(N0*TMath::Exp(-time/tau)*(1+fTheory->Func(time, par, fFuncValues))+bkg);
(N0*TMath::Exp(-time/tau)*(1.0+fTheory->Func(time, par, fFuncValues))+bkg);
chisq += diff*diff / (fData.fError[i]*fData.fError[i]);
}
}

View File

@ -320,6 +320,7 @@ typedef vector<PMsrPlotStructure> PMsrPlotList;
* <p>
*/
typedef struct {
bool fValid;
PMsrLines fStatLines;
TString fDate; ///< string holding fitting date and time
bool fChisq; ///< flag telling if min = chi2 or min = max.likelyhood

View File

@ -512,7 +512,7 @@ int main(int argc, char *argv[])
for (int i=2; i<argc; i++) {
if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--keep-mn2-output")) {
keep_mn2_output = true;
} else if (!strcmp(argv[i], "-c") || !strcmp(argv[1], "--chisq-only")) {
} else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--chisq-only")) {
chisq_only = true;
} else if (!strcmp(argv[i], "--debug")) {
debug = true;