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 runInfo
|
||||||
* \param runListCollection
|
* \param runListCollection
|
||||||
|
* \param chisq_only
|
||||||
*/
|
*/
|
||||||
PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection) :
|
PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, bool chisq_only) :
|
||||||
fRunInfo(runInfo)
|
fChisqOnly(chisq_only), fRunInfo(runInfo)
|
||||||
{
|
{
|
||||||
fUseChi2 = true; // chi^2 is the default
|
fUseChi2 = true; // chi^2 is the default
|
||||||
|
|
||||||
@ -111,14 +112,35 @@ PFitter::~PFitter()
|
|||||||
*/
|
*/
|
||||||
bool PFitter::DoFit()
|
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)
|
if (fUseChi2)
|
||||||
cout << endl << "Chi Square fit will be executed" << endl;
|
cout << endl << "Chi Square fit will be executed" << endl;
|
||||||
else
|
else
|
||||||
cout << endl << "Maximum Likelihood fit will be executed" << endl;
|
cout << endl << "Maximum Likelihood fit will be executed" << endl;
|
||||||
|
|
||||||
// feed minuit parameters
|
|
||||||
SetParameters();
|
|
||||||
|
|
||||||
bool status;
|
bool status;
|
||||||
// init positive errors to default false, if minos is called, it will be set true there
|
// 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++) {
|
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
|
class PFitter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection);
|
PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, bool chisq_only = false);
|
||||||
virtual ~PFitter();
|
virtual ~PFitter();
|
||||||
|
|
||||||
bool IsValid() { return fIsValid; }
|
bool IsValid() { return fIsValid; }
|
||||||
@ -71,6 +71,7 @@ class PFitter
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool fIsValid;
|
bool fIsValid;
|
||||||
|
bool fChisqOnly;
|
||||||
bool fUseChi2;
|
bool fUseChi2;
|
||||||
|
|
||||||
PMsrHandler *fRunInfo;
|
PMsrHandler *fRunInfo;
|
||||||
|
@ -57,7 +57,7 @@ using namespace std;
|
|||||||
*/
|
*/
|
||||||
void musrfit_syntax()
|
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 << " <msr-file>: msr input file";
|
||||||
cout << endl << " 'musrfit <msr-file>' will execute musrfit";
|
cout << endl << " 'musrfit <msr-file>' will execute musrfit";
|
||||||
cout << endl << " 'musrfit' or 'musrfit --help' will show this help";
|
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 << " -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 << " 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 << " 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 << " --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 << " --dump <type> is writing a data file with the fit data and the theory";
|
||||||
cout << endl << " <type> can be 'ascii', 'root'";
|
cout << endl << " <type> can be 'ascii', 'root'";
|
||||||
@ -473,6 +476,7 @@ int main(int argc, char *argv[])
|
|||||||
int status;
|
int status;
|
||||||
bool debug = false;
|
bool debug = false;
|
||||||
bool keep_mn2_output = false;
|
bool keep_mn2_output = false;
|
||||||
|
bool chisq_only = false;
|
||||||
TString dump("");
|
TString dump("");
|
||||||
|
|
||||||
// check syntax
|
// check syntax
|
||||||
@ -508,6 +512,8 @@ int main(int argc, char *argv[])
|
|||||||
for (int i=2; i<argc; i++) {
|
for (int i=2; i<argc; i++) {
|
||||||
if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--keep-mn2-output")) {
|
if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--keep-mn2-output")) {
|
||||||
keep_mn2_output = true;
|
keep_mn2_output = true;
|
||||||
|
} else if (!strcmp(argv[i], "-c") || !strcmp(argv[1], "--chisq-only")) {
|
||||||
|
chisq_only = true;
|
||||||
} else if (!strcmp(argv[i], "--debug")) {
|
} else if (!strcmp(argv[i], "--debug")) {
|
||||||
debug = true;
|
debug = true;
|
||||||
} else if (!strcmp(argv[i], "--dump")) {
|
} else if (!strcmp(argv[i], "--dump")) {
|
||||||
@ -623,14 +629,14 @@ int main(int argc, char *argv[])
|
|||||||
// do fitting
|
// do fitting
|
||||||
PFitter *fitter = 0;
|
PFitter *fitter = 0;
|
||||||
if (success) {
|
if (success) {
|
||||||
fitter = new PFitter(msrHandler, runListCollection);
|
fitter = new PFitter(msrHandler, runListCollection, chisq_only);
|
||||||
success = fitter->IsValid();
|
success = fitter->IsValid();
|
||||||
if (success)
|
if (success)
|
||||||
fitter->DoFit();
|
fitter->DoFit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// write log file
|
// write log file
|
||||||
if (success) {
|
if (success && !chisq_only) {
|
||||||
status = msrHandler->WriteMsrLogFile();
|
status = msrHandler->WriteMsrLogFile();
|
||||||
if (status != PMUSR_SUCCESS) {
|
if (status != PMUSR_SUCCESS) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
@ -648,7 +654,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if dump is wanted
|
// check if dump is wanted
|
||||||
if (success && !dump.IsNull()) {
|
if (success && !dump.IsNull() && !chisq_only) {
|
||||||
cout << endl << "will write dump file ..." << endl;
|
cout << endl << "will write dump file ..." << endl;
|
||||||
dump.ToLower();
|
dump.ToLower();
|
||||||
if (dump.Contains("ascii"))
|
if (dump.Contains("ascii"))
|
||||||
@ -660,7 +666,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// rename MINUIT2.OUTPUT and MINUIT2.root file if wanted
|
// rename MINUIT2.OUTPUT and MINUIT2.root file if wanted
|
||||||
if (keep_mn2_output) {
|
if (keep_mn2_output && !chisq_only) {
|
||||||
// 1st rename MINUIT2.OUTPUT
|
// 1st rename MINUIT2.OUTPUT
|
||||||
TString fln = TString(argv[1]);
|
TString fln = TString(argv[1]);
|
||||||
char ext[32];
|
char ext[32];
|
||||||
@ -697,7 +703,7 @@ int main(int argc, char *argv[])
|
|||||||
fitter = 0;
|
fitter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl << "done ..." << endl;
|
cout << endl << "done ..." << endl;
|
||||||
|
|
||||||
return PMUSR_SUCCESS;
|
return PMUSR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user