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);
501 Bool_t post_msg(
true);
505 Double_t normalizer = 1.0;
520 #pragma omp parallel for default(shared) private(i,time,theo,data,post_msg) schedule(dynamic,chunk) reduction(+:mllh)
523 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
527 data =
fData.GetValue()->at(i);
532 std::cerr <<
">> PRunSingleHisto::CalcMaxLikelihood: **WARNING** NEGATIVE theory!!" << std::endl;
538 mllh += (theo-data) + data*log(data/theo);
544 return normalizer*2.0*mllh;
603 N0 = par[
fRunInfo->GetNormParamNo()-1];
613 if (
fRunInfo->GetLifetimeParamNo() != -1)
614 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
620 if (
fRunInfo->GetBkgFitParamNo() == -1) {
627 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
631 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
632 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
640 Bool_t post_msg(
true);
644 Double_t normalizer = 1.0;
659 #pragma omp parallel for default(shared) private(i,time,theo,data,post_msg) schedule(dynamic,chunk) reduction(+:mllh)
662 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
666 data =
fData.GetValue()->at(i);
671 std::cerr <<
">> PRunSingleHisto::CalcMaxLikelihood: **WARNING** NEGATIVE theory!!" << std::endl;
677 mllh += data*log(data/theo);
681 return normalizer*2.0*mllh;
726 std::vector<Double_t> par;
728 for (UInt_t i=0; i<paramList->size(); i++)
729 par.push_back((*paramList)[i].fValue);
735 N0 = par[
fRunInfo->GetNormParamNo()-1];
745 if (
fRunInfo->GetLifetimeParamNo() != -1)
746 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
752 if (
fRunInfo->GetBkgFitParamNo() == -1) {
759 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
763 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
768 UInt_t size =
fData.GetValue()->size();
769 Double_t start =
fData.GetDataTimeStart();
770 Double_t resolution =
fData.GetDataTimeStep();
772 for (UInt_t i=0; i<size; i++) {
773 time = start +
static_cast<Double_t
>(i)*resolution;
862 if (tok.size() == 3) {
866 idx = str.First(
"+");
868 str.Remove(0, idx+1);
877 idx = str.First(
"-");
879 str.Remove(0, idx+1);
884 }
else if ((tok.size() > 3) && (tok.size() % 2 == 1)) {
885 UInt_t pos = 2*(
fRunNo+1)-1;
887 if (pos + 1 >= tok.size()) {
888 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
889 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
894 idx = str.First(
"+");
896 str.Remove(0, idx+1);
905 idx = str.First(
"-");
907 str.Remove(0, idx+1);
914 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
915 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
1011 Bool_t success =
true;
1022 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
1023 std::cerr << std::endl;
1039 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
1040 histoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
1043 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **PANIC ERROR**:";
1044 std::cerr << std::endl <<
">> histoNo found = " << histoNo[i] <<
", which is NOT present in the data file!?!?";
1045 std::cerr << std::endl <<
">> Will quit :-(";
1046 std::cerr << std::endl;
1054 std::cout.precision(10);
1055 std::cout << std::endl <<
">> PRunSingleHisto::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ns)" << std::endl;
1058 if (!
GetProperT0(runData, globalBlock, histoNo)) {
1063 std::vector<PDoubleVector> forward;
1064 forward.resize(histoNo.size());
1065 for (UInt_t i=0; i<histoNo.size(); i++) {
1066 forward[i].resize(runData->
GetDataBin(histoNo[i])->size());
1067 forward[i] = *runData->
GetDataBin(histoNo[i]);
1076 if (
fRunInfo->GetRunNameSize() > 1) {
1078 std::vector<PDoubleVector> addForward;
1079 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1083 if (addRunData ==
nullptr) {
1084 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1085 std::cerr << std::endl;
1090 addForward.resize(histoNo.size());
1091 for (UInt_t j=0; j<histoNo.size(); j++) {
1092 addForward[j].resize(addRunData->
GetDataBin(histoNo[j])->size());
1093 addForward[j] = *addRunData->
GetDataBin(histoNo[j]);
1099 for (UInt_t k=0; k<histoNo.size(); k++) {
1100 addRunSize = addForward[k].size();
1101 for (UInt_t j=0; j<addRunSize; j++) {
1103 if ((
static_cast<Int_t
>(j)+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k]) >= 0) &&
1104 (j+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k]) < addRunSize)) {
1105 forward[k][j] += addForward[k][j+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k])];
1113 fForward.resize(forward[0].size());
1114 for (UInt_t i=0; i<
fForward.size(); i++) {
1119 for (UInt_t i=1; i<histoNo.size(); i++) {
1120 for (UInt_t j=0; j<runData->
GetDataBin(histoNo[i])->size(); j++) {
1123 fForward[j] += forward[i][j+
static_cast<Int_t
>(
fT0s[i])-
static_cast<Int_t
>(
fT0s[0])];
1137 Bool_t lifetimecorrection =
false;
1139 lifetimecorrection = plot->at(0).fLifeTimeCorrection;
1221 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1224 if (
fRunInfo->GetBkgRange(0) >= 0) {
1228 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1229 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1230 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareFitData(): **WARNING** Neither fix background nor background bins are given!";
1231 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1232 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1233 std::cerr << std::endl;
1238 for (UInt_t i=0; i<
fForward.size(); i++) {
1245 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1246 Double_t value = 0.0;
1247 Double_t normalizer = 1.0;
1259 value /= normalizer;
1260 fData.AppendValue(value);
1262 fData.AppendErrorValue(1.0/normalizer);
1264 fData.AppendErrorValue(TMath::Sqrt(value));
1267 value /= normalizer;
1268 fData.AppendValue(value);
1270 fData.AppendErrorValue(1.0/normalizer);
1272 fData.AppendErrorValue(TMath::Sqrt(value));
1308 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1309 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1313 Double_t dataNorm = 1.0, theoryNorm = 1.0;
1317 theoryNorm =
static_cast<Double_t
>(
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking)/
static_cast<Double_t
>(
fPacking);
1324 Int_t end = start + ((
fForward.size()-start)/packing)*packing;
1328 start = (
static_cast<Int_t
>(
fT0s[0])+offset) - ((
static_cast<Int_t
>(
fT0s[0])+offset)/packing)*packing;
1329 end = start + ((
fForward.size()-start)/packing)*packing;
1330 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **WARNING** data range was not provided, will try data range start = " << start <<
".";
1331 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1332 std::cerr << std::endl;
1342 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1343 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **ERROR** start data bin doesn't make any sense!";
1344 std::cerr << std::endl;
1348 if ((end < 0) || (end >
static_cast<Int_t
>(
fForward.size()))) {
1349 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **ERROR** end data bin doesn't make any sense!";
1350 std::cerr << std::endl;
1355 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1356 Double_t value = 0.0;
1358 fData.SetDataTimeStart(
fTimeResolution*((
static_cast<Double_t
>(start)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)));
1361 for (Int_t i=start; i<end; i++) {
1362 if (((i-start) % packing == 0) && (i != start)) {
1364 fData.AppendValue(value);
1366 fData.AppendErrorValue(1.0);
1368 fData.AppendErrorValue(TMath::Sqrt(value*dataNorm));
1379 std::vector<Double_t> par;
1381 for (UInt_t i=0; i<paramList->size(); i++)
1382 par.push_back((*paramList)[i].fValue);
1388 N0 = par[
fRunInfo->GetNormParamNo()-1];
1399 if (
fRunInfo->GetLifetimeParamNo() != -1)
1400 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
1406 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1408 if (
fRunInfo->GetBkgRange(0) >= 0) {
1412 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1413 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1414 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **WARNING** Neither fix background nor background bins are given!";
1415 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1416 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1417 std::cerr << std::endl;
1426 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
1431 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1438 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1440 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1444 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1448 Double_t theoryValue;
1449 for (UInt_t i=0; i<size; i++) {
1450 time =
fData.GetTheoryTimeStart() + i*
fData.GetTheoryTimeStep();
1452 if (fabs(theoryValue) > 1.0e10) {
1455 fData.AppendTheoryValue(N0*TMath::Exp(-time/tau)*(1.0+theoryValue)+bkg);
1497 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1498 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1501 if (
fMsrInfo->GetMsrPlotList()->at(0).fRRFPacking > 0) {
1502 packing =
fMsrInfo->GetMsrPlotList()->at(0).fRRFPacking;
1506 Double_t dataNorm = 1.0, theoryNorm = 1.0;
1510 theoryNorm =
static_cast<Double_t
>(
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking)/
static_cast<Double_t
>(
fPacking);
1516 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1521 Int_t end = start + ((
fForward.size()-start)/packing)*packing;
1526 start = (
static_cast<Int_t
>(
fT0s[0])+offset) - ((
static_cast<Int_t
>(
fT0s[0])+offset)/packing)*packing;
1527 end = start + ((
fForward.size()-start)/packing)*packing;
1528 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **WARNING** data range was not provided, will try data range start = " << start <<
".";
1529 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1530 std::cerr << std::endl;
1541 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1542 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1543 std::cerr << std::endl;
1547 if ((end < 0) || (end >
static_cast<Int_t
>(
fForward.size()))) {
1548 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1549 std::cerr << std::endl;
1556 std::vector<Double_t> par;
1558 for (UInt_t i=0; i<paramList->size(); i++)
1559 par.push_back((*paramList)[i].fValue);
1565 N0 = par[
fRunInfo->GetNormParamNo()-1];
1576 if (
fRunInfo->GetLifetimeParamNo() != -1)
1577 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
1583 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1585 if (
fRunInfo->GetBkgRange(0) >= 0) {
1589 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1590 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1591 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **WARNING** Neither fix background nor background bins are given!";
1592 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1593 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1594 std::cerr << std::endl;
1603 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
1607 Double_t value = 0.0;
1608 Double_t expval = 0.0;
1609 Double_t rrf_val = 0.0;
1610 Double_t time = 0.0;
1613 fData.SetDataTimeStart(
fTimeResolution*((
static_cast<Double_t
>(start)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)));
1617 Double_t gammaRRF = 0.0, wRRF = 0.0, phaseRRF = 0.0;
1618 if (
fMsrInfo->GetMsrPlotList()->at(0).fRRFFreq == 0.0) {
1619 for (Int_t i=start; i<end; i++) {
1620 if (((i-start) % packing == 0) && (i != start)) {
1623 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;
1624 expval = TMath::Exp(+time/tau)/N0;
1625 fData.AppendValue(-1.0+expval*(value-bkg));
1626 fData.AppendErrorValue(expval*TMath::Sqrt(value*dataNorm));
1633 switch (
fMsrInfo->GetMsrPlotList()->at(0).fRRFUnit) {
1635 gammaRRF = TMath::TwoPi()*1.0e-3;
1638 gammaRRF = TMath::TwoPi();
1650 gammaRRF = TMath::TwoPi();
1653 wRRF = gammaRRF *
fMsrInfo->GetMsrPlotList()->at(0).fRRFFreq;
1654 phaseRRF =
fMsrInfo->GetMsrPlotList()->at(0).fRRFPhase / 180.0 * TMath::Pi();
1656 Double_t error = 0.0;
1657 for (Int_t i=start; i<end; i++) {
1658 if (((i-start) % packing == 0) && (i != start)) {
1659 fData.AppendValue(2.0*value/packing);
1660 fData.AppendErrorValue(expval*TMath::Sqrt(error/packing));
1665 expval = TMath::Exp(+time/tau)/N0;
1675 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1680 Double_t theoryValue;
1681 UInt_t size =
fForward.size()/packing;
1682 const Int_t factor = 8;
1683 UInt_t rebinRRF = 0;
1686 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1688 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1692 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1695 rebinRRF =
static_cast<UInt_t
>((TMath::Pi()/2.0/wRRF)/
fTimeResolution);
1696 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1697 fData.SetTheoryTimeStep(TMath::Pi()/2.0/wRRF/rebinRRF);
1700 for (UInt_t i=0; i<size; i++) {
1701 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1704 theoryValue *= 2.0*TMath::Cos(wRRF * time + phaseRRF);
1706 if (fabs(theoryValue) > 10.0) {
1709 fData.AppendTheoryValue(theoryValue);
1715 if (rebinRRF != 0) {
1716 Double_t dval = 0.0;
1718 for (UInt_t i=0; i<
fData.GetTheory()->size(); i++) {
1719 if ((i % rebinRRF == 0) && (i != 0)) {
1720 theo.push_back(dval/rebinRRF);
1723 dval +=
fData.GetTheory()->at(i);
1725 fData.SetTheoryTimeStart(
fData.GetTheoryTimeStart()+
static_cast<Double_t
>(rebinRRF-1)*
fData.GetTheoryTimeStep()/2.0);
1726 fData.SetTheoryTimeStep(rebinRRF*
fData.GetTheoryTimeStep());
1727 fData.ReplaceTheory(theo);
1800 fT0s.resize(histoNo.size());
1801 for (UInt_t i=0; i<
fT0s.size(); i++) {
1806 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1812 if (
fT0s[i] == -1.0) {
1818 for (UInt_t i=0; i<histoNo.size(); i++) {
1819 if (
fT0s[i] == -1.0) {
1820 if (runData->
GetT0Bin(histoNo[i]) > 0.0) {
1828 for (UInt_t i=0; i<histoNo.size(); i++) {
1829 if (
fT0s[i] == -1.0) {
1833 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1834 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1835 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(histoNo[i]);
1836 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1837 std::cerr << std::endl;
1842 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
1843 if ((
fT0s[i] < 0.0) || (
fT0s[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1844 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[i] <<
") doesn't make any sense!";
1845 std::cerr << std::endl;
1851 if (
fRunInfo->GetRunNameSize() > 1) {
1854 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1858 if (addRunData ==
nullptr) {
1859 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1860 std::cerr << std::endl;
1866 fAddT0s[i-1].resize(histoNo.size());
1867 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1872 for (UInt_t j=0; j<
fRunInfo->GetT0BinSize(); j++) {
1877 for (UInt_t j=0; j<histoNo.size(); j++) {
1879 if (addRunData->
GetT0Bin(histoNo[j]) > 0.0) {
1886 for (UInt_t j=0; j<histoNo.size(); j++) {
1887 if (
fAddT0s[i-1][j] == -1.0) {
1891 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1892 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1893 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(histoNo[j]);
1894 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1895 std::cerr << std::endl;
1900 for (UInt_t j=0; j<
fRunInfo->GetForwardHistoNoSize(); j++) {
1901 if ((
fAddT0s[i-1][j] < 0.0) || (
fAddT0s[i-1][j] >
static_cast<Int_t
>(addRunData->
GetDataBin(histoNo[j])->size()))) {
1902 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** addt0 data bin (" <<
fAddT0s[i-1][j] <<
") doesn't make any sense!";
1903 std::cerr << std::endl;
1970 start =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1973 end =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1979 start =
static_cast<Int_t
>(
fT0s[0])+offset;
1981 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** data range was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start <<
".";
1982 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1983 std::cerr << std::endl;
1988 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** data range was not provided, will try data range end = " << end <<
".";
1989 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1990 std::cerr << std::endl;
2001 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
2002 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **ERROR** start data bin (" << start <<
") doesn't make any sense!";
2003 std::cerr << std::endl;
2008 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **ERROR** end data bin (" << end <<
") doesn't make any sense!";
2009 std::cerr << std::endl;
2012 if (end >
static_cast<Int_t
>(
fForward.size())) {
2013 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** end data bin (" << end <<
") > histo length (" <<
fForward.size() <<
").";
2014 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
2015 std::cerr << std::endl;
2016 end =
static_cast<Int_t
>(
fForward.size())-1;
2027 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange **WARNING** needed to shift forward lgb,";
2028 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
2122 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
2123 std::cerr <<
">> Will set it to fgb/lgb which given in time is: " <<
fFitStartTime <<
"..." <<
fFitEndTime <<
" (usec)" << std::endl;
2176 UInt_t paramNo =
fRunInfo->GetNormParamNo();
2177 if (paramNo > 10000)
2184 if (paramNo > param->size()) {
2185 std::cerr << std::endl <<
">> PRunSingleHisto::EstimateN0: **ERROR** found parameter number " << paramNo <<
", which is larger than the number of parameters = " << param->size() << std::endl;
2190 if (param->at(paramNo-1).fStep == 0.0)
2196 Int_t paramNoBkg =
fRunInfo->GetBkgFitParamNo();
2197 Bool_t scaleBkg =
true;
2198 Double_t bkg=0.0, errBkg=1.0;
2199 if ((paramNoBkg > 10000) || (paramNoBkg == -1)) {
2202 if (paramNoBkg-1 <
static_cast<Int_t
>(param->size())) {
2203 bkg = param->at(paramNoBkg-1).fValue;
2204 errBkg = param->at(paramNoBkg-1).fStep;
2212 UInt_t t0 =
static_cast<UInt_t
>(round(
fT0s[0]));
2213 Double_t dval = 0.0;
2215 Double_t denom = 0.0;
2219 for (UInt_t i=t0; i<
fForward.size(); i++) {
2220 xx = exp(-dt*
static_cast<Double_t
>(i-t0)/tau);
2225 for (UInt_t i=t0; i<
fForward.size(); i++) {
2226 xx = exp(-dt*
static_cast<Double_t
>(i-t0)/tau);
2229 denom += xx*xx/dval;
2231 Double_t N0 = nom/denom;
2239 Double_t rescale = 1;
2240 if ((param->at(paramNo-1).fValue != 0.0) && scaleBkg) {
2241 rescale = N0 / param->at(paramNo-1).fValue;
2246 std::cout <<
">> PRunSingleHisto::EstimateN0: found N0=" << param->at(paramNo-1).fValue <<
", will set it to N0=" << N0 << std::endl;
2248 std::cout <<
">> PRunSingleHisto::EstimateN0: found Bkg=" << param->at(paramNoBkg-1).fValue <<
", will set it to Bkg=" << bkg << std::endl;
2249 fMsrInfo->SetMsrParamValue(paramNo-1, N0);
2250 fMsrInfo->SetMsrParamStep(paramNo-1, sqrt(fabs(N0)));
2252 fMsrInfo->SetMsrParamValue(paramNoBkg-1, bkg);
2253 fMsrInfo->SetMsrParamStep(paramNoBkg-1, errBkg);
2310 Double_t beamPeriod = 0.0;
2313 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
2315 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
2317 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
2323 Int_t start =
fRunInfo->GetBkgRange(0);
2324 Int_t end =
fRunInfo->GetBkgRange(1);
2326 std::cout << std::endl <<
"PRunSingleHisto::EstimatBkg(): end = " << end <<
" > start = " << start <<
"! Will swap them!";
2333 if (beamPeriod != 0.0) {
2335 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
2338 std::cout << std::endl <<
"PRunSingleHisto::EstimatBkg(): Background " << start <<
", " << end;
2345 std::cerr << std::endl <<
">> PRunSingleHisto::EstimatBkg(): **ERROR** background bin values out of bound!";
2346 std::cerr << std::endl <<
">> histo lengths = " <<
fForward.size();
2347 std::cerr << std::endl <<
">> background start = " << start;
2348 std::cerr << std::endl;
2354 std::cerr << std::endl <<
">> PRunSingleHisto::EstimatBkg(): **ERROR** background bin values out of bound!";
2355 std::cerr << std::endl <<
">> histo lengths = " <<
fForward.size();
2356 std::cerr << std::endl <<
">> background end = " << end;
2357 std::cerr << std::endl;
2365 for (UInt_t i=start; i<end; i++)
2367 bkg /=
static_cast<Double_t
>(end - start + 1);
2426 Bool_t willScale =
true;
2429 for (UInt_t i=0; i<cmd->size(); i++) {
2430 if (cmd->at(i).fLine.Contains(
"SCALE_N0_BKG", TString::kIgnoreCase)) {
2432 if (tokens.size() != 2) {
2433 std::cerr << std::endl <<
">> PRunSingleHisto::IsScaleN0AndBkg(): **WARNING** Found uncorrect 'SCALE_N0_BKG' command, will ignore it.";
2434 std::cerr << std::endl <<
">> Allowed commands: SCALE_N0_BKG TRUE | FALSE" << std::endl;
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).
static bool IsEqualNoCase(const std::string &a, const std::string &b)
static std::vector< std::string > Split(const std::string &str, const std::string &delimiters)