From 379345496b261241e58323809c4800e30027017b Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Tue, 15 Nov 2011 08:46:00 +0000 Subject: [PATCH] if the background is estimated from an interval rather than fitted, it will be added as a comment to the background interval tag. (MUSR-192) --- ChangeLog | 2 ++ src/classes/PMsrHandler.cpp | 23 ++++++++++++++++- src/classes/PMusr.cpp | 46 ++++++++++++++++++++++++++++++++- src/classes/PRunAsymmetry.cpp | 3 +++ src/classes/PRunSingleHisto.cpp | 2 +- src/include/PMusr.h | 5 +++- 6 files changed, 77 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e356aaa..2e9a622d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ changes since 0.9.0 =================================== +NEW if the background is estimated form an interval rather than fitted, it will be added as a comment + to the background interval tag. (MUSR-192). NEW forward/backward accept now not only c0 c1 c2 ... cn, but also c0-cn cm-cp, or c0 c1-cn cm cx-cy, etc. (MUSR-201, improvement whish). NEW added minimal NeXus IDF 2 support. NEW Added the online documentation to the repository. It can be found under "doc/html". diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index 3cb3fa63..5ac78a28 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -746,6 +746,21 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) fout << left << fRuns[runNo].GetBkgRange(j); } } + if (fRuns[runNo].GetBkgEstimated(0) != PMUSR_UNDEFINED) { + Int_t precision=4; + if ((Int_t)log10(fRuns[runNo].GetBkgEstimated(0))+1 >= 4) + precision = 2; + fout << " # estimated bkg: "; + fout << fixed; + fout.precision(precision); + fout << fRuns[runNo].GetBkgEstimated(0); + if (fRuns[runNo].GetBkgEstimated(1) != PMUSR_UNDEFINED) { + fout << " / "; + fout << fixed; + fout.precision(precision); + fout << fRuns[runNo].GetBkgEstimated(1); + } + } fout << endl; } else if (sstr.BeginsWith("data")) { dataTagMissing[runNo] = false; @@ -2465,8 +2480,14 @@ Bool_t PMsrHandler::HandleRunEntry(PMsrLines &lines) iter = lines.begin(); while ((iter != lines.end()) && !error) { + // remove potential comment at the end of lines + str = iter->fLine; + Ssiz_t idx = str.Index("#"); + if (idx != -1) + str.Remove(idx); + // tokenize line - tokens = iter->fLine.Tokenize(" \t"); + tokens = str.Tokenize(" \t"); if (!tokens) { cerr << endl << ">> PMsrHandler::HandleRunEntry: **SEVERE ERROR** Couldn't tokenize Parameters in line " << iter->fLineNo; cerr << endl << endl; diff --git a/src/classes/PMusr.cpp b/src/classes/PMusr.cpp index fe58b9d5..58ecda97 100644 --- a/src/classes/PMusr.cpp +++ b/src/classes/PMusr.cpp @@ -577,8 +577,10 @@ PMsrRunBlock::PMsrRunBlock() fBkgFitParamNo = -1; // undefined background parameter number fLifetimeParamNo = -1; // undefined lifetime parameter number fLifetimeCorrection = false; // lifetime correction == false by default (used in single histogram musrview) - for (UInt_t i=0; i<2; i++) + for (UInt_t i=0; i<2; i++) { + fBkgEstimated[i] = PMUSR_UNDEFINED; fBkgFix[i] = PMUSR_UNDEFINED; + } for (UInt_t i=0; i<4; i++) { fBkgRange[i] = -1; // undefined start background range fDataRange[i] = -1; // undefined start data range @@ -955,6 +957,48 @@ void PMsrRunBlock::SetMap(Int_t mapVal, Int_t idx) fMap[idx] = mapVal; } +//-------------------------------------------------------------------------- +// GetBkgEstimated +//-------------------------------------------------------------------------- +/** + *

get estimated background value at position idx. If not present, + * PMUSR_UNDEFINED is returned. + * + * return: + * - estimated background value, if idx is within proper boundaries + * - PMUSR_UNDEFINED, otherwise + * + * \param idx index of the estimated background value to be returned + */ +Double_t PMsrRunBlock::GetBkgEstimated(UInt_t idx) +{ + if (idx >= 2) + return PMUSR_UNDEFINED; + + return fBkgEstimated[idx]; +} + + +//-------------------------------------------------------------------------- +// SetBkgEstimated +//-------------------------------------------------------------------------- +/** + *

set estimated background value at position idx + * + * \param dval estimated background value + * \param idx index of the estimated background value to be set. + */ +void PMsrRunBlock::SetBkgEstimated(Double_t dval, Int_t idx) +{ + if (idx >= 2) { + cerr << endl << ">> PMsrRunBlock::SetBkgEstimated: **WARNING** idx=" << idx << ", only idx=0,1 are sensible."; + cerr << endl; + return; + } + + fBkgEstimated[idx] = dval; +} + //-------------------------------------------------------------------------- // GetBkgFix //-------------------------------------------------------------------------- diff --git a/src/classes/PRunAsymmetry.cpp b/src/classes/PRunAsymmetry.cpp index 02f9eb45..6db0d6bb 100644 --- a/src/classes/PRunAsymmetry.cpp +++ b/src/classes/PRunAsymmetry.cpp @@ -820,6 +820,9 @@ Bool_t PRunAsymmetry::SubtractEstimatedBkg() fBackward[i] -= bkg[1]; } + fRunInfo->SetBkgEstimated(bkg[0], 0); + fRunInfo->SetBkgEstimated(bkg[1], 1); + return true; } diff --git a/src/classes/PRunSingleHisto.cpp b/src/classes/PRunSingleHisto.cpp index a0f98be4..335e0530 100644 --- a/src/classes/PRunSingleHisto.cpp +++ b/src/classes/PRunSingleHisto.cpp @@ -1358,7 +1358,7 @@ Bool_t PRunSingleHisto::EstimateBkg(UInt_t histoNo) else fBackground = bkg * fRunInfo->GetPacking(); // keep background (per bin) - cout << endl << ">> fRunInfo->fRunName=" << fRunInfo->GetRunName()->Data() << ", histNo=" << histoNo << ", fBackground=" << fBackground; + fRunInfo->SetBkgEstimated(fBackground, 0); return true; } diff --git a/src/include/PMusr.h b/src/include/PMusr.h index 5f62216f..6d9bbd0c 100644 --- a/src/include/PMusr.h +++ b/src/include/PMusr.h @@ -441,6 +441,7 @@ class PMsrRunBlock { virtual Int_t GetForwardHistoNo(UInt_t idx=0); virtual UInt_t GetBackwardHistoNoSize() { return fBackwardHistoNo.size(); } virtual Int_t GetBackwardHistoNo(UInt_t idx=0); + virtual Double_t GetBkgEstimated(UInt_t idx); virtual Double_t GetBkgFix(UInt_t idx); virtual Int_t GetBkgRange(UInt_t idx); virtual Int_t GetDataRange(UInt_t idx); @@ -472,7 +473,8 @@ class PMsrRunBlock { virtual void SetMap(Int_t mapVal, Int_t idx=-1); virtual void SetForwardHistoNo(Int_t histoNo, Int_t idx=-1); virtual void SetBackwardHistoNo(Int_t histoNo, Int_t idx=-1); - virtual void SetBkgFix(Double_t dval, Int_t idx=-1); + virtual void SetBkgEstimated(Double_t dval, Int_t idx); + virtual void SetBkgFix(Double_t dval, Int_t idx); virtual void SetBkgRange(Int_t ival, Int_t idx); virtual void SetDataRange(Int_t ival, Int_t idx); virtual void SetT0(Int_t ival, Int_t idx=-1); @@ -501,6 +503,7 @@ class PMsrRunBlock { PIntVector fMap; ///< map vector needed to switch parameters for different runs within a single theory PIntVector fForwardHistoNo; ///< forward histogram number (fit type 0, 2, 4) PIntVector fBackwardHistoNo; ///< backward histogram number (fit type 2, 4) + Double_t fBkgEstimated[2]; ///< keeps estimated background values (if present) Double_t fBkgFix[2]; ///< fixed background in (1/ns) (fit type 0, 2, 4) Int_t fBkgRange[4]; ///< background bin range (fit type 0, 2, 4) Int_t fDataRange[4]; ///< data bin range (fit type 0, 2, 4)