added calculate chisq/maxLH only once without fitting and send the result to the stdout
This commit is contained in:
parent
dee034e99e
commit
72c39e6ce7
@ -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<double> param = fMnUserParams.Params();
|
||||
std::vector<double> error = fMnUserParams.Errors();
|
||||
int usedParams = 0;
|
||||
for (unsigned int i=0; i<error.size(); i++) {
|
||||
if (error[i] != 0.0)
|
||||
usedParams++;
|
||||
}
|
||||
int ndf = fFitterFcn->GetTotalNoOfFittedBins() - 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<fParams.size(); i++) {
|
||||
|
@ -63,7 +63,7 @@ Will handle all the possible minuit commands and actually do things ...
|
||||
class PFitter
|
||||
{
|
||||
public:
|
||||
PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection);
|
||||
PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, bool chisq_only = false);
|
||||
virtual ~PFitter();
|
||||
|
||||
bool IsValid() { return fIsValid; }
|
||||
@ -71,6 +71,7 @@ class PFitter
|
||||
|
||||
private:
|
||||
bool fIsValid;
|
||||
bool fChisqOnly;
|
||||
bool fUseChi2;
|
||||
|
||||
PMsrHandler *fRunInfo;
|
||||
|
@ -57,7 +57,7 @@ using namespace std;
|
||||
*/
|
||||
void musrfit_syntax()
|
||||
{
|
||||
cout << endl << "usage: musrfit [<msr-file> [-k, --keep-mn2-ouput] [--debug] [--dump <type>]] | --version | --help";
|
||||
cout << endl << "usage: musrfit [<msr-file> [-k, --keep-mn2-ouput] [-c, --chisq-only] [--debug] [--dump <type>]] | --version | --help";
|
||||
cout << endl << " <msr-file>: msr input file";
|
||||
cout << endl << " 'musrfit <msr-file>' 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 <msr-file>-mn2.output and <msr-file>-mn2.root, repectively,";
|
||||
cout << endl << " e.g. <msr-file> = 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 <type> is writing a data file with the fit data and the theory";
|
||||
cout << endl << " <type> 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; 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")) {
|
||||
chisq_only = true;
|
||||
} else if (!strcmp(argv[i], "--debug")) {
|
||||
debug = true;
|
||||
} else if (!strcmp(argv[i], "--dump")) {
|
||||
@ -623,14 +629,14 @@ int main(int argc, char *argv[])
|
||||
// do fitting
|
||||
PFitter *fitter = 0;
|
||||
if (success) {
|
||||
fitter = new PFitter(msrHandler, runListCollection);
|
||||
fitter = new PFitter(msrHandler, runListCollection, chisq_only);
|
||||
success = fitter->IsValid();
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user