48#include "PStringUtils.h"
119 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **SEVERE ERROR**: Couldn't find any packing information!";
120 std::cerr << std::endl <<
">> This is very bad :-(, will quit ...";
121 std::cerr << std::endl;
131 Bool_t alphaFixedToOne =
false;
132 Bool_t alphaSetDefault =
false;
133 if (
fRunInfo->GetAlphaParamNo() == -1) {
138 alphaSetDefault = true;
139 }
else if ((
fRunInfo->GetAlphaParamNo() < 0) || (
fRunInfo->GetAlphaParamNo() > (Int_t)param->size())) {
140 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **ERROR** alpha parameter no = " << fRunInfo->GetAlphaParamNo();
141 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
142 std::cerr << std::endl;
146 if (((*param)[fRunInfo->GetAlphaParamNo()-1].fStep == 0.0) &&
147 ((*param)[fRunInfo->GetAlphaParamNo()-1].fValue == 1.0))
148 alphaFixedToOne = true;
152 Bool_t betaFixedToOne =
false;
154 betaFixedToOne = true;
155 }
else if ((
fRunInfo->GetBetaParamNo() < 0) || (
fRunInfo->GetBetaParamNo() > (Int_t)param->size())) {
156 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **ERROR** beta parameter no = " << fRunInfo->GetBetaParamNo();
157 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
158 std::cerr << std::endl;
162 if (((*param)[fRunInfo->GetBetaParamNo()-1].fStep == 0.0) &&
163 ((*param)[fRunInfo->GetBetaParamNo()-1].fValue == 1.0))
164 betaFixedToOne = true;
168 if (alphaFixedToOne && betaFixedToOne)
170 else if (!alphaFixedToOne && betaFixedToOne & !alphaSetDefault)
172 else if (alphaFixedToOne && !betaFixedToOne)
174 else if (!alphaFixedToOne && betaFixedToOne & alphaSetDefault)
176 else if (!alphaFixedToOne && !betaFixedToOne & alphaSetDefault)
229 Double_t chisq = 0.0;
231 Double_t asymFcnValue = 0.0;
235 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
240 Double_t time(1.0),alphaest;
244 alphaest =
fRunInfo->GetEstimatedAlpha();
252 a = par[
fRunInfo->GetAlphaParamNo()-1];
264 b = par[
fRunInfo->GetBetaParamNo()-1];
274 a = par[
fRunInfo->GetAlphaParamNo()-1];
282 b = par[
fRunInfo->GetBetaParamNo()-1];
297 b = par[
fRunInfo->GetBetaParamNo()-1];
321 #pragma omp parallel for default(shared) private(i,time,diff,asymFcnValue,f) schedule(dynamic,chunk) reduction(+:chisq)
324 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
326 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0))-(-f*(a*b+1.0)-(a-1.0))/((a+1.0)+f*(a*b-1.0));
327 diff =
fData.GetValue()->at(i) - asymFcnValue;
328 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
365 std::cout << std::endl <<
"PRunAsymmetryBNMR::CalcMaxLikelihood(): not implemented yet ..." << std::endl;
414 std::vector<std::string> tok = PStringUtils::Split(fitRange.Data(),
" \t");
416 if (tok.size() == 3) {
420 idx = str.First(
"+");
422 str.Remove(0, idx+1);
431 idx = str.First(
"-");
433 str.Remove(0, idx+1);
438 }
else if ((tok.size() > 3) && (tok.size() % 2 == 1)) {
439 UInt_t pos = 2*(
fRunNo+1)-1;
441 if (pos + 1 >= tok.size()) {
442 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
443 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
448 idx = str.First(
"+");
450 str.Remove(0, idx+1);
459 idx = str.First(
"-");
461 str.Remove(0, idx+1);
468 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
469 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
520 std::vector<Double_t> par;
522 for (UInt_t i=0; i<paramList->size(); i++)
523 par.push_back((*paramList)[i].fValue);
526 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
531 Double_t asymFcnValue = 0.0;
532 Double_t a, b, f, alphaest;
536 alphaest =
fRunInfo->GetEstimatedAlpha();
538 for (UInt_t i=0; i<
fData.GetValue()->size(); i++) {
539 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
546 a = par[
fRunInfo->GetAlphaParamNo()-1];
554 asymFcnValue = (f*(a+1.0)-(a-1.0))/((a+1.0)-f*(a-1.0)) - (-f*(a+1.0)-(a-1.0))/((a+1.0)+f*(a-1.0));
558 b = par[
fRunInfo->GetBetaParamNo()-1];
566 asymFcnValue = f*(b+1.0)/(2.0-f*(b-1.0))-f*(b+1.0)/(2.0+f*(b-1.0));
570 a = par[
fRunInfo->GetAlphaParamNo()-1];
578 b = par[
fRunInfo->GetBetaParamNo()-1];
586 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0))-(-f*(a*b+1.0)-(a-1.0))/((a+1.0)+f*(a*b-1.0));
591 asymFcnValue = (f*(a+1.0)-(a-1.0))/((a+1.0)-f*(a-1.0)) - (-f*(a+1.0)-(a-1.0))/((a+1.0)+f*(a-1.0));
596 b = par[
fRunInfo->GetBetaParamNo()-1];
604 asymFcnValue = (f*(a*b+1.0)-(a-1.0))/((a+1.0)-f*(a*b-1.0))-(-f*(a*b+1.0)-(a-1.0))/((a+1.0)+f*(a*b-1.0));
610 fData.AppendTheoryValue(asymFcnValue);
653 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
654 std::cerr << std::endl;
671 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
672 forwardHistoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
674 if (!runData->
IsPresent(forwardHistoNo[i])) {
675 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **PANIC ERROR**:";
676 std::cerr << std::endl <<
">> forwardHistoNo found = " << forwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
677 std::cerr << std::endl <<
">> Will quit :-(";
678 std::cerr << std::endl;
680 forwardHistoNo.clear();
681 backwardHistoNo.clear();
685 for (UInt_t i=0; i<
fRunInfo->GetBackwardHistoNoSize(); i++) {
686 backwardHistoNo.push_back(
fRunInfo->GetBackwardHistoNo(i));
688 if (!runData->
IsPresent(backwardHistoNo[i])) {
689 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **PANIC ERROR**:";
690 std::cerr << std::endl <<
">> backwardHistoNo found = " << backwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
691 std::cerr << std::endl <<
">> Will quit :-(";
692 std::cerr << std::endl;
694 forwardHistoNo.clear();
695 backwardHistoNo.clear();
714 std::cout.precision(10);
715 std::cout << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ms)" << std::endl;
718 if (!
GetProperT0(runData, globalBlock, forwardHistoNo, backwardHistoNo)) {
723 std::vector<PDoubleVector> forward, backward;
724 forward.resize(forwardHistoNo.size());
725 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
726 forward[i].resize(runData->
GetDataBin(forwardHistoNo[i])->size());
727 forward[i] = *runData->
GetDataBin(forwardHistoNo[i]);
729 backward.resize(backwardHistoNo.size());
730 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
731 backward[i].resize(runData->
GetDataBin(backwardHistoNo[i])->size());
732 backward[i] = *runData->
GetDataBin(backwardHistoNo[i]);
737 if (
fRunInfo->GetRunNameSize() > 1) {
739 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
742 if (addRunData ==
nullptr) {
743 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
744 std::cerr << std::endl;
750 for (UInt_t k=0; k<forwardHistoNo.size(); k++) {
751 addRunSize = addRunData->
GetDataBin(forwardHistoNo[k])->size();
752 for (UInt_t j=0; j<addRunData->
GetDataBin(forwardHistoNo[k])->size(); j++) {
754 if ((
static_cast<Int_t
>(j)+
static_cast<Int_t
>(
fAddT0s[i-1][2*k])-
static_cast<Int_t
>(
fT0s[2*k]) >= 0) &&
755 (j+
static_cast<Int_t
>(
fAddT0s[i-1][2*k])-
static_cast<Int_t
>(
fT0s[2*k]) < addRunSize)) {
756 forward[k][j] += addRunData->
GetDataBin(forwardHistoNo[k])->at(j+
static_cast<Int_t
>(
fAddT0s[i-1][2*k])-
static_cast<Int_t
>(
fT0s[2*k]));
762 for (UInt_t k=0; k<backwardHistoNo.size(); k++) {
763 addRunSize = addRunData->
GetDataBin(backwardHistoNo[k])->size();
764 for (UInt_t j=0; j<addRunData->
GetDataBin(backwardHistoNo[k])->size(); j++) {
766 if ((
static_cast<Int_t
>(j)+
static_cast<Int_t
>(
fAddT0s[i-1][2*k+1])-
static_cast<Int_t
>(
fT0s[2*k+1]) >= 0) &&
767 (j+
static_cast<Int_t
>(
fAddT0s[i-1][2*k+1])-
static_cast<Int_t
>(
fT0s[2*k+1]) < addRunSize)) {
768 backward[k][j] += addRunData->
GetDataBin(backwardHistoNo[k])->at(j+
static_cast<Int_t
>(
fAddT0s[i-1][2*k+1])-
static_cast<Int_t
>(
fT0s[2*k+1]));
778 for (UInt_t i=0; i<
fForwardp.size(); i++) {
792 if (
fRunInfo->GetBkgRange(0) >= 0) {
796 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.1), 0);
797 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[0]*0.6), 1);
798 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.1), 2);
799 fRunInfo->SetBkgRange(
static_cast<Int_t
>(
fT0s[1]*0.6), 3);
800 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **WARNING** Neither fix background nor background bins are given!";
801 std::cerr << std::endl <<
">> Will try the following:";
802 std::cerr << std::endl <<
">> forward: bkg start = " <<
fRunInfo->GetBkgRange(0) <<
", bkg end = " <<
fRunInfo->GetBkgRange(1);
803 std::cerr << std::endl <<
">> backward: bkg start = " <<
fRunInfo->GetBkgRange(2) <<
", bkg end = " <<
fRunInfo->GetBkgRange(3);
804 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS MAKES ANY SENSE! Better check ...";
805 std::cerr << std::endl;
814 UInt_t histoNo[2] = {forwardHistoNo[0], backwardHistoNo[0]};
839 forwardHistoNo.clear();
840 backwardHistoNo.clear();
869 for (UInt_t i=0; i<
fForwardp.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"))
943 for (UInt_t i=0; i<2; i++) {
944 if (end[i] < start[i]) {
945 std::cout << std::endl <<
"PRunAsymmetryBNMR::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) {
956 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
959 std::cout <<
"PRunAsymmetryBNMR::SubtractEstimatedBkg(): Background " << start[i] <<
", " << end[i] << std::endl;
960 if (end[i] == start[i])
961 end[i] =
fRunInfo->GetBkgRange(2*i+1);
966 if ((start[0] < 0) || (start[0] >=
fForwardp.size()) ||
967 (start[1] < 0) || (start[1] >=
fBackwardp.size())) {
968 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
969 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForwardp.size() <<
"/" <<
fBackwardp.size() <<
").";
970 std::cerr << std::endl <<
">> background start (f/b) = (" << start[0] <<
"/" << start[1] <<
").";
975 if ((end[0] < 0) || (end[0] >=
fForwardp.size()) ||
976 (end[1] < 0) || (end[1] >=
fBackwardp.size())) {
977 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
978 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForwardp.size() <<
"/" <<
fBackwardp.size() <<
").";
979 std::cerr << std::endl <<
">> background end (f/b) = (" << end[0] <<
"/" << end[1] <<
").";
984 Double_t bkgp[2] = {0.0, 0.0};
985 Double_t errBkgp[2] = {0.0, 0.0};
986 Double_t bkgm[2] = {0.0, 0.0};
987 Double_t errBkgm[2] = {0.0, 0.0};
990 for (UInt_t i=start[0]; i<=end[0]; i++) {
994 errBkgp[0] = TMath::Sqrt(bkgp[0])/(end[0] - start[0] + 1);
995 bkgp[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
996 std::cout << std::endl <<
">> estimated pos hel forward histo background: " << bkgp[0];
997 errBkgm[0] = TMath::Sqrt(bkgp[0])/(end[0] - start[0] + 1);
998 bkgm[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
999 std::cout << std::endl <<
">> estimated neg hel forward histo background: " << bkgm[0];
1002 for (UInt_t i=start[1]; i<=end[1]; i++) {
1006 errBkgp[1] = TMath::Sqrt(bkgp[1])/(end[1] - start[1] + 1);
1007 bkgp[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
1008 std::cout << std::endl <<
">> estimated pos hel backward histo background: " << bkgp[1];
1009 errBkgm[1] = TMath::Sqrt(bkgm[1])/(end[1] - start[1] + 1);
1010 bkgm[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
1011 std::cout << std::endl <<
">> estimated neg hel backward histo background: " << bkgm[1];
1014 Double_t errVal = 0.0;
1015 for (UInt_t i=0; i<
fForwardp.size(); i++) {
1017 errVal = TMath::Sqrt(
fForwardp[i]+errBkgp[0]*errBkgp[0]);
1022 errVal = TMath::Sqrt(
fBackwardp[i]+errBkgp[1]*errBkgp[1]);
1027 errVal = TMath::Sqrt(
fForwardm[i]+errBkgm[0]*errBkgm[0]);
1032 errVal = TMath::Sqrt(
fBackwardm[i]+errBkgm[1]*errBkgm[1]);
1039 for (UInt_t i=0; i<
fForwardp.size(); i++) {
1046 fRunInfo->SetBkgEstimated(bkgp[0], 0);
1047 fRunInfo->SetBkgEstimated(bkgp[1], 1);
1048 fRunInfo->SetBkgEstimated(bkgm[0], 3);
1049 fRunInfo->SetBkgEstimated(bkgm[1], 4);
1054 fRunInfo->SetEstimatedAlpha(alpha);
1084 Double_t valuep = 0.0;
1085 Double_t errorp = 0.0;
1086 Double_t valuem = 0.0;
1087 Double_t errorm = 0.0;
1104 if (valuep == 0.0) {
1109 if (valuem == 0.0) {
1141 if (valuep == 0.0) {
1146 if (valuem == 0.0) {
1164 UInt_t noOfBins = forwardpPacked.
GetValue()->size();
1165 if (forwardpPacked.
GetValue()->size() != backwardpPacked.
GetValue()->size()) {
1166 if (forwardpPacked.
GetValue()->size() > backwardpPacked.
GetValue()->size())
1167 noOfBins = backwardpPacked.
GetValue()->size();
1171 Double_t asym,error;
1172 Double_t fp, bp, efp, ebp;
1173 Double_t fm, bm, efm, ebm;
1178 for (UInt_t i=0; i<noOfBins; i++) {
1180 fp = forwardpPacked.
GetValue()->at(i);
1181 bp = backwardpPacked.
GetValue()->at(i);
1182 efp = forwardpPacked.
GetError()->at(i);
1183 ebp = backwardpPacked.
GetError()->at(i);
1184 fm = forwardmPacked.
GetValue()->at(i);
1185 bm = backwardmPacked.
GetValue()->at(i);
1186 efm = forwardmPacked.
GetError()->at(i);
1187 ebm = backwardmPacked.
GetError()->at(i);
1190 asym = (fp-bp) / (fp+bp) - (fm-bm) / (fm+bm);
1193 fData.AppendValue(asym);
1196 errorp = 2.0/((fp+bp)*(fp+bp))*TMath::Sqrt(bp*bp*efp*efp+ebp*ebp*fp*fp);
1200 errorm = 2.0/((fm+bm)*(fm+bm))*TMath::Sqrt(bm*bm*efm*efm+ebm*ebm*fm*fm);
1204 error = TMath::Sqrt(errorp*errorp+errorm*errorm);
1205 fData.AppendErrorValue(error);
1240 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1241 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1245 std::vector<Double_t> par;
1247 for (UInt_t i=0; i<paramList->size(); i++)
1248 par.push_back((*paramList)[i].fValue);
1256 Int_t t0[2] = {
static_cast<Int_t
>(
fT0s[0]),
static_cast<Int_t
>(
fT0s[1])};
1260 if (start[0]-t0[0] != start[1]-t0[1]) {
1261 if (abs(start[0]-t0[0]) > abs(start[1]-t0[1])) {
1263 fgb[1] = t0[1] + start[0]-t0[0];
1264 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **WARNING** needed to shift backward fgb from ";
1265 std::cerr << start[1] <<
" to " << fgb[1] << std::endl;
1267 fgb[0] = t0[0] + start[1]-t0[1];
1269 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **WARNING** needed to shift forward fgb from ";
1270 std::cerr << start[0] <<
" to " << fgb[0] << std::endl;
1277 Int_t val = fgb[0]-packing*(fgb[0]/packing);
1279 if (fgb[1] - fgb[0] < 0)
1281 }
while (val + fgb[1] - fgb[0] < 0);
1284 start[1] = val + fgb[1] - fgb[0];
1287 UInt_t noOfBins0 = (runData->
GetDataBin(histoNo[0])->size()-start[0])/packing;
1288 UInt_t noOfBins1 = (runData->
GetDataBin(histoNo[1])->size()-start[1])/packing;
1289 if (noOfBins0 > noOfBins1)
1290 noOfBins0 = noOfBins1;
1291 end[0] = start[0] + noOfBins0 * packing;
1292 end[1] = start[1] + noOfBins0 * packing;
1296 for (UInt_t i=0; i<2; i++) {
1297 if (end[i] < start[i]) {
1298 Int_t keep = end[i];
1303 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1304 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1305 std::cerr << std::endl;
1309 if ((end[i] < 0) || (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1310 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1311 std::cerr << std::endl;
1315 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1316 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
1317 std::cerr << std::endl;
1327 Double_t valuep = 0.0;
1328 Double_t errorp = 0.0;
1329 Double_t valuem = 0.0;
1330 Double_t errorm = 0.0;
1331 Double_t value = 0.0;
1332 Double_t error = 0.0;
1335 for (Int_t i=start[0]; i<end[0]; i++) {
1342 if (((i-start[0]) % packing == 0) && (i != start[0])) {
1349 if (valuep == 0.0) {
1354 if (valuem == 0.0) {
1372 for (Int_t i=start[1]; i<end[1]; i++) {
1379 if (((i-start[1]) % packing == 0) && (i != start[1])) {
1386 if (valuep == 0.0) {
1391 if (valuem == 0.0) {
1409 UInt_t noOfBins = forwardpPacked.
GetValue()->size();
1410 if (forwardpPacked.
GetValue()->size() != backwardpPacked.
GetValue()->size()) {
1411 if (forwardpPacked.
GetValue()->size() > backwardpPacked.
GetValue()->size())
1412 noOfBins = backwardpPacked.
GetValue()->size();
1417 Double_t fp, bp, efp, ebp, alpha, beta = 1.0;
1418 Double_t fm, bm, efm, ebm;
1421 fData.SetDataTimeStart(
fTimeResolution*(
static_cast<Double_t
>(start[0])-t0[0]+
static_cast<Double_t
>(packing-1)/2.0));
1435 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1447 beta = par[
fRunInfo->GetBetaParamNo()-1];
1457 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1465 beta = par[
fRunInfo->GetBetaParamNo()-1];
1480 beta = par[
fRunInfo->GetBetaParamNo()-1];
1492 for (UInt_t i=0; i<forwardpPacked.
GetValue()->size(); i++) {
1494 fp = forwardpPacked.
GetValue()->at(i);
1495 bp = backwardpPacked.
GetValue()->at(i);
1496 efp = forwardpPacked.
GetError()->at(i);
1497 ebp = backwardpPacked.
GetError()->at(i);
1498 fm = forwardmPacked.
GetValue()->at(i);
1499 bm = backwardmPacked.
GetValue()->at(i);
1500 efm = forwardmPacked.
GetError()->at(i);
1501 ebm = backwardmPacked.
GetError()->at(i);
1504 asym = (alpha*fp-bp) / (alpha*beta*fp+bp) - (alpha*fm-bm) / (alpha*beta*fm+bm);
1507 fData.AppendValue(asym);
1510 errorp = 2.0/((fp+bp)*(fp+bp))*TMath::Sqrt(bp*bp*efp*efp+ebp*ebp*fp*fp);
1514 errorm = 2.0/((fm+bm)*(fm+bm))*TMath::Sqrt(bm*bm*efm*efm+ebm*ebm*fm*fm);
1517 error = TMath::Sqrt(errorp*errorp+errorm*errorm);
1518 fData.AppendErrorValue(error);
1535 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1540 UInt_t size = runData->
GetDataBin(histoNo[0])->size();
1543 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1545 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1549 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1553 for (UInt_t i=0; i<size; i++) {
1554 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1556 if (fabs(value) > 10.0) {
1559 fData.AppendTheoryValue(value);
1596 size_t size = 2*forwardHistoNo.size();
1597 if (backwardHistoNo.size() > forwardHistoNo.size())
1598 size = 2*backwardHistoNo.size();
1600 for (UInt_t i=0; i<
fT0s.size(); i++) {
1605 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1611 if (
fT0s[i] == -1) {
1617 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1618 if (
fT0s[2*i] == -1.0)
1619 if (runData->
GetT0Bin(forwardHistoNo[i]) > 0.0) {
1624 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1625 if (
fT0s[2*i+1] == -1.0)
1626 if (runData->
GetT0Bin(backwardHistoNo[i]) > 0.0) {
1633 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1634 if (
fT0s[2*i] == -1.0) {
1638 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1639 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1640 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(forwardHistoNo[i]);
1641 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1642 std::cerr << std::endl;
1645 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1646 if (
fT0s[2*i+1] == -1.0) {
1650 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1651 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1652 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[i]);
1653 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1654 std::cerr << std::endl;
1659 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1660 if ((
fT0s[2*i] < 0) || (
fT0s[2*i] >
static_cast<Int_t
>(runData->
GetDataBin(forwardHistoNo[i])->size()))) {
1661 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[2*i] <<
") doesn't make any sense!";
1662 std::cerr << std::endl <<
">> forwardHistoNo " << forwardHistoNo[i];
1663 std::cerr << std::endl;
1667 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1668 if ((
fT0s[2*i+1] < 0) || (
fT0s[2*i+1] >
static_cast<Int_t
>(runData->
GetDataBin(backwardHistoNo[i])->size()))) {
1669 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **ERROR** t0 data bin (" <<
fT0s[2*i+1] <<
") doesn't make any sense!";
1670 std::cerr << std::endl <<
">> backwardHistoNo " << backwardHistoNo[i];
1671 std::cerr << std::endl;
1677 if (
fRunInfo->GetRunNameSize() > 1) {
1680 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1683 if (addRunData == 0) {
1684 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1685 std::cerr << std::endl;
1692 fAddT0s[i-1].resize(2*forwardHistoNo.size());
1693 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1698 for (Int_t j=0; j<
fRunInfo->GetAddT0BinSize(i-1); j++) {
1703 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1704 if (
fAddT0s[i-1][2*j] == -1.0)
1705 if (addRunData->
GetT0Bin(forwardHistoNo[j]) > 0.0) {
1710 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1711 if (
fAddT0s[i-1][2*j+1] == -1.0)
1712 if (addRunData->
GetT0Bin(backwardHistoNo[j]) > 0.0) {
1719 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1720 if (
fAddT0s[i-1][2*j] == -1.0) {
1724 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1725 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1726 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(forwardHistoNo[j]);
1727 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1728 std::cerr << std::endl;
1731 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1732 if (
fAddT0s[i-1][2*j+1] == -1.0) {
1736 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1737 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1738 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[j]);
1739 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1740 std::cerr << std::endl;
1771 if (start[0] == -1) {
1772 start[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1774 if (start[1] == -1) {
1775 start[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(2);
1778 end[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1781 end[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(3);
1784 Double_t t0[2] = {
fT0s[0],
fT0s[1]};
1789 start[0] =
static_cast<Int_t
>(t0[0])+offset;
1790 fRunInfo->SetDataRange(start[0], 0);
1791 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[0] <<
".";
1792 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1793 std::cerr << std::endl;
1796 start[1] =
static_cast<Int_t
>(t0[1])+offset;
1797 fRunInfo->SetDataRange(start[1], 2);
1798 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[1] <<
".";
1799 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1800 std::cerr << std::endl;
1803 end[0] = runData->
GetDataBin(histoNo[0])->size();
1805 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range end = " << end[0] <<
".";
1806 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1807 std::cerr << std::endl;
1810 end[1] = runData->
GetDataBin(histoNo[1])->size();
1812 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range end = " << end[1] <<
".";
1813 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1814 std::cerr << std::endl;
1819 for (UInt_t i=0; i<2; i++) {
1820 if (end[i] < start[i]) {
1821 Int_t keep = end[i];
1826 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1827 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **ERROR** start data bin doesn't make any sense!";
1828 std::cerr << std::endl;
1833 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **ERROR** end data bin (" << end[i] <<
") doesn't make any sense!";
1834 std::cerr << std::endl;
1837 if (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())) {
1838 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** end data bin (" << end[i] <<
") > histo length (" <<
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()) <<
").";
1839 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
1840 std::cerr << std::endl;
1841 end[i] =
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())-1;
1844 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1845 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **ERROR** t0 data bin doesn't make any sense!";
1846 std::cerr << std::endl;
1852 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) > fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1853 start[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(start[0]) - t0[0]);
1854 end[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(end[0]) - t0[0]);
1855 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange **WARNING** needed to shift backward data range.";
1856 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(2) <<
", " <<
fRunInfo->GetDataRange(3);
1857 std::cerr << std::endl <<
">> used : " << start[1] <<
", " << end[1];
1858 std::cerr << std::endl;
1860 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) < fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1861 start[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(start[1]) - t0[1]);
1862 end[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(end[1]) - t0[1]);
1863 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange **WARNING** needed to shift forward data range.";
1864 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(0) <<
", " <<
fRunInfo->GetDataRange(1);
1865 std::cerr << std::endl <<
">> used : " << start[0] <<
", " << end[0];
1866 std::cerr << std::endl;
1925 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
1926 std::cerr <<
">> Will set it to fgb/lgb which given in time is: " <<
fFitStartTime <<
"..." <<
fFitEndTime <<
" (usec)" << std::endl;
1950 Double_t SumF[2] = {0.0, 0.0};
1951 Double_t SumB[2] = {0.0, 0.0};
1956 for (Int_t i=0; i<
fForwardp.size(); i++) {
1968 if ( (SumF[0]+SumF[1]) == 0) {
1971 alpha = (SumB[0]+SumB[1])/(SumF[0]+SumF[1]);
1973 std::cout << std::endl <<
">> PRunAsymmetryBNMR::EstimateAlpha(): alpha estimate=" << alpha << 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.
#define ACCEL_PERIOD_RAL
RAL (Rutherford Appleton Lab) - pulsed beam.
virtual void SetFitRange(Double_t dval, UInt_t idx)
virtual Double_t GetFitRange(UInt_t idx)
virtual UInt_t GetT0BinSize()
virtual Bool_t IsFitRangeInBin()
virtual Int_t GetFitRangeOffset(UInt_t idx)
virtual Double_t GetT0Bin(UInt_t idx=0)
MSR file parser and manager for the musrfit framework.
virtual 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 Bool_t GetProperT0(PRawRunData *runData, PMsrGlobalBlock *globalBlock, PUIntVector &forwardHisto, PUIntVector &backwardHistoNo)
Retrieves proper t0 values for all histograms.
UInt_t fAlphaBetaTag
Tag indicating α/β configuration: 1=both unity, 2=α free/β unity, 3=α unity/β free,...
Bool_t SubtractEstimatedBkg()
Estimates and subtracts background from histograms.
Bool_t SubtractFixBkg()
Subtracts fixed background from histograms.
virtual ~PRunAsymmetryBNMR()
Destructor.
virtual UInt_t GetNoOfFitBins()
Returns the number of bins used in the fit.
virtual Bool_t PrepareViewData(PRawRunData *runData, UInt_t histoNo[2])
Prepares data for viewing/plotting.
UInt_t fNoOfFitBins
Number of bins included in the fit.
PDoubleVector fBackwardmErr
Negative helicity backward histogram errors.
virtual Double_t EstimateAlpha()
Estimates α parameter from data.
virtual Double_t CalcChiSquareExpected(const std::vector< Double_t > &par)
Calculates expected chi-square (for statistical analysis).
virtual Bool_t PrepareFitData()
Prepares data specifically for fitting.
PDoubleVector fForwardm
Negative helicity forward histogram data.
virtual Bool_t PrepareData()
Prepares all data for fitting or viewing.
PDoubleVector fForwardpErr
Positive helicity forward histogram errors.
Bool_t fTheoAsData
If true, theory calculated only at data points; if false, extra points for nicer Fourier transforms.
Int_t fGoodBins[4]
Good bin boundaries: [0]=forward first, [1]=forward last, [2]=backward first, [3]=backward last.
Int_t fStartTimeBin
First bin index for fitting.
virtual void CalcNoOfFitBins()
Calculates the number of bins to be fitted.
PDoubleVector fBackwardpErr
Positive helicity backward histogram errors.
virtual void CalcTheory()
Calculates theoretical asymmetry function.
virtual Double_t CalcMaxLikelihood(const std::vector< Double_t > &par)
Calculates maximum likelihood estimator.
PDoubleVector fForwardmErr
Negative helicity forward histogram errors.
PDoubleVector fBackwardp
Positive helicity backward histogram data.
virtual Double_t CalcChiSquare(const std::vector< Double_t > &par)
Calculates chi-square for the current parameter set.
virtual void SetFitRangeBin(const TString fitRange)
Sets the fit range in bins.
PDoubleVector fBackwardm
Negative helicity backward histogram data.
Int_t fEndTimeBin
Last bin index for fitting.
PRunAsymmetryBNMR()
Default constructor.
virtual void GetProperFitRange(PMsrGlobalBlock *globalBlock)
Determines the proper fit range from global block.
PDoubleVector fForwardp
Positive helicity forward histogram data.
virtual Bool_t GetProperDataRange(PRawRunData *runData, UInt_t histoNo[2])
Retrieves proper data range for histograms.
Int_t fPacking
Bin packing factor from RUN or GLOBAL block.
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)
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.
virtual void AppendErrorValue(Double_t dval)
virtual void AppendValue(Double_t dval)
virtual const PDoubleVector * GetValue()
Returns pointer to data value vector (asymmetry, counts, or y-data)
virtual const PDoubleVector * GetError()
Returns pointer to data error vector (statistical uncertainties)