From aca61d4731e542903eb9fd4f9bea8bdd2832b0f2 Mon Sep 17 00:00:00 2001 From: nemu Date: Thu, 3 Feb 2011 10:31:57 +0000 Subject: [PATCH] improved parameter formating --- ChangeLog | 2 ++ src/classes/PMsrHandler.cpp | 67 ++++++++++++++++++++++++++++++++----- src/include/PMsrHandler.h | 1 + 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a933179..c326ee8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. 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) +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 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 diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index 2b008c6f..53f578f9 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -848,8 +848,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) for (UInt_t j=0; j<2; j++) { if (fRuns[runNo].GetFitRange(j) == -1) break; - fout.width(8); - fout.precision(NeededPrecision(fRuns[runNo].GetFitRange(j), 6)); + neededWidth = 7; + neededPrec = LastSignificant(fRuns[runNo].GetFitRange(j)); + fout.width(neededWidth); + fout.precision(neededPrec); fout << left << fixed << fRuns[runNo].GetFitRange(j); if (j==0) fout << " "; @@ -956,16 +958,20 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) fout << endl; } else if (sstr.BeginsWith("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 << " "; - fout.precision(NeededPrecision(fPlots[plotNo].fTmax[0], 6)); + neededPrec = LastSignificant(fPlots[plotNo].fTmax[0]); + fout.precision(neededPrec); fout << fPlots[plotNo].fTmax[0]; if (fPlots[plotNo].fYmin.size() > 0) { fout << " "; - fout.precision(NeededPrecision(fPlots[plotNo].fYmin[0], 6)); + neededPrec = LastSignificant(fPlots[plotNo].fYmin[0]); + fout.precision(neededPrec); 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 << endl; @@ -1541,7 +1547,9 @@ Int_t PMsrHandler::WriteMsrFile(const Char_t *filename, map *co if (fRuns[i].GetFitRange(j) == -1) break; 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 << endl; @@ -4695,8 +4703,7 @@ void PMsrHandler::CheckMaxLikelihood() * \param dval value for which the precision has to be estimated * \param precLimit precision limit * - * return: - * needed precision fo the fit-range + * return: needed precision */ 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; } +//-------------------------------------------------------------------------- +// LastSignifiant (private) +//-------------------------------------------------------------------------- +/** + *

Gets the last significant digit down to precLimit. + * + * \param dval value for which the last signigicant digit shall be found + * \param precLimit precision limit + * + * return: 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=0; i--) { + if (str[i] != '0') { + if ((i-decimalPoint) < precLimit) + lastSignificant = i-decimalPoint; + else + lastSignificant = precLimit; + break; + } + } + + return lastSignificant; +} + // end --------------------------------------------------------------------- diff --git a/src/include/PMsrHandler.h b/src/include/PMsrHandler.h index 10195de2..d12c9f8a 100644 --- a/src/include/PMsrHandler.h +++ b/src/include/PMsrHandler.h @@ -141,6 +141,7 @@ class PMsrHandler 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 LastSignificant(Double_t dval, UInt_t precLimit=6); }; #endif // _PMSRHANDLER_H_