write mlog-file routine fully rewritten to make it more robust. BMW is to prefect guy to test it since he is most creative in complex msr-files ;-)

This commit is contained in:
nemu
2009-05-20 08:52:41 +00:00
parent 0b2e989141
commit 2c9f392b81
2 changed files with 492 additions and 538 deletions

View File

@ -329,7 +329,14 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
{ {
const unsigned int prec = 6; // output precision for float/doubles 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 // construct log file name
// first find the last '.' in the filename // first find the last '.' in the filename
@ -351,530 +358,505 @@ int PMsrHandler::WriteMsrLogFile(TString ext)
str += "mlog"; str += "mlog";
ofstream f; ifstream fin;
ofstream fout;
// open mlog-file // open msr-file for reading
f.open(str.Data(), iostream::out); fin.open(fFileName.Data(), iostream::in);
if (!f.is_open()) { if (!fin.is_open()) {
return PMUSR_MSR_LOG_FILE_WRITE_ERROR; return PMUSR_MSR_LOG_FILE_WRITE_ERROR;
} }
// write mlog-file // open mlog-file for writing
int lineNo = 1; fout.open(str.Data(), iostream::out);
if (!fout.is_open()) {
return PMUSR_MSR_LOG_FILE_WRITE_ERROR;
}
// write title tag = MSR_TAG_TITLE;
f << fTitle.Data(); // read msr-file
CheckAndWriteComment(f, ++lineNo); while (!fin.eof()) {
// write fit parameter block // read a line
f << endl << "FITPARAMETER"; fin.getline(line, sizeof(line));
CheckAndWriteComment(f, ++lineNo); str = line;
f << endl; lineNo++;
for (unsigned int i=0; i<fParam.size(); i++) {
// check for tag
if (str.BeginsWith("FITPARAMETER")) { // FITPARAMETER block tag
tag = MSR_TAG_FITPARAMETER;
} else if (str.BeginsWith("THEORY")) { // THEORY block tag
tag = MSR_TAG_THEORY;
fout << str.Data() << endl;
continue;
} else if (str.BeginsWith("FUNCTIONS")) { // FUNCTIONS block tag
tag = MSR_TAG_FUNCTIONS;
fout << str.Data() << endl;
continue;
} else if (str.BeginsWith("RUN")) { // RUN block tag
tag = MSR_TAG_RUN;
runNo++;
} else if (str.BeginsWith("COMMANDS")) { // COMMANDS block tag
tag = MSR_TAG_COMMANDS;
fout << str.Data() << endl;
continue;
} else if (str.BeginsWith("FOURIER")) { // FOURIER block tag
tag = MSR_TAG_FOURIER;
fout << str.Data() << endl;
continue;
} else if (str.BeginsWith("PLOT")) { // PLOT block tag
tag = MSR_TAG_PLOT;
plotNo++;
} else if (str.BeginsWith("STATISTIC")) { // STATISTIC block tag
tag = MSR_TAG_STATISTIC;
}
// handle blocks
switch (tag) {
case MSR_TAG_TITLE:
fout << str.Data() << endl;
break;
case MSR_TAG_FITPARAMETER:
tokens = str.Tokenize(" \t");
if (tokens->GetEntries() == 0) { // not a parameter line
fout << str.Data() << endl;
} else {
ostr = dynamic_cast<TObjString*>(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 // parameter no
f.width(9); fout.width(9);
f << right << fParam[i].fNo; fout << right << fParam[number].fNo;
f << " "; fout << " ";
// parameter name // parameter name
f.width(11); fout.width(11);
f << left << fParam[i].fName.Data(); fout << left << fParam[number].fName.Data();
f << " "; fout << " ";
// value of the parameter // value of the parameter
f.width(9); fout.width(9);
f.precision(prec); fout.precision(prec);
f << left << fParam[i].fValue; fout << left << fParam[number].fValue;
f << " "; fout << " ";
// value of step/error/neg.error // value of step/error/neg.error
f.width(11); fout.width(11);
f.precision(prec); fout.precision(prec);
f << left << fParam[i].fStep; fout << left << fParam[number].fStep;
f << " "; fout << " ";
f.width(11); fout.width(11);
f.precision(prec); fout.precision(prec);
if ((fParam[i].fNoOfParams == 5) || (fParam[i].fNoOfParams == 7)) // pos. error given if ((fParam[number].fNoOfParams == 5) || (fParam[number].fNoOfParams == 7)) // pos. error given
if (fParam[i].fPosErrorPresent && (fParam[i].fStep != 0)) // pos error is a number if (fParam[number].fPosErrorPresent && (fParam[number].fStep != 0)) // pos error is a number
f << left << fParam[i].fPosError; fout << left << fParam[number].fPosError;
else // pos error is a none else // pos error is a none
f << left << "none"; fout << left << "none";
else // no pos. error else // no pos. error
f << left << "none"; fout << left << "none";
f << " "; fout << " ";
// boundaries // boundaries
if (fParam[i].fNoOfParams > 5) { if (fParam[number].fNoOfParams > 5) {
f.width(7); fout.width(7);
f.precision(prec); fout.precision(prec);
if (fParam[i].fLowerBoundaryPresent) if (fParam[number].fLowerBoundaryPresent)
f << left << fParam[i].fLowerBoundary; fout << left << fParam[number].fLowerBoundary;
else else
f << left << "none"; fout << left << "none";
f << " "; fout << " ";
f.width(7); fout.width(7);
f.precision(prec); fout.precision(prec);
if (fParam[i].fUpperBoundaryPresent) if (fParam[number].fUpperBoundaryPresent)
f << left << fParam[i].fUpperBoundary; fout << left << fParam[number].fUpperBoundary;
else else
f << left << "none"; fout << left << "none";
f << " "; fout << " ";
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
// terminate parameter line if not the last line } else { // not a parameter, hence just copy it
if (i != fParam.size()-1) fout << str.Data() << endl;
f << endl;
} }
}
// write theory block break;
case MSR_TAG_THEORY:
found = false;
for (unsigned int i=0; i<fTheory.size(); i++) { for (unsigned int i=0; i<fTheory.size(); i++) {
f << endl << fTheory[i].fLine.Data(); if (fTheory[i].fLineNo == lineNo) {
CheckAndWriteComment(f, ++lineNo); fout << fTheory[i].fLine.Data() << endl;
} found = true;
// write functions block
if (GetNoOfFuncs() != 0) {
f << endl << "FUNCTIONS";
CheckAndWriteComment(f, ++lineNo);
for (int i=0; i<GetNoOfFuncs(); i++) {
str = *fFuncHandler->GetFuncString(i);
str.ToLower();
f << endl << str.Data();
CheckAndWriteComment(f, ++lineNo);
} }
} }
if (!found) {
// write run block fout << str.Data() << endl;
for (unsigned int i=0; i<fRuns.size(); i++) {
// run header
f << endl << "RUN " << fRuns[i].fRunName[0].Data() << " ";
str = fRuns[i].fBeamline[0];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fInstitute[0];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fFileFormat[0];
str.ToUpper();
f << str.Data() << " (name beamline institute data-file-format)";
CheckAndWriteComment(f, ++lineNo);
// check for ADDRUN entries
if (fRuns[i].fRunName.size() > 1) {
for (unsigned int j=1; j<fRuns[i].fRunName.size(); j++) {
f << endl << "ADDRUN " << fRuns[i].fRunName[j].Data() << " ";
str = fRuns[i].fBeamline[j];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fInstitute[j];
str.ToUpper();
f << str.Data() << " ";
str = fRuns[i].fFileFormat[j];
str.ToUpper();
f << str.Data() << " (name beamline institute data-file-format)";
CheckAndWriteComment(f, ++lineNo);
} }
break;
case MSR_TAG_FUNCTIONS:
sstr = str;
sstr.Remove(TString::kLeading, ' ');
if (str.BeginsWith("fun")) {
if (FilterNumber(sstr, "fun", 0, number)) {
sstr = *fFuncHandler->GetFuncString(number-1);
sstr.ToLower();
fout << sstr.Data() << endl;
} }
// fittype } else {
f.width(16); fout << str.Data() << endl;
switch (fRuns[i].fFitType) { }
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: case MSR_FITTYPE_SINGLE_HISTO:
f << endl << left << "fittype" << MSR_FITTYPE_SINGLE_HISTO << " (single histogram fit)"; fout << left << "fittype" << MSR_FITTYPE_SINGLE_HISTO << " (single histogram fit)" << endl;
break; break;
case MSR_FITTYPE_ASYM: case MSR_FITTYPE_ASYM:
f << endl << left << "fittype" << MSR_FITTYPE_ASYM << " (asymmetry fit)"; fout << left << "fittype" << MSR_FITTYPE_ASYM << " (asymmetry fit)" << endl ;
break; break;
case MSR_FITTYPE_ASYM_RRF: case MSR_FITTYPE_ASYM_RRF:
f << endl << left << "fittype" << MSR_FITTYPE_ASYM_RRF << " (RRF asymmetry fit)"; fout << left << "fittype" << MSR_FITTYPE_ASYM_RRF << " (RRF asymmetry fit)" << endl ;
break; break;
case MSR_FITTYPE_NON_MUSR: case MSR_FITTYPE_NON_MUSR:
f << endl << left << "fittype" << MSR_FITTYPE_NON_MUSR << " (non muSR fit)"; fout << left << "fittype" << MSR_FITTYPE_NON_MUSR << " (non muSR fit)" << endl ;
break; break;
default: default:
break; break;
} }
CheckAndWriteComment(f, ++lineNo); } else if (sstr.BeginsWith("rrffrequency")) {
// rrffrequency fout.width(16);
if (fRuns[i].fRRFFreq != -1.0) { fout << left << "rrffrequency";
f.width(16); fout.precision(prec);
f << endl << left << "rrffrequency"; fout << fRuns[runNo].fRRFFreq << endl;
f.precision(prec); } else if (sstr.BeginsWith("rrfpacking")) {
f << fRuns[i].fRRFFreq; fout.width(16);
CheckAndWriteComment(f, ++lineNo); fout << left << "rrfpacking";
} fout.precision(prec);
// rrfpacking fout << fRuns[runNo].fRRFPacking << endl;
if (fRuns[i].fRRFPacking != -1) { } else if (sstr.BeginsWith("alpha ")) {
f.width(16); fout.width(16);
f << endl << left << "rrfpacking"; fout << left << "alpha";
f.precision(prec); fout << fRuns[runNo].fAlphaParamNo << endl;
f << fRuns[i].fRRFPacking; } else if (sstr.BeginsWith("beta ")) {
CheckAndWriteComment(f, ++lineNo); fout.width(16);
} fout << left << "beta";
// alpha fout << fRuns[runNo].fBetaParamNo << endl;
if (fRuns[i].fAlphaParamNo != -1) { } else if (sstr.BeginsWith("alpha2")) {
f.width(16); fout.width(16);
f << endl << left << "alpha"; fout << left << "alpha2";
f << fRuns[i].fAlphaParamNo; fout << fRuns[runNo].fAlphaParamNo << endl;
CheckAndWriteComment(f, ++lineNo); } else if (sstr.BeginsWith("beta2")) {
} fout.width(16);
// beta fout << left << "beta2";
if (fRuns[i].fBetaParamNo != -1) { fout << fRuns[runNo].fBetaParamNo << endl;
f.width(16); } else if (sstr.BeginsWith("norm")) {
f << endl << left << "beta"; fout.width(16);
f << fRuns[i].fBetaParamNo; fout << left << "norm";
CheckAndWriteComment(f, ++lineNo);
}
// alpha2
if (fRuns[i].fAlpha2ParamNo != -1) {
f.width(16);
f << endl << left << "alpha2";
f << fRuns[i].fAlpha2ParamNo;
CheckAndWriteComment(f, ++lineNo);
}
// beta2
if (fRuns[i].fBeta2ParamNo != -1) {
f.width(16);
f << endl << left << "beta2";
f << fRuns[i].fBeta2ParamNo;
CheckAndWriteComment(f, ++lineNo);
}
// norm
if (fRuns[i].fNormParamNo != -1) {
f.width(16);
f << endl << left << "norm";
// check if norm is give as a function // check if norm is give as a function
if (fRuns[i].fNormParamNo >= MSR_PARAM_FUN_OFFSET) if (fRuns[runNo].fNormParamNo >= MSR_PARAM_FUN_OFFSET)
f << "fun" << fRuns[i].fNormParamNo-MSR_PARAM_FUN_OFFSET; fout << "fun" << fRuns[runNo].fNormParamNo-MSR_PARAM_FUN_OFFSET;
else else
f << fRuns[i].fNormParamNo; fout << fRuns[runNo].fNormParamNo;
CheckAndWriteComment(f, ++lineNo); 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;
} }
// backgr.fit } else if (sstr.BeginsWith("map")) {
if (fRuns[i].fBkgFitParamNo != -1) { fout << "map ";
f.width(16); for (unsigned int j=0; j<fRuns[runNo].fMap.size(); j++) {
f << endl << left << "backgr.fit"; fout.width(5);
f << fRuns[i].fBkgFitParamNo; fout << right << fRuns[runNo].fMap[j];
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<fRuns[i].fMap.size(); j++) {
f.width(5);
f << right << fRuns[i].fMap[j];
} }
// if there are less maps then 10 fill with zeros // if there are less maps then 10 fill with zeros
if (fRuns[i].fMap.size() < 10) { if (fRuns[runNo].fMap.size() < 10) {
for (unsigned int j=fRuns[i].fMap.size(); j<10; j++) for (unsigned int j=fRuns[runNo].fMap.size(); j<10; j++)
f << " 0"; fout << " 0";
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
// forward } else if (sstr.BeginsWith("forward")) {
if (fRuns[i].fForwardHistoNo != -1) { fout.width(16);
f.width(16); fout << left << "forward";
f << endl << left << "forward"; fout << fRuns[runNo].fForwardHistoNo << endl;
f << fRuns[i].fForwardHistoNo; } else if (sstr.BeginsWith("backward")) {
CheckAndWriteComment(f, ++lineNo); fout.width(16);
fout << left << "backward";
fout << fRuns[runNo].fBackwardHistoNo << endl;
} else if (sstr.BeginsWith("right")) {
fout.width(16);
fout << left << "right";
fout << fRuns[runNo].fRightHistoNo << endl;
} else if (sstr.BeginsWith("left")) {
fout.width(16);
fout << left << "left";
fout << fRuns[runNo].fLeftHistoNo << endl;
} else if (sstr.BeginsWith("backgr.fix")) {
fout.width(15);
fout << left << "backgr.fix";
for (unsigned int j=0; j<fRuns[runNo].fBkgFix.size(); j++) {
fout.precision(prec);
fout.width(12);
fout << left << fRuns[runNo].fBkgFix[j];
} }
// backward fout << endl;
if (fRuns[i].fBackwardHistoNo != -1) { } else if (sstr.BeginsWith("background")) {
f.width(16); fout.width(16);
f << endl << left << "backward"; fout << left << "background";
f << fRuns[i].fBackwardHistoNo; for (unsigned int j=0; j<fRuns[runNo].fBkgRange.size(); j++) {
CheckAndWriteComment(f, ++lineNo); fout.width(8);
fout << left << fRuns[runNo].fBkgRange[j];
} }
// right fout << endl;
if (fRuns[i].fRightHistoNo != -1) { } else if (sstr.BeginsWith("data")) {
f.width(16); fout.width(16);
f << endl << left << "right"; fout << left << "data";
f << fRuns[i].fRightHistoNo; for (unsigned int j=0; j<fRuns[runNo].fDataRange.size(); j++) {
CheckAndWriteComment(f, ++lineNo); fout.width(8);
fout << left << fRuns[runNo].fDataRange[j];
} }
// left fout << endl;
if (fRuns[i].fLeftHistoNo != -1) { } else if (sstr.BeginsWith("t0")) {
f.width(16); fout.width(16);
f << endl << left << "left"; fout << left << "t0";
f << fRuns[i].fLeftHistoNo; for (unsigned int j=0; j<fRuns[runNo].fT0.size(); j++) {
CheckAndWriteComment(f, ++lineNo); fout.width(8);
fout << left << fRuns[runNo].fT0[j];
} }
// backgr.fix fout << endl;
if (fRuns[i].fBkgFix.size() > 0) { } else if (sstr.BeginsWith("xy-data")) {
f.width(15); if (fRuns[runNo].fXYDataIndex[0] != -1) { // indices
f << endl << left << "backgr.fix"; fout.width(16);
for (unsigned int j=0; j<fRuns[i].fBkgFix.size(); j++) { fout << left << "xy-data";
f.precision(prec);
f.width(12);
f << left << fRuns[i].fBkgFix[j];
}
CheckAndWriteComment(f, ++lineNo);
}
// background
if (fRuns[i].fBkgRange.size() > 0) {
f.width(16);
f << endl << left << "background";
for (unsigned int j=0; j<fRuns[i].fBkgRange.size(); j++) {
f.width(8);
f << left << fRuns[i].fBkgRange[j];
}
CheckAndWriteComment(f, ++lineNo);
}
// data
if (fRuns[i].fDataRange.size() > 0) {
f.width(16);
f << endl << left << "data";
for (unsigned int j=0; j<fRuns[i].fDataRange.size(); j++) {
f.width(8);
f << left << fRuns[i].fDataRange[j];
}
CheckAndWriteComment(f, ++lineNo);
}
// t0
if (fRuns[i].fT0.size() > 0) {
f.width(16);
f << endl << left << "t0";
for (unsigned int j=0; j<fRuns[i].fT0.size(); j++) {
f.width(8);
f << left << fRuns[i].fT0[j];
}
CheckAndWriteComment(f, ++lineNo);
}
// xy-data (indices)
if (fRuns[i].fXYDataIndex[0] != -1) {
f.width(16);
f << endl << left << "xy-data";
for (unsigned int j=0; j<2; j++) { for (unsigned int j=0; j<2; j++) {
if (fRuns[i].fXYDataIndex[j] == -1) if (fRuns[runNo].fXYDataIndex[j] == -1)
break; break;
f.width(8); fout.width(8);
f.precision(2); fout.precision(2);
f << left << fixed << fRuns[i].fXYDataIndex[j]; fout << left << fixed << fRuns[runNo].fXYDataIndex[j];
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
} } else if (!fRuns[runNo].fXYDataLabel[0].IsWhitespace()) { // labels
// xy-data (labels) fout.width(16);
if (!fRuns[i].fXYDataLabel[0].IsWhitespace()) { fout << endl << left << "xy-data";
f.width(16);
f << endl << left << "xy-data";
for (unsigned int j=0; j<2; j++) { for (unsigned int j=0; j<2; j++) {
if (fRuns[i].fXYDataLabel[j].IsWhitespace()) if (fRuns[runNo].fXYDataLabel[j].IsWhitespace())
break; break;
f.width(8); fout.width(8);
f << left << fixed << fRuns[i].fXYDataLabel[j].Data(); fout << left << fixed << fRuns[runNo].fXYDataLabel[j].Data();
if (j == 0) if (j == 0)
f << " "; fout << " ";
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
} }
// fit } else if (sstr.BeginsWith("fit")) {
if (fRuns[i].fFitRange[0] != -1) { fout.width(16);
f.width(16); fout << left << "fit";
f << endl << left << "fit";
for (unsigned int j=0; j<2; j++) { for (unsigned int j=0; j<2; j++) {
if (fRuns[i].fFitRange[j] == -1) if (fRuns[runNo].fFitRange[j] == -1)
break; break;
f.width(8); fout.width(8);
f.precision(2); fout.precision(2);
f << left << fixed << fRuns[i].fFitRange[j]; fout << left << fixed << fRuns[runNo].fFitRange[j];
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
} else if (sstr.BeginsWith("packing")) {
fout.width(16);
fout << left << "packing";
fout << fRuns[runNo].fPacking << endl;
} else {
fout << str.Data() << endl;
} }
// packing break;
f.width(16); case MSR_TAG_COMMANDS:
f << endl << left << "packing"; fout << str.Data() << endl;
f << fRuns[i].fPacking; break;
CheckAndWriteComment(f, ++lineNo); case MSR_TAG_FOURIER:
} sstr = str;
sstr.Remove(TString::kLeading, ' ');
// write command block if (sstr.BeginsWith("units")) {
f << endl << "COMMANDS"; fout << "units ";
CheckAndWriteComment(f, ++lineNo);
for (unsigned int i=0; i<fCommands.size(); i++) {
f << endl << fCommands[i].fLine.Data();
CheckAndWriteComment(f, ++lineNo);
}
// write fourier block if present
if (fFourier.fFourierBlockPresent) {
f << endl << "FOURIER";
CheckAndWriteComment(f, ++lineNo);
// write 'units' parameter if present
if (fFourier.fUnits != FOURIER_UNIT_NOT_GIVEN) {
f << endl << "units ";
if (fFourier.fUnits == FOURIER_UNIT_FIELD) { if (fFourier.fUnits == FOURIER_UNIT_FIELD) {
f << "Gauss"; fout << "Gauss";
} else if (fFourier.fUnits == FOURIER_UNIT_FREQ) { } else if (fFourier.fUnits == FOURIER_UNIT_FREQ) {
f << "MHz "; fout << "MHz ";
} else if (fFourier.fUnits == FOURIER_UNIT_CYCLES) { } else if (fFourier.fUnits == FOURIER_UNIT_CYCLES) {
f << "Mc/s"; fout << "Mc/s";
} }
f << " # units either 'Gauss', 'MHz', or 'Mc/s'"; fout << " # units either 'Gauss', 'MHz', or 'Mc/s'";
CheckAndWriteComment(f, ++lineNo); fout << endl;
} } else if (sstr.BeginsWith("fourier_power")) {
fout << "fourier_power " << fFourier.fFourierPower << endl;
// write 'fourier_power' parameter if present } else if (sstr.BeginsWith("apodization")) {
if (fFourier.fFourierPower >= 0) { fout << "apodization ";
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) { if (fFourier.fApodization == FOURIER_APOD_NONE) {
f << "NONE "; fout << "NONE ";
} else if (fFourier.fApodization == FOURIER_APOD_WEAK) { } else if (fFourier.fApodization == FOURIER_APOD_WEAK) {
f << "WEAK "; fout << "WEAK ";
} else if (fFourier.fApodization == FOURIER_APOD_MEDIUM) { } else if (fFourier.fApodization == FOURIER_APOD_MEDIUM) {
f << "MEDIUM"; fout << "MEDIUM";
} else if (fFourier.fApodization == FOURIER_APOD_STRONG) { } else if (fFourier.fApodization == FOURIER_APOD_STRONG) {
f << "STRONG"; fout << "STRONG";
} }
f << " # NONE, WEAK, MEDIUM, STRONG"; fout << " # NONE, WEAK, MEDIUM, STRONG";
CheckAndWriteComment(f, ++lineNo); fout << endl;
} } else if (sstr.BeginsWith("plot")) {
fout << "plot ";
// write 'plot' if present
if (fFourier.fPlotTag != FOURIER_PLOT_NOT_GIVEN) {
f << endl << "plot ";
if (fFourier.fPlotTag == FOURIER_PLOT_REAL) { if (fFourier.fPlotTag == FOURIER_PLOT_REAL) {
f << "REAL "; fout << "REAL ";
} else if (fFourier.fPlotTag == FOURIER_PLOT_IMAG) { } else if (fFourier.fPlotTag == FOURIER_PLOT_IMAG) {
f << "IMAG "; fout << "IMAG ";
} else if (fFourier.fPlotTag == FOURIER_PLOT_REAL_AND_IMAG) { } else if (fFourier.fPlotTag == FOURIER_PLOT_REAL_AND_IMAG) {
f << "REAL_AND_IMAG"; fout << "REAL_AND_IMAG";
} else if (fFourier.fPlotTag == FOURIER_PLOT_POWER) { } else if (fFourier.fPlotTag == FOURIER_PLOT_POWER) {
f << "POWER"; fout << "POWER";
} else if (fFourier.fPlotTag == FOURIER_PLOT_PHASE) { } else if (fFourier.fPlotTag == FOURIER_PLOT_PHASE) {
f << "PHASE"; fout << "PHASE";
} }
f << " # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE"; fout << " # REAL, IMAG, REAL_AND_IMAG, POWER, PHASE";
CheckAndWriteComment(f, ++lineNo); fout << endl;
} } else if (sstr.BeginsWith("phase")) {
// write 'phase' if present
if (fFourier.fPhaseParamNo > 0) { if (fFourier.fPhaseParamNo > 0) {
f << endl << "phase par" << fFourier.fPhaseParamNo; fout << "phase par" << fFourier.fPhaseParamNo << endl;
CheckAndWriteComment(f, ++lineNo);
} else { } else {
if (fFourier.fPhase != -999.0) { if (fFourier.fPhase != -999.0) {
f << endl << "phase " << fFourier.fPhase; fout << "phase " << fFourier.fPhase << endl;
CheckAndWriteComment(f, ++lineNo);
} }
} }
} else if (sstr.BeginsWith("range_for_phase_correction")) {
// write 'range_for_phase_correction' if present fout << "range_for_phase_correction " << fFourier.fRangeForPhaseCorrection[0] << " " << fFourier.fRangeForPhaseCorrection[1] << endl;
if (fFourier.fRangeForPhaseCorrection[0] != -1.0) { } else if (sstr.BeginsWith("range ")) {
f << endl << "range_for_phase_correction " << fFourier.fRangeForPhaseCorrection[0] << " " << fFourier.fRangeForPhaseCorrection[1]; fout << "range " << fFourier.fPlotRange[0] << " " << fFourier.fPlotRange[1] << endl;
CheckAndWriteComment(f, ++lineNo); } else {
fout << str.Data() << endl;
} }
break;
// write 'range' if present case MSR_TAG_PLOT:
if (fFourier.fPlotRange[0] != -1.0) { sstr = str;
f << endl << "range " << fFourier.fPlotRange[0] << " " << fFourier.fPlotRange[1]; sstr.Remove(TString::kLeading, ' ');
CheckAndWriteComment(f, ++lineNo); if (sstr.BeginsWith("PLOT")) {
} switch (fPlots[plotNo].fPlotType) {
}
// write plot block
for (unsigned int i=0; i<fPlots.size(); i++) {
// plot header
switch (fPlots[i].fPlotType) {
case MSR_PLOT_SINGLE_HISTO: case MSR_PLOT_SINGLE_HISTO:
f << endl << "PLOT " << fPlots[i].fPlotType << " (single histo plot)"; fout << "PLOT " << fPlots[plotNo].fPlotType << " (single histo plot)" << endl;
break; break;
case MSR_PLOT_ASYM: case MSR_PLOT_ASYM:
f << endl << "PLOT " << fPlots[i].fPlotType << " (asymmetry plot)"; fout << "PLOT " << fPlots[plotNo].fPlotType << " (asymmetry plot)" << endl;
break; break;
case MSR_PLOT_ASYM_RRF: case MSR_PLOT_ASYM_RRF:
f << endl << "PLOT " << fPlots[i].fPlotType << " (rotating reference frame plot)"; fout << "PLOT " << fPlots[plotNo].fPlotType << " (rotating reference frame plot)" << endl;
break; break;
case MSR_PLOT_NON_MUSR: case MSR_PLOT_NON_MUSR:
f << endl << "PLOT " << fPlots[i].fPlotType << " (non muSR plot)"; fout << "PLOT " << fPlots[plotNo].fPlotType << " (non muSR plot)" << endl;
break; break;
default: default:
break; break;
} }
CheckAndWriteComment(f, ++lineNo); } else if (sstr.BeginsWith("runs")) {
// runs fout << "runs ";
f << endl << "runs "; fout.precision(0);
f.precision(0); for (unsigned int j=0; j<fPlots[plotNo].fRuns.size(); j++) {
for (unsigned int j=0; j<fPlots[i].fRuns.size(); j++) { if (fPlots[plotNo].fPlotType != MSR_PLOT_ASYM_RRF) { // all but MSR_PLOT_ASYM_RRF
if (fPlots[i].fPlotType != MSR_PLOT_ASYM_RRF) { // all but MSR_PLOT_ASYM_RRF fout.width(4);
f.width(4); fout << fPlots[plotNo].fRuns[j].Re();
f << fPlots[i].fRuns[j].Re();
} else { // MSR_PLOT_ASYM_RRF } else { // MSR_PLOT_ASYM_RRF
f << fPlots[i].fRuns[j].Re() << "," << fPlots[i].fRuns[j].Im() << " "; fout << fPlots[plotNo].fRuns[j].Re() << "," << fPlots[plotNo].fRuns[j].Im() << " ";
} }
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
// range } else if (sstr.BeginsWith("range")) {
f << endl << "range "; fout << "range ";
f.precision(2); fout.precision(2);
f << fPlots[i].fTmin << " " << fPlots[i].fTmax; fout << fPlots[plotNo].fTmin << " " << fPlots[plotNo].fTmax;
if (fPlots[i].fYmin != -999.0) { if (fPlots[plotNo].fYmin != -999.0) {
f << " " << fPlots[i].fYmin << " " << fPlots[i].fYmax; fout << " " << fPlots[plotNo].fYmin << " " << fPlots[plotNo].fYmax;
} }
CheckAndWriteComment(f, ++lineNo); fout << endl;
} else {
fout << str.Data() << endl;
} }
break;
if (!fCopyStatisticsBlock) { // write a new statistics block case MSR_TAG_STATISTIC:
// write statistic block sstr = str;
sstr.Remove(TString::kLeading, ' ');
if (sstr.BeginsWith("STATISTIC")) {
TDatime dt; TDatime dt;
f << endl << "STATISTIC --- " << dt.AsSQLString(); fout << "STATISTIC --- " << dt.AsSQLString() << endl;
CheckAndWriteComment(f, ++lineNo); } else if (sstr.BeginsWith("chisq")) {
// if fMin and fNdf are given, make new statistic block
if ((fStatistic.fMin != -1.0) && (fStatistic.fNdf != 0)) {
// throw away the old statistics block
fStatistic.fStatLines.clear();
// create the new statistics block
PMsrLineStructure line;
if (fStatistic.fValid) { // valid fit result if (fStatistic.fValid) { // valid fit result
if (fStatistic.fChisq) { // chi^2 str = " chisq = ";
line.fLine = " chisq = "; str += fStatistic.fMin;
line.fLine += fStatistic.fMin; str += ", NDF = ";
line.fLine += ", NDF = "; str += fStatistic.fNdf;
line.fLine += fStatistic.fNdf; str += ", chisq/NDF = ";
line.fLine += ", chisq/NDF = "; str += fStatistic.fMin / fStatistic.fNdf;
line.fLine += fStatistic.fMin / fStatistic.fNdf; fout << str.Data() << endl;
cout << line.fLine.Data() << endl; cout << endl << str.Data() << endl;
} else { } else {
line.fLine = " maxLH = "; fout << "*** FIT DID NOT CONVERGE ***" << endl;
line.fLine += fStatistic.fMin; cout << endl << "*** FIT DID NOT CONVERGE ***" << endl;
line.fLine += ", NDF = "; }
line.fLine += fStatistic.fNdf; } else if (sstr.BeginsWith("chisq")) {
line.fLine += ", maxLH/NDF = "; if (fStatistic.fValid) { // valid fit result
line.fLine += fStatistic.fMin / fStatistic.fNdf; str = " maxLH = ";
cout << line.fLine.Data() << endl; str += fStatistic.fMin;
str += ", NDF = ";
str += fStatistic.fNdf;
str += ", maxLH/NDF = ";
str += fStatistic.fMin / fStatistic.fNdf;
fout << str.Data() << endl;
cout << endl << str.Data() << endl;
} else {
fout << "*** FIT DID NOT CONVERGE ***" << endl;
cout << endl << "*** FIT DID NOT CONVERGE ***" << endl;
} }
} else { } else {
line.fLine = "*** FIT DID NOT CONVERGE ***"; fout << str.Data() << endl;
cout << endl << line.fLine.Data() << endl;
} }
fStatistic.fStatLines.push_back(line); break;
default:
break;
} }
} }
// write the statistics block
for (unsigned int i=0; i<fStatistic.fStatLines.size(); i++) {
f << endl << fStatistic.fStatLines[i].fLine.Data();
CheckAndWriteComment(f, ++lineNo);
}
// close mlog-file // close files
f.close(); fout.close();
fin.close();
return PMUSR_SUCCESS; return PMUSR_SUCCESS;
} }
@ -3139,30 +3121,4 @@ bool PMsrHandler::CheckFuncs()
return result; return result;
} }
//--------------------------------------------------------------------------
// CheckAndWriteComment
//--------------------------------------------------------------------------
/**
* <p>
*
* \param f
* \param lineNo
*/
void PMsrHandler::CheckAndWriteComment(ofstream &f, int &lineNo)
{
unsigned int i;
// check if lineNo is present
for (i=0; i<fComments.size(); i++) {
if (fComments[i].fLineNo == lineNo) {
break;
}
}
if (i<fComments.size()) {
f << endl << fComments[i].fLine.Data();
CheckAndWriteComment(f, ++lineNo);
}
}
// end --------------------------------------------------------------------- // end ---------------------------------------------------------------------

View File

@ -126,8 +126,6 @@ class PMsrHandler
virtual bool HandlePlotEntry(PMsrLines &line); virtual bool HandlePlotEntry(PMsrLines &line);
virtual bool HandleStatisticEntry(PMsrLines &line); virtual bool HandleStatisticEntry(PMsrLines &line);
virtual void CheckAndWriteComment(ofstream &f, int &lineNo);
virtual void FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLines &run); virtual void FillParameterInUse(PMsrLines &theory, PMsrLines &funcs, PMsrLines &run);
virtual void InitRunParameterStructure(PMsrRunStructure &param); virtual void InitRunParameterStructure(PMsrRunStructure &param);