tries to deal with precision request MUSR-167
This commit is contained in:
parent
2cb6219fd0
commit
fbd0cae432
@ -331,7 +331,9 @@ Int_t PMsrHandler::ReadMsrFile()
|
|||||||
*/
|
*/
|
||||||
Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||||
{
|
{
|
||||||
const UInt_t prec = 6; // output precision for float/doubles
|
const UInt_t prec = 6; // default output precision for float/doubles
|
||||||
|
UInt_t neededPrec = 0;
|
||||||
|
UInt_t neededWidth = 9;
|
||||||
|
|
||||||
Int_t tag, lineNo = 0, number;
|
Int_t tag, lineNo = 0, number;
|
||||||
Int_t runNo = -1, addRunNo = 0;
|
Int_t runNo = -1, addRunNo = 0;
|
||||||
@ -496,17 +498,27 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
|||||||
fout << left << fParam[number].fName.Data();
|
fout << left << fParam[number].fName.Data();
|
||||||
fout << " ";
|
fout << " ";
|
||||||
// value of the parameter
|
// value of the parameter
|
||||||
fout.width(9);
|
neededPrec = NeededPrecision(fParam[number].fStep)+1;
|
||||||
fout.precision(prec);
|
if (fParam[number].fPosErrorPresent && (NeededPrecision(fParam[number].fPosError)+1 > neededPrec))
|
||||||
|
neededPrec = NeededPrecision(fParam[number].fPosError)+1;
|
||||||
|
if (neededPrec < 6)
|
||||||
|
neededWidth = 9;
|
||||||
|
else
|
||||||
|
neededWidth = neededPrec + 3;
|
||||||
|
fout.width(neededWidth);
|
||||||
|
fout.setf(ios::fixed, ios::floatfield);
|
||||||
|
fout.precision(neededPrec);
|
||||||
fout << left << fParam[number].fValue;
|
fout << left << fParam[number].fValue;
|
||||||
fout << " ";
|
fout << " ";
|
||||||
// value of step/error/neg.error
|
// value of step/error/neg.error
|
||||||
fout.width(11);
|
fout.width(11);
|
||||||
fout.precision(prec);
|
fout.setf(ios::fixed);
|
||||||
|
fout.precision(neededPrec);
|
||||||
fout << left << fParam[number].fStep;
|
fout << left << fParam[number].fStep;
|
||||||
fout << " ";
|
fout << " ";
|
||||||
fout.width(11);
|
fout.width(11);
|
||||||
fout.precision(prec);
|
fout.setf(ios::fixed);
|
||||||
|
fout.precision(neededPrec);
|
||||||
if ((fParam[number].fNoOfParams == 5) || (fParam[number].fNoOfParams == 7)) // pos. error given
|
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
|
if (fParam[number].fPosErrorPresent && (fParam[number].fStep != 0)) // pos error is a number
|
||||||
fout << left << fParam[number].fPosError;
|
fout << left << fParam[number].fPosError;
|
||||||
@ -515,6 +527,7 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
|||||||
else // no pos. error
|
else // no pos. error
|
||||||
fout << left << "none";
|
fout << left << "none";
|
||||||
fout << " ";
|
fout << " ";
|
||||||
|
fout.unsetf(ios::floatfield);
|
||||||
// boundaries
|
// boundaries
|
||||||
if (fParam[number].fNoOfParams > 5) {
|
if (fParam[number].fNoOfParams > 5) {
|
||||||
fout.width(7);
|
fout.width(7);
|
||||||
@ -836,7 +849,7 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
|||||||
if (fRuns[runNo].GetFitRange(j) == -1)
|
if (fRuns[runNo].GetFitRange(j) == -1)
|
||||||
break;
|
break;
|
||||||
fout.width(8);
|
fout.width(8);
|
||||||
fout.precision(NeededPrecision(fRuns[runNo].GetFitRange(j)));
|
fout.precision(NeededPrecision(fRuns[runNo].GetFitRange(j), 6));
|
||||||
fout << left << fixed << fRuns[runNo].GetFitRange(j);
|
fout << left << fixed << fRuns[runNo].GetFitRange(j);
|
||||||
if (j==0)
|
if (j==0)
|
||||||
fout << " ";
|
fout << " ";
|
||||||
@ -943,16 +956,16 @@ 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]));
|
fout.precision(NeededPrecision(fPlots[plotNo].fTmin[0], 6));
|
||||||
fout << fPlots[plotNo].fTmin[0];
|
fout << fPlots[plotNo].fTmin[0];
|
||||||
fout << " ";
|
fout << " ";
|
||||||
fout.precision(NeededPrecision(fPlots[plotNo].fTmax[0]));
|
fout.precision(NeededPrecision(fPlots[plotNo].fTmax[0], 6));
|
||||||
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]));
|
fout.precision(NeededPrecision(fPlots[plotNo].fYmin[0], 6));
|
||||||
fout << fPlots[plotNo].fYmin[0] << " ";
|
fout << fPlots[plotNo].fYmin[0] << " ";
|
||||||
fout.precision(NeededPrecision(fPlots[plotNo].fYmax[0]));
|
fout.precision(NeededPrecision(fPlots[plotNo].fYmax[0], 6));
|
||||||
fout << fPlots[plotNo].fYmax[0];
|
fout << fPlots[plotNo].fYmax[0];
|
||||||
}
|
}
|
||||||
fout << endl;
|
fout << endl;
|
||||||
@ -1528,7 +1541,7 @@ 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)));
|
fout.precision(NeededPrecision(fRuns[i].GetFitRange(j), 6));
|
||||||
fout << left << fixed << fRuns[i].GetFitRange(j);
|
fout << left << fixed << fRuns[i].GetFitRange(j);
|
||||||
}
|
}
|
||||||
fout << endl;
|
fout << endl;
|
||||||
@ -4677,35 +4690,30 @@ void PMsrHandler::CheckMaxLikelihood()
|
|||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>Calculates the needed precision of Double_t values for WriteMsrLogFile and WriteMsrFile of the fit range.
|
* <p>Calculates the needed precision of Double_t values for WriteMsrLogFile and WriteMsrFile of the fit range.
|
||||||
* If a precision of > 6 decimal places is needed, a warning is placed and a value of 6 is returned.
|
* If a precision of > precLimit decimal places is needed, a warning is placed and a value of precLimit is returned.
|
||||||
*
|
*
|
||||||
* \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
|
||||||
*
|
*
|
||||||
* <b>return:</b>
|
* <b>return:</b>
|
||||||
* needed precision fo the fit-range
|
* needed precision fo the fit-range
|
||||||
*/
|
*/
|
||||||
UInt_t PMsrHandler::NeededPrecision(Double_t dval)
|
UInt_t PMsrHandler::NeededPrecision(Double_t dval, UInt_t precLimit)
|
||||||
{
|
{
|
||||||
UInt_t prec=0;
|
UInt_t prec=0;
|
||||||
|
|
||||||
Int_t ival = static_cast<Int_t>(round(dval*1.0e6));
|
if (dval == 0.0)
|
||||||
|
return prec;
|
||||||
|
|
||||||
if ((ival % 10) != 0)
|
for (UInt_t i=0; i<precLimit; i++) {
|
||||||
prec = 6;
|
if ((Int_t)(dval*pow(10.0,(Double_t)i)) != 0) {
|
||||||
else if ((ival % 100) != 0)
|
prec = i;
|
||||||
prec = 5;
|
break;
|
||||||
else if ((ival % 1000) != 0)
|
}
|
||||||
prec = 4;
|
}
|
||||||
else if ((ival % 10000) != 0)
|
|
||||||
prec = 3;
|
if (prec == precLimit) {
|
||||||
else if ((ival % 100000) != 0)
|
cerr << endl << ">> PMsrHandler::NeededPrecision(): **WARNING** precision limit of " << precLimit << ", requested.";
|
||||||
prec = 2;
|
|
||||||
else if ((ival % 1000000) != 0)
|
|
||||||
prec = 1;
|
|
||||||
else if (static_cast<Double_t>(ival)-dval*1.0e6 > 0.1) {
|
|
||||||
prec = 4;
|
|
||||||
cerr << endl << ">> PMsrHandler::NeededPrecision(): **WARNING** fit range value = " << dval << ", is asking for a rediculous resolution.";
|
|
||||||
cerr << endl << ">> Will limit the precision to 6 decimal places, only." << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return prec;
|
return prec;
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* Copyright (C) 2007-2010 by Andreas Suter *
|
* Copyright (C) 2007-2011 by Andreas Suter *
|
||||||
* andreas.suter@psi.c *
|
* andreas.suter@psi.ch *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
@ -140,7 +140,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);
|
virtual UInt_t NeededPrecision(Double_t dval, UInt_t precLimit=13);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PMSRHANDLER_H_
|
#endif // _PMSRHANDLER_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user