diff --git a/src/classes/PFitter.cpp b/src/classes/PFitter.cpp index 7fdb47bc..4a868d04 100644 --- a/src/classes/PFitter.cpp +++ b/src/classes/PFitter.cpp @@ -58,9 +58,10 @@ using namespace std; * * \param runInfo * \param runListCollection + * \param chisq_only */ -PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection) : - fRunInfo(runInfo) +PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, bool chisq_only) : + fChisqOnly(chisq_only), fRunInfo(runInfo) { fUseChi2 = true; // chi^2 is the default @@ -111,14 +112,35 @@ PFitter::~PFitter() */ bool PFitter::DoFit() { + // feed minuit parameters + SetParameters(); + + // check if only chisq/maxLH shall be calculated once + if (fChisqOnly) { + std::vector param = fMnUserParams.Params(); + std::vector error = fMnUserParams.Errors(); + int usedParams = 0; + for (unsigned int i=0; iGetTotalNoOfFittedBins() - usedParams; + double val = (*fFitterFcn)(param); + if (fUseChi2) { + cout << endl << endl << ">> chisq = " << val << ", NDF = " << ndf << ", chisq/NDF = " << val/ndf; + } else { // max. log likelihood + cout << endl << endl << ">> maxLH = " << val << ", NDF = " << ndf << ", maxLH/NDF = " << val/ndf; + } + cout << endl << endl; + return true; + } + + // real fit wanted if (fUseChi2) cout << endl << "Chi Square fit will be executed" << endl; else cout << endl << "Maximum Likelihood fit will be executed" << endl; - // feed minuit parameters - SetParameters(); - bool status; // init positive errors to default false, if minos is called, it will be set true there for (unsigned int i=0; i [-k, --keep-mn2-ouput] [--debug] [--dump ]] | --version | --help"; + cout << endl << "usage: musrfit [ [-k, --keep-mn2-ouput] [-c, --chisq-only] [--debug] [--dump ]] | --version | --help"; cout << endl << " : msr input file"; cout << endl << " 'musrfit ' will execute musrfit"; cout << endl << " 'musrfit' or 'musrfit --help' will show this help"; @@ -65,6 +65,9 @@ void musrfit_syntax() cout << endl << " -k, --keep-mn2-output: will rename the files MINUIT2.OUTPUT and "; cout << endl << " MINUIT2.root to -mn2.output and -mn2.root, repectively,"; cout << endl << " e.g. = 147.msr -> 147-mn2.output, 147-mn2.root"; + cout << endl << " -c, --chisq-only: instead of fitting the data, chisq is just calculated"; + cout << endl << " once and the result is set to the stdout. This feature is useful"; + cout << endl << " to adjust initial parameters."; cout << endl << " --debug is used to print additional infos"; cout << endl << " --dump is writing a data file with the fit data and the theory"; cout << endl << " can be 'ascii', 'root'"; @@ -473,6 +476,7 @@ int main(int argc, char *argv[]) int status; bool debug = false; bool keep_mn2_output = false; + bool chisq_only = false; TString dump(""); // check syntax @@ -508,6 +512,8 @@ int main(int argc, char *argv[]) for (int i=2; iIsValid(); if (success) fitter->DoFit(); } // write log file - if (success) { + if (success && !chisq_only) { status = msrHandler->WriteMsrLogFile(); if (status != PMUSR_SUCCESS) { switch (status) { @@ -648,7 +654,7 @@ int main(int argc, char *argv[]) } // check if dump is wanted - if (success && !dump.IsNull()) { + if (success && !dump.IsNull() && !chisq_only) { cout << endl << "will write dump file ..." << endl; dump.ToLower(); if (dump.Contains("ascii")) @@ -660,7 +666,7 @@ int main(int argc, char *argv[]) } // rename MINUIT2.OUTPUT and MINUIT2.root file if wanted - if (keep_mn2_output) { + if (keep_mn2_output && !chisq_only) { // 1st rename MINUIT2.OUTPUT TString fln = TString(argv[1]); char ext[32]; @@ -697,7 +703,7 @@ int main(int argc, char *argv[]) fitter = 0; } -cout << endl << "done ..." << endl; + cout << endl << "done ..." << endl; return PMUSR_SUCCESS; }