47#include "PStringUtils.h"
121 std::cerr << std::endl <<
">> PRunSingleHisto::PRunSingleHisto: **SEVERE ERROR**: Couldn't find any packing information!";
122 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
123 std::cerr << std::endl;
137 std::cerr << std::endl <<
">> PRunSingleHisto::PRunSingleHisto: **SEVERE ERROR**: Couldn't prepare data for fitting!";
138 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
139 std::cerr << std::endl;
211 Double_t chisq = 0.0;
218 N0 = par[
fRunInfo->GetNormParamNo()-1];
228 if (
fRunInfo->GetLifetimeParamNo() != -1)
229 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
235 if (
fRunInfo->GetBkgFitParamNo() == -1) {
242 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
246 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
247 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
265 #pragma omp parallel for default(shared) private(i,time,diff) schedule(dynamic,chunk) reduction(+:chisq)
268 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
269 diff =
fData.GetValue()->at(i) -
271 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
326 Double_t chisq = 0.0;
334 N0 = par[
fRunInfo->GetNormParamNo()-1];
344 if (
fRunInfo->GetLifetimeParamNo() != -1)
345 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
351 if (
fRunInfo->GetBkgFitParamNo() == -1) {
358 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
362 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
363 Int_t funcNo =
fMsrInfo->GetFuncNo(i);
381 #pragma omp parallel for default(shared) private(i,time,theo,diff) schedule(dynamic,chunk) reduction(+:chisq)
384 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
386 diff =
fData.GetValue()->at(i) - theo;
387 chisq += diff*diff / theo;
464 N0 = par[
fRunInfo->GetNormParamNo()-1];
474 if (
fRunInfo->GetLifetimeParamNo() != -1)
475 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
481 if (
fRunInfo->GetBkgFitParamNo() == -1) {
488 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
492 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
493 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
504 Double_t normalizer = 1.0;
519 #pragma omp parallel for default(shared) private(i,time,theo,data) schedule(dynamic,chunk) reduction(+:mllh)
522 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
526 data =
fData.GetValue()->at(i);
529 std::cerr <<
">> PRunSingleHisto::CalcMaxLikelihood: **WARNING** NEGATIVE theory!!" << std::endl;
534 mllh += (theo-data) + data*log(data/theo);
540 return normalizer*2.0*mllh;
599 N0 = par[
fRunInfo->GetNormParamNo()-1];
609 if (
fRunInfo->GetLifetimeParamNo() != -1)
610 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
616 if (
fRunInfo->GetBkgFitParamNo() == -1) {
623 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
627 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
628 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
639 Double_t normalizer = 1.0;
654 #pragma omp parallel for default(shared) private(i,time,theo,data) schedule(dynamic,chunk) reduction(+:mllh)
657 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
661 data =
fData.GetValue()->at(i);
664 std::cerr <<
">> PRunSingleHisto::CalcMaxLikelihood: **WARNING** NEGATIVE theory!!" << std::endl;
669 mllh += data*log(data/theo);
673 return normalizer*2.0*mllh;
718 std::vector<Double_t> par;
720 for (UInt_t i=0; i<paramList->size(); i++)
721 par.push_back((*paramList)[i].fValue);
727 N0 = par[
fRunInfo->GetNormParamNo()-1];
737 if (
fRunInfo->GetLifetimeParamNo() != -1)
738 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
744 if (
fRunInfo->GetBkgFitParamNo() == -1) {
751 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
755 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
760 UInt_t size =
fData.GetValue()->size();
761 Double_t start =
fData.GetDataTimeStart();
762 Double_t resolution =
fData.GetDataTimeStep();
764 for (UInt_t i=0; i<size; i++) {
765 time = start +
static_cast<Double_t
>(i)*resolution;
852 std::vector<std::string> tok = PStringUtils::Split(fitRange.Data(),
" \t");
854 if (tok.size() == 3) {
858 idx = str.First(
"+");
860 str.Remove(0, idx+1);
869 idx = str.First(
"-");
871 str.Remove(0, idx+1);
876 }
else if ((tok.size() > 3) && (tok.size() % 2 == 1)) {
877 UInt_t pos = 2*(
fRunNo+1)-1;
879 if (pos + 1 >= tok.size()) {
880 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
881 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
886 idx = str.First(
"+");
888 str.Remove(0, idx+1);
897 idx = str.First(
"-");
899 str.Remove(0, idx+1);
906 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
907 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
1003 Bool_t success =
true;
1014 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
1015 std::cerr << std::endl;
1031 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
1032 histoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
1035 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **PANIC ERROR**:";
1036 std::cerr << std::endl <<
">> histoNo found = " << histoNo[i] <<
", which is NOT present in the data file!?!?";
1037 std::cerr << std::endl <<
">> Will quit :-(";
1038 std::cerr << std::endl;
1046 std::cout.precision(10);
1047 std::cout << std::endl <<
">> PRunSingleHisto::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ns)" << std::endl;
1050 if (!
GetProperT0(runData, globalBlock, histoNo)) {
1055 std::vector<PDoubleVector> forward;
1056 forward.resize(histoNo.size());
1057 for (UInt_t i=0; i<histoNo.size(); i++) {
1058 forward[i].resize(runData->
GetDataBin(histoNo[i])->size());
1059 forward[i] = *runData->
GetDataBin(histoNo[i]);
1068 if (
fRunInfo->GetRunNameSize() > 1) {
1070 std::vector<PDoubleVector> addForward;
1071 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1075 if (addRunData ==
nullptr) {
1076 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1077 std::cerr << std::endl;
1082 addForward.resize(histoNo.size());
1083 for (UInt_t j=0; j<histoNo.size(); j++) {
1084 addForward[j].resize(addRunData->
GetDataBin(histoNo[j])->size());
1085 addForward[j] = *addRunData->
GetDataBin(histoNo[j]);
1091 for (UInt_t k=0; k<histoNo.size(); k++) {
1092 addRunSize = addForward[k].size();
1093 for (UInt_t j=0; j<addRunSize; j++) {
1095 if ((
static_cast<Int_t
>(j)+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k]) >= 0) &&
1096 (j+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k]) < addRunSize)) {
1097 forward[k][j] += addForward[k][j+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k])];
1105 fForward.resize(forward[0].size());
1106 for (UInt_t i=0; i<
fForward.size(); i++) {
1111 for (UInt_t i=1; i<histoNo.size(); i++) {
1112 for (UInt_t j=0; j<runData->
GetDataBin(histoNo[i])->size(); j++) {
1115 fForward[j] += forward[i][j+
static_cast<Int_t
>(
fT0s[i])-
static_cast<Int_t
>(
fT0s[0])];
1129 Bool_t lifetimecorrection =
false;
1131 lifetimecorrection = plot->at(0).fLifeTimeCorrection;
1213 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1216 if (
fRunInfo->GetBkgRange(0) >= 0) {
1220 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1221 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1222 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareFitData(): **WARNING** Neither fix background nor background bins are given!";
1223 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1224 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1225 std::cerr << std::endl;
1230 for (UInt_t i=0; i<
fForward.size(); i++) {
1237 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1238 Double_t value = 0.0;
1239 Double_t normalizer = 1.0;
1251 value /= normalizer;
1252 fData.AppendValue(value);
1254 fData.AppendErrorValue(1.0/normalizer);
1256 fData.AppendErrorValue(TMath::Sqrt(value));
1259 value /= normalizer;
1260 fData.AppendValue(value);
1262 fData.AppendErrorValue(1.0/normalizer);
1264 fData.AppendErrorValue(TMath::Sqrt(value));
1300 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1301 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1305 Double_t dataNorm = 1.0, theoryNorm = 1.0;
1309 theoryNorm =
static_cast<Double_t
>(
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking)/
static_cast<Double_t
>(
fPacking);
1316 Int_t end = start + ((
fForward.size()-start)/packing)*packing;
1320 start = (
static_cast<Int_t
>(
fT0s[0])+offset) - ((
static_cast<Int_t
>(
fT0s[0])+offset)/packing)*packing;
1321 end = start + ((
fForward.size()-start)/packing)*packing;
1322 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **WARNING** data range was not provided, will try data range start = " << start <<
".";
1323 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1324 std::cerr << std::endl;
1334 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1335 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **ERROR** start data bin doesn't make any sense!";
1336 std::cerr << std::endl;
1340 if ((end < 0) || (end >
static_cast<Int_t
>(
fForward.size()))) {
1341 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **ERROR** end data bin doesn't make any sense!";
1342 std::cerr << std::endl;
1347 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1348 Double_t value = 0.0;
1350 fData.SetDataTimeStart(
fTimeResolution*((
static_cast<Double_t
>(start)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)));
1353 for (Int_t i=start; i<end; i++) {
1354 if (((i-start) % packing == 0) && (i != start)) {
1356 fData.AppendValue(value);
1358 fData.AppendErrorValue(1.0);
1360 fData.AppendErrorValue(TMath::Sqrt(value*dataNorm));
1371 std::vector<Double_t> par;
1373 for (UInt_t i=0; i<paramList->size(); i++)
1374 par.push_back((*paramList)[i].fValue);
1380 N0 = par[
fRunInfo->GetNormParamNo()-1];
1391 if (
fRunInfo->GetLifetimeParamNo() != -1)
1392 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
1398 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1400 if (
fRunInfo->GetBkgRange(0) >= 0) {
1404 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1405 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1406 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **WARNING** Neither fix background nor background bins are given!";
1407 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1408 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1409 std::cerr << std::endl;
1418 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
1423 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1430 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1432 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1436 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1440 Double_t theoryValue;
1441 for (UInt_t i=0; i<size; i++) {
1442 time =
fData.GetTheoryTimeStart() + i*
fData.GetTheoryTimeStep();
1444 if (fabs(theoryValue) > 1.0e10) {
1447 fData.AppendTheoryValue(N0*TMath::Exp(-time/tau)*(1.0+theoryValue)+bkg);
1489 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1490 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1493 if (
fMsrInfo->GetMsrPlotList()->at(0).fRRFPacking > 0) {
1494 packing =
fMsrInfo->GetMsrPlotList()->at(0).fRRFPacking;
1498 Double_t dataNorm = 1.0, theoryNorm = 1.0;
1502 theoryNorm =
static_cast<Double_t
>(
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking)/
static_cast<Double_t
>(
fPacking);
1508 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1513 Int_t end = start + ((
fForward.size()-start)/packing)*packing;
1518 start = (
static_cast<Int_t
>(
fT0s[0])+offset) - ((
static_cast<Int_t
>(
fT0s[0])+offset)/packing)*packing;
1519 end = start + ((
fForward.size()-start)/packing)*packing;
1520 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **WARNING** data range was not provided, will try data range start = " << start <<
".";
1521 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1522 std::cerr << std::endl;
1533 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1534 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1535 std::cerr << std::endl;
1539 if ((end < 0) || (end >
static_cast<Int_t
>(
fForward.size()))) {
1540 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1541 std::cerr << std::endl;
1548 std::vector<Double_t> par;
1550 for (UInt_t i=0; i<paramList->size(); i++)
1551 par.push_back((*paramList)[i].fValue);
1557 N0 = par[
fRunInfo->GetNormParamNo()-1];
1568 if (
fRunInfo->GetLifetimeParamNo() != -1)
1569 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
1575 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1577 if (
fRunInfo->GetBkgRange(0) >= 0) {
1581 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1582 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1583 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **WARNING** Neither fix background nor background bins are given!";
1584 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1585 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1586 std::cerr << std::endl;
1595 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
1599 Double_t value = 0.0;
1600 Double_t expval = 0.0;
1601 Double_t rrf_val = 0.0;
1602 Double_t time = 0.0;
1605 fData.SetDataTimeStart(
fTimeResolution*((
static_cast<Double_t
>(start)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)));
1609 Double_t gammaRRF = 0.0, wRRF = 0.0, phaseRRF = 0.0;
1610 if (
fMsrInfo->GetMsrPlotList()->at(0).fRRFFreq == 0.0) {
1611 for (Int_t i=start; i<end; i++) {
1612 if (((i-start) % packing == 0) && (i != start)) {
1615 time = (((
static_cast<Double_t
>(i)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)))*
fTimeResolution -
static_cast<Double_t
>(packing)*
fTimeResolution;
1616 expval = TMath::Exp(+time/tau)/N0;
1617 fData.AppendValue(-1.0+expval*(value-bkg));
1618 fData.AppendErrorValue(expval*TMath::Sqrt(value*dataNorm));
1625 switch (
fMsrInfo->GetMsrPlotList()->at(0).fRRFUnit) {
1627 gammaRRF = TMath::TwoPi()*1.0e-3;
1630 gammaRRF = TMath::TwoPi();
1642 gammaRRF = TMath::TwoPi();
1645 wRRF = gammaRRF *
fMsrInfo->GetMsrPlotList()->at(0).fRRFFreq;
1646 phaseRRF =
fMsrInfo->GetMsrPlotList()->at(0).fRRFPhase / 180.0 * TMath::Pi();
1648 Double_t error = 0.0;
1649 for (Int_t i=start; i<end; i++) {
1650 if (((i-start) % packing == 0) && (i != start)) {
1651 fData.AppendValue(2.0*value/packing);
1652 fData.AppendErrorValue(expval*TMath::Sqrt(error/packing));
1657 expval = TMath::Exp(+time/tau)/N0;
1667 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1672 Double_t theoryValue;
1673 UInt_t size =
fForward.size()/packing;
1674 const Int_t factor = 8;
1675 UInt_t rebinRRF = 0;
1678 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1680 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1684 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1687 rebinRRF =
static_cast<UInt_t
>((TMath::Pi()/2.0/wRRF)/
fTimeResolution);
1688 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1689 fData.SetTheoryTimeStep(TMath::Pi()/2.0/wRRF/rebinRRF);
1692 for (UInt_t i=0; i<size; i++) {
1693 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1696 theoryValue *= 2.0*TMath::Cos(wRRF * time + phaseRRF);
1698 if (fabs(theoryValue) > 10.0) {
1701 fData.AppendTheoryValue(theoryValue);
1707 if (rebinRRF != 0) {
1708 Double_t dval = 0.0;
1710 for (UInt_t i=0; i<
fData.GetTheory()->size(); i++) {
1711 if ((i % rebinRRF == 0) && (i != 0)) {
1712 theo.push_back(dval/rebinRRF);
1715 dval +=
fData.GetTheory()->at(i);
1717 fData.SetTheoryTimeStart(
fData.GetTheoryTimeStart()+
static_cast<Double_t
>(rebinRRF-1)*
fData.GetTheoryTimeStep()/2.0);
1718 fData.SetTheoryTimeStep(rebinRRF*
fData.GetTheoryTimeStep());
1719 fData.ReplaceTheory(theo);
1792 fT0s.resize(histoNo.size());
1793 for (UInt_t i=0; i<
fT0s.size(); i++) {
1798 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1804 if (
fT0s[i] == -1.0) {
1810 for (UInt_t i=0; i<histoNo.size(); i++) {
1811 if (
fT0s[i] == -1.0) {
1812 if (runData->
GetT0Bin(histoNo[i]) > 0.0) {
1820 for (UInt_t i=0; i<histoNo.size(); i++) {
1821 if (
fT0s[i] == -1.0) {
1825 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1826 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1827 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(histoNo[i]);
1828 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1829 std::cerr << std::endl;
1834 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
1835 if ((
fT0s[i] < 0.0) || (
fT0s[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1836 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[i] <<
") doesn't make any sense!";
1837 std::cerr << std::endl;
1843 if (
fRunInfo->GetRunNameSize() > 1) {
1846 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1850 if (addRunData ==
nullptr) {
1851 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1852 std::cerr << std::endl;
1858 fAddT0s[i-1].resize(histoNo.size());
1859 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1864 for (UInt_t j=0; j<
fRunInfo->GetT0BinSize(); j++) {
1869 for (UInt_t j=0; j<histoNo.size(); j++) {
1871 if (addRunData->
GetT0Bin(histoNo[j]) > 0.0) {
1878 for (UInt_t j=0; j<histoNo.size(); j++) {
1879 if (
fAddT0s[i-1][j] == -1.0) {
1883 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1884 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1885 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(histoNo[j]);
1886 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1887 std::cerr << std::endl;
1892 for (UInt_t j=0; j<
fRunInfo->GetForwardHistoNoSize(); j++) {
1893 if ((
fAddT0s[i-1][j] < 0.0) || (
fAddT0s[i-1][j] >
static_cast<Int_t
>(addRunData->
GetDataBin(histoNo[j])->size()))) {
1894 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** addt0 data bin (" <<
fAddT0s[i-1][j] <<
") doesn't make any sense!";
1895 std::cerr << std::endl;
1962 start =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1965 end =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1971 start =
static_cast<Int_t
>(
fT0s[0])+offset;
1973 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** data range was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start <<
".";
1974 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1975 std::cerr << std::endl;
1980 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** data range was not provided, will try data range end = " << end <<
".";
1981 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1982 std::cerr << std::endl;
1993 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1994 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **ERROR** start data bin (" << start <<
") doesn't make any sense!";
1995 std::cerr << std::endl;
2000 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **ERROR** end data bin (" << end <<
") doesn't make any sense!";
2001 std::cerr << std::endl;
2004 if (end >
static_cast<Int_t
>(
fForward.size())) {
2005 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** end data bin (" << end <<
") > histo length (" <<
fForward.size() <<
").";
2006 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
2007 std::cerr << std::endl;
2008 end =
static_cast<Int_t
>(
fForward.size())-1;
2019 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange **WARNING** needed to shift forward lgb,";
2020 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
2114 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
2115 std::cerr <<
">> Will set it to fgb/lgb which given in time is: " <<
fFitStartTime <<
"..." <<
fFitEndTime <<
" (usec)" << std::endl;
2168 UInt_t paramNo =
fRunInfo->GetNormParamNo();
2169 if (paramNo > 10000)
2176 if (paramNo > param->size()) {
2177 std::cerr << std::endl <<
">> PRunSingleHisto::EstimateN0: **ERROR** found parameter number " << paramNo <<
", which is larger than the number of parameters = " << param->size() << std::endl;
2182 if (param->at(paramNo-1).fStep == 0.0)
2188 Int_t paramNoBkg =
fRunInfo->GetBkgFitParamNo();
2189 Bool_t scaleBkg =
true;
2190 Double_t bkg=0.0, errBkg=1.0;
2191 if ((paramNoBkg > 10000) || (paramNoBkg == -1)) {
2194 if (paramNoBkg-1 <
static_cast<Int_t
>(param->size())) {
2195 bkg = param->at(paramNoBkg-1).fValue;
2196 errBkg = param->at(paramNoBkg-1).fStep;
2204 UInt_t t0 =
static_cast<UInt_t
>(round(
fT0s[0]));
2205 Double_t dval = 0.0;
2207 Double_t denom = 0.0;
2211 for (UInt_t i=t0; i<
fForward.size(); i++) {
2212 xx = exp(-dt*
static_cast<Double_t
>(i-t0)/tau);
2217 for (UInt_t i=t0; i<
fForward.size(); i++) {
2218 xx = exp(-dt*
static_cast<Double_t
>(i-t0)/tau);
2221 denom += xx*xx/dval;
2223 Double_t N0 = nom/denom;
2231 Double_t rescale = 1;
2232 if ((param->at(paramNo-1).fValue != 0.0) && scaleBkg) {
2233 rescale = N0 / param->at(paramNo-1).fValue;
2238 std::cout <<
">> PRunSingleHisto::EstimateN0: found N0=" << param->at(paramNo-1).fValue <<
", will set it to N0=" << N0 << std::endl;
2240 std::cout <<
">> PRunSingleHisto::EstimateN0: found Bkg=" << param->at(paramNoBkg-1).fValue <<
", will set it to Bkg=" << bkg << std::endl;
2241 fMsrInfo->SetMsrParamValue(paramNo-1, N0);
2242 fMsrInfo->SetMsrParamStep(paramNo-1, sqrt(fabs(N0)));
2244 fMsrInfo->SetMsrParamValue(paramNoBkg-1, bkg);
2245 fMsrInfo->SetMsrParamStep(paramNoBkg-1, errBkg);
2302 Double_t beamPeriod = 0.0;
2305 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
2307 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
2309 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
2315 Int_t start =
fRunInfo->GetBkgRange(0);
2316 Int_t end =
fRunInfo->GetBkgRange(1);
2318 std::cout << std::endl <<
"PRunSingleHisto::EstimatBkg(): end = " << end <<
" > start = " << start <<
"! Will swap them!";
2325 if (beamPeriod != 0.0) {
2327 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
2330 std::cout << std::endl <<
"PRunSingleHisto::EstimatBkg(): Background " << start <<
", " << end;
2337 std::cerr << std::endl <<
">> PRunSingleHisto::EstimatBkg(): **ERROR** background bin values out of bound!";
2338 std::cerr << std::endl <<
">> histo lengths = " <<
fForward.size();
2339 std::cerr << std::endl <<
">> background start = " << start;
2340 std::cerr << std::endl;
2346 std::cerr << std::endl <<
">> PRunSingleHisto::EstimatBkg(): **ERROR** background bin values out of bound!";
2347 std::cerr << std::endl <<
">> histo lengths = " <<
fForward.size();
2348 std::cerr << std::endl <<
">> background end = " << end;
2349 std::cerr << std::endl;
2357 for (UInt_t i=start; i<end; i++)
2359 bkg /=
static_cast<Double_t
>(end - start + 1);
2418 Bool_t willScale =
true;
2421 for (UInt_t i=0; i<cmd->size(); i++) {
2422 if (cmd->at(i).fLine.Contains(
"SCALE_N0_BKG", TString::kIgnoreCase)) {
2423 std::vector<std::string> tokens = PStringUtils::Split(cmd->at(i).fLine.Data(),
" \t");
2424 if (tokens.size() != 2) {
2425 std::cerr << std::endl <<
">> PRunSingleHisto::IsScaleN0AndBkg(): **WARNING** Found uncorrect 'SCALE_N0_BKG' command, will ignore it.";
2426 std::cerr << std::endl <<
">> Allowed commands: SCALE_N0_BKG TRUE | FALSE" << std::endl;
2429 if (PStringUtils::IsEqualNoCase(tokens[1],
"FALSE")) {
std::vector< UInt_t > PUIntVector
#define ACCEL_PERIOD_TRIUMF
TRIUMF accelerator cycle: 43.37 ns.
@ kFit
Fitting mode - perform least-squares fit to data.
@ kView
Viewing mode - display data and theory without fitting.
#define RRF_UNIT_MHz
Frequency in MHz (megahertz)
#define MSR_PARAM_FUN_OFFSET
Offset added to function indices for parameter parsing.
std::vector< PMsrPlotStructure > PMsrPlotList
std::vector< PMsrLineStructure > PMsrLines
std::vector< PMsrParamStructure > PMsrParamList
#define RRF_UNIT_Mcs
Angular frequency in Mc/s (Mega-cycles per second)
#define RRF_UNIT_G
Equivalent magnetic field in Gauss (G)
#define RRF_UNIT_kHz
Frequency in kHz (kilohertz)
#define ACCEL_PERIOD_PSI
PSI (Paul Scherrer Institute) accelerator cycle: 19.75 ns.
#define RRF_UNIT_T
Equivalent magnetic field in Tesla (T)
std::vector< Double_t > PDoubleVector
#define ACCEL_PERIOD_RAL
RAL (Rutherford Appleton Lab) - pulsed beam.
virtual void SetFitRange(Double_t dval, UInt_t idx)
virtual Double_t GetFitRange(UInt_t idx)
virtual UInt_t GetT0BinSize()
virtual Bool_t IsFitRangeInBin()
virtual Int_t GetFitRangeOffset(UInt_t idx)
virtual Double_t GetT0Bin(UInt_t idx=0)
MSR file parser and manager for the musrfit framework.
virtual const PDoubleVector * GetDataBin(const UInt_t histoNo)
virtual const Double_t GetT0Bin(const UInt_t histoNo)
virtual const Double_t GetTimeResolution()
virtual const Bool_t IsPresent(UInt_t histoNo)
virtual const UInt_t GetNoOfTemperatures()
virtual const Double_t GetField()
virtual const Double_t GetEnergy()
virtual const Double_t GetT0BinEstimated(const UInt_t histoNo)
virtual const PDoublePairVector * GetTemperature() const
Double_t fTimeResolution
Time resolution of raw histogram data in microseconds (μs), e.g., 0.01953125 μs for PSI GPS.
Bool_t fValid
Flag indicating if run object initialized successfully; false if any error occurred.
Double_t fFitEndTime
Fit range end time in microseconds (μs) relative to t0.
PDoubleVector fFuncValues
Cached values of user-defined functions from FUNCTIONS block, evaluated at current parameters.
PMsrHandler * fMsrInfo
Pointer to MSR file handler (owned externally, not deleted here)
virtual void DeadTimeCorrection(std::vector< PDoubleVector > &histos, PUIntVector &histoNo)
carry out dead time correction
PMetaData fMetaData
Experimental metadata extracted from data file header (magnetic field, temperature,...
std::unique_ptr< PTheory > fTheory
Theory function evaluator (smart pointer, automatically deleted)
std::vector< PDoubleVector > fAddT0s
Time-zero bin values for additional runs to be added to main run.
EPMusrHandleTag fHandleTag
Operation mode: kFit (fitting), kView (display only), kEmpty (uninitialized)
virtual void CalculateKaiserFilterCoeff(Double_t wc, Double_t A, Double_t dw)
Calculates Kaiser window FIR filter coefficients for RRF smoothing.
PRunData fData
Processed data container: background-corrected, packed, with theory values.
PRunDataHandler * fRawData
Pointer to raw data handler (owned externally, not deleted here)
PDoubleVector fT0s
Time-zero bin values for all histograms in this run (forward, backward, etc.)
PRunBase()
Default constructor.
Int_t fRunNo
Run number (0-based index in MSR file RUN blocks)
PMsrRunBlock * fRunInfo
Pointer to this run's RUN block settings within fMsrInfo.
Double_t fFitStartTime
Fit range start time in microseconds (μs) relative to t0.
virtual void FilterTheo()
Applies Kaiser FIR filter to theory values for RRF fits.
Raw data file reader and format converter for μSR data.
virtual Double_t CalcChiSquare(const std::vector< Double_t > &par)
Calculates χ² between histogram data and theory.
virtual void CalcNoOfFitBins()
Calculates start/end bin indices from fit time range.
virtual Double_t CalcChiSquareExpected(const std::vector< Double_t > &par)
Calculates expected χ² based on theory predictions.
virtual Bool_t IsScaleN0AndBkg()
Determines if N₀ and background should be scaled to 1/ns.
Double_t fBackground
Background level in counts/bin (estimated from pre-t0 bins or fixed value from RUN block)
UInt_t fNoOfFitBins
Number of bins within fit range (fStartTimeBin to fEndTimeBin)
virtual ~PRunSingleHisto()
Virtual destructor cleaning up allocated resources.
virtual Bool_t PrepareViewData(PRawRunData *runData, const UInt_t histoNo)
Prepares processed histogram data for viewing/plotting.
virtual Double_t CalcMaxLikelihood(const std::vector< Double_t > &par)
Calculates maximum likelihood for Poisson-distributed histogram counts.
virtual Bool_t EstimateBkg(UInt_t histoNo)
Estimates background from pre-t0 bins.
virtual void CalcTheory()
Evaluates theory function at all data points or high-resolution grid.
virtual UInt_t GetNoOfFitBins()
Returns the number of bins included in the fit range.
virtual void EstimateN0()
Estimates initial normalization N₀ from histogram data.
Int_t fEndTimeBin
Last bin index in fit range (exclusive: loop as i < fEndTimeBin)
PRunSingleHisto()
Default constructor creating an empty, invalid single histogram run object.
virtual void GetProperFitRange(PMsrGlobalBlock *globalBlock)
Determines fit range from MSR file settings.
virtual void SetFitRangeBin(const TString fitRange)
Sets fit range using bin-offset specification (COMMANDS block syntax).
Bool_t fScaleN0AndBkg
Scaling mode: true = scale N₀ and B to 1/ns, false = leave as 1/bin (determined by IsScaleN0AndBkg())
Int_t fStartTimeBin
First bin index in fit range (inclusive, 0-based after packing)
virtual Bool_t GetProperDataRange()
Determines data range (region of valid histogram data).
virtual Bool_t GetProperT0(PRawRunData *runData, PMsrGlobalBlock *globalBlock, PUIntVector &histoNo)
Determines and validates t0 values for histogram.
Bool_t fTheoAsData
Theory mode: true = at data points, false = high-resolution grid for smooth Fourier transforms.
Int_t fGoodBins[2]
Good bin markers for COMMANDS block: [0]=fgb (first good bin/t0), [1]=lgb (last good bin)
Int_t fPacking
Bin packing factor (REQUIRED: from RUN or GLOBAL block)
virtual Bool_t PrepareRawViewData(PRawRunData *runData, const UInt_t histoNo)
Prepares raw histogram data for viewing (minimal processing).
virtual Double_t CalcMaxLikelihoodExpected(const std::vector< Double_t > &par)
Calculates expected maximum likelihood.
virtual Bool_t PrepareData()
Main data preparation orchestrator.
virtual Bool_t PrepareFitData(PRawRunData *runData, const UInt_t histoNo)
Prepares histogram data for fitting.
PDoubleVector fForward
Forward detector histogram (background-corrected, packed)