48#include "PStringUtils.h"
112 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **SEVERE ERROR**: Couldn't find any RRF packing information!";
113 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
114 std::cerr << std::endl;
124 if (
fRunInfo->GetAlphaParamNo() == -1) {
125 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** no alpha parameter given! This is needed for an asymmetry fit!";
126 std::cerr << std::endl;
131 if ((
fRunInfo->GetAlphaParamNo() < 0) || (
fRunInfo->GetAlphaParamNo() >
static_cast<Int_t
>(param->size()))) {
132 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** alpha parameter no = " << fRunInfo->GetAlphaParamNo();
133 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
134 std::cerr << std::endl;
139 Bool_t alphaFixedToOne =
false;
140 if (((*param)[
fRunInfo->GetAlphaParamNo()-1].fStep == 0.0) &&
141 ((*param)[
fRunInfo->GetAlphaParamNo()-1].fValue == 1.0))
142 alphaFixedToOne =
true;
145 Bool_t betaFixedToOne =
false;
147 betaFixedToOne = true;
148 }
else if ((
fRunInfo->GetBetaParamNo() < 0) || (
fRunInfo->GetBetaParamNo() >
static_cast<Int_t
>(param->size()))) {
149 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** beta parameter no = " << fRunInfo->GetBetaParamNo();
150 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
151 std::cerr << std::endl;
155 if (((*param)[fRunInfo->GetBetaParamNo()-1].fStep == 0.0) &&
156 ((*param)[fRunInfo->GetBetaParamNo()-1].fValue == 1.0))
157 betaFixedToOne = true;
161 if (alphaFixedToOne && betaFixedToOne)
163 else if (!alphaFixedToOne && betaFixedToOne)
165 else if (alphaFixedToOne && !betaFixedToOne)
217 Double_t chisq = 0.0;
219 Double_t asymFcnValue = 0.0;
223 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
239 a = par[
fRunInfo->GetAlphaParamNo()-1];
251 b = par[
fRunInfo->GetBetaParamNo()-1];
261 a = par[
fRunInfo->GetAlphaParamNo()-1];
269 b = par[
fRunInfo->GetBetaParamNo()-1];
293 #pragma omp parallel for default(shared) private(i,time,diff,asymFcnValue,f) schedule(dynamic,chunk) reduction(+:chisq)
296 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
298 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0));
299 diff =
fData.GetValue()->at(i) - asymFcnValue;
300 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
344 std::cout << std::endl <<
"PRunAsymmetryRRF::CalcMaxLikelihood(): not implemented yet ..." << std::endl;
401 std::vector<std::string> tok = PStringUtils::Split(fitRange.Data(),
" \t");
403 if (tok.size() == 3) {
407 idx = str.First(
"+");
409 str.Remove(0, idx+1);
418 idx = str.First(
"-");
420 str.Remove(0, idx+1);
425 }
else if ((tok.size() > 3) && (tok.size() % 2 == 1)) {
426 UInt_t pos = 2*(
fRunNo+1)-1;
428 if (pos + 1 >= tok.size()) {
429 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
430 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
435 idx = str.First(
"+");
437 str.Remove(0, idx+1);
446 idx = str.First(
"-");
448 str.Remove(0, idx+1);
455 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
456 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
517 std::vector<Double_t> par;
519 for (UInt_t i=0; i<paramList->size(); i++)
520 par.push_back((*paramList)[i].fValue);
523 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
528 Double_t asymFcnValue = 0.0;
531 for (UInt_t i=0; i<
fData.GetValue()->size(); i++) {
532 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
539 a = par[
fRunInfo->GetAlphaParamNo()-1];
547 asymFcnValue = (f*(a+1.0)-(a-1.0))/((a+1.0)-f*(a-1.0));
551 b = par[
fRunInfo->GetBetaParamNo()-1];
559 asymFcnValue = f*(b+1.0)/(2.0-f*(b-1.0));
563 a = par[
fRunInfo->GetAlphaParamNo()-1];
571 b = par[
fRunInfo->GetBetaParamNo()-1];
579 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0));
585 fData.AppendTheoryValue(asymFcnValue);
636 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
637 std::cerr << std::endl;
654 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
655 forwardHistoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
657 if (!runData->
IsPresent(forwardHistoNo[i])) {
658 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
659 std::cerr << std::endl <<
">> forwardHistoNo found = " << forwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
660 std::cerr << std::endl <<
">> Will quit :-(";
661 std::cerr << std::endl;
663 forwardHistoNo.clear();
664 backwardHistoNo.clear();
668 for (UInt_t i=0; i<
fRunInfo->GetBackwardHistoNoSize(); i++) {
669 backwardHistoNo.push_back(
fRunInfo->GetBackwardHistoNo(i));
671 if (!runData->
IsPresent(backwardHistoNo[i])) {
672 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
673 std::cerr << std::endl <<
">> backwardHistoNo found = " << backwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
674 std::cerr << std::endl <<
">> Will quit :-(";
675 std::cerr << std::endl;
677 forwardHistoNo.clear();
678 backwardHistoNo.clear();
685 std::cout.precision(10);
686 std::cout << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ns)" << std::endl;
689 if (!
GetProperT0(runData, globalBlock, forwardHistoNo, backwardHistoNo)) {
694 std::vector<PDoubleVector> forward, backward;
695 forward.resize(forwardHistoNo.size());
696 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
697 forward[i].resize(runData->
GetDataBin(forwardHistoNo[i])->size());
698 forward[i] = *runData->
GetDataBin(forwardHistoNo[i]);
705 backward.resize(backwardHistoNo.size());
706 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
707 backward[i].resize(runData->
GetDataBin(backwardHistoNo[i])->size());
708 backward[i] = *runData->
GetDataBin(backwardHistoNo[i]);
717 if (
fRunInfo->GetRunNameSize() > 1) {
719 std::vector<PDoubleVector> addForward, addBackward;
720 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
723 if (addRunData ==
nullptr) {
724 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
725 std::cerr << std::endl;
731 addForward.resize(forwardHistoNo.size());
732 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
733 addForward[j].resize(addRunData->
GetDataBin(forwardHistoNo[j])->size());
734 addForward[j] = *addRunData->
GetDataBin(forwardHistoNo[j]);
738 addBackward.resize(backwardHistoNo.size());
739 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
740 addBackward[j].resize(addRunData->
GetDataBin(backwardHistoNo[j])->size());
741 addBackward[j] = *addRunData->
GetDataBin(backwardHistoNo[j]);
747 for (UInt_t k=0; k<forwardHistoNo.size(); k++) {
748 addRunSize = addRunData->
GetDataBin(forwardHistoNo[k])->size();
749 for (UInt_t j=0; j<addRunData->
GetDataBin(forwardHistoNo[k])->size(); j++) {
751 if (((Int_t)j+(Int_t)
fAddT0s[i-1][2*k]-(Int_t)
fT0s[2*k] >= 0) && (j+(Int_t)
fAddT0s[i-1][2*k]-(Int_t)
fT0s[2*k] < addRunSize)) {
752 forward[k][j] += addForward[k][j+(Int_t)
fAddT0s[i-1][2*k]-(Int_t)
fT0s[2*k]];
758 for (UInt_t k=0; k<backwardHistoNo.size(); k++) {
759 addRunSize = addRunData->
GetDataBin(backwardHistoNo[k])->size();
760 for (UInt_t j=0; j<addRunData->
GetDataBin(backwardHistoNo[k])->size(); j++) {
762 if (((Int_t)j+(Int_t)
fAddT0s[i-1][2*k+1]-(Int_t)
fT0s[2*k+1] >= 0) && (j+(Int_t)
fAddT0s[i-1][2*k+1]-(Int_t)
fT0s[2*k+1] < addRunSize)) {
763 backward[k][j] += addBackward[k][j+(Int_t)
fAddT0s[i-1][2*k+1]-(Int_t)
fT0s[2*k+1]];
773 for (UInt_t i=0; i<
fForward.size(); i++) {
779 for (UInt_t i=1; i<forwardHistoNo.size(); i++) {
780 for (UInt_t j=0; j<runData->
GetDataBin(forwardHistoNo[i])->size(); j++) {
789 for (UInt_t i=1; i<backwardHistoNo.size(); i++) {
790 for (UInt_t j=0; j<runData->
GetDataBin(backwardHistoNo[i])->size(); j++) {
800 if (
fRunInfo->GetBkgRange(0) >= 0) {
804 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
805 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
806 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.1), 2);
807 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.6), 3);
808 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **WARNING** Neither fix background nor background bins are given!";
809 std::cerr << std::endl <<
">> Will try the following:";
810 std::cerr << std::endl <<
">> forward: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
811 std::cerr << std::endl <<
">> backward: bkg start = " <<
fRunInfo->GetBkgRange(2) <<
", bkg end = " <<
fRunInfo->GetBkgRange(3);
812 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
813 std::cerr << std::endl;
822 UInt_t histoNo[2] = {forwardHistoNo[0], backwardHistoNo[0]};
847 forwardHistoNo.clear();
848 backwardHistoNo.clear();
875 for (UInt_t i=0; i<
fForward.size(); i++) {
918 Double_t beamPeriod = 0.0;
921 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
923 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
925 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
931 UInt_t start[2] = {
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(0)),
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(2))};
932 UInt_t end[2] = {
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(1)),
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(3))};
933 for (UInt_t i=0; i<2; i++) {
934 if (end[i] < start[i]) {
935 std::cout << std::endl <<
"PRunAsymmetryRRF::SubtractEstimatedBkg(): end = " << end[i] <<
" > start = " << start[i] <<
"! Will swap them!";
936 UInt_t keep = end[i];
943 for (UInt_t i=0; i<2; i++) {
944 if (beamPeriod != 0.0) {
945 Double_t timeBkg =
static_cast<Double_t
>(end[i]-start[i])*
fTimeResolution;
946 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
948 end[i] = start[i] +
static_cast<UInt_t
>((fullCycles*beamPeriod)/
fTimeResolution);
949 std::cout <<
"PRunAsymmetryRRF::SubtractEstimatedBkg(): Background " << start[i] <<
", " << end[i] << std::endl;
950 if (end[i] == start[i])
951 end[i] =
fRunInfo->GetBkgRange(2*i+1);
957 std::cerr << std::endl <<
">> PRunAsymmetryRRF::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
958 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForward.size() <<
"/" <<
fBackward.size() <<
").";
959 std::cerr << std::endl <<
">> background start (f/b) = (" << start[0] <<
"/" << start[1] <<
").";
965 std::cerr << std::endl <<
">> PRunAsymmetryRRF::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
966 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForward.size() <<
"/" <<
fBackward.size() <<
").";
967 std::cerr << std::endl <<
">> background end (f/b) = (" << end[0] <<
"/" << end[1] <<
").";
972 Double_t bkg[2] = {0.0, 0.0};
973 Double_t errBkg[2] = {0.0, 0.0};
976 for (UInt_t i=start[0]; i<=end[0]; i++)
978 errBkg[0] = TMath::Sqrt(bkg[0])/(end[0] - start[0] + 1);
979 bkg[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
980 std::cout << std::endl <<
">> estimated forward histo background: " << bkg[0];
983 for (UInt_t i=start[1]; i<=end[1]; i++)
985 errBkg[1] = TMath::Sqrt(bkg[1])/(end[1] - start[1] + 1);
986 bkg[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
987 std::cout << std::endl <<
">> estimated backward histo background: " << bkg[1] << std::endl;
990 Double_t errVal = 0.0;
991 for (UInt_t i=0; i<
fForward.size(); i++) {
993 errVal = TMath::Sqrt(
fForward[i]+errBkg[0]*errBkg[0]);
998 errVal = TMath::Sqrt(
fBackward[i]+errBkg[1]*errBkg[1]);
1005 for (UInt_t i=0; i<
fForward.size(); i++) {
1010 fRunInfo->SetBkgEstimated(bkg[0], 0);
1011 fRunInfo->SetBkgEstimated(bkg[1], 1);
1051 Int_t lgb_offset =
fGoodBins[1]-
static_cast<Int_t
>(
fT0s[0])+fgbOffset;
1052 if (lgb_offset <
fGoodBins[3]-
static_cast<Int_t
>(
fT0s[1])+fgbOffset)
1053 lgb_offset =
fGoodBins[3]-
static_cast<Int_t
>(
fT0s[1])+fgbOffset;
1055 Int_t fgb =
static_cast<Int_t
>(
fT0s[0])+fgbOffset;
1058 Int_t lgb = fgb + lgb_offset;
1063 Int_t dt0 =
static_cast<Int_t
>(
fT0s[0])-
static_cast<Int_t
>(
fT0s[1]);
1067 Double_t asymVal, asymValErr;
1068 Double_t ff, bb, eff, ebb;
1070 for (Int_t i=fgb; i<lgb; i++) {
1079 asymVal = (ff-bb)/(ff+bb);
1082 asym.push_back(asymVal);
1085 if ((asymVal != 0.0) && (ff+bb) > 0.0)
1086 asymValErr = 2.0/pow((ff+bb),2.0)*sqrt(bb*bb*eff*eff+ff*ff*ebb*ebb);
1089 asymErr.push_back(asymValErr);
1094 Double_t wRRF = globalBlock->
GetRRFFreq(
"Mc");
1095 Double_t phaseRRF = globalBlock->
GetRRFPhase()*TMath::TwoPi()/180.0;
1097 Double_t startTime =
fTimeResolution *
static_cast<Double_t
>(fgbOffset);
1099 for (UInt_t i=0; i<asym.size(); i++) {
1101 asym[i] *= 2.0*cos(wRRF*time+phaseRRF);
1107 for (UInt_t i=0; i<asym.size(); i++) {
1118 for (UInt_t i=0; i<asymErr.size(); i++) {
1120 asymRRFErr.push_back(sqrt(2.0*asymValErr)/
fRRFPacking);
1123 asymValErr += asymErr[i]*asymErr[i];
1129 for (UInt_t i=0; i<asymRRF.size(); i++) {
1130 fData.AppendValue(asymRRF[i]);
1131 fData.AppendErrorValue(asymRRFErr[i]);
1180 std::vector<Double_t> par;
1182 for (UInt_t i=0; i<paramList->size(); i++)
1183 par.push_back((*paramList)[i].fValue);
1188 Int_t t0[2] = {
static_cast<Int_t
>(
fT0s[0]),
static_cast<Int_t
>(
fT0s[1])};
1192 if (start[0]-t0[0] != start[1]-t0[1]) {
1193 if (abs(start[0]-t0[0]) > abs(start[1]-t0[1])) {
1195 fgb[1] = t0[1] + start[0]-t0[0];
1196 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **WARNING** needed to shift backward fgb from ";
1197 std::cerr << start[1] <<
" to " << fgb[1] << std::endl;
1199 fgb[0] = t0[0] + start[1]-t0[1];
1201 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **WARNING** needed to shift forward fgb from ";
1202 std::cerr << start[0] <<
" to " << fgb[0] << std::endl;
1212 UInt_t noOfBins0 = runData->
GetDataBin(histoNo[0])->size()-start[0];
1213 UInt_t noOfBins1 = runData->
GetDataBin(histoNo[1])->size()-start[1];
1214 if (noOfBins0 > noOfBins1)
1215 noOfBins0 = noOfBins1;
1216 end[0] = start[0] + noOfBins0;
1217 end[1] = start[1] + noOfBins0;
1220 for (UInt_t i=0; i<2; i++) {
1222 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1223 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1224 std::cerr << std::endl;
1228 if ((end[i] < 0) || (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1229 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1230 std::cerr << std::endl;
1234 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1235 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
1236 std::cerr << std::endl;
1248 Double_t asym, error;
1249 Double_t f, b, ef, eb, alpha = 1.0, beta = 1.0;
1259 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1271 beta = par[
fRunInfo->GetBetaParamNo()-1];
1281 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1289 beta = par[
fRunInfo->GetBetaParamNo()-1];
1302 Int_t dtBin = start[1]-start[0];
1303 for (Int_t i=start[0]; i<end[0]; i++) {
1311 asym = (alpha*f-b) / (alpha*beta*f+b);
1314 asymVec.push_back(asym);
1317 error = 2.0/((f+b)*(f+b))*TMath::Sqrt(b*b*ef*ef+eb*eb*f*f);
1320 asymErr.push_back(error);
1326 Double_t wRRF = globalBlock->
GetRRFFreq(
"Mc");
1327 Double_t phaseRRF = globalBlock->
GetRRFPhase()*TMath::TwoPi()/180.0;
1328 Double_t startTime=
fTimeResolution*(
static_cast<Double_t
>(start[0])-t0[0]);
1329 Double_t time = 0.0;
1330 for (UInt_t i=0; i<asymVec.size(); i++) {
1332 asymVec[i] *= 2.0*cos(wRRF*time+phaseRRF);
1335 Double_t dval = 0.0;
1337 for (UInt_t i=0; i<asymVec.size(); i++) {
1348 for (UInt_t i=0; i<asymErr.size(); i++) {
1353 dval += asymErr[i]*asymErr[i];
1359 for (UInt_t i=0; i<asymRRF.size(); i++) {
1360 fData.AppendValue(asymRRF[i]);
1361 fData.AppendErrorValue(asymRRFErr[i]);
1378 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1383 UInt_t size = runData->
GetDataBin(histoNo[0])->size();
1385 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1387 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1391 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1394 for (UInt_t i=0; i<size; i++) {
1395 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1397 if (fabs(dval) > 10.0) {
1400 fData.AppendTheoryValue(dval);
1436 size_t size = 2*forwardHistoNo.size();
1437 if (backwardHistoNo.size() > forwardHistoNo.size())
1438 size = 2*backwardHistoNo.size();
1440 for (UInt_t i=0; i<
fT0s.size(); i++) {
1445 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1451 if (
fT0s[i] == -1.0) {
1457 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1458 if (
fT0s[2*i] == -1.0)
1459 if (runData->
GetT0Bin(forwardHistoNo[i]) > 0.0) {
1464 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1465 if (
fT0s[2*i+1] == -1.0)
1466 if (runData->
GetT0Bin(backwardHistoNo[i]) > 0.0) {
1473 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1474 if (
fT0s[2*i] == -1.0) {
1478 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1479 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1480 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(forwardHistoNo[i]);
1481 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1482 std::cerr << std::endl;
1485 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1486 if (
fT0s[2*i+1] == -1.0) {
1490 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1491 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1492 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[i]);
1493 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1494 std::cerr << std::endl;
1499 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1500 if ((
fT0s[2*i] < 0) || (
fT0s[2*i] >
static_cast<Int_t
>(runData->
GetDataBin(forwardHistoNo[i])->size()))) {
1501 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[2*i] <<
") doesn't make any sense!";
1502 std::cerr << std::endl <<
">> forwardHistoNo " << forwardHistoNo[i];
1503 std::cerr << std::endl;
1507 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1508 if ((
fT0s[2*i+1] < 0) || (
fT0s[2*i+1] >
static_cast<Int_t
>(runData->
GetDataBin(backwardHistoNo[i])->size()))) {
1509 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** t0 data bin (" <<
fT0s[2*i+1] <<
") doesn't make any sense!";
1510 std::cerr << std::endl <<
">> backwardHistoNo " << backwardHistoNo[i];
1511 std::cerr << std::endl;
1517 if (
fRunInfo->GetRunNameSize() > 1) {
1520 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1523 if (addRunData ==
nullptr) {
1524 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1525 std::cerr << std::endl;
1532 fAddT0s[i-1].resize(2*forwardHistoNo.size());
1533 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1538 for (Int_t j=0; j<
fRunInfo->GetAddT0BinSize(i-1); j++) {
1543 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1544 if (
fAddT0s[i-1][2*j] == -1.0)
1545 if (addRunData->
GetT0Bin(forwardHistoNo[j]) > 0.0) {
1550 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1551 if (
fAddT0s[i-1][2*j+1] == -1.0)
1552 if (addRunData->
GetT0Bin(backwardHistoNo[j]) > 0.0) {
1559 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1560 if (
fAddT0s[i-1][2*j] == -1.0) {
1564 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1565 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1566 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(forwardHistoNo[j]);
1567 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1568 std::cerr << std::endl;
1571 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1572 if (
fAddT0s[i-1][2*j+1] == -1.0) {
1576 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1577 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1578 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[j]);
1579 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1580 std::cerr << std::endl;
1611 if (start[0] == -1) {
1612 start[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1614 if (start[1] == -1) {
1615 start[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(2);
1618 end[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1621 end[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(3);
1624 Double_t t0[2] = {
fT0s[0],
fT0s[1]};
1629 start[0] =
static_cast<Int_t
>(t0[0])+offset;
1630 fRunInfo->SetDataRange(start[0], 0);
1631 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[0] <<
".";
1632 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1633 std::cerr << std::endl;
1636 start[1] =
static_cast<Int_t
>(t0[1])+offset;
1637 fRunInfo->SetDataRange(start[1], 2);
1638 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[1] <<
".";
1639 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1640 std::cerr << std::endl;
1643 end[0] = runData->
GetDataBin(histoNo[0])->size();
1645 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range end = " << end[0] <<
".";
1646 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1647 std::cerr << std::endl;
1650 end[1] = runData->
GetDataBin(histoNo[1])->size();
1652 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range end = " << end[1] <<
".";
1653 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1654 std::cerr << std::endl;
1659 for (UInt_t i=0; i<2; i++) {
1660 if (end[i] < start[i]) {
1661 Int_t keep = end[i];
1666 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1667 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** start data bin doesn't make any sense!";
1668 std::cerr << std::endl;
1673 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** end data bin (" << end[i] <<
") doesn't make any sense!";
1674 std::cerr << std::endl;
1677 if (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())) {
1678 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** end data bin (" << end[i] <<
") > histo length (" << (Int_t)runData->
GetDataBin(histoNo[i])->size() <<
").";
1679 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
1680 std::cerr << std::endl;
1681 end[i] =
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())-1;
1684 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1685 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** t0 data bin doesn't make any sense!";
1686 std::cerr << std::endl;
1692 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) > fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1693 start[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(start[0]) - t0[0]);
1694 end[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(end[0]) - t0[0]);
1695 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange **WARNING** needed to shift backward data range.";
1696 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(2) <<
", " <<
fRunInfo->GetDataRange(3);
1697 std::cerr << std::endl <<
">> used : " << start[1] <<
", " << end[1];
1698 std::cerr << std::endl;
1700 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) < fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1701 start[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(start[1]) - t0[1]);
1702 end[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(end[1]) - t0[1]);
1703 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange **WARNING** needed to shift forward data range.";
1704 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(0) <<
", " <<
fRunInfo->GetDataRange(1);
1705 std::cerr << std::endl <<
">> used : " << start[0] <<
", " << end[0];
1706 std::cerr << std::endl;
1719 std::cerr << std::endl <<
">> PRunAsymmetry::GetProperDataRange **WARNING** needed to shift forward lgb,";
1720 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
1726 std::cerr << std::endl <<
">> PRunAsymmetry::GetProperDataRange **WARNING** needed to shift backward lgb,";
1727 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
1777 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
1778 std::cerr <<
">> Will set it to fgb/lgb which given in time is: " <<
fFitStartTime <<
"..." <<
fFitEndTime <<
" (usec)" << 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 MSR_PARAM_FUN_OFFSET
Offset added to function indices for parameter parsing.
std::vector< PMsrParamStructure > PMsrParamList
#define ACCEL_PERIOD_PSI
PSI (Paul Scherrer Institute) accelerator cycle: 19.75 ns.
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)
virtual Double_t GetRRFPhase()
virtual Double_t GetRRFFreq(const char *unit)
MSR file parser and manager for the musrfit framework.
virtual PMsrParamList * GetMsrParamList()
Returns pointer to fit parameter list.
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
virtual void GetProperFitRange(PMsrGlobalBlock *globalBlock)
Determines the proper fit range from global block.
PRunAsymmetryRRF()
Default constructor.
virtual UInt_t GetNoOfFitBins()
Returns the number of bins used in the fit.
Int_t fGoodBins[4]
Good bin boundaries: [0]=forward first, [1]=forward last, [2]=backward first, [3]=backward last.
PDoubleVector fForwardErr
Forward detector histogram errors.
virtual Double_t CalcChiSquareExpected(const std::vector< Double_t > &par)
Calculates expected chi-square (for statistical analysis).
virtual Bool_t GetProperDataRange(PRawRunData *runData, UInt_t histoNo[2])
Retrieves proper data range for histograms.
Bool_t fTheoAsData
If true, theory calculated only at data points; if false, extra points for nicer Fourier transforms.
virtual Bool_t PrepareViewData(PRawRunData *runData, UInt_t histoNo[2])
Prepares RRF data for viewing/plotting.
Bool_t SubtractEstimatedBkg()
Estimates and subtracts background from histograms.
virtual ~PRunAsymmetryRRF()
Destructor.
virtual Bool_t PrepareData()
Prepares all data for RRF fitting or viewing.
Int_t fEndTimeBin
Last bin index for fitting (after RRF transformation)
Int_t fRRFPacking
RRF packing factor from GLOBAL block (required for RRF analysis)
Bool_t SubtractFixBkg()
Subtracts fixed background from histograms.
virtual Bool_t GetProperT0(PRawRunData *runData, PMsrGlobalBlock *globalBlock, PUIntVector &forwardHisto, PUIntVector &backwardHistoNo)
Retrieves proper t0 values for all histograms.
virtual void SetFitRangeBin(const TString fitRange)
Sets the fit range in bins (can be changed dynamically via COMMAND block).
PDoubleVector fForward
Forward detector histogram data.
UInt_t fNoOfFitBins
Number of bins included in the fit after RRF packing.
PDoubleVector fBackward
Backward detector histogram data.
UInt_t fAlphaBetaTag
Tag indicating α/β configuration: 1=both unity, 2=α free/β unity, 3=α unity/β free,...
virtual Bool_t PrepareFitData()
Prepares RRF data specifically for fitting.
virtual void CalcTheory()
Calculates theoretical RRF asymmetry function.
virtual Double_t CalcChiSquare(const std::vector< Double_t > &par)
Calculates chi-square for the RRF asymmetry fit.
virtual void CalcNoOfFitBins()
Calculates the number of bins to be fitted.
virtual Double_t CalcMaxLikelihood(const std::vector< Double_t > &par)
Calculates maximum likelihood estimator.
Int_t fStartTimeBin
First bin index for fitting (after RRF transformation)
PDoubleVector fBackwardErr
Backward detector histogram errors.
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)
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.
Raw data file reader and format converter for μSR data.