45#include <TObjString.h>
111 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **SEVERE ERROR**: Couldn't find any RRF packing information!";
112 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
113 std::cerr << std::endl;
123 if (
fRunInfo->GetAlphaParamNo() == -1) {
124 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** no alpha parameter given! This is needed for an asymmetry fit!";
125 std::cerr << std::endl;
130 if ((
fRunInfo->GetAlphaParamNo() < 0) || (
fRunInfo->GetAlphaParamNo() >
static_cast<Int_t
>(param->size()))) {
131 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** alpha parameter no = " << fRunInfo->GetAlphaParamNo();
132 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
133 std::cerr << std::endl;
138 Bool_t alphaFixedToOne =
false;
139 if (((*param)[
fRunInfo->GetAlphaParamNo()-1].fStep == 0.0) &&
140 ((*param)[
fRunInfo->GetAlphaParamNo()-1].fValue == 1.0))
141 alphaFixedToOne =
true;
144 Bool_t betaFixedToOne =
false;
146 betaFixedToOne = true;
147 }
else if ((
fRunInfo->GetBetaParamNo() < 0) || (
fRunInfo->GetBetaParamNo() >
static_cast<Int_t
>(param->size()))) {
148 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** beta parameter no = " << fRunInfo->GetBetaParamNo();
149 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
150 std::cerr << std::endl;
154 if (((*param)[fRunInfo->GetBetaParamNo()-1].fStep == 0.0) &&
155 ((*param)[fRunInfo->GetBetaParamNo()-1].fValue == 1.0))
156 betaFixedToOne = true;
160 if (alphaFixedToOne && betaFixedToOne)
162 else if (!alphaFixedToOne && betaFixedToOne)
164 else if (alphaFixedToOne && !betaFixedToOne)
216 Double_t chisq = 0.0;
218 Double_t asymFcnValue = 0.0;
222 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
238 a = par[
fRunInfo->GetAlphaParamNo()-1];
250 b = par[
fRunInfo->GetBetaParamNo()-1];
260 a = par[
fRunInfo->GetAlphaParamNo()-1];
268 b = par[
fRunInfo->GetBetaParamNo()-1];
292 #pragma omp parallel for default(shared) private(i,time,diff,asymFcnValue,f) schedule(dynamic,chunk) reduction(+:chisq)
295 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
297 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0));
298 diff =
fData.GetValue()->at(i) - asymFcnValue;
299 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
343 std::cout << std::endl <<
"PRunAsymmetryRRF::CalcMaxLikelihood(): not implemented yet ..." << std::endl;
396 TObjArray *tok =
nullptr;
397 TObjString *ostr =
nullptr;
402 tok = fitRange.Tokenize(
" \t");
404 if (tok->GetEntries() == 3) {
406 ostr =
static_cast<TObjString*
>(tok->At(1));
407 str = ostr->GetString();
409 idx = str.First(
"+");
411 str.Remove(0, idx+1);
418 ostr =
static_cast<TObjString*
>(tok->At(2));
419 str = ostr->GetString();
421 idx = str.First(
"-");
423 str.Remove(0, idx+1);
428 }
else if ((tok->GetEntries() > 3) && (tok->GetEntries() % 2 == 1)) {
429 Int_t pos = 2*(
fRunNo+1)-1;
431 if (pos + 1 >= tok->GetEntries()) {
432 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
433 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
436 ostr =
static_cast<TObjString*
>(tok->At(pos));
437 str = ostr->GetString();
439 idx = str.First(
"+");
441 str.Remove(0, idx+1);
448 ostr =
static_cast<TObjString*
>(tok->At(pos+1));
449 str = ostr->GetString();
451 idx = str.First(
"-");
453 str.Remove(0, idx+1);
460 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
461 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
527 std::vector<Double_t> par;
529 for (UInt_t i=0; i<paramList->size(); i++)
530 par.push_back((*paramList)[i].fValue);
533 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
538 Double_t asymFcnValue = 0.0;
541 for (UInt_t i=0; i<
fData.GetValue()->size(); i++) {
542 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
549 a = par[
fRunInfo->GetAlphaParamNo()-1];
557 asymFcnValue = (f*(a+1.0)-(a-1.0))/((a+1.0)-f*(a-1.0));
561 b = par[
fRunInfo->GetBetaParamNo()-1];
569 asymFcnValue = f*(b+1.0)/(2.0-f*(b-1.0));
573 a = par[
fRunInfo->GetAlphaParamNo()-1];
581 b = par[
fRunInfo->GetBetaParamNo()-1];
589 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0));
595 fData.AppendTheoryValue(asymFcnValue);
646 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
647 std::cerr << std::endl;
664 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
665 forwardHistoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
667 if (!runData->
IsPresent(forwardHistoNo[i])) {
668 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
669 std::cerr << std::endl <<
">> forwardHistoNo found = " << forwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
670 std::cerr << std::endl <<
">> Will quit :-(";
671 std::cerr << std::endl;
673 forwardHistoNo.clear();
674 backwardHistoNo.clear();
678 for (UInt_t i=0; i<
fRunInfo->GetBackwardHistoNoSize(); i++) {
679 backwardHistoNo.push_back(
fRunInfo->GetBackwardHistoNo(i));
681 if (!runData->
IsPresent(backwardHistoNo[i])) {
682 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
683 std::cerr << std::endl <<
">> backwardHistoNo found = " << backwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
684 std::cerr << std::endl <<
">> Will quit :-(";
685 std::cerr << std::endl;
687 forwardHistoNo.clear();
688 backwardHistoNo.clear();
695 std::cout.precision(10);
696 std::cout << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ns)" << std::endl;
699 if (!
GetProperT0(runData, globalBlock, forwardHistoNo, backwardHistoNo)) {
704 std::vector<PDoubleVector> forward, backward;
705 forward.resize(forwardHistoNo.size());
706 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
707 forward[i].resize(runData->
GetDataBin(forwardHistoNo[i])->size());
708 forward[i] = *runData->
GetDataBin(forwardHistoNo[i]);
715 backward.resize(backwardHistoNo.size());
716 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
717 backward[i].resize(runData->
GetDataBin(backwardHistoNo[i])->size());
718 backward[i] = *runData->
GetDataBin(backwardHistoNo[i]);
727 if (
fRunInfo->GetRunNameSize() > 1) {
729 std::vector<PDoubleVector> addForward, addBackward;
730 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
733 if (addRunData ==
nullptr) {
734 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
735 std::cerr << std::endl;
741 addForward.resize(forwardHistoNo.size());
742 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
743 addForward[j].resize(addRunData->
GetDataBin(forwardHistoNo[j])->size());
744 addForward[j] = *addRunData->
GetDataBin(forwardHistoNo[j]);
748 addBackward.resize(backwardHistoNo.size());
749 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
750 addBackward[j].resize(addRunData->
GetDataBin(backwardHistoNo[j])->size());
751 addBackward[j] = *addRunData->
GetDataBin(backwardHistoNo[j]);
757 for (UInt_t k=0; k<forwardHistoNo.size(); k++) {
758 addRunSize = addRunData->
GetDataBin(forwardHistoNo[k])->size();
759 for (UInt_t j=0; j<addRunData->
GetDataBin(forwardHistoNo[k])->size(); j++) {
761 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)) {
762 forward[k][j] += addForward[k][j+(Int_t)
fAddT0s[i-1][2*k]-(Int_t)
fT0s[2*k]];
768 for (UInt_t k=0; k<backwardHistoNo.size(); k++) {
769 addRunSize = addRunData->
GetDataBin(backwardHistoNo[k])->size();
770 for (UInt_t j=0; j<addRunData->
GetDataBin(backwardHistoNo[k])->size(); j++) {
772 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)) {
773 backward[k][j] += addBackward[k][j+(Int_t)
fAddT0s[i-1][2*k+1]-(Int_t)
fT0s[2*k+1]];
783 for (UInt_t i=0; i<
fForward.size(); i++) {
789 for (UInt_t i=1; i<forwardHistoNo.size(); i++) {
790 for (UInt_t j=0; j<runData->
GetDataBin(forwardHistoNo[i])->size(); j++) {
799 for (UInt_t i=1; i<backwardHistoNo.size(); i++) {
800 for (UInt_t j=0; j<runData->
GetDataBin(backwardHistoNo[i])->size(); j++) {
810 if (
fRunInfo->GetBkgRange(0) >= 0) {
814 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
815 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
816 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.1), 2);
817 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.6), 3);
818 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **WARNING** Neither fix background nor background bins are given!";
819 std::cerr << std::endl <<
">> Will try the following:";
820 std::cerr << std::endl <<
">> forward: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
821 std::cerr << std::endl <<
">> backward: bkg start = " <<
fRunInfo->GetBkgRange(2) <<
", bkg end = " <<
fRunInfo->GetBkgRange(3);
822 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
823 std::cerr << std::endl;
832 UInt_t histoNo[2] = {forwardHistoNo[0], backwardHistoNo[0]};
857 forwardHistoNo.clear();
858 backwardHistoNo.clear();
885 for (UInt_t i=0; i<
fForward.size(); i++) {
928 Double_t beamPeriod = 0.0;
931 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
933 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
935 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
941 UInt_t start[2] = {
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(0)),
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(2))};
942 UInt_t end[2] = {
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(1)),
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(3))};
943 for (UInt_t i=0; i<2; i++) {
944 if (end[i] < start[i]) {
945 std::cout << std::endl <<
"PRunAsymmetryRRF::SubtractEstimatedBkg(): end = " << end[i] <<
" > start = " << start[i] <<
"! Will swap them!";
946 UInt_t keep = end[i];
953 for (UInt_t i=0; i<2; i++) {
954 if (beamPeriod != 0.0) {
955 Double_t timeBkg =
static_cast<Double_t
>(end[i]-start[i])*
fTimeResolution;
956 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
958 end[i] = start[i] +
static_cast<UInt_t
>((fullCycles*beamPeriod)/
fTimeResolution);
959 std::cout <<
"PRunAsymmetryRRF::SubtractEstimatedBkg(): Background " << start[i] <<
", " << end[i] << std::endl;
960 if (end[i] == start[i])
961 end[i] =
fRunInfo->GetBkgRange(2*i+1);
967 std::cerr << std::endl <<
">> PRunAsymmetryRRF::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
968 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForward.size() <<
"/" <<
fBackward.size() <<
").";
969 std::cerr << std::endl <<
">> background start (f/b) = (" << start[0] <<
"/" << start[1] <<
").";
975 std::cerr << std::endl <<
">> PRunAsymmetryRRF::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
976 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForward.size() <<
"/" <<
fBackward.size() <<
").";
977 std::cerr << std::endl <<
">> background end (f/b) = (" << end[0] <<
"/" << end[1] <<
").";
982 Double_t bkg[2] = {0.0, 0.0};
983 Double_t errBkg[2] = {0.0, 0.0};
986 for (UInt_t i=start[0]; i<=end[0]; i++)
988 errBkg[0] = TMath::Sqrt(bkg[0])/(end[0] - start[0] + 1);
989 bkg[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
990 std::cout << std::endl <<
">> estimated forward histo background: " << bkg[0];
993 for (UInt_t i=start[1]; i<=end[1]; i++)
995 errBkg[1] = TMath::Sqrt(bkg[1])/(end[1] - start[1] + 1);
996 bkg[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
997 std::cout << std::endl <<
">> estimated backward histo background: " << bkg[1] << std::endl;
1000 Double_t errVal = 0.0;
1001 for (UInt_t i=0; i<
fForward.size(); i++) {
1003 errVal = TMath::Sqrt(
fForward[i]+errBkg[0]*errBkg[0]);
1008 errVal = TMath::Sqrt(
fBackward[i]+errBkg[1]*errBkg[1]);
1015 for (UInt_t i=0; i<
fForward.size(); i++) {
1020 fRunInfo->SetBkgEstimated(bkg[0], 0);
1021 fRunInfo->SetBkgEstimated(bkg[1], 1);
1061 Int_t lgb_offset =
fGoodBins[1]-
static_cast<Int_t
>(
fT0s[0])+fgbOffset;
1062 if (lgb_offset <
fGoodBins[3]-
static_cast<Int_t
>(
fT0s[1])+fgbOffset)
1063 lgb_offset =
fGoodBins[3]-
static_cast<Int_t
>(
fT0s[1])+fgbOffset;
1065 Int_t fgb =
static_cast<Int_t
>(
fT0s[0])+fgbOffset;
1068 Int_t lgb = fgb + lgb_offset;
1073 Int_t dt0 =
static_cast<Int_t
>(
fT0s[0])-
static_cast<Int_t
>(
fT0s[1]);
1077 Double_t asymVal, asymValErr;
1078 Double_t ff, bb, eff, ebb;
1080 for (Int_t i=fgb; i<lgb; i++) {
1089 asymVal = (ff-bb)/(ff+bb);
1092 asym.push_back(asymVal);
1095 if ((asymVal != 0.0) && (ff+bb) > 0.0)
1096 asymValErr = 2.0/pow((ff+bb),2.0)*sqrt(bb*bb*eff*eff+ff*ff*ebb*ebb);
1099 asymErr.push_back(asymValErr);
1104 Double_t wRRF = globalBlock->
GetRRFFreq(
"Mc");
1105 Double_t phaseRRF = globalBlock->
GetRRFPhase()*TMath::TwoPi()/180.0;
1107 Double_t startTime =
fTimeResolution *
static_cast<Double_t
>(fgbOffset);
1109 for (UInt_t i=0; i<asym.size(); i++) {
1111 asym[i] *= 2.0*cos(wRRF*time+phaseRRF);
1117 for (UInt_t i=0; i<asym.size(); i++) {
1128 for (UInt_t i=0; i<asymErr.size(); i++) {
1130 asymRRFErr.push_back(sqrt(2.0*asymValErr)/
fRRFPacking);
1133 asymValErr += asymErr[i]*asymErr[i];
1139 for (UInt_t i=0; i<asymRRF.size(); i++) {
1140 fData.AppendValue(asymRRF[i]);
1141 fData.AppendErrorValue(asymRRFErr[i]);
1190 std::vector<Double_t> par;
1192 for (UInt_t i=0; i<paramList->size(); i++)
1193 par.push_back((*paramList)[i].fValue);
1198 Int_t t0[2] = {
static_cast<Int_t
>(
fT0s[0]),
static_cast<Int_t
>(
fT0s[1])};
1202 if (start[0]-t0[0] != start[1]-t0[1]) {
1203 if (abs(start[0]-t0[0]) > abs(start[1]-t0[1])) {
1205 fgb[1] = t0[1] + start[0]-t0[0];
1206 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **WARNING** needed to shift backward fgb from ";
1207 std::cerr << start[1] <<
" to " << fgb[1] << std::endl;
1209 fgb[0] = t0[0] + start[1]-t0[1];
1211 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **WARNING** needed to shift forward fgb from ";
1212 std::cerr << start[0] <<
" to " << fgb[0] << std::endl;
1222 UInt_t noOfBins0 = runData->
GetDataBin(histoNo[0])->size()-start[0];
1223 UInt_t noOfBins1 = runData->
GetDataBin(histoNo[1])->size()-start[1];
1224 if (noOfBins0 > noOfBins1)
1225 noOfBins0 = noOfBins1;
1226 end[0] = start[0] + noOfBins0;
1227 end[1] = start[1] + noOfBins0;
1230 for (UInt_t i=0; i<2; i++) {
1232 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1233 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1234 std::cerr << std::endl;
1238 if ((end[i] < 0) || (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1239 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1240 std::cerr << std::endl;
1244 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1245 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
1246 std::cerr << std::endl;
1258 Double_t asym, error;
1259 Double_t f, b, ef, eb, alpha = 1.0, beta = 1.0;
1269 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1281 beta = par[
fRunInfo->GetBetaParamNo()-1];
1291 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1299 beta = par[
fRunInfo->GetBetaParamNo()-1];
1312 Int_t dtBin = start[1]-start[0];
1313 for (Int_t i=start[0]; i<end[0]; i++) {
1321 asym = (alpha*f-b) / (alpha*beta*f+b);
1324 asymVec.push_back(asym);
1327 error = 2.0/((f+b)*(f+b))*TMath::Sqrt(b*b*ef*ef+eb*eb*f*f);
1330 asymErr.push_back(error);
1336 Double_t wRRF = globalBlock->
GetRRFFreq(
"Mc");
1337 Double_t phaseRRF = globalBlock->
GetRRFPhase()*TMath::TwoPi()/180.0;
1338 Double_t startTime=
fTimeResolution*(
static_cast<Double_t
>(start[0])-t0[0]);
1339 Double_t time = 0.0;
1340 for (UInt_t i=0; i<asymVec.size(); i++) {
1342 asymVec[i] *= 2.0*cos(wRRF*time+phaseRRF);
1345 Double_t dval = 0.0;
1347 for (UInt_t i=0; i<asymVec.size(); i++) {
1358 for (UInt_t i=0; i<asymErr.size(); i++) {
1363 dval += asymErr[i]*asymErr[i];
1369 for (UInt_t i=0; i<asymRRF.size(); i++) {
1370 fData.AppendValue(asymRRF[i]);
1371 fData.AppendErrorValue(asymRRFErr[i]);
1388 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1393 UInt_t size = runData->
GetDataBin(histoNo[0])->size();
1395 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1397 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1401 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1404 for (UInt_t i=0; i<size; i++) {
1405 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1407 if (fabs(dval) > 10.0) {
1410 fData.AppendTheoryValue(dval);
1446 size_t size = 2*forwardHistoNo.size();
1447 if (backwardHistoNo.size() > forwardHistoNo.size())
1448 size = 2*backwardHistoNo.size();
1450 for (UInt_t i=0; i<
fT0s.size(); i++) {
1455 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1461 if (
fT0s[i] == -1.0) {
1467 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1468 if (
fT0s[2*i] == -1.0)
1469 if (runData->
GetT0Bin(forwardHistoNo[i]) > 0.0) {
1474 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1475 if (
fT0s[2*i+1] == -1.0)
1476 if (runData->
GetT0Bin(backwardHistoNo[i]) > 0.0) {
1483 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1484 if (
fT0s[2*i] == -1.0) {
1488 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1489 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1490 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(forwardHistoNo[i]);
1491 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1492 std::cerr << std::endl;
1495 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1496 if (
fT0s[2*i+1] == -1.0) {
1500 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1501 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1502 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[i]);
1503 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1504 std::cerr << std::endl;
1509 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1510 if ((
fT0s[2*i] < 0) || (
fT0s[2*i] >
static_cast<Int_t
>(runData->
GetDataBin(forwardHistoNo[i])->size()))) {
1511 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[2*i] <<
") doesn't make any sense!";
1512 std::cerr << std::endl <<
">> forwardHistoNo " << forwardHistoNo[i];
1513 std::cerr << std::endl;
1517 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1518 if ((
fT0s[2*i+1] < 0) || (
fT0s[2*i+1] >
static_cast<Int_t
>(runData->
GetDataBin(backwardHistoNo[i])->size()))) {
1519 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** t0 data bin (" <<
fT0s[2*i+1] <<
") doesn't make any sense!";
1520 std::cerr << std::endl <<
">> backwardHistoNo " << backwardHistoNo[i];
1521 std::cerr << std::endl;
1527 if (
fRunInfo->GetRunNameSize() > 1) {
1530 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1533 if (addRunData ==
nullptr) {
1534 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1535 std::cerr << std::endl;
1542 fAddT0s[i-1].resize(2*forwardHistoNo.size());
1543 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1548 for (Int_t j=0; j<
fRunInfo->GetAddT0BinSize(i-1); j++) {
1553 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1554 if (
fAddT0s[i-1][2*j] == -1.0)
1555 if (addRunData->
GetT0Bin(forwardHistoNo[j]) > 0.0) {
1560 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1561 if (
fAddT0s[i-1][2*j+1] == -1.0)
1562 if (addRunData->
GetT0Bin(backwardHistoNo[j]) > 0.0) {
1569 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1570 if (
fAddT0s[i-1][2*j] == -1.0) {
1574 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1575 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1576 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(forwardHistoNo[j]);
1577 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1578 std::cerr << std::endl;
1581 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1582 if (
fAddT0s[i-1][2*j+1] == -1.0) {
1586 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1587 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1588 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[j]);
1589 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1590 std::cerr << std::endl;
1621 if (start[0] == -1) {
1622 start[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1624 if (start[1] == -1) {
1625 start[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(2);
1628 end[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1631 end[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(3);
1634 Double_t t0[2] = {
fT0s[0],
fT0s[1]};
1639 start[0] =
static_cast<Int_t
>(t0[0])+offset;
1640 fRunInfo->SetDataRange(start[0], 0);
1641 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[0] <<
".";
1642 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1643 std::cerr << std::endl;
1646 start[1] =
static_cast<Int_t
>(t0[1])+offset;
1647 fRunInfo->SetDataRange(start[1], 2);
1648 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[1] <<
".";
1649 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1650 std::cerr << std::endl;
1653 end[0] = runData->
GetDataBin(histoNo[0])->size();
1655 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range end = " << end[0] <<
".";
1656 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1657 std::cerr << std::endl;
1660 end[1] = runData->
GetDataBin(histoNo[1])->size();
1662 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range end = " << end[1] <<
".";
1663 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1664 std::cerr << std::endl;
1669 for (UInt_t i=0; i<2; i++) {
1670 if (end[i] < start[i]) {
1671 Int_t keep = end[i];
1676 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1677 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** start data bin doesn't make any sense!";
1678 std::cerr << std::endl;
1683 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** end data bin (" << end[i] <<
") doesn't make any sense!";
1684 std::cerr << std::endl;
1687 if (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())) {
1688 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** end data bin (" << end[i] <<
") > histo length (" << (Int_t)runData->
GetDataBin(histoNo[i])->size() <<
").";
1689 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
1690 std::cerr << std::endl;
1691 end[i] =
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())-1;
1694 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1695 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** t0 data bin doesn't make any sense!";
1696 std::cerr << std::endl;
1702 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) > fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1703 start[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(start[0]) - t0[0]);
1704 end[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(end[0]) - t0[0]);
1705 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange **WARNING** needed to shift backward data range.";
1706 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(2) <<
", " <<
fRunInfo->GetDataRange(3);
1707 std::cerr << std::endl <<
">> used : " << start[1] <<
", " << end[1];
1708 std::cerr << std::endl;
1710 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) < fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1711 start[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(start[1]) - t0[1]);
1712 end[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(end[1]) - t0[1]);
1713 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange **WARNING** needed to shift forward data range.";
1714 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(0) <<
", " <<
fRunInfo->GetDataRange(1);
1715 std::cerr << std::endl <<
">> used : " << start[0] <<
", " << end[0];
1716 std::cerr << std::endl;
1729 std::cerr << std::endl <<
">> PRunAsymmetry::GetProperDataRange **WARNING** needed to shift forward lgb,";
1730 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
1736 std::cerr << std::endl <<
">> PRunAsymmetry::GetProperDataRange **WARNING** needed to shift backward lgb,";
1737 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
1787 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
1788 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.