add N0 estimate to single histogram fit. Some improvements in musredit (see ChangLog)
This commit is contained in:
@@ -52,9 +52,9 @@ using namespace std;
|
||||
*
|
||||
* \param fileName name of a msr-file.
|
||||
*/
|
||||
PMsrHandler::PMsrHandler(const Char_t *fileName, const Bool_t writeExpectedChisq) :
|
||||
fWriteExpectedChisq(writeExpectedChisq), fFileName(fileName)
|
||||
{
|
||||
PMsrHandler::PMsrHandler(const Char_t *fileName, PStartupOptions *startupOptions) :
|
||||
fStartupOptions(startupOptions), fFileName(fileName)
|
||||
{
|
||||
// init variables
|
||||
fMsrBlockCounter = 0;
|
||||
|
||||
@@ -1056,8 +1056,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fMinExpected != 0.0) {
|
||||
str.Form(" expected chisq = %.1lf, NDF = %d, expected chisq/NDF = %lf",
|
||||
fStatistic.fMinExpected, fStatistic.fNdf, fStatistic.fMinExpected/fStatistic.fNdf);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
if (messages)
|
||||
cout << endl << str.Data() << endl;
|
||||
|
||||
@@ -1065,8 +1067,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fNdfPerHisto[i] > 0) {
|
||||
str.Form(" run block %d: (NDF/red.chisq/red.chisq_e) = (%d/%lf/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i], fStatistic.fMinExpectedPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1076,8 +1080,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
for (UInt_t i=0; i<fStatistic.fNdfPerHisto.size(); i++) {
|
||||
str.Form(" run block %d: (NDF/red.chisq) = (%d/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1107,8 +1113,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fMinExpected != 0.0) {
|
||||
str.Form(" expected chisq = %.1lf, NDF = %d, expected chisq/NDF = %lf",
|
||||
fStatistic.fMinExpected, fStatistic.fNdf, fStatistic.fMinExpected/fStatistic.fNdf);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
|
||||
@@ -1116,8 +1124,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fNdfPerHisto[i] > 0) {
|
||||
str.Form(" run block %d: (NDF/red.chisq/red.chisq_e) = (%d/%lf/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i], fStatistic.fMinExpectedPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1127,8 +1137,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
for (UInt_t i=0; i<fStatistic.fNdfPerHisto.size(); i++) {
|
||||
str.Form(" run block %d: (NDF/red.chisq) = (%d/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1180,8 +1192,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fMinExpected != 0.0) {
|
||||
str.Form(" expected chisq = %.1lf, NDF = %d, expected chisq/NDF = %lf",
|
||||
fStatistic.fMinExpected, fStatistic.fNdf, fStatistic.fMinExpected/fStatistic.fNdf);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
|
||||
@@ -1189,8 +1203,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fNdfPerHisto[i] > 0) {
|
||||
str.Form(" run block %d: (NDF/red.chisq/red.chisq_e) = (%d/%lf/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i], fStatistic.fMinExpectedPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1200,8 +1216,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
for (UInt_t i=0; i<fStatistic.fNdfPerHisto.size(); i++) {
|
||||
str.Form(" run block %d: (NDF/red.chisq) = (%d/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1237,8 +1255,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fMinExpected != 0.0) {
|
||||
str.Form(" expected chisq = %.1lf, NDF = %d, expected chisq/NDF = %lf",
|
||||
fStatistic.fMinExpected, fStatistic.fNdf, fStatistic.fMinExpected/fStatistic.fNdf);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
|
||||
@@ -1246,8 +1266,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
if (fStatistic.fNdfPerHisto[i] > 0) {
|
||||
str.Form(" run block %d: (NDF/red.chisq/red.chisq_e) =(%d/%lf/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinExpectedPerHisto[i]/fStatistic.fNdfPerHisto[i], fStatistic.fMinExpectedPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -1257,8 +1279,10 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages)
|
||||
for (UInt_t i=0; i<fStatistic.fNdfPerHisto.size(); i++) {
|
||||
str.Form(" run block %d: (NDF/red.chisq) = (%d/%lf)",
|
||||
i+1, fStatistic.fNdfPerHisto[i], fStatistic.fMinPerHisto[i]/fStatistic.fNdfPerHisto[i]);
|
||||
if (fWriteExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
if (fStartupOptions) {
|
||||
if (fStartupOptions->writeExpectedChisq)
|
||||
fout << str.Data() << endl;
|
||||
}
|
||||
|
||||
if (messages)
|
||||
cout << str.Data() << endl;
|
||||
@@ -5127,6 +5151,34 @@ void PMsrHandler::GetGroupingString(Int_t runNo, TString detector, TString &grou
|
||||
grouping.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// EstimateN0 (public)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>returns if N0 shall be estimated
|
||||
*/
|
||||
Bool_t PMsrHandler::EstimateN0()
|
||||
{
|
||||
if (fStartupOptions == 0)
|
||||
return true;
|
||||
|
||||
return fStartupOptions->estimateN0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// GetAlphaEstimateN0 (public)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>returns alpha to estimate N0
|
||||
*/
|
||||
Double_t PMsrHandler::GetAlphaEstimateN0()
|
||||
{
|
||||
if (fStartupOptions == 0)
|
||||
return 0.0;
|
||||
|
||||
return fStartupOptions->alphaEstimateN0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// NeededPrecision (private)
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <omp.h>
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
using namespace std;
|
||||
@@ -810,6 +811,10 @@ Bool_t PRunSingleHisto::PrepareData()
|
||||
*/
|
||||
Bool_t PRunSingleHisto::PrepareFitData(PRawRunData* runData, const UInt_t histoNo)
|
||||
{
|
||||
if (fMsrInfo->EstimateN0()) {
|
||||
EstimateN0();
|
||||
}
|
||||
|
||||
// transform raw histo data. This is done the following way (for details see the manual):
|
||||
// for the single histo fit, just the rebinned raw data are copied
|
||||
|
||||
@@ -1398,6 +1403,68 @@ Bool_t PRunSingleHisto::PrepareViewData(PRawRunData* runData, const UInt_t histo
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// EstimateN0 (private)
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>Estimate the N0 for the given run.
|
||||
*/
|
||||
void PRunSingleHisto::EstimateN0()
|
||||
{
|
||||
// check that 'norm' in the msr-file run block is indeed a parameter number.
|
||||
// in case it is a function, nothing will be done.
|
||||
UInt_t paramNo = fRunInfo->GetNormParamNo();
|
||||
if (paramNo > 10000) // i.e. fun or map
|
||||
return;
|
||||
|
||||
// still missing: set this value in the parameters
|
||||
PMsrParamList *param = fMsrInfo->GetMsrParamList();
|
||||
assert(param);
|
||||
|
||||
if (paramNo > param->size()) {
|
||||
cerr << endl << ">> PRunSingleHisto::EstimateN0: **ERROR** found parameter number " << paramNo << ", which is larger than the number of parameters = " << param->size() << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// estimate N0
|
||||
Double_t dt = fTimeResolution;
|
||||
Double_t tau = PMUON_LIFETIME;
|
||||
|
||||
UInt_t t0 = (UInt_t)round(fT0s[0]);
|
||||
Double_t alpha = fMsrInfo->GetAlphaEstimateN0();
|
||||
Double_t dval = 0.0;
|
||||
Double_t nom = 0.0;
|
||||
Double_t denom = 0.0;
|
||||
Double_t xx = 0.0;
|
||||
|
||||
// calc nominator
|
||||
for (UInt_t i=t0; i<fForward.size(); i++) {
|
||||
xx = exp(-dt*(Double_t)(i-t0)/tau);
|
||||
xx += alpha;
|
||||
nom += xx;
|
||||
}
|
||||
|
||||
// calc: denominator
|
||||
for (UInt_t i=t0; i<fForward.size(); i++) {
|
||||
xx = exp(-dt*(Double_t)(i-t0)/tau);
|
||||
xx += alpha;
|
||||
dval = fForward[i];
|
||||
if (dval > 0)
|
||||
denom += xx*xx/dval;
|
||||
}
|
||||
Double_t N0 = nom/denom;
|
||||
|
||||
if (fScaleN0AndBkg) {
|
||||
N0 /= fTimeResolution*1.0e3;
|
||||
} else {
|
||||
N0 *= fRunInfo->GetPacking();
|
||||
}
|
||||
|
||||
cout << ">> PRunSingleHisto::EstimateN0: found N0=" << param->at(paramNo-1).fValue << ", will set it to N0=" << N0 << endl;
|
||||
fMsrInfo->SetMsrParamValue(paramNo-1, N0);
|
||||
fMsrInfo->SetMsrParamStep(paramNo-1, sqrt(fabs(N0)));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// EstimatBkg (private)
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -166,7 +166,9 @@ void PStartupHandler::OnStartDocument()
|
||||
fFourierDefaults.fPlotRange[1] = -1.0;
|
||||
fFourierDefaults.fPhaseIncrement = 1.0;
|
||||
|
||||
fWritePerRunBlockChisq = false;
|
||||
fStartupOptions.writeExpectedChisq = false;
|
||||
fStartupOptions.estimateN0 = true;
|
||||
fStartupOptions.alphaEstimateN0 = 0.0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -197,6 +199,10 @@ void PStartupHandler::OnStartElement(const Char_t *str, const TList *attributes)
|
||||
fKey = eDataPath;
|
||||
} else if (!strcmp(str, "write_per_run_block_chisq")) {
|
||||
fKey = eWritePerRunBlockChisq;
|
||||
} else if (!strcmp(str, "estimate_n0")) {
|
||||
fKey = eEstimateN0;
|
||||
} else if (!strcmp(str, "alpha_estimate_n0")) {
|
||||
fKey = eAlphaEstimateN0;
|
||||
} else if (!strcmp(str, "marker")) {
|
||||
fKey = eMarker;
|
||||
} else if (!strcmp(str, "color")) {
|
||||
@@ -254,7 +260,17 @@ void PStartupHandler::OnCharacters(const Char_t *str)
|
||||
case eWritePerRunBlockChisq:
|
||||
tstr = TString(str);
|
||||
if (tstr.BeginsWith("y") || tstr.BeginsWith("Y"))
|
||||
fWritePerRunBlockChisq = true;
|
||||
fStartupOptions.writeExpectedChisq = true;
|
||||
break;
|
||||
case eEstimateN0:
|
||||
tstr = TString(str);
|
||||
if (tstr.BeginsWith("n") || tstr.BeginsWith("N"))
|
||||
fStartupOptions.estimateN0 = false;
|
||||
break;
|
||||
case eAlphaEstimateN0:
|
||||
tstr = TString(str);
|
||||
if (tstr.IsFloat())
|
||||
fStartupOptions.alphaEstimateN0 = tstr.Atof();
|
||||
break;
|
||||
case eMarker:
|
||||
// check that str is a number
|
||||
|
||||
Reference in New Issue
Block a user