added the command SCALE_N0_BKG TRUE | FALSE to the command-block. This can be used to force a single histogram fit to use either 1/ns scaling for N0 and background or 1/bins one.

This commit is contained in:
nemu 2011-02-14 19:52:00 +00:00
parent 8369690dc3
commit ccd9d6ccfd
6 changed files with 144 additions and 22 deletions

View File

@ -6,6 +6,8 @@
changes since 0.8.0 changes since 0.8.0
=================================== ===================================
NEW added the command SCALE_N0_BKG TRUE | FALSE to the command-block. This can be used to force a single histogram fit
to use either 1/ns scaling for N0 and background or 1/bins one.
NEW any2many: some more work, including the PSI-BIN write routines which are officially not released yet. NEW any2many: some more work, including the PSI-BIN write routines which are officially not released yet.
NEW extended global mode in msr2data NEW extended global mode in msr2data
NEW any2many: an attempt to write the universial musr-data-file converter. Just started, needs still some work. NEW any2many: an attempt to write the universial musr-data-file converter. Just started, needs still some work.

View File

@ -304,6 +304,8 @@ Bool_t PFitter::CheckCommands()
continue; continue;
} else if (it->fLine.Contains("MAX_LIKELIHOOD", TString::kIgnoreCase)) { } else if (it->fLine.Contains("MAX_LIKELIHOOD", TString::kIgnoreCase)) {
continue; continue;
} else if (it->fLine.Contains("SCALE_N0_BKG", TString::kIgnoreCase)) {
continue;
} else if (it->fLine.Contains("INTERACTIVE", TString::kIgnoreCase)) { } else if (it->fLine.Contains("INTERACTIVE", TString::kIgnoreCase)) {
cmd.first = PMN_INTERACTIVE; cmd.first = PMN_INTERACTIVE;
cmd.second = cmdLineNo; cmd.second = cmdLineNo;

View File

@ -115,6 +115,7 @@ ClassImpQ(PMusrCanvas)
*/ */
PMusrCanvas::PMusrCanvas() PMusrCanvas::PMusrCanvas()
{ {
fScaleN0AndBkg = true;
fValid = false; fValid = false;
fDifferenceView = false; fDifferenceView = false;
fCurrentPlotView = PV_DATA; fCurrentPlotView = PV_DATA;
@ -344,6 +345,8 @@ void PMusrCanvas::SetMsrHandler(PMsrHandler *msrHandler)
{ {
fMsrHandler = msrHandler; fMsrHandler = msrHandler;
fScaleN0AndBkg = IsScaleN0AndBkg();
// check if a fourier block is present in the msr-file, and if yes extract the given values // check if a fourier block is present in the msr-file, and if yes extract the given values
if (fMsrHandler->GetMsrFourierList()->fFourierBlockPresent) { if (fMsrHandler->GetMsrFourierList()->fFourierBlockPresent) {
fFourier.fFourierBlockPresent = true; fFourier.fFourierBlockPresent = true;
@ -1298,6 +1301,7 @@ void PMusrCanvas::InitFourier()
*/ */
void PMusrCanvas::InitMusrCanvas(const Char_t* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh) void PMusrCanvas::InitMusrCanvas(const Char_t* title, Int_t wtopx, Int_t wtopy, Int_t ww, Int_t wh)
{ {
fScaleN0AndBkg = true;
fValid = false; fValid = false;
fDifferenceView = false; fDifferenceView = false;
fCurrentPlotView = PV_DATA; fCurrentPlotView = PV_DATA;
@ -3027,7 +3031,10 @@ void PMusrCanvas::PlotData(Bool_t unzoom)
if (runList->at(0).IsLifetimeCorrected()) { // lifetime correction if (runList->at(0).IsLifetimeCorrected()) { // lifetime correction
yAxisTitle = "asymmetry"; yAxisTitle = "asymmetry";
} else { // no liftime correction } else { // no liftime correction
if (fScaleN0AndBkg)
yAxisTitle = "N(t) per nsec"; yAxisTitle = "N(t) per nsec";
else
yAxisTitle = "N(t) per bin";
} }
break; break;
case MSR_PLOT_ASYM: case MSR_PLOT_ASYM:
@ -5165,3 +5172,46 @@ void PMusrCanvas::SaveDataAscii()
cout << endl << ">> Data windows saved in ascii format ..." << endl; cout << endl << ">> Data windows saved in ascii format ..." << endl;
} }
//--------------------------------------------------------------------------
// IsScaleN0AndBkg (private)
//--------------------------------------------------------------------------
/**
* <p>Checks if N0/Bkg normalization to 1/ns is whished. The default is yes, since most of the users want to have it that way.
* To overwrite this, one should add the line 'SCALE_N0_BKG FALSE' to the command block of the msr-file.
*
* <b>return:</b>
* - true, if scaling of N0 and Bkg to 1/ns is whished
* - false, otherwise
*
* \param histoNo forward histogram number of the run
*/
Bool_t PMusrCanvas::IsScaleN0AndBkg()
{
Bool_t willScale = true;
PMsrLines *cmd = fMsrHandler->GetMsrCommands();
for (UInt_t i=0; i<cmd->size(); i++) {
if (cmd->at(i).fLine.Contains("SCALE_N0_BKG", TString::kIgnoreCase)) {
TObjArray *tokens = 0;
TObjString *ostr = 0;
TString str;
tokens = cmd->at(i).fLine.Tokenize(" \t");
if (tokens->GetEntries() != 2) {
cerr << endl << ">> PRunSingleHisto::IsScaleN0AndBkg(): **WARNING** Found uncorrect 'SCALE_N0_BKG' command, will ignore it.";
cerr << endl << ">> Allowed commands: SCALE_N0_BKG TRUE | FALSE" << endl;
return willScale;
}
ostr = dynamic_cast<TObjString*>(tokens->At(1));
str = ostr->GetString();
if (!str.CompareTo("FALSE", TString::kIgnoreCase)) {
willScale = false;
}
// clean up
if (tokens)
delete tokens;
}
}
return willScale;
}

View File

@ -33,6 +33,10 @@
#include <fstream> #include <fstream>
using namespace std; using namespace std;
#include <TString.h>
#include <TObjArray.h>
#include <TObjString.h>
#include "PMusr.h" #include "PMusr.h"
#include "PRunSingleHisto.h" #include "PRunSingleHisto.h"
@ -44,6 +48,7 @@ using namespace std;
*/ */
PRunSingleHisto::PRunSingleHisto() : PRunBase() PRunSingleHisto::PRunSingleHisto() : PRunBase()
{ {
fScaleN0AndBkg = true;
fNoOfFitBins = 0; fNoOfFitBins = 0;
} }
@ -60,6 +65,8 @@ PRunSingleHisto::PRunSingleHisto() : PRunBase()
*/ */
PRunSingleHisto::PRunSingleHisto(PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag) : PRunBase(msrInfo, rawData, runNo, tag) PRunSingleHisto::PRunSingleHisto(PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag) : PRunBase(msrInfo, rawData, runNo, tag)
{ {
fScaleN0AndBkg = IsScaleN0AndBkg();
if (!PrepareData()) { if (!PrepareData()) {
cerr << endl << ">> PRunSingleHisto::PRunSingleHisto: **SEVERE ERROR**: Couldn't prepare data for fitting!"; cerr << endl << ">> PRunSingleHisto::PRunSingleHisto: **SEVERE ERROR**: Couldn't prepare data for fitting!";
cerr << endl << ">> This is very bad :-(, will quit ..."; cerr << endl << ">> This is very bad :-(, will quit ...";
@ -79,7 +86,7 @@ PRunSingleHisto::~PRunSingleHisto()
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// CalcChiSquare // CalcChiSquare (public)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Calculate chi-square. * <p>Calculate chi-square.
@ -94,7 +101,7 @@ Double_t PRunSingleHisto::CalcChiSquare(const std::vector<Double_t>& par)
Double_t chisq = 0.0; Double_t chisq = 0.0;
Double_t diff = 0.0; Double_t diff = 0.0;
Double_t N0; Double_t N0 = 0.0;
// check if norm is a parameter or a function // check if norm is a parameter or a function
if (fRunInfo->GetNormParamNo() < MSR_PARAM_FUN_OFFSET) { // norm is a parameter if (fRunInfo->GetNormParamNo() < MSR_PARAM_FUN_OFFSET) { // norm is a parameter
@ -144,11 +151,14 @@ Double_t PRunSingleHisto::CalcChiSquare(const std::vector<Double_t>& par)
// the correction factor is need since the data scales like pack*t_res, // the correction factor is need since the data scales like pack*t_res,
// whereas the error scales like sqrt(pack*t_res) // whereas the error scales like sqrt(pack*t_res)
return chisq * fRunInfo->GetPacking() * (fTimeResolution * 1.0e3); if (fScaleN0AndBkg)
chisq *= fRunInfo->GetPacking() * (fTimeResolution * 1.0e3);
return chisq;
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// CalcMaxLikelihood // CalcMaxLikelihood (public)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Calculate log maximum-likelihood. * <p>Calculate log maximum-likelihood.
@ -204,7 +214,9 @@ Double_t PRunSingleHisto::CalcMaxLikelihood(const std::vector<Double_t>& par)
Double_t data; Double_t data;
Double_t time; Double_t time;
// norm is needed since there is no simple scaling like in chisq case to get the correct Max.Log.Likelihood value when normlizing N(t) to 1/ns // norm is needed since there is no simple scaling like in chisq case to get the correct Max.Log.Likelihood value when normlizing N(t) to 1/ns
Double_t normalizer = fRunInfo->GetPacking() * (fTimeResolution * 1.0e3); Double_t normalizer = 1.0;
if (fScaleN0AndBkg)
normalizer = fRunInfo->GetPacking() * (fTimeResolution * 1.0e3);
for (UInt_t i=0; i<fData.GetValue()->size(); i++) { for (UInt_t i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (Double_t)i*fData.GetDataTimeStep(); time = fData.GetDataTimeStart() + (Double_t)i*fData.GetDataTimeStep();
if ((time>=fFitStartTime) && (time<=fFitEndTime)) { if ((time>=fFitStartTime) && (time<=fFitEndTime)) {
@ -225,7 +237,7 @@ Double_t PRunSingleHisto::CalcMaxLikelihood(const std::vector<Double_t>& par)
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// CalcTheory // CalcTheory (public)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Calculate theory for a given set of fit-parameters. * <p>Calculate theory for a given set of fit-parameters.
@ -310,7 +322,7 @@ UInt_t PRunSingleHisto::GetNoOfFitBins()
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// PrepareData // PrepareData (private)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Prepare data for fitting or viewing. What is already processed at this stage: * <p>Prepare data for fitting or viewing. What is already processed at this stage:
@ -501,7 +513,7 @@ Bool_t PRunSingleHisto::PrepareData()
// keep the time resolution in (us) // keep the time resolution in (us)
fTimeResolution = runData->GetTimeResolution()/1.0e3; fTimeResolution = runData->GetTimeResolution()/1.0e3;
cout.precision(8); cout.precision(8);
cout << endl << ">> PRunSingleHisto::PrepareData(): time resolution=" << fixed << runData->GetTimeResolution() << "(ns)" << endl; cout << endl << ">> PRunSingleHisto::PrepareData(): time resolution=" << fixed << runData->GetTimeResolution() << "(ns)";
if (fHandleTag == kFit) if (fHandleTag == kFit)
success = PrepareFitData(runData, histoNo[0]); success = PrepareFitData(runData, histoNo[0]);
@ -519,7 +531,7 @@ Bool_t PRunSingleHisto::PrepareData()
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// PrepareFitData // PrepareFitData (private)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for fitting. * <p>Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for fitting.
@ -607,9 +619,11 @@ Bool_t PRunSingleHisto::PrepareFitData(PRawRunData* runData, const UInt_t histoN
// everything looks fine, hence fill data set // everything looks fine, hence fill data set
Int_t t0 = fT0s[0]; Int_t t0 = fT0s[0];
Double_t value = 0.0; Double_t value = 0.0;
Double_t normalizer = 1.0;
// in order that after rebinning the fit does not need to be redone (important for plots) // in order that after rebinning the fit does not need to be redone (important for plots)
// the value is normalize to per 1 nsec // the value is normalize to per 1 nsec if scaling is whished
Double_t normalizer = fRunInfo->GetPacking() * (fTimeResolution * 1.0e3); // fTimeResolution us->ns if (fScaleN0AndBkg)
normalizer = fRunInfo->GetPacking() * (fTimeResolution * 1.0e3); // fTimeResolution us->ns
// data start at data_start-t0 // data start at data_start-t0
// time shifted so that packing is included correctly, i.e. t0 == t0 after packing // time shifted so that packing is included correctly, i.e. t0 == t0 after packing
fData.SetDataTimeStart(fTimeResolution*((Double_t)start-(Double_t)t0+(Double_t)(fRunInfo->GetPacking()-1)/2.0)); fData.SetDataTimeStart(fTimeResolution*((Double_t)start-(Double_t)t0+(Double_t)(fRunInfo->GetPacking()-1)/2.0));
@ -651,7 +665,7 @@ Bool_t PRunSingleHisto::PrepareFitData(PRawRunData* runData, const UInt_t histoN
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// PrepareRawViewData // PrepareRawViewData (private)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for viewing * <p>Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for viewing
@ -723,6 +737,7 @@ Bool_t PRunSingleHisto::PrepareRawViewData(PRawRunData* runData, const UInt_t hi
if (((i-start) % packing == 0) && (i != start)) { // fill data if (((i-start) % packing == 0) && (i != start)) { // fill data
// in order that after rebinning the fit does not need to be redone (important for plots) // in order that after rebinning the fit does not need to be redone (important for plots)
// the value is normalize to per 1 nsec // the value is normalize to per 1 nsec
if (fScaleN0AndBkg)
normalizer = packing * (fTimeResolution * 1e3); // fTimeResolution us->ns normalizer = packing * (fTimeResolution * 1e3); // fTimeResolution us->ns
value /= normalizer; value /= normalizer;
fData.AppendValue(value); fData.AppendValue(value);
@ -828,7 +843,7 @@ Bool_t PRunSingleHisto::PrepareRawViewData(PRawRunData* runData, const UInt_t hi
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// PrepareViewData // PrepareViewData (private)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for viewing * <p>Take the pre-processed data (i.e. grouping and addrun are preformed) and form the histogram for viewing
@ -975,6 +990,7 @@ Bool_t PRunSingleHisto::PrepareViewData(PRawRunData* runData, const UInt_t histo
if (((i-start) % packing == 0) && (i != start)) { // fill data if (((i-start) % packing == 0) && (i != start)) { // fill data
// in order that after rebinning the fit does not need to be redone (important for plots) // in order that after rebinning the fit does not need to be redone (important for plots)
// the value is normalize to per 1 nsec // the value is normalize to per 1 nsec
if (fScaleN0AndBkg)
normalizer = packing * (fTimeResolution * 1.0e3); // fTimeResolution us->ns normalizer = packing * (fTimeResolution * 1.0e3); // fTimeResolution us->ns
value /= normalizer; value /= normalizer;
time = (((Double_t)i-(Double_t)(packing-1)/2.0)-t0)*fTimeResolution; time = (((Double_t)i-(Double_t)(packing-1)/2.0)-t0)*fTimeResolution;
@ -1106,7 +1122,7 @@ Bool_t PRunSingleHisto::PrepareViewData(PRawRunData* runData, const UInt_t histo
} }
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
// EstimatBkg // EstimatBkg (private)
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/** /**
* <p>Estimate the background for a given interval. * <p>Estimate the background for a given interval.
@ -1179,11 +1195,58 @@ Bool_t PRunSingleHisto::EstimateBkg(UInt_t histoNo)
// forward // forward
for (UInt_t i=start; i<end; i++) for (UInt_t i=start; i<end; i++)
bkg += runData->GetDataBin(histoNo)->at(i); bkg += runData->GetDataBin(histoNo)->at(i);
cout << endl << "debug> bkg=" << bkg << ", end=" << end << ", start=" << start;
bkg /= static_cast<Double_t>(end - start + 1); bkg /= static_cast<Double_t>(end - start + 1);
if (fScaleN0AndBkg)
fBackground = bkg / (fTimeResolution * 1e3); // keep background (per 1 nsec) for chisq, max.log.likelihood, fTimeResolution us->ns fBackground = bkg / (fTimeResolution * 1e3); // keep background (per 1 nsec) for chisq, max.log.likelihood, fTimeResolution us->ns
else
fBackground = bkg * fRunInfo->GetPacking(); // keep background (per bin)
cout << endl << ">> fRunInfo->fRunName=" << fRunInfo->GetRunName()->Data() << ", histNo=" << histoNo << ", fBackground=" << fBackground; cout << endl << ">> fRunInfo->fRunName=" << fRunInfo->GetRunName()->Data() << ", histNo=" << histoNo << ", fBackground=" << fBackground;
return true; return true;
} }
//--------------------------------------------------------------------------
// IsScaleN0AndBkg (private)
//--------------------------------------------------------------------------
/**
* <p>Checks if N0/Bkg normalization to 1/ns is whished. The default is yes, since most of the users want to have it that way.
* To overwrite this, one should add the line 'SCALE_N0_BKG FALSE' to the command block of the msr-file.
*
* <b>return:</b>
* - true, if scaling of N0 and Bkg to 1/ns is whished
* - false, otherwise
*
* \param histoNo forward histogram number of the run
*/
Bool_t PRunSingleHisto::IsScaleN0AndBkg()
{
Bool_t willScale = true;
PMsrLines *cmd = fMsrInfo->GetMsrCommands();
for (UInt_t i=0; i<cmd->size(); i++) {
if (cmd->at(i).fLine.Contains("SCALE_N0_BKG", TString::kIgnoreCase)) {
TObjArray *tokens = 0;
TObjString *ostr = 0;
TString str;
tokens = cmd->at(i).fLine.Tokenize(" \t");
if (tokens->GetEntries() != 2) {
cerr << endl << ">> PRunSingleHisto::IsScaleN0AndBkg(): **WARNING** Found uncorrect 'SCALE_N0_BKG' command, will ignore it.";
cerr << endl << ">> Allowed commands: SCALE_N0_BKG TRUE | FALSE" << endl;
return willScale;
}
ostr = dynamic_cast<TObjString*>(tokens->At(1));
str = ostr->GetString();
if (!str.CompareTo("FALSE", TString::kIgnoreCase)) {
willScale = false;
}
// clean up
if (tokens)
delete tokens;
}
}
return willScale;
}

View File

@ -231,6 +231,7 @@ class PMusrCanvas : public TObject, public TQObject
virtual void SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat); virtual void SaveGraphicsAndQuit(Char_t *fileName, Char_t *graphicsFormat);
private: private:
Bool_t fScaleN0AndBkg; ///< true=N0 and background is scaled to (1/ns), otherwise (1/bin) for the single histogram case
Bool_t fBatchMode; ///< musrview in ROOT batch mode Bool_t fBatchMode; ///< musrview in ROOT batch mode
Bool_t fValid; ///< if true, everything looks OK Bool_t fValid; ///< if true, everything looks OK
Bool_t fDifferenceView; ///< tag showing that the shown data, fourier, are the difference between data and theory Bool_t fDifferenceView; ///< tag showing that the shown data, fourier, are the difference between data and theory
@ -318,6 +319,8 @@ class PMusrCanvas : public TObject, public TQObject
virtual void SaveDataAscii(); virtual void SaveDataAscii();
virtual Bool_t IsScaleN0AndBkg();
ClassDef(PMusrCanvas, 1) ClassDef(PMusrCanvas, 1)
}; };

View File

@ -57,10 +57,12 @@ class PRunSingleHisto : public PRunBase
virtual Bool_t PrepareViewData(PRawRunData* runData, const UInt_t histoNo); virtual Bool_t PrepareViewData(PRawRunData* runData, const UInt_t histoNo);
private: private:
Bool_t fScaleN0AndBkg; ///< true=scale N0 and background to 1/ns, otherwise 1/bin
UInt_t fNoOfFitBins; ///< number of bins to be fitted UInt_t fNoOfFitBins; ///< number of bins to be fitted
Double_t fBackground; ///< needed if background range is given (units: 1/bin) Double_t fBackground; ///< needed if background range is given (units: 1/bin)
Bool_t EstimateBkg(UInt_t histoNo); virtual Bool_t EstimateBkg(UInt_t histoNo);
virtual Bool_t IsScaleN0AndBkg();
}; };
#endif // _PRUNSINGLEHISTO_H_ #endif // _PRUNSINGLEHISTO_H_