From acb5eda3140317e938c36c737bad3308730d43c8 Mon Sep 17 00:00:00 2001 From: nemu Date: Thu, 26 Feb 2009 07:49:43 +0000 Subject: [PATCH] added info if fit does not converge --- src/classes/PFitter.cpp | 30 +++++++++++++++++++++++++++-- src/classes/PMsrHandler.cpp | 34 +++++++++++++++++++-------------- src/classes/PRunSingleHisto.cpp | 2 +- src/include/PMusr.h | 1 + src/musrfit.cpp | 2 +- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/classes/PFitter.cpp b/src/classes/PFitter.cpp index 4a868d04..74823be3 100644 --- a/src/classes/PFitter.cpp +++ b/src/classes/PFitter.cpp @@ -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; ifValue.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; iSetMsrParamPosErrorPresent(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; } diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index 025a41b7..c8a8e724 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -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); diff --git a/src/classes/PRunSingleHisto.cpp b/src/classes/PRunSingleHisto.cpp index 3976580f..ea9f58e1 100644 --- a/src/classes/PRunSingleHisto.cpp +++ b/src/classes/PRunSingleHisto.cpp @@ -141,7 +141,7 @@ double PRunSingleHisto::CalcChiSquare(const std::vector& 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]); } } diff --git a/src/include/PMusr.h b/src/include/PMusr.h index c10a6635..e67264b5 100644 --- a/src/include/PMusr.h +++ b/src/include/PMusr.h @@ -320,6 +320,7 @@ typedef vector PMsrPlotList; *

*/ 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 diff --git a/src/musrfit.cpp b/src/musrfit.cpp index 2bdac57c..79f76c17 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -512,7 +512,7 @@ int main(int argc, char *argv[]) for (int i=2; i