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;
132 if ((fRunInfo->GetAlphaParamNo()-MSR_PARAM_FUN_OFFSET < 0) ||
133 (fRunInfo->GetAlphaParamNo()-MSR_PARAM_FUN_OFFSET > msrInfo->GetNoOfFuncs())) {
134 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** alpha parameter is a function with no = " << fRunInfo->GetAlphaParamNo();
135 std::cerr << std::endl <<
">> This is out of bound, since there are only " << msrInfo->GetNoOfFuncs() <<
" functions.";
136 std::cerr << std::endl;
140 }
else if ((fRunInfo->GetAlphaParamNo() < 0) || (fRunInfo->GetAlphaParamNo() >
static_cast<Int_t
>(param->size()))) {
141 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** alpha parameter no = " << fRunInfo->GetAlphaParamNo();
142 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
143 std::cerr << std::endl;
148 Bool_t alphaFixedToOne =
false;
150 if (((*param)[fRunInfo->GetAlphaParamNo()-1].fStep == 0.0) &&
151 ((*param)[fRunInfo->GetAlphaParamNo()-1].fValue == 1.0))
152 alphaFixedToOne = true;
156 Bool_t betaFixedToOne =
false;
157 if (fRunInfo->GetBetaParamNo() == -1) {
158 betaFixedToOne = true;
160 if ((fRunInfo->GetBetaParamNo()-MSR_PARAM_FUN_OFFSET < 0) ||
161 (fRunInfo->GetBetaParamNo()-MSR_PARAM_FUN_OFFSET > msrInfo->GetNoOfFuncs())) {
162 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** beta parameter is a function with no = " << fRunInfo->GetBetaParamNo();
163 std::cerr << std::endl <<
">> This is out of bound, since there are only " << msrInfo->GetNoOfFuncs() <<
" functions.";
164 std::cerr << std::endl;
168 }
else if ((fRunInfo->GetBetaParamNo() < 0) || (fRunInfo->GetBetaParamNo() >
static_cast<Int_t
>(param->size()))) {
169 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PRunAsymmetryRRF(): **ERROR** beta parameter no = " << fRunInfo->GetBetaParamNo();
170 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
171 std::cerr << std::endl;
175 if (((*param)[fRunInfo->GetBetaParamNo()-1].fStep == 0.0) &&
176 ((*param)[fRunInfo->GetBetaParamNo()-1].fValue == 1.0))
177 betaFixedToOne = true;
181 if (alphaFixedToOne && betaFixedToOne)
183 else if (!alphaFixedToOne && betaFixedToOne)
185 else if (alphaFixedToOne && !betaFixedToOne)
237 Double_t chisq = 0.0;
239 Double_t asymFcnValue = 0.0;
243 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
259 a = par[
fRunInfo->GetAlphaParamNo()-1];
271 b = par[
fRunInfo->GetBetaParamNo()-1];
281 a = par[
fRunInfo->GetAlphaParamNo()-1];
289 b = par[
fRunInfo->GetBetaParamNo()-1];
313 #pragma omp parallel for default(shared) private(i,time,diff,asymFcnValue,f) schedule(dynamic,chunk) reduction(+:chisq)
316 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
318 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0));
319 diff =
fData.GetValue()->at(i) - asymFcnValue;
320 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
364 std::cout << std::endl <<
"PRunAsymmetryRRF::CalcMaxLikelihood(): not implemented yet ..." << std::endl;
423 if (tok.size() == 3) {
427 idx = str.First(
"+");
429 str.Remove(0, idx+1);
438 idx = str.First(
"-");
440 str.Remove(0, idx+1);
445 }
else if ((tok.size() > 3) && (tok.size() % 2 == 1)) {
446 UInt_t pos = 2*(
fRunNo+1)-1;
448 if (pos + 1 >= tok.size()) {
449 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
450 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
455 idx = str.First(
"+");
457 str.Remove(0, idx+1);
466 idx = str.First(
"-");
468 str.Remove(0, idx+1);
475 std::cerr << std::endl <<
">> PRunSingleHisto::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
476 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
537 std::vector<Double_t> par;
539 for (UInt_t i=0; i<paramList->size(); i++)
540 par.push_back((*paramList)[i].fValue);
543 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
548 Double_t asymFcnValue = 0.0;
551 for (UInt_t i=0; i<
fData.GetValue()->size(); i++) {
552 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
559 a = par[
fRunInfo->GetAlphaParamNo()-1];
567 asymFcnValue = (f*(a+1.0)-(a-1.0))/((a+1.0)-f*(a-1.0));
571 b = par[
fRunInfo->GetBetaParamNo()-1];
579 asymFcnValue = f*(b+1.0)/(2.0-f*(b-1.0));
583 a = par[
fRunInfo->GetAlphaParamNo()-1];
591 b = par[
fRunInfo->GetBetaParamNo()-1];
599 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0));
605 fData.AppendTheoryValue(asymFcnValue);
656 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
657 std::cerr << std::endl;
674 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
675 forwardHistoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
677 if (!runData->
IsPresent(forwardHistoNo[i])) {
678 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
679 std::cerr << std::endl <<
">> forwardHistoNo found = " << forwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
680 std::cerr << std::endl <<
">> Will quit :-(";
681 std::cerr << std::endl;
683 forwardHistoNo.clear();
684 backwardHistoNo.clear();
688 for (UInt_t i=0; i<
fRunInfo->GetBackwardHistoNoSize(); i++) {
689 backwardHistoNo.push_back(
fRunInfo->GetBackwardHistoNo(i));
691 if (!runData->
IsPresent(backwardHistoNo[i])) {
692 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **PANIC ERROR**:";
693 std::cerr << std::endl <<
">> backwardHistoNo found = " << backwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
694 std::cerr << std::endl <<
">> Will quit :-(";
695 std::cerr << std::endl;
697 forwardHistoNo.clear();
698 backwardHistoNo.clear();
705 std::cout.precision(10);
706 std::cout << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ns)" << std::endl;
709 if (!
GetProperT0(runData, globalBlock, forwardHistoNo, backwardHistoNo)) {
714 std::vector<PDoubleVector> forward, backward;
715 forward.resize(forwardHistoNo.size());
716 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
717 forward[i].resize(runData->
GetDataBin(forwardHistoNo[i])->size());
718 forward[i] = *runData->
GetDataBin(forwardHistoNo[i]);
725 backward.resize(backwardHistoNo.size());
726 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
727 backward[i].resize(runData->
GetDataBin(backwardHistoNo[i])->size());
728 backward[i] = *runData->
GetDataBin(backwardHistoNo[i]);
737 if (
fRunInfo->GetRunNameSize() > 1) {
739 std::vector<PDoubleVector> addForward, addBackward;
740 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
743 if (addRunData ==
nullptr) {
744 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
745 std::cerr << std::endl;
751 addForward.resize(forwardHistoNo.size());
752 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
753 addForward[j].resize(addRunData->
GetDataBin(forwardHistoNo[j])->size());
754 addForward[j] = *addRunData->
GetDataBin(forwardHistoNo[j]);
758 addBackward.resize(backwardHistoNo.size());
759 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
760 addBackward[j].resize(addRunData->
GetDataBin(backwardHistoNo[j])->size());
761 addBackward[j] = *addRunData->
GetDataBin(backwardHistoNo[j]);
767 for (UInt_t k=0; k<forwardHistoNo.size(); k++) {
768 addRunSize = addRunData->
GetDataBin(forwardHistoNo[k])->size();
769 for (UInt_t j=0; j<addRunData->
GetDataBin(forwardHistoNo[k])->size(); j++) {
771 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)) {
772 forward[k][j] += addForward[k][j+(Int_t)
fAddT0s[i-1][2*k]-(Int_t)
fT0s[2*k]];
778 for (UInt_t k=0; k<backwardHistoNo.size(); k++) {
779 addRunSize = addRunData->
GetDataBin(backwardHistoNo[k])->size();
780 for (UInt_t j=0; j<addRunData->
GetDataBin(backwardHistoNo[k])->size(); j++) {
782 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)) {
783 backward[k][j] += addBackward[k][j+(Int_t)
fAddT0s[i-1][2*k+1]-(Int_t)
fT0s[2*k+1]];
793 for (UInt_t i=0; i<
fForward.size(); i++) {
799 for (UInt_t i=1; i<forwardHistoNo.size(); i++) {
800 for (UInt_t j=0; j<runData->
GetDataBin(forwardHistoNo[i])->size(); j++) {
809 for (UInt_t i=1; i<backwardHistoNo.size(); i++) {
810 for (UInt_t j=0; j<runData->
GetDataBin(backwardHistoNo[i])->size(); j++) {
820 if (
fRunInfo->GetBkgRange(0) >= 0) {
824 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
825 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
826 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.1), 2);
827 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.6), 3);
828 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **WARNING** Neither fix background nor background bins are given!";
829 std::cerr << std::endl <<
">> Will try the following:";
830 std::cerr << std::endl <<
">> forward: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
831 std::cerr << std::endl <<
">> backward: bkg start = " <<
fRunInfo->GetBkgRange(2) <<
", bkg end = " <<
fRunInfo->GetBkgRange(3);
832 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS MAKES ANY SENSE! Better check ...";
833 std::cerr << std::endl;
842 UInt_t histoNo[2] = {forwardHistoNo[0], backwardHistoNo[0]};
867 forwardHistoNo.clear();
868 backwardHistoNo.clear();
895 for (UInt_t i=0; i<
fForward.size(); i++) {
938 Double_t beamPeriod = 0.0;
941 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
943 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
945 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
951 UInt_t start[2] = {
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(0)),
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(2))};
952 UInt_t end[2] = {
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(1)),
static_cast<UInt_t
>(
fRunInfo->GetBkgRange(3))};
953 for (UInt_t i=0; i<2; i++) {
954 if (end[i] < start[i]) {
955 std::cout << std::endl <<
"PRunAsymmetryRRF::SubtractEstimatedBkg(): end = " << end[i] <<
" > start = " << start[i] <<
"! Will swap them!";
956 UInt_t keep = end[i];
963 for (UInt_t i=0; i<2; i++) {
964 if (beamPeriod != 0.0) {
965 Double_t timeBkg =
static_cast<Double_t
>(end[i]-start[i])*
fTimeResolution;
966 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
968 end[i] = start[i] +
static_cast<UInt_t
>((fullCycles*beamPeriod)/
fTimeResolution);
969 std::cout <<
"PRunAsymmetryRRF::SubtractEstimatedBkg(): Background " << start[i] <<
", " << end[i] << std::endl;
970 if (end[i] == start[i])
971 end[i] =
fRunInfo->GetBkgRange(2*i+1);
977 std::cerr << std::endl <<
">> PRunAsymmetryRRF::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
978 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForward.size() <<
"/" <<
fBackward.size() <<
").";
979 std::cerr << std::endl <<
">> background start (f/b) = (" << start[0] <<
"/" << start[1] <<
").";
985 std::cerr << std::endl <<
">> PRunAsymmetryRRF::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
986 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForward.size() <<
"/" <<
fBackward.size() <<
").";
987 std::cerr << std::endl <<
">> background end (f/b) = (" << end[0] <<
"/" << end[1] <<
").";
992 Double_t bkg[2] = {0.0, 0.0};
993 Double_t errBkg[2] = {0.0, 0.0};
996 for (UInt_t i=start[0]; i<=end[0]; i++)
998 errBkg[0] = TMath::Sqrt(bkg[0])/(end[0] - start[0] + 1);
999 bkg[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
1000 std::cout << std::endl <<
">> estimated forward histo background: " << bkg[0];
1003 for (UInt_t i=start[1]; i<=end[1]; i++)
1005 errBkg[1] = TMath::Sqrt(bkg[1])/(end[1] - start[1] + 1);
1006 bkg[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
1007 std::cout << std::endl <<
">> estimated backward histo background: " << bkg[1] << std::endl;
1010 Double_t errVal = 0.0;
1011 for (UInt_t i=0; i<
fForward.size(); i++) {
1013 errVal = TMath::Sqrt(
fForward[i]+errBkg[0]*errBkg[0]);
1018 errVal = TMath::Sqrt(
fBackward[i]+errBkg[1]*errBkg[1]);
1025 for (UInt_t i=0; i<
fForward.size(); i++) {
1030 fRunInfo->SetBkgEstimated(bkg[0], 0);
1031 fRunInfo->SetBkgEstimated(bkg[1], 1);
1071 Int_t lgb_offset =
fGoodBins[1]-
static_cast<Int_t
>(
fT0s[0])+fgbOffset;
1072 if (lgb_offset <
fGoodBins[3]-
static_cast<Int_t
>(
fT0s[1])+fgbOffset)
1073 lgb_offset =
fGoodBins[3]-
static_cast<Int_t
>(
fT0s[1])+fgbOffset;
1075 Int_t fgb =
static_cast<Int_t
>(
fT0s[0])+fgbOffset;
1078 Int_t lgb = fgb + lgb_offset;
1083 Int_t dt0 =
static_cast<Int_t
>(
fT0s[0])-
static_cast<Int_t
>(
fT0s[1]);
1087 Double_t asymVal, asymValErr;
1088 Double_t ff, bb, eff, ebb;
1090 for (Int_t i=fgb; i<lgb; i++) {
1099 asymVal = (ff-bb)/(ff+bb);
1102 asym.push_back(asymVal);
1105 if ((asymVal != 0.0) && (ff+bb) > 0.0)
1106 asymValErr = 2.0/pow((ff+bb),2.0)*sqrt(bb*bb*eff*eff+ff*ff*ebb*ebb);
1109 asymErr.push_back(asymValErr);
1114 Double_t wRRF = globalBlock->
GetRRFFreq(
"Mc");
1115 Double_t phaseRRF = globalBlock->
GetRRFPhase()*TMath::TwoPi()/180.0;
1117 Double_t startTime =
fTimeResolution *
static_cast<Double_t
>(fgbOffset);
1119 for (UInt_t i=0; i<asym.size(); i++) {
1121 asym[i] *= 2.0*cos(wRRF*time+phaseRRF);
1127 for (UInt_t i=0; i<asym.size(); i++) {
1138 for (UInt_t i=0; i<asymErr.size(); i++) {
1140 asymRRFErr.push_back(sqrt(2.0*asymValErr)/
fRRFPacking);
1143 asymValErr += asymErr[i]*asymErr[i];
1149 for (UInt_t i=0; i<asymRRF.size(); i++) {
1150 fData.AppendValue(asymRRF[i]);
1151 fData.AppendErrorValue(asymRRFErr[i]);
1200 std::vector<Double_t> par;
1202 for (UInt_t i=0; i<paramList->size(); i++)
1203 par.push_back((*paramList)[i].fValue);
1208 Int_t t0[2] = {
static_cast<Int_t
>(
fT0s[0]),
static_cast<Int_t
>(
fT0s[1])};
1212 if (start[0]-t0[0] != start[1]-t0[1]) {
1213 if (abs(start[0]-t0[0]) > abs(start[1]-t0[1])) {
1215 fgb[1] = t0[1] + start[0]-t0[0];
1216 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **WARNING** needed to shift backward fgb from ";
1217 std::cerr << start[1] <<
" to " << fgb[1] << std::endl;
1219 fgb[0] = t0[0] + start[1]-t0[1];
1221 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **WARNING** needed to shift forward fgb from ";
1222 std::cerr << start[0] <<
" to " << fgb[0] << std::endl;
1232 UInt_t noOfBins0 = runData->
GetDataBin(histoNo[0])->size()-start[0];
1233 UInt_t noOfBins1 = runData->
GetDataBin(histoNo[1])->size()-start[1];
1234 if (noOfBins0 > noOfBins1)
1235 noOfBins0 = noOfBins1;
1236 end[0] = start[0] + noOfBins0;
1237 end[1] = start[1] + noOfBins0;
1240 for (UInt_t i=0; i<2; i++) {
1242 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1243 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1244 std::cerr << std::endl;
1248 if ((end[i] < 0) || (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1249 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1250 std::cerr << std::endl;
1254 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1255 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
1256 std::cerr << std::endl;
1268 Double_t asym, error;
1269 Double_t f, b, ef, eb, alpha = 1.0, beta = 1.0;
1279 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1291 beta = par[
fRunInfo->GetBetaParamNo()-1];
1301 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1309 beta = par[
fRunInfo->GetBetaParamNo()-1];
1322 Int_t dtBin = start[1]-start[0];
1323 for (Int_t i=start[0]; i<end[0]; i++) {
1331 asym = (alpha*f-b) / (alpha*beta*f+b);
1334 asymVec.push_back(asym);
1337 error = 2.0/((f+b)*(f+b))*TMath::Sqrt(b*b*ef*ef+eb*eb*f*f);
1340 asymErr.push_back(error);
1346 Double_t wRRF = globalBlock->
GetRRFFreq(
"Mc");
1347 Double_t phaseRRF = globalBlock->
GetRRFPhase()*TMath::TwoPi()/180.0;
1348 Double_t startTime=
fTimeResolution*(
static_cast<Double_t
>(start[0])-t0[0]);
1349 Double_t time = 0.0;
1350 for (UInt_t i=0; i<asymVec.size(); i++) {
1352 asymVec[i] *= 2.0*cos(wRRF*time+phaseRRF);
1355 Double_t dval = 0.0;
1357 for (UInt_t i=0; i<asymVec.size(); i++) {
1368 for (UInt_t i=0; i<asymErr.size(); i++) {
1373 dval += asymErr[i]*asymErr[i];
1379 for (UInt_t i=0; i<asymRRF.size(); i++) {
1380 fData.AppendValue(asymRRF[i]);
1381 fData.AppendErrorValue(asymRRFErr[i]);
1398 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1403 UInt_t size = runData->
GetDataBin(histoNo[0])->size();
1405 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1407 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1411 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1414 for (UInt_t i=0; i<size; i++) {
1415 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1417 if (fabs(dval) > 10.0) {
1420 fData.AppendTheoryValue(dval);
1456 size_t size = 2*forwardHistoNo.size();
1457 if (backwardHistoNo.size() > forwardHistoNo.size())
1458 size = 2*backwardHistoNo.size();
1460 for (UInt_t i=0; i<
fT0s.size(); i++) {
1465 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1471 if (
fT0s[i] == -1.0) {
1477 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1478 if (
fT0s[2*i] == -1.0)
1479 if (runData->
GetT0Bin(forwardHistoNo[i]) > 0.0) {
1484 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1485 if (
fT0s[2*i+1] == -1.0)
1486 if (runData->
GetT0Bin(backwardHistoNo[i]) > 0.0) {
1493 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1494 if (
fT0s[2*i] == -1.0) {
1498 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1499 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1500 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(forwardHistoNo[i]);
1501 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1502 std::cerr << std::endl;
1505 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1506 if (
fT0s[2*i+1] == -1.0) {
1510 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1511 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1512 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[i]);
1513 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1514 std::cerr << std::endl;
1519 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1520 if ((
fT0s[2*i] < 0) || (
fT0s[2*i] >
static_cast<Int_t
>(runData->
GetDataBin(forwardHistoNo[i])->size()))) {
1521 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[2*i] <<
") doesn't make any sense!";
1522 std::cerr << std::endl <<
">> forwardHistoNo " << forwardHistoNo[i];
1523 std::cerr << std::endl;
1527 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1528 if ((
fT0s[2*i+1] < 0) || (
fT0s[2*i+1] >
static_cast<Int_t
>(runData->
GetDataBin(backwardHistoNo[i])->size()))) {
1529 std::cerr << std::endl <<
">> PRunAsymmetryRRF::PrepareData(): **ERROR** t0 data bin (" <<
fT0s[2*i+1] <<
") doesn't make any sense!";
1530 std::cerr << std::endl <<
">> backwardHistoNo " << backwardHistoNo[i];
1531 std::cerr << std::endl;
1537 if (
fRunInfo->GetRunNameSize() > 1) {
1540 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1543 if (addRunData ==
nullptr) {
1544 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1545 std::cerr << std::endl;
1552 fAddT0s[i-1].resize(2*forwardHistoNo.size());
1553 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1558 for (Int_t j=0; j<
fRunInfo->GetAddT0BinSize(i-1); j++) {
1563 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1564 if (
fAddT0s[i-1][2*j] == -1.0)
1565 if (addRunData->
GetT0Bin(forwardHistoNo[j]) > 0.0) {
1570 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1571 if (
fAddT0s[i-1][2*j+1] == -1.0)
1572 if (addRunData->
GetT0Bin(backwardHistoNo[j]) > 0.0) {
1579 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1580 if (
fAddT0s[i-1][2*j] == -1.0) {
1584 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1585 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1586 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(forwardHistoNo[j]);
1587 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1588 std::cerr << std::endl;
1591 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1592 if (
fAddT0s[i-1][2*j+1] == -1.0) {
1596 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1597 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1598 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[j]);
1599 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1600 std::cerr << std::endl;
1631 if (start[0] == -1) {
1632 start[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1634 if (start[1] == -1) {
1635 start[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(2);
1638 end[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1641 end[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(3);
1644 Double_t t0[2] = {
fT0s[0],
fT0s[1]};
1649 start[0] =
static_cast<Int_t
>(t0[0])+offset;
1650 fRunInfo->SetDataRange(start[0], 0);
1651 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[0] <<
".";
1652 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1653 std::cerr << std::endl;
1656 start[1] =
static_cast<Int_t
>(t0[1])+offset;
1657 fRunInfo->SetDataRange(start[1], 2);
1658 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[1] <<
".";
1659 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1660 std::cerr << std::endl;
1663 end[0] = runData->
GetDataBin(histoNo[0])->size();
1665 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range end = " << end[0] <<
".";
1666 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1667 std::cerr << std::endl;
1670 end[1] = runData->
GetDataBin(histoNo[1])->size();
1672 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range end = " << end[1] <<
".";
1673 std::cerr << std::endl <<
">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE.";
1674 std::cerr << std::endl;
1679 for (UInt_t i=0; i<2; i++) {
1680 if (end[i] < start[i]) {
1681 Int_t keep = end[i];
1686 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1687 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** start data bin doesn't make any sense!";
1688 std::cerr << std::endl;
1693 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** end data bin (" << end[i] <<
") doesn't make any sense!";
1694 std::cerr << std::endl;
1697 if (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())) {
1698 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **WARNING** end data bin (" << end[i] <<
") > histo length (" << (Int_t)runData->
GetDataBin(histoNo[i])->size() <<
").";
1699 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
1700 std::cerr << std::endl;
1701 end[i] =
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())-1;
1704 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1705 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange(): **ERROR** t0 data bin doesn't make any sense!";
1706 std::cerr << std::endl;
1712 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) > fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1713 start[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(start[0]) - t0[0]);
1714 end[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(end[0]) - t0[0]);
1715 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange **WARNING** needed to shift backward data range.";
1716 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(2) <<
", " <<
fRunInfo->GetDataRange(3);
1717 std::cerr << std::endl <<
">> used : " << start[1] <<
", " << end[1];
1718 std::cerr << std::endl;
1720 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) < fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1721 start[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(start[1]) - t0[1]);
1722 end[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(end[1]) - t0[1]);
1723 std::cerr << std::endl <<
">> PRunAsymmetryRRF::GetProperDataRange **WARNING** needed to shift forward data range.";
1724 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(0) <<
", " <<
fRunInfo->GetDataRange(1);
1725 std::cerr << std::endl <<
">> used : " << start[0] <<
", " << end[0];
1726 std::cerr << std::endl;
1739 std::cerr << std::endl <<
">> PRunAsymmetry::GetProperDataRange **WARNING** needed to shift forward lgb,";
1740 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
1746 std::cerr << std::endl <<
">> PRunAsymmetry::GetProperDataRange **WARNING** needed to shift backward lgb,";
1747 std::cerr << std::endl <<
">> from " <<
fGoodBins[1] <<
" to " <<
fForward.size()-1 << std::endl;
1797 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
1798 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.
static std::vector< std::string > Split(const std::string &str, const std::string &delimiters)