diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index a61003ee..3db25eb7 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -329,7 +329,14 @@ int PMsrHandler::WriteMsrLogFile(TString ext) { const unsigned int prec = 6; // output precision for float/doubles - TString str; + int tag, lineNo = 0, number; + int runNo = -1, addRunNo = 0; + int plotNo = -1; + char line[128]; + TString str, sstr; + TObjArray *tokens; + TObjString *ostr; + bool found = false; // construct log file name // first find the last '.' in the filename @@ -351,530 +358,505 @@ int PMsrHandler::WriteMsrLogFile(TString ext) str += "mlog"; - ofstream f; + ifstream fin; + ofstream fout; - // open mlog-file - f.open(str.Data(), iostream::out); - if (!f.is_open()) { + // open msr-file for reading + fin.open(fFileName.Data(), iostream::in); + if (!fin.is_open()) { return PMUSR_MSR_LOG_FILE_WRITE_ERROR; } - // write mlog-file - int lineNo = 1; - - // write title - f << fTitle.Data(); - CheckAndWriteComment(f, ++lineNo); - - // write fit parameter block - f << endl << "FITPARAMETER"; - CheckAndWriteComment(f, ++lineNo); - f << endl; - for (unsigned int i=0; i 5) { - f.width(7); - f.precision(prec); - if (fParam[i].fLowerBoundaryPresent) - f << left << fParam[i].fLowerBoundary; - else - f << left << "none"; - f << " "; - f.width(7); - f.precision(prec); - if (fParam[i].fUpperBoundaryPresent) - f << left << fParam[i].fUpperBoundary; - else - f << left << "none"; - f << " "; - } - CheckAndWriteComment(f, ++lineNo); - // terminate parameter line if not the last line - if (i != fParam.size()-1) - f << endl; + // open mlog-file for writing + fout.open(str.Data(), iostream::out); + if (!fout.is_open()) { + return PMUSR_MSR_LOG_FILE_WRITE_ERROR; } - // write theory block - for (unsigned int i=0; iGetFuncString(i); - str.ToLower(); - f << endl << str.Data(); - CheckAndWriteComment(f, ++lineNo); - } - } + // read a line + fin.getline(line, sizeof(line)); + str = line; + lineNo++; - // write run block - for (unsigned int i=0; i 1) { - for (unsigned int j=1; j= MSR_PARAM_FUN_OFFSET) - f << "fun" << fRuns[i].fNormParamNo-MSR_PARAM_FUN_OFFSET; - else - f << fRuns[i].fNormParamNo; - CheckAndWriteComment(f, ++lineNo); - } - // backgr.fit - if (fRuns[i].fBkgFitParamNo != -1) { - f.width(16); - f << endl << left << "backgr.fit"; - f << fRuns[i].fBkgFitParamNo; - CheckAndWriteComment(f, ++lineNo); - } - // rphase - if (fRuns[i].fPhaseParamNo != -1) { - f.width(16); - f << endl << left << "rphase"; - f << fRuns[i].fPhaseParamNo; - CheckAndWriteComment(f, ++lineNo); - } - // lifetime - if (fRuns[i].fLifetimeParamNo != -1) { - f.width(16); - f << endl << left << "lifetime"; - f << fRuns[i].fLifetimeParamNo; - CheckAndWriteComment(f, ++lineNo); - } - // lifetimecorrection - if ((fRuns[i].fLifetimeCorrection) && (fRuns[i].fFitType == MSR_FITTYPE_SINGLE_HISTO)) { - f << endl << "lifetimecorrection"; - CheckAndWriteComment(f, ++lineNo); - } - // map - f << endl << "map "; - for (unsigned int j=0; j 0) { - f.width(15); - f << endl << left << "backgr.fix"; - for (unsigned int j=0; j 0) { - f.width(16); - f << endl << left << "background"; - for (unsigned int j=0; j 0) { - f.width(16); - f << endl << left << "data"; - for (unsigned int j=0; j 0) { - f.width(16); - f << endl << left << "t0"; - for (unsigned int j=0; j= 0) { - f << endl << "fourier_power " << fFourier.fFourierPower; - CheckAndWriteComment(f, ++lineNo); - } - - // write 'appodization' if present - if (fFourier.fApodization != FOURIER_APOD_NOT_GIVEN) { - f << endl << "apodization "; - if (fFourier.fApodization == FOURIER_APOD_NONE) { - f << "NONE "; - } else if (fFourier.fApodization == FOURIER_APOD_WEAK) { - f << "WEAK "; - } else if (fFourier.fApodization == FOURIER_APOD_MEDIUM) { - f << "MEDIUM"; - } else if (fFourier.fApodization == FOURIER_APOD_STRONG) { - f << "STRONG"; - } - f << " # NONE, WEAK, MEDIUM, STRONG"; - CheckAndWriteComment(f, ++lineNo); - } - - // write 'plot' if present - if (fFourier.fPlotTag != FOURIER_PLOT_NOT_GIVEN) { - f << endl << "plot "; - if (fFourier.fPlotTag == FOURIER_PLOT_REAL) { - f << "REAL "; - } else if (fFourier.fPlotTag == FOURIER_PLOT_IMAG) { - f << "IMAG "; - } else if (fFourier.fPlotTag == FOURIER_PLOT_REAL_AND_IMAG) { - f << "REAL_AND_IMAG"; - } else if (fFourier.fPlotTag == FOURIER_PLOT_POWER) { - f << "POWER"; - } else if (fFourier.fPlotTag == FOURIER_PLOT_PHASE) { - f << "PHASE"; - } - f << " # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE"; - CheckAndWriteComment(f, ++lineNo); - } - - // write 'phase' if present - if (fFourier.fPhaseParamNo > 0) { - f << endl << "phase par" << fFourier.fPhaseParamNo; - CheckAndWriteComment(f, ++lineNo); - } else { - if (fFourier.fPhase != -999.0) { - f << endl << "phase " << fFourier.fPhase; - CheckAndWriteComment(f, ++lineNo); - } - } - - // write 'range_for_phase_correction' if present - if (fFourier.fRangeForPhaseCorrection[0] != -1.0) { - f << endl << "range_for_phase_correction " << fFourier.fRangeForPhaseCorrection[0] << " " << fFourier.fRangeForPhaseCorrection[1]; - CheckAndWriteComment(f, ++lineNo); - } - - // write 'range' if present - if (fFourier.fPlotRange[0] != -1.0) { - f << endl << "range " << fFourier.fPlotRange[0] << " " << fFourier.fPlotRange[1]; - CheckAndWriteComment(f, ++lineNo); - } - } - - // write plot block - for (unsigned int i=0; iGetEntries() == 0) { // not a parameter line + fout << str.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 << line.fLine.Data() << endl; + ostr = dynamic_cast(tokens->At(0)); + sstr = ostr->GetString(); + if (sstr.IsDigit()) { // parameter + number = sstr.Atoi(); + number--; + // make sure number makes sense + assert ((number >= 0) && (number < (int)fParam.size())); + // parameter no + fout.width(9); + fout << right << fParam[number].fNo; + fout << " "; + // parameter name + fout.width(11); + fout << left << fParam[number].fName.Data(); + fout << " "; + // value of the parameter + fout.width(9); + fout.precision(prec); + fout << left << fParam[number].fValue; + fout << " "; + // value of step/error/neg.error + fout.width(11); + fout.precision(prec); + fout << left << fParam[number].fStep; + fout << " "; + fout.width(11); + fout.precision(prec); + if ((fParam[number].fNoOfParams == 5) || (fParam[number].fNoOfParams == 7)) // pos. error given + if (fParam[number].fPosErrorPresent && (fParam[number].fStep != 0)) // pos error is a number + fout << left << fParam[number].fPosError; + else // pos error is a none + fout << left << "none"; + else // no pos. error + fout << left << "none"; + fout << " "; + // boundaries + if (fParam[number].fNoOfParams > 5) { + fout.width(7); + fout.precision(prec); + if (fParam[number].fLowerBoundaryPresent) + fout << left << fParam[number].fLowerBoundary; + else + fout << left << "none"; + fout << " "; + fout.width(7); + fout.precision(prec); + if (fParam[number].fUpperBoundaryPresent) + fout << left << fParam[number].fUpperBoundary; + else + fout << left << "none"; + fout << " "; + } + fout << endl; + } else { // not a parameter, hence just copy it + fout << str.Data() << endl; + } } - } else { - line.fLine = "*** FIT DID NOT CONVERGE ***"; - cout << endl << line.fLine.Data() << endl; - } - fStatistic.fStatLines.push_back(line); + break; + case MSR_TAG_THEORY: + found = false; + for (unsigned int i=0; iGetFuncString(number-1); + sstr.ToLower(); + fout << sstr.Data() << endl; + } + } else { + fout << str.Data() << endl; + } + break; + case MSR_TAG_RUN: + sstr = str; + sstr.Remove(TString::kLeading, ' '); + if (sstr.BeginsWith("RUN")) { + fout << "RUN " << fRuns[runNo].fRunName[0].Data() << " "; + str = fRuns[runNo].fBeamline[0]; + str.ToUpper(); + fout << str.Data() << " "; + str = fRuns[runNo].fInstitute[0]; + str.ToUpper(); + fout << str.Data() << " "; + str = fRuns[runNo].fFileFormat[0]; + str.ToUpper(); + fout << str.Data() << " (name beamline institute data-file-format)" << endl; + } else if (sstr.BeginsWith("ADDRUN")) { + addRunNo++; + fout << "ADDRUN " << fRuns[runNo].fRunName[addRunNo].Data() << " "; + str = fRuns[runNo].fBeamline[addRunNo]; + str.ToUpper(); + fout << str.Data() << " "; + str = fRuns[runNo].fInstitute[addRunNo]; + str.ToUpper(); + fout << str.Data() << " "; + str = fRuns[runNo].fFileFormat[addRunNo]; + str.ToUpper(); + fout << str.Data() << " (name beamline institute data-file-format)" << endl; + } else if (sstr.BeginsWith("fittype")) { + fout.width(16); + switch (fRuns[runNo].fFitType) { + case MSR_FITTYPE_SINGLE_HISTO: + fout << left << "fittype" << MSR_FITTYPE_SINGLE_HISTO << " (single histogram fit)" << endl; + break; + case MSR_FITTYPE_ASYM: + fout << left << "fittype" << MSR_FITTYPE_ASYM << " (asymmetry fit)" << endl ; + break; + case MSR_FITTYPE_ASYM_RRF: + fout << left << "fittype" << MSR_FITTYPE_ASYM_RRF << " (RRF asymmetry fit)" << endl ; + break; + case MSR_FITTYPE_NON_MUSR: + fout << left << "fittype" << MSR_FITTYPE_NON_MUSR << " (non muSR fit)" << endl ; + break; + default: + break; + } + } else if (sstr.BeginsWith("rrffrequency")) { + fout.width(16); + fout << left << "rrffrequency"; + fout.precision(prec); + fout << fRuns[runNo].fRRFFreq << endl; + } else if (sstr.BeginsWith("rrfpacking")) { + fout.width(16); + fout << left << "rrfpacking"; + fout.precision(prec); + fout << fRuns[runNo].fRRFPacking << endl; + } else if (sstr.BeginsWith("alpha ")) { + fout.width(16); + fout << left << "alpha"; + fout << fRuns[runNo].fAlphaParamNo << endl; + } else if (sstr.BeginsWith("beta ")) { + fout.width(16); + fout << left << "beta"; + fout << fRuns[runNo].fBetaParamNo << endl; + } else if (sstr.BeginsWith("alpha2")) { + fout.width(16); + fout << left << "alpha2"; + fout << fRuns[runNo].fAlphaParamNo << endl; + } else if (sstr.BeginsWith("beta2")) { + fout.width(16); + fout << left << "beta2"; + fout << fRuns[runNo].fBetaParamNo << endl; + } else if (sstr.BeginsWith("norm")) { + fout.width(16); + fout << left << "norm"; + // check if norm is give as a function + if (fRuns[runNo].fNormParamNo >= MSR_PARAM_FUN_OFFSET) + fout << "fun" << fRuns[runNo].fNormParamNo-MSR_PARAM_FUN_OFFSET; + else + fout << fRuns[runNo].fNormParamNo; + fout << endl; + } else if (sstr.BeginsWith("backgr.fit")) { + fout.width(16); + fout << left << "backgr.fit"; + fout << fRuns[runNo].fBkgFitParamNo << endl; + } else if (sstr.BeginsWith("rphase")) { + fout.width(16); + fout << left << "rphase"; + fout << fRuns[runNo].fPhaseParamNo << endl; + } else if (sstr.BeginsWith("lifetime ")) { + fout.width(16); + fout << left << "lifetime"; + fout << fRuns[runNo].fLifetimeParamNo << endl; + } else if (sstr.BeginsWith("lifetimecorrection")) { + if ((fRuns[runNo].fLifetimeCorrection) && (fRuns[runNo].fFitType == MSR_FITTYPE_SINGLE_HISTO)) { + fout << "lifetimecorrection" << endl; + } + } else if (sstr.BeginsWith("map")) { + fout << "map "; + for (unsigned int j=0; j 0) { + fout << "phase par" << fFourier.fPhaseParamNo << endl; + } else { + if (fFourier.fPhase != -999.0) { + fout << "phase " << fFourier.fPhase << endl; + } + } + } else if (sstr.BeginsWith("range_for_phase_correction")) { + fout << "range_for_phase_correction " << fFourier.fRangeForPhaseCorrection[0] << " " << fFourier.fRangeForPhaseCorrection[1] << endl; + } else if (sstr.BeginsWith("range ")) { + fout << "range " << fFourier.fPlotRange[0] << " " << fFourier.fPlotRange[1] << endl; + } else { + fout << str.Data() << endl; + } + break; + case MSR_TAG_PLOT: + sstr = str; + sstr.Remove(TString::kLeading, ' '); + if (sstr.BeginsWith("PLOT")) { + switch (fPlots[plotNo].fPlotType) { + case MSR_PLOT_SINGLE_HISTO: + fout << "PLOT " << fPlots[plotNo].fPlotType << " (single histo plot)" << endl; + break; + case MSR_PLOT_ASYM: + fout << "PLOT " << fPlots[plotNo].fPlotType << " (asymmetry plot)" << endl; + break; + case MSR_PLOT_ASYM_RRF: + fout << "PLOT " << fPlots[plotNo].fPlotType << " (rotating reference frame plot)" << endl; + break; + case MSR_PLOT_NON_MUSR: + fout << "PLOT " << fPlots[plotNo].fPlotType << " (non muSR plot)" << endl; + break; + default: + break; + } + } else if (sstr.BeginsWith("runs")) { + fout << "runs "; + fout.precision(0); + for (unsigned int j=0; j - * - * \param f - * \param lineNo - */ -void PMsrHandler::CheckAndWriteComment(ofstream &f, int &lineNo) -{ - unsigned int i; - - // check if lineNo is present - for (i=0; i