improved parameter formating

This commit is contained in:
nemu
2011-02-03 10:31:57 +00:00
parent fbd0cae432
commit aca61d4731
3 changed files with 61 additions and 9 deletions

View File

@ -17,6 +17,8 @@ FIXED 2 little annoying problems: (i) now it is possible to zoom down to the sin
(ii) when switching between data- and difference-view, the x-range doesn't change anymore. (ii) when switching between data- and difference-view, the x-range doesn't change anymore.
FIXED musrt0 crash for histogram number out of range (MUSR-157) FIXED musrt0 crash for histogram number out of range (MUSR-157)
FIXED fixes the inadequate attempt to use log max likelihood fit for asymmetry/non-muSR fit (MUSR-148) FIXED fixes the inadequate attempt to use log max likelihood fit for asymmetry/non-muSR fit (MUSR-148)
CHANGED the formating of the parameters such that they show the precision corresponding to the error. At the
same time some other parameter formating is improved (MUSR-167)
CHANGED the default behavior of msr2data for writing output-file headers (see svn-log 4758) CHANGED the default behavior of msr2data for writing output-file headers (see svn-log 4758)
CHANGED the behavior of msr2data when non-existing files are encountered---as far as possible they should be ignored now CHANGED the behavior of msr2data when non-existing files are encountered---as far as possible they should be ignored now
CHANGED less strict handling of empty FUNCTION block CHANGED less strict handling of empty FUNCTION block

View File

@ -848,8 +848,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
for (UInt_t j=0; j<2; j++) { for (UInt_t j=0; j<2; j++) {
if (fRuns[runNo].GetFitRange(j) == -1) if (fRuns[runNo].GetFitRange(j) == -1)
break; break;
fout.width(8); neededWidth = 7;
fout.precision(NeededPrecision(fRuns[runNo].GetFitRange(j), 6)); neededPrec = LastSignificant(fRuns[runNo].GetFitRange(j));
fout.width(neededWidth);
fout.precision(neededPrec);
fout << left << fixed << fRuns[runNo].GetFitRange(j); fout << left << fixed << fRuns[runNo].GetFitRange(j);
if (j==0) if (j==0)
fout << " "; fout << " ";
@ -956,16 +958,20 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
fout << endl; fout << endl;
} else if (sstr.BeginsWith("range")) { } else if (sstr.BeginsWith("range")) {
fout << "range "; fout << "range ";
fout.precision(NeededPrecision(fPlots[plotNo].fTmin[0], 6)); neededPrec = LastSignificant(fPlots[plotNo].fTmin[0]);
fout.precision(neededPrec);
fout << fPlots[plotNo].fTmin[0]; fout << fPlots[plotNo].fTmin[0];
fout << " "; fout << " ";
fout.precision(NeededPrecision(fPlots[plotNo].fTmax[0], 6)); neededPrec = LastSignificant(fPlots[plotNo].fTmax[0]);
fout.precision(neededPrec);
fout << fPlots[plotNo].fTmax[0]; fout << fPlots[plotNo].fTmax[0];
if (fPlots[plotNo].fYmin.size() > 0) { if (fPlots[plotNo].fYmin.size() > 0) {
fout << " "; fout << " ";
fout.precision(NeededPrecision(fPlots[plotNo].fYmin[0], 6)); neededPrec = LastSignificant(fPlots[plotNo].fYmin[0]);
fout.precision(neededPrec);
fout << fPlots[plotNo].fYmin[0] << " "; fout << fPlots[plotNo].fYmin[0] << " ";
fout.precision(NeededPrecision(fPlots[plotNo].fYmax[0], 6)); neededPrec = LastSignificant(fPlots[plotNo].fYmax[0]);
fout.precision(neededPrec);
fout << fPlots[plotNo].fYmax[0]; fout << fPlots[plotNo].fYmax[0];
} }
fout << endl; fout << endl;
@ -1541,7 +1547,9 @@ Int_t PMsrHandler::WriteMsrFile(const Char_t *filename, map<UInt_t, TString> *co
if (fRuns[i].GetFitRange(j) == -1) if (fRuns[i].GetFitRange(j) == -1)
break; break;
fout.width(8); fout.width(8);
fout.precision(NeededPrecision(fRuns[i].GetFitRange(j), 6)); UInt_t neededPrec = 2;
neededPrec = LastSignificant(fRuns[i].GetFitRange(j));
fout.precision(neededPrec);
fout << left << fixed << fRuns[i].GetFitRange(j); fout << left << fixed << fRuns[i].GetFitRange(j);
} }
fout << endl; fout << endl;
@ -4695,8 +4703,7 @@ void PMsrHandler::CheckMaxLikelihood()
* \param dval value for which the precision has to be estimated * \param dval value for which the precision has to be estimated
* \param precLimit precision limit * \param precLimit precision limit
* *
* <b>return:</b> * <b>return:</b> needed precision
* needed precision fo the fit-range
*/ */
UInt_t PMsrHandler::NeededPrecision(Double_t dval, UInt_t precLimit) UInt_t PMsrHandler::NeededPrecision(Double_t dval, UInt_t precLimit)
{ {
@ -4719,4 +4726,46 @@ UInt_t PMsrHandler::NeededPrecision(Double_t dval, UInt_t precLimit)
return prec; return prec;
} }
//--------------------------------------------------------------------------
// LastSignifiant (private)
//--------------------------------------------------------------------------
/**
* <p>Gets the last significant digit down to precLimit.
*
* \param dval value for which the last signigicant digit shall be found
* \param precLimit precision limit
*
* <b>return:</b> last significant digit down to precLimit
*/
UInt_t PMsrHandler::LastSignificant(Double_t dval, UInt_t precLimit)
{
UInt_t lastSignificant = 2;
UInt_t decimalPoint = 0;
char str[128];
sprintf(str, "%lf", dval);
// find decimal point
for (UInt_t i=0; i<strlen(str); i++) {
if (str[i] == '.') {
decimalPoint = i;
break;
}
}
// find last significant digit
for (UInt_t i=strlen(str)-1; i>=0; i--) {
if (str[i] != '0') {
if ((i-decimalPoint) < precLimit)
lastSignificant = i-decimalPoint;
else
lastSignificant = precLimit;
break;
}
}
return lastSignificant;
}
// end --------------------------------------------------------------------- // end ---------------------------------------------------------------------

View File

@ -141,6 +141,7 @@ class PMsrHandler
virtual Bool_t FilterNumber(TString str, const Char_t *filter, Int_t offset, Int_t &no); virtual Bool_t FilterNumber(TString str, const Char_t *filter, Int_t offset, Int_t &no);
virtual UInt_t NeededPrecision(Double_t dval, UInt_t precLimit=13); virtual UInt_t NeededPrecision(Double_t dval, UInt_t precLimit=13);
virtual UInt_t LastSignificant(Double_t dval, UInt_t precLimit=6);
}; };
#endif // _PMSRHANDLER_H_ #endif // _PMSRHANDLER_H_