44#include <TObjString.h>
120 std::cerr << std::endl <<
">> PRunSingleHisto::PRunSingleHisto: **SEVERE ERROR**: Couldn't find any packing information!";
121 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
122 std::cerr << std::endl;
136 std::cerr << std::endl <<
">> PRunSingleHisto::PRunSingleHisto: **SEVERE ERROR**: Couldn't prepare data for fitting!";
137 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
138 std::cerr << std::endl;
210 Double_t chisq = 0.0;
217 N0 = par[
fRunInfo->GetNormParamNo()-1];
227 if (
fRunInfo->GetLifetimeParamNo() != -1)
228 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
234 if (
fRunInfo->GetBkgFitParamNo() == -1) {
241 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
245 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
246 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
264 #pragma omp parallel for default(shared) private(i,time,diff) schedule(dynamic,chunk) reduction(+:chisq)
267 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
268 diff =
fData.GetValue()->at(i) -
270 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
325 Double_t chisq = 0.0;
333 N0 = par[
fRunInfo->GetNormParamNo()-1];
343 if (
fRunInfo->GetLifetimeParamNo() != -1)
344 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
350 if (
fRunInfo->GetBkgFitParamNo() == -1) {
357 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
361 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
362 Int_t funcNo =
fMsrInfo->GetFuncNo(i);
380 #pragma omp parallel for default(shared) private(i,time,theo,diff) schedule(dynamic,chunk) reduction(+:chisq)
383 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
385 diff =
fData.GetValue()->at(i) - theo;
386 chisq += diff*diff / theo;
463 N0 = par[
fRunInfo->GetNormParamNo()-1];
473 if (
fRunInfo->GetLifetimeParamNo() != -1)
474 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
480 if (
fRunInfo->GetBkgFitParamNo() == -1) {
487 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
491 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
492 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
503 Double_t normalizer = 1.0;
518 #pragma omp parallel for default(shared) private(i,time,theo,data) schedule(dynamic,chunk) reduction(-:mllh)
521 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
525 data =
fData.GetValue()->at(i);
528 std::cerr <<
">> PRunSingleHisto::CalcMaxLikelihood: **WARNING** NEGATIVE theory!!" << std::endl;
533 mllh += (theo-data) + data*log(data/theo);
539 return normalizer*2.0*mllh;
598 N0 = par[
fRunInfo->GetNormParamNo()-1];
608 if (
fRunInfo->GetLifetimeParamNo() != -1)
609 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
615 if (
fRunInfo->GetBkgFitParamNo() == -1) {
622 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
626 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
627 UInt_t funcNo =
fMsrInfo->GetFuncNo(i);
638 Double_t normalizer = 1.0;
653 #pragma omp parallel for default(shared) private(i,time,theo,data) schedule(dynamic,chunk) reduction(-:mllh)
656 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
660 data =
fData.GetValue()->at(i);
663 std::cerr <<
">> PRunSingleHisto::CalcMaxLikelihood: **WARNING** NEGATIVE theory!!" << std::endl;
668 mllh += data*log(data/theo);
672 return normalizer*2.0*mllh;
717 std::vector<Double_t> par;
719 for (UInt_t i=0; i<paramList->size(); i++)
720 par.push_back((*paramList)[i].fValue);
726 N0 = par[
fRunInfo->GetNormParamNo()-1];
736 if (
fRunInfo->GetLifetimeParamNo() != -1)
737 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
743 if (
fRunInfo->GetBkgFitParamNo() == -1) {
750 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
754 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
759 UInt_t size =
fData.GetValue()->size();
760 Double_t start =
fData.GetDataTimeStart();
761 Double_t resolution =
fData.GetDataTimeStep();
763 for (UInt_t i=0; i<size; i++) {
764 time = start +
static_cast<Double_t
>(i)*resolution;
847 TObjArray *tok =
nullptr;
848 TObjString *ostr =
nullptr;
853 tok = fitRange.Tokenize(
" \t");
855 if (tok->GetEntries() == 3) {
857 ostr =
dynamic_cast<TObjString*
>(tok->At(1));
858 str = ostr->GetString();
860 idx = str.First(
"+");
862 str.Remove(0, idx+1);
869 ostr =
dynamic_cast<TObjString*
>(tok->At(2));
870 str = ostr->GetString();
872 idx = str.First(
"-");
874 str.Remove(0, idx+1);
879 }
else if ((tok->GetEntries() > 3) && (tok->GetEntries() % 2 == 1)) {
880 Int_t pos = 2*(
fRunNo+1)-1;
882 if (pos + 1 >= tok->GetEntries()) {
883 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
884 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
887 ostr =
dynamic_cast<TObjString*
>(tok->At(pos));
888 str = ostr->GetString();
890 idx = str.First(
"+");
892 str.Remove(0, idx+1);
899 ostr =
dynamic_cast<TObjString*
>(tok->At(pos+1));
900 str = ostr->GetString();
902 idx = str.First(
"-");
904 str.Remove(0, idx+1);
911 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
912 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
1013 Bool_t success =
true;
1024 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
1025 std::cerr << std::endl;
1041 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
1042 histoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
1045 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **PANIC ERROR**:";
1046 std::cerr << std::endl <<
">> histoNo found = " << histoNo[i] <<
", which is NOT present in the data file!?!?";
1047 std::cerr << std::endl <<
">> Will quit :-(";
1048 std::cerr << std::endl;
1056 std::cout.precision(10);
1057 std::cout << std::endl <<
">> PRunSingleHisto::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ns)" << std::endl;
1060 if (!
GetProperT0(runData, globalBlock, histoNo)) {
1065 std::vector<PDoubleVector> forward;
1066 forward.resize(histoNo.size());
1067 for (UInt_t i=0; i<histoNo.size(); i++) {
1068 forward[i].resize(runData->
GetDataBin(histoNo[i])->size());
1069 forward[i] = *runData->
GetDataBin(histoNo[i]);
1078 if (
fRunInfo->GetRunNameSize() > 1) {
1080 std::vector<PDoubleVector> addForward;
1081 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1085 if (addRunData ==
nullptr) {
1086 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1087 std::cerr << std::endl;
1092 addForward.resize(histoNo.size());
1093 for (UInt_t j=0; j<histoNo.size(); j++) {
1094 addForward[j].resize(addRunData->
GetDataBin(histoNo[j])->size());
1095 addForward[j] = *addRunData->
GetDataBin(histoNo[j]);
1101 for (UInt_t k=0; k<histoNo.size(); k++) {
1102 addRunSize = addForward[k].size();
1103 for (UInt_t j=0; j<addRunSize; j++) {
1105 if ((
static_cast<Int_t
>(j)+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k]) >= 0) &&
1106 (j+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k]) < addRunSize)) {
1107 forward[k][j] += addForward[k][j+
static_cast<Int_t
>(
fAddT0s[i-1][k])-
static_cast<Int_t
>(
fT0s[k])];
1115 fForward.resize(forward[0].size());
1116 for (UInt_t i=0; i<
fForward.size(); i++) {
1121 for (UInt_t i=1; i<histoNo.size(); i++) {
1122 for (UInt_t j=0; j<runData->
GetDataBin(histoNo[i])->size(); j++) {
1125 fForward[j] += forward[i][j+
static_cast<Int_t
>(
fT0s[i])-
static_cast<Int_t
>(
fT0s[0])];
1139 Bool_t lifetimecorrection =
false;
1141 lifetimecorrection = plot->at(0).fLifeTimeCorrection;
1223 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1226 if (
fRunInfo->GetBkgRange(0) >= 0) {
1230 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1231 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1232 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareFitData(): **WARNING** Neither fix background nor background bins are given!";
1233 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1234 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1235 std::cerr << std::endl;
1240 for (UInt_t i=0; i<
fForward.size(); i++) {
1247 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1248 Double_t value = 0.0;
1249 Double_t normalizer = 1.0;
1261 value /= normalizer;
1262 fData.AppendValue(value);
1264 fData.AppendErrorValue(1.0/normalizer);
1266 fData.AppendErrorValue(TMath::Sqrt(value));
1269 value /= normalizer;
1270 fData.AppendValue(value);
1272 fData.AppendErrorValue(1.0/normalizer);
1274 fData.AppendErrorValue(TMath::Sqrt(value));
1310 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1311 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1315 Double_t dataNorm = 1.0, theoryNorm = 1.0;
1319 theoryNorm =
static_cast<Double_t
>(
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking)/
static_cast<Double_t
>(
fPacking);
1326 Int_t end = start + ((
fForward.size()-start)/packing)*packing;
1330 start = (
static_cast<Int_t
>(
fT0s[0])+offset) - ((
static_cast<Int_t
>(
fT0s[0])+offset)/packing)*packing;
1331 end = start + ((
fForward.size()-start)/packing)*packing;
1332 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **WARNING** data range was not provided, will try data range start = " << start <<
".";
1333 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1334 std::cerr << std::endl;
1344 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1345 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **ERROR** start data bin doesn't make any sense!";
1346 std::cerr << std::endl;
1350 if ((end < 0) || (end >
static_cast<Int_t
>(
fForward.size()))) {
1351 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **ERROR** end data bin doesn't make any sense!";
1352 std::cerr << std::endl;
1357 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1358 Double_t value = 0.0;
1360 fData.SetDataTimeStart(
fTimeResolution*((
static_cast<Double_t
>(start)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)));
1363 for (Int_t i=start; i<end; i++) {
1364 if (((i-start) % packing == 0) && (i != start)) {
1366 fData.AppendValue(value);
1368 fData.AppendErrorValue(1.0);
1370 fData.AppendErrorValue(TMath::Sqrt(value*dataNorm));
1381 std::vector<Double_t> par;
1383 for (UInt_t i=0; i<paramList->size(); i++)
1384 par.push_back((*paramList)[i].fValue);
1390 N0 = par[
fRunInfo->GetNormParamNo()-1];
1401 if (
fRunInfo->GetLifetimeParamNo() != -1)
1402 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
1408 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1410 if (
fRunInfo->GetBkgRange(0) >= 0) {
1414 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1415 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1416 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareRawViewData(): **WARNING** Neither fix background nor background bins are given!";
1417 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1418 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1419 std::cerr << std::endl;
1428 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
1433 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1440 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1442 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1446 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1450 Double_t theoryValue;
1451 for (UInt_t i=0; i<size; i++) {
1452 time =
fData.GetTheoryTimeStart() + i*
fData.GetTheoryTimeStep();
1454 if (fabs(theoryValue) > 1.0e10) {
1457 fData.AppendTheoryValue(N0*TMath::Exp(-time/tau)*(1.0+theoryValue)+bkg);
1499 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1500 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1503 if (
fMsrInfo->GetMsrPlotList()->at(0).fRRFPacking > 0) {
1504 packing =
fMsrInfo->GetMsrPlotList()->at(0).fRRFPacking;
1508 Double_t dataNorm = 1.0, theoryNorm = 1.0;
1512 theoryNorm =
static_cast<Double_t
>(
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking)/
static_cast<Double_t
>(
fPacking);
1518 Int_t t0 =
static_cast<Int_t
>(
fT0s[0]);
1523 Int_t end = start + ((
fForward.size()-start)/packing)*packing;
1528 start = (
static_cast<Int_t
>(
fT0s[0])+offset) - ((
static_cast<Int_t
>(
fT0s[0])+offset)/packing)*packing;
1529 end = start + ((
fForward.size()-start)/packing)*packing;
1530 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **WARNING** data range was not provided, will try data range start = " << start <<
".";
1531 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1532 std::cerr << std::endl;
1543 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
1544 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1545 std::cerr << std::endl;
1549 if ((end < 0) || (end >
static_cast<Int_t
>(
fForward.size()))) {
1550 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1551 std::cerr << std::endl;
1558 std::vector<Double_t> par;
1560 for (UInt_t i=0; i<paramList->size(); i++)
1561 par.push_back((*paramList)[i].fValue);
1567 N0 = par[
fRunInfo->GetNormParamNo()-1];
1578 if (
fRunInfo->GetLifetimeParamNo() != -1)
1579 tau = par[
fRunInfo->GetLifetimeParamNo()-1];
1585 if (
fRunInfo->GetBkgFitParamNo() == -1) {
1587 if (
fRunInfo->GetBkgRange(0) >= 0) {
1591 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
1592 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
1593 std::cerr << std::endl <<
">> PRunSingleHisto::PrepareViewData(): **WARNING** Neither fix background nor background bins are given!";
1594 std::cerr << std::endl <<
">> Will try the following: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
1595 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
1596 std::cerr << std::endl;
1605 bkg = par[
fRunInfo->GetBkgFitParamNo()-1];
1609 Double_t value = 0.0;
1610 Double_t expval = 0.0;
1611 Double_t rrf_val = 0.0;
1612 Double_t time = 0.0;
1615 fData.SetDataTimeStart(
fTimeResolution*((
static_cast<Double_t
>(start)-0.5) +
static_cast<Double_t
>(packing)/2.0 -
static_cast<Double_t
>(t0)));
1619 Double_t gammaRRF = 0.0, wRRF = 0.0, phaseRRF = 0.0;
1620 if (
fMsrInfo->GetMsrPlotList()->at(0).fRRFFreq == 0.0) {
1621 for (Int_t i=start; i<end; i++) {
1622 if (((i-start) % packing == 0) && (i != start)) {
1625 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;
1626 expval = TMath::Exp(+time/tau)/N0;
1627 fData.AppendValue(-1.0+expval*(value-bkg));
1628 fData.AppendErrorValue(expval*TMath::Sqrt(value*dataNorm));
1635 switch (
fMsrInfo->GetMsrPlotList()->at(0).fRRFUnit) {
1637 gammaRRF = TMath::TwoPi()*1.0e-3;
1640 gammaRRF = TMath::TwoPi();
1652 gammaRRF = TMath::TwoPi();
1655 wRRF = gammaRRF *
fMsrInfo->GetMsrPlotList()->at(0).fRRFFreq;
1656 phaseRRF =
fMsrInfo->GetMsrPlotList()->at(0).fRRFPhase / 180.0 * TMath::Pi();
1658 Double_t error = 0.0;
1659 for (Int_t i=start; i<end; i++) {
1660 if (((i-start) % packing == 0) && (i != start)) {
1661 fData.AppendValue(2.0*value/packing);
1662 fData.AppendErrorValue(expval*TMath::Sqrt(error/packing));
1667 expval = TMath::Exp(+time/tau)/N0;
1677 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1682 Double_t theoryValue;
1683 UInt_t size =
fForward.size()/packing;
1684 const Int_t factor = 8;
1685 UInt_t rebinRRF = 0;
1688 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1690 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1694 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1697 rebinRRF =
static_cast<UInt_t
>((TMath::Pi()/2.0/wRRF)/
fTimeResolution);
1698 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1699 fData.SetTheoryTimeStep(TMath::Pi()/2.0/wRRF/rebinRRF);
1702 for (UInt_t i=0; i<size; i++) {
1703 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1706 theoryValue *= 2.0*TMath::Cos(wRRF * time + phaseRRF);
1708 if (fabs(theoryValue) > 10.0) {
1711 fData.AppendTheoryValue(theoryValue);
1717 if (rebinRRF != 0) {
1718 Double_t dval = 0.0;
1720 for (UInt_t i=0; i<
fData.GetTheory()->size(); i++) {
1721 if ((i % rebinRRF == 0) && (i != 0)) {
1722 theo.push_back(dval/rebinRRF);
1725 dval +=
fData.GetTheory()->at(i);
1727 fData.SetTheoryTimeStart(
fData.GetTheoryTimeStart()+
static_cast<Double_t
>(rebinRRF-1)*
fData.GetTheoryTimeStep()/2.0);
1728 fData.SetTheoryTimeStep(rebinRRF*
fData.GetTheoryTimeStep());
1729 fData.ReplaceTheory(theo);
1802 fT0s.resize(histoNo.size());
1803 for (UInt_t i=0; i<
fT0s.size(); i++) {
1808 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1814 if (
fT0s[i] == -1.0) {
1820 for (UInt_t i=0; i<histoNo.size(); i++) {
1821 if (
fT0s[i] == -1.0) {
1822 if (runData->
GetT0Bin(histoNo[i]) > 0.0) {
1830 for (UInt_t i=0; i<histoNo.size(); i++) {
1831 if (
fT0s[i] == -1.0) {
1835 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1836 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1837 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(histoNo[i]);
1838 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1839 std::cerr << std::endl;
1844 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
1845 if ((
fT0s[i] < 0.0) || (
fT0s[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1846 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[i] <<
") doesn't make any sense!";
1847 std::cerr << std::endl;
1853 if (
fRunInfo->GetRunNameSize() > 1) {
1856 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1860 if (addRunData ==
nullptr) {
1861 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1862 std::cerr << std::endl;
1868 fAddT0s[i-1].resize(histoNo.size());
1869 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1874 for (UInt_t j=0; j<
fRunInfo->GetT0BinSize(); j++) {
1879 for (UInt_t j=0; j<histoNo.size(); j++) {
1881 if (addRunData->
GetT0Bin(histoNo[j]) > 0.0) {
1888 for (UInt_t j=0; j<histoNo.size(); j++) {
1889 if (
fAddT0s[i-1][j] == -1.0) {
1893 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1894 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1895 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(histoNo[j]);
1896 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1897 std::cerr << std::endl;
1902 for (UInt_t j=0; j<
fRunInfo->GetForwardHistoNoSize(); j++) {
1903 if ((
fAddT0s[i-1][j] < 0.0) || (
fAddT0s[i-1][j] >
static_cast<Int_t
>(addRunData->
GetDataBin(histoNo[j])->size()))) {
1904 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperT0(): **ERROR** addt0 data bin (" <<
fAddT0s[i-1][j] <<
") doesn't make any sense!";
1905 std::cerr << std::endl;
1972 start =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1975 end =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1981 start =
static_cast<Int_t
>(
fT0s[0])+offset;
1983 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** data range was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start <<
".";
1984 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1985 std::cerr << std::endl;
1990 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** data range was not provided, will try data range end = " << end <<
".";
1991 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1992 std::cerr << std::endl;
2003 if ((start < 0) || (start >
static_cast<Int_t
>(
fForward.size()))) {
2004 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **ERROR** start data bin (" << start <<
") doesn't make any sense!";
2005 std::cerr << std::endl;
2010 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **ERROR** end data bin (" << end <<
") doesn't make any sense!";
2011 std::cerr << std::endl;
2014 if (end >
static_cast<Int_t
>(
fForward.size())) {
2015 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange(): **WARNING** end data bin (" << end <<
") > histo length (" <<
fForward.size() <<
").";
2016 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
2017 std::cerr << std::endl;
2018 end =
static_cast<Int_t
>(
fForward.size())-1;
2029 std::cerr << std::endl <<
">> PRunSingleHisto::GetProperDataRange **WARNING** needed to shift forward lgb,";
2030 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
2124 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
2125 std::cerr <<
">> Will set it to fgb/lgb which given in time is: " <<
fFitStartTime <<
"..." <<
fFitEndTime <<
" (usec)" << std::endl;
2178 UInt_t paramNo =
fRunInfo->GetNormParamNo();
2179 if (paramNo > 10000)
2186 if (paramNo > param->size()) {
2187 std::cerr << std::endl <<
">> PRunSingleHisto::EstimateN0: **ERROR** found parameter number " << paramNo <<
", which is larger than the number of parameters = " << param->size() << std::endl;
2192 if (param->at(paramNo-1).fStep == 0.0)
2198 Int_t paramNoBkg =
fRunInfo->GetBkgFitParamNo();
2199 Bool_t scaleBkg =
true;
2200 Double_t bkg=0.0, errBkg=1.0;
2201 if ((paramNoBkg > 10000) || (paramNoBkg == -1)) {
2204 if (paramNoBkg-1 <
static_cast<Int_t
>(param->size())) {
2205 bkg = param->at(paramNoBkg-1).fValue;
2206 errBkg = param->at(paramNoBkg-1).fStep;
2214 UInt_t t0 =
static_cast<UInt_t
>(round(
fT0s[0]));
2215 Double_t dval = 0.0;
2217 Double_t denom = 0.0;
2221 for (UInt_t i=t0; i<
fForward.size(); i++) {
2222 xx = exp(-dt*
static_cast<Double_t
>(i-t0)/tau);
2227 for (UInt_t i=t0; i<
fForward.size(); i++) {
2228 xx = exp(-dt*
static_cast<Double_t
>(i-t0)/tau);
2231 denom += xx*xx/dval;
2233 Double_t N0 = nom/denom;
2241 Double_t rescale = 1;
2242 if ((param->at(paramNo-1).fValue != 0.0) && scaleBkg) {
2243 rescale = N0 / param->at(paramNo-1).fValue;
2248 std::cout <<
">> PRunSingleHisto::EstimateN0: found N0=" << param->at(paramNo-1).fValue <<
", will set it to N0=" << N0 << std::endl;
2250 std::cout <<
">> PRunSingleHisto::EstimateN0: found Bkg=" << param->at(paramNoBkg-1).fValue <<
", will set it to Bkg=" << bkg << std::endl;
2251 fMsrInfo->SetMsrParamValue(paramNo-1, N0);
2252 fMsrInfo->SetMsrParamStep(paramNo-1, sqrt(fabs(N0)));
2254 fMsrInfo->SetMsrParamValue(paramNoBkg-1, bkg);
2255 fMsrInfo->SetMsrParamStep(paramNoBkg-1, errBkg);
2312 Double_t beamPeriod = 0.0;
2315 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
2317 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
2319 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
2325 Int_t start =
fRunInfo->GetBkgRange(0);
2326 Int_t end =
fRunInfo->GetBkgRange(1);
2328 std::cout << std::endl <<
"PRunSingleHisto::EstimatBkg(): end = " << end <<
" > start = " << start <<
"! Will swap them!";
2335 if (beamPeriod != 0.0) {
2337 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
2340 std::cout << std::endl <<
"PRunSingleHisto::EstimatBkg(): Background " << start <<
", " << end;
2347 std::cerr << std::endl <<
">> PRunSingleHisto::EstimatBkg(): **ERROR** background bin values out of bound!";
2348 std::cerr << std::endl <<
">> histo lengths = " <<
fForward.size();
2349 std::cerr << std::endl <<
">> background start = " << start;
2350 std::cerr << std::endl;
2356 std::cerr << std::endl <<
">> PRunSingleHisto::EstimatBkg(): **ERROR** background bin values out of bound!";
2357 std::cerr << std::endl <<
">> histo lengths = " <<
fForward.size();
2358 std::cerr << std::endl <<
">> background end = " << end;
2359 std::cerr << std::endl;
2367 for (UInt_t i=start; i<end; i++)
2369 bkg /=
static_cast<Double_t
>(end - start + 1);
2428 Bool_t willScale =
true;
2431 for (UInt_t i=0; i<cmd->size(); i++) {
2432 if (cmd->at(i).fLine.Contains(
"SCALE_N0_BKG", TString::kIgnoreCase)) {
2433 TObjArray *tokens =
nullptr;
2434 TObjString *ostr =
nullptr;
2436 tokens = cmd->at(i).fLine.Tokenize(
" \t");
2437 if (tokens->GetEntries() != 2) {
2438 std::cerr << std::endl <<
">> PRunSingleHisto::IsScaleN0AndBkg(): **WARNING** Found uncorrect 'SCALE_N0_BKG' command, will ignore it.";
2439 std::cerr << std::endl <<
">> Allowed commands: SCALE_N0_BKG TRUE | FALSE" << std::endl;
2442 ostr =
dynamic_cast<TObjString*
>(tokens->At(1));
2443 str = ostr->GetString();
2444 if (!str.CompareTo(
"FALSE", TString::kIgnoreCase)) {
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)