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;
140 if ((fRunInfo->GetAlphaParamNo()-MSR_PARAM_FUN_OFFSET < 0) ||
141 (fRunInfo->GetAlphaParamNo()-MSR_PARAM_FUN_OFFSET > msrInfo->GetNoOfFuncs())) {
142 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **ERROR** alpha parameter is a function with no = " << fRunInfo->GetAlphaParamNo();
143 std::cerr << std::endl <<
">> This is out of bound, since there are only " << msrInfo->GetNoOfFuncs() <<
" functions.";
144 std::cerr << std::endl;
148 }
else if ((fRunInfo->GetAlphaParamNo() < 0) || (fRunInfo->GetAlphaParamNo() > (Int_t)param->size())) {
149 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **ERROR** alpha parameter no = " << fRunInfo->GetAlphaParamNo();
150 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
151 std::cerr << std::endl;
155 if (((*param)[fRunInfo->GetAlphaParamNo()-1].fStep == 0.0) &&
156 ((*param)[fRunInfo->GetAlphaParamNo()-1].fValue == 1.0))
157 alphaFixedToOne = true;
161 Bool_t betaFixedToOne =
false;
162 if (fRunInfo->GetBetaParamNo() == -1) {
163 betaFixedToOne = true;
165 if ((fRunInfo->GetBetaParamNo()-MSR_PARAM_FUN_OFFSET < 0) ||
166 (fRunInfo->GetBetaParamNo()-MSR_PARAM_FUN_OFFSET > msrInfo->GetNoOfFuncs())) {
167 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **ERROR** beta parameter is a function with no = " << fRunInfo->GetBetaParamNo();
168 std::cerr << std::endl <<
">> This is out of bound, since there are only " << msrInfo->GetNoOfFuncs() <<
" functions.";
169 std::cerr << std::endl;
173 }
else if ((fRunInfo->GetBetaParamNo() < 0) || (fRunInfo->GetBetaParamNo() > (Int_t)param->size())) {
174 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PRunAsymmetryBNMR(): **ERROR** beta parameter no = " << fRunInfo->GetBetaParamNo();
175 std::cerr << std::endl <<
">> This is out of bound, since there are only " << param->size() <<
" parameters.";
176 std::cerr << std::endl;
180 if (((*param)[fRunInfo->GetBetaParamNo()-1].fStep == 0.0) &&
181 ((*param)[fRunInfo->GetBetaParamNo()-1].fValue == 1.0))
182 betaFixedToOne = true;
186 if (alphaFixedToOne && betaFixedToOne)
188 else if (!alphaFixedToOne && betaFixedToOne & !alphaSetDefault)
190 else if (alphaFixedToOne && !betaFixedToOne)
192 else if (!alphaFixedToOne && betaFixedToOne & alphaSetDefault)
194 else if (!alphaFixedToOne && !betaFixedToOne & alphaSetDefault)
247 Double_t chisq = 0.0;
249 Double_t asymFcnValue = 0.0;
253 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
258 Double_t time(1.0),alphaest;
262 alphaest =
fRunInfo->GetEstimatedAlpha();
270 a = par[
fRunInfo->GetAlphaParamNo()-1];
282 b = par[
fRunInfo->GetBetaParamNo()-1];
292 a = par[
fRunInfo->GetAlphaParamNo()-1];
300 b = par[
fRunInfo->GetBetaParamNo()-1];
315 b = par[
fRunInfo->GetBetaParamNo()-1];
339 #pragma omp parallel for default(shared) private(i,time,diff,asymFcnValue,f) schedule(dynamic,chunk) reduction(+:chisq)
342 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
344 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));
345 diff =
fData.GetValue()->at(i) - asymFcnValue;
346 chisq += diff*diff / (
fData.GetError()->at(i)*
fData.GetError()->at(i));
383 std::cout << std::endl <<
"PRunAsymmetryBNMR::CalcMaxLikelihood(): not implemented yet ..." << std::endl;
434 if (tok.size() == 3) {
438 idx = str.First(
"+");
440 str.Remove(0, idx+1);
449 idx = str.First(
"-");
451 str.Remove(0, idx+1);
456 }
else if ((tok.size() > 3) && (tok.size() % 2 == 1)) {
457 UInt_t pos = 2*(
fRunNo+1)-1;
459 if (pos + 1 >= tok.size()) {
460 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
461 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
466 idx = str.First(
"+");
468 str.Remove(0, idx+1);
477 idx = str.First(
"-");
479 str.Remove(0, idx+1);
486 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SetFitRangeBin(): **ERROR** invalid FIT_RANGE command found: '" << fitRange <<
"'";
487 std::cerr << std::endl <<
">> will ignore it. Sorry ..." << std::endl;
538 std::vector<Double_t> par;
540 for (UInt_t i=0; i<paramList->size(); i++)
541 par.push_back((*paramList)[i].fValue);
544 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
549 Double_t asymFcnValue = 0.0;
550 Double_t a, b, f, alphaest;
554 alphaest =
fRunInfo->GetEstimatedAlpha();
556 for (UInt_t i=0; i<
fData.GetValue()->size(); i++) {
557 time =
fData.GetDataTimeStart() +
static_cast<Double_t
>(i)*
fData.GetDataTimeStep();
564 a = par[
fRunInfo->GetAlphaParamNo()-1];
572 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));
576 b = par[
fRunInfo->GetBetaParamNo()-1];
584 asymFcnValue = f*(b+1.0)/(2.0-f*(b-1.0))-f*(b+1.0)/(2.0+f*(b-1.0));
588 a = par[
fRunInfo->GetAlphaParamNo()-1];
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));
609 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));
614 b = par[
fRunInfo->GetBetaParamNo()-1];
622 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));
628 fData.AppendTheoryValue(asymFcnValue);
671 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **ERROR** Couldn't get run " <<
fRunInfo->GetRunName()->Data() <<
"!";
672 std::cerr << std::endl;
689 for (UInt_t i=0; i<
fRunInfo->GetForwardHistoNoSize(); i++) {
690 forwardHistoNo.push_back(
fRunInfo->GetForwardHistoNo(i));
692 if (!runData->
IsPresent(forwardHistoNo[i])) {
693 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **PANIC ERROR**:";
694 std::cerr << std::endl <<
">> forwardHistoNo found = " << forwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
695 std::cerr << std::endl <<
">> Will quit :-(";
696 std::cerr << std::endl;
698 forwardHistoNo.clear();
699 backwardHistoNo.clear();
703 for (UInt_t i=0; i<
fRunInfo->GetBackwardHistoNoSize(); i++) {
704 backwardHistoNo.push_back(
fRunInfo->GetBackwardHistoNo(i));
706 if (!runData->
IsPresent(backwardHistoNo[i])) {
707 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **PANIC ERROR**:";
708 std::cerr << std::endl <<
">> backwardHistoNo found = " << backwardHistoNo[i] <<
", which is NOT present in the data file!?!?";
709 std::cerr << std::endl <<
">> Will quit :-(";
710 std::cerr << std::endl;
712 forwardHistoNo.clear();
713 backwardHistoNo.clear();
732 std::cout.precision(10);
733 std::cout << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): time resolution=" << std::fixed << runData->
GetTimeResolution() <<
"(ms)" << std::endl;
736 if (!
GetProperT0(runData, globalBlock, forwardHistoNo, backwardHistoNo)) {
741 std::vector<PDoubleVector> forward, backward;
742 forward.resize(forwardHistoNo.size());
743 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
744 forward[i].resize(runData->
GetDataBin(forwardHistoNo[i])->size());
745 forward[i] = *runData->
GetDataBin(forwardHistoNo[i]);
747 backward.resize(backwardHistoNo.size());
748 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
749 backward[i].resize(runData->
GetDataBin(backwardHistoNo[i])->size());
750 backward[i] = *runData->
GetDataBin(backwardHistoNo[i]);
755 if (
fRunInfo->GetRunNameSize() > 1) {
757 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
760 if (addRunData ==
nullptr) {
761 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
762 std::cerr << std::endl;
768 for (UInt_t k=0; k<forwardHistoNo.size(); k++) {
769 addRunSize = addRunData->
GetDataBin(forwardHistoNo[k])->size();
770 for (UInt_t j=0; j<addRunData->
GetDataBin(forwardHistoNo[k])->size(); j++) {
772 if ((
static_cast<Int_t
>(j)+
static_cast<Int_t
>(
fAddT0s[i-1][2*k])-
static_cast<Int_t
>(
fT0s[2*k]) >= 0) &&
773 (j+
static_cast<Int_t
>(
fAddT0s[i-1][2*k])-
static_cast<Int_t
>(
fT0s[2*k]) < addRunSize)) {
774 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]));
780 for (UInt_t k=0; k<backwardHistoNo.size(); k++) {
781 addRunSize = addRunData->
GetDataBin(backwardHistoNo[k])->size();
782 for (UInt_t j=0; j<addRunData->
GetDataBin(backwardHistoNo[k])->size(); j++) {
784 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) &&
785 (j+
static_cast<Int_t
>(
fAddT0s[i-1][2*k+1])-
static_cast<Int_t
>(
fT0s[2*k+1]) < addRunSize)) {
786 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]));
796 for (UInt_t i=0; i<
fForwardp.size(); i++) {
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 <<
">> PRunAsymmetryBNMR::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 GUARANTEE 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();
887 for (UInt_t i=0; i<
fForwardp.size(); i++) {
946 Double_t beamPeriod = 0.0;
949 if (
fRunInfo->GetInstitute()->Contains(
"psi"))
951 else if (
fRunInfo->GetInstitute()->Contains(
"ral"))
953 else if (
fRunInfo->GetInstitute()->Contains(
"triumf"))
961 for (UInt_t i=0; i<2; i++) {
962 if (end[i] < start[i]) {
963 std::cout << std::endl <<
"PRunAsymmetryBNMR::SubtractEstimatedBkg(): end = " << end[i] <<
" > start = " << start[i] <<
"! Will swap them!";
964 UInt_t keep = end[i];
971 for (UInt_t i=0; i<2; i++) {
972 if (beamPeriod != 0.0) {
974 UInt_t fullCycles =
static_cast<UInt_t
>(timeBkg/beamPeriod);
977 std::cout <<
"PRunAsymmetryBNMR::SubtractEstimatedBkg(): Background " << start[i] <<
", " << end[i] << std::endl;
978 if (end[i] == start[i])
979 end[i] =
fRunInfo->GetBkgRange(2*i+1);
984 if ((start[0] < 0) || (start[0] >=
fForwardp.size()) ||
985 (start[1] < 0) || (start[1] >=
fBackwardp.size())) {
986 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
987 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForwardp.size() <<
"/" <<
fBackwardp.size() <<
").";
988 std::cerr << std::endl <<
">> background start (f/b) = (" << start[0] <<
"/" << start[1] <<
").";
993 if ((end[0] < 0) || (end[0] >=
fForwardp.size()) ||
994 (end[1] < 0) || (end[1] >=
fBackwardp.size())) {
995 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
996 std::cerr << std::endl <<
">> histo lengths (f/b) = (" <<
fForwardp.size() <<
"/" <<
fBackwardp.size() <<
").";
997 std::cerr << std::endl <<
">> background end (f/b) = (" << end[0] <<
"/" << end[1] <<
").";
1002 Double_t bkgp[2] = {0.0, 0.0};
1003 Double_t errBkgp[2] = {0.0, 0.0};
1004 Double_t bkgm[2] = {0.0, 0.0};
1005 Double_t errBkgm[2] = {0.0, 0.0};
1008 for (UInt_t i=start[0]; i<=end[0]; i++) {
1012 errBkgp[0] = TMath::Sqrt(bkgp[0])/(end[0] - start[0] + 1);
1013 bkgp[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
1014 std::cout << std::endl <<
">> estimated pos hel forward histo background: " << bkgp[0];
1015 errBkgm[0] = TMath::Sqrt(bkgp[0])/(end[0] - start[0] + 1);
1016 bkgm[0] /=
static_cast<Double_t
>(end[0] - start[0] + 1);
1017 std::cout << std::endl <<
">> estimated neg hel forward histo background: " << bkgm[0];
1020 for (UInt_t i=start[1]; i<=end[1]; i++) {
1024 errBkgp[1] = TMath::Sqrt(bkgp[1])/(end[1] - start[1] + 1);
1025 bkgp[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
1026 std::cout << std::endl <<
">> estimated pos hel backward histo background: " << bkgp[1];
1027 errBkgm[1] = TMath::Sqrt(bkgm[1])/(end[1] - start[1] + 1);
1028 bkgm[1] /=
static_cast<Double_t
>(end[1] - start[1] + 1);
1029 std::cout << std::endl <<
">> estimated neg hel backward histo background: " << bkgm[1];
1032 Double_t errVal = 0.0;
1033 for (UInt_t i=0; i<
fForwardp.size(); i++) {
1035 errVal = TMath::Sqrt(
fForwardp[i]+errBkgp[0]*errBkgp[0]);
1040 errVal = TMath::Sqrt(
fBackwardp[i]+errBkgp[1]*errBkgp[1]);
1045 errVal = TMath::Sqrt(
fForwardm[i]+errBkgm[0]*errBkgm[0]);
1050 errVal = TMath::Sqrt(
fBackwardm[i]+errBkgm[1]*errBkgm[1]);
1057 for (UInt_t i=0; i<
fForwardp.size(); i++) {
1064 fRunInfo->SetBkgEstimated(bkgp[0], 0);
1065 fRunInfo->SetBkgEstimated(bkgp[1], 1);
1066 fRunInfo->SetBkgEstimated(bkgm[0], 3);
1067 fRunInfo->SetBkgEstimated(bkgm[1], 4);
1072 fRunInfo->SetEstimatedAlpha(alpha);
1102 Double_t valuep = 0.0;
1103 Double_t errorp = 0.0;
1104 Double_t valuem = 0.0;
1105 Double_t errorm = 0.0;
1122 if (valuep == 0.0) {
1127 if (valuem == 0.0) {
1159 if (valuep == 0.0) {
1164 if (valuem == 0.0) {
1182 UInt_t noOfBins = forwardpPacked.
GetValue()->size();
1183 if (forwardpPacked.
GetValue()->size() != backwardpPacked.
GetValue()->size()) {
1184 if (forwardpPacked.
GetValue()->size() > backwardpPacked.
GetValue()->size())
1185 noOfBins = backwardpPacked.
GetValue()->size();
1189 Double_t asym,error;
1190 Double_t fp, bp, efp, ebp;
1191 Double_t fm, bm, efm, ebm;
1196 for (UInt_t i=0; i<noOfBins; i++) {
1198 fp = forwardpPacked.
GetValue()->at(i);
1199 bp = backwardpPacked.
GetValue()->at(i);
1200 efp = forwardpPacked.
GetError()->at(i);
1201 ebp = backwardpPacked.
GetError()->at(i);
1202 fm = forwardmPacked.
GetValue()->at(i);
1203 bm = backwardmPacked.
GetValue()->at(i);
1204 efm = forwardmPacked.
GetError()->at(i);
1205 ebm = backwardmPacked.
GetError()->at(i);
1208 asym = (fp-bp) / (fp+bp) - (fm-bm) / (fm+bm);
1211 fData.AppendValue(asym);
1214 errorp = 2.0/((fp+bp)*(fp+bp))*TMath::Sqrt(bp*bp*efp*efp+ebp*ebp*fp*fp);
1218 errorm = 2.0/((fm+bm)*(fm+bm))*TMath::Sqrt(bm*bm*efm*efm+ebm*ebm*fm*fm);
1222 error = TMath::Sqrt(errorp*errorp+errorm*errorm);
1223 fData.AppendErrorValue(error);
1258 if (
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
1259 packing =
fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
1263 std::vector<Double_t> par;
1265 for (UInt_t i=0; i<paramList->size(); i++)
1266 par.push_back((*paramList)[i].fValue);
1274 Int_t t0[2] = {
static_cast<Int_t
>(
fT0s[0]),
static_cast<Int_t
>(
fT0s[1])};
1278 if (start[0]-t0[0] != start[1]-t0[1]) {
1279 if (abs(start[0]-t0[0]) > abs(start[1]-t0[1])) {
1281 fgb[1] = t0[1] + start[0]-t0[0];
1282 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **WARNING** needed to shift backward fgb from ";
1283 std::cerr << start[1] <<
" to " << fgb[1] << std::endl;
1285 fgb[0] = t0[0] + start[1]-t0[1];
1287 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **WARNING** needed to shift forward fgb from ";
1288 std::cerr << start[0] <<
" to " << fgb[0] << std::endl;
1295 Int_t val = fgb[0]-packing*(fgb[0]/packing);
1297 if (fgb[1] - fgb[0] < 0)
1299 }
while (val + fgb[1] - fgb[0] < 0);
1302 start[1] = val + fgb[1] - fgb[0];
1305 UInt_t noOfBins0 = (runData->
GetDataBin(histoNo[0])->size()-start[0])/packing;
1306 UInt_t noOfBins1 = (runData->
GetDataBin(histoNo[1])->size()-start[1])/packing;
1307 if (noOfBins0 > noOfBins1)
1308 noOfBins0 = noOfBins1;
1309 end[0] = start[0] + noOfBins0 * packing;
1310 end[1] = start[1] + noOfBins0 * packing;
1314 for (UInt_t i=0; i<2; i++) {
1315 if (end[i] < start[i]) {
1316 Int_t keep = end[i];
1321 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1322 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
1323 std::cerr << std::endl;
1327 if ((end[i] < 0) || (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1328 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
1329 std::cerr << std::endl;
1333 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1334 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
1335 std::cerr << std::endl;
1345 Double_t valuep = 0.0;
1346 Double_t errorp = 0.0;
1347 Double_t valuem = 0.0;
1348 Double_t errorm = 0.0;
1349 Double_t value = 0.0;
1350 Double_t error = 0.0;
1353 for (Int_t i=start[0]; i<end[0]; i++) {
1360 if (((i-start[0]) % packing == 0) && (i != start[0])) {
1367 if (valuep == 0.0) {
1372 if (valuem == 0.0) {
1390 for (Int_t i=start[1]; i<end[1]; i++) {
1397 if (((i-start[1]) % packing == 0) && (i != start[1])) {
1404 if (valuep == 0.0) {
1409 if (valuem == 0.0) {
1427 UInt_t noOfBins = forwardpPacked.
GetValue()->size();
1428 if (forwardpPacked.
GetValue()->size() != backwardpPacked.
GetValue()->size()) {
1429 if (forwardpPacked.
GetValue()->size() > backwardpPacked.
GetValue()->size())
1430 noOfBins = backwardpPacked.
GetValue()->size();
1435 Double_t fp, bp, efp, ebp, alpha, beta = 1.0;
1436 Double_t fm, bm, efm, ebm;
1439 fData.SetDataTimeStart(
fTimeResolution*(
static_cast<Double_t
>(start[0])-t0[0]+
static_cast<Double_t
>(packing-1)/2.0));
1453 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1465 beta = par[
fRunInfo->GetBetaParamNo()-1];
1475 alpha = par[
fRunInfo->GetAlphaParamNo()-1];
1483 beta = par[
fRunInfo->GetBetaParamNo()-1];
1498 beta = par[
fRunInfo->GetBetaParamNo()-1];
1510 for (UInt_t i=0; i<forwardpPacked.
GetValue()->size(); i++) {
1512 fp = forwardpPacked.
GetValue()->at(i);
1513 bp = backwardpPacked.
GetValue()->at(i);
1514 efp = forwardpPacked.
GetError()->at(i);
1515 ebp = backwardpPacked.
GetError()->at(i);
1516 fm = forwardmPacked.
GetValue()->at(i);
1517 bm = backwardmPacked.
GetValue()->at(i);
1518 efm = forwardmPacked.
GetError()->at(i);
1519 ebm = backwardmPacked.
GetError()->at(i);
1522 asym = (alpha*fp-bp) / (alpha*beta*fp+bp) - (alpha*fm-bm) / (alpha*beta*fm+bm);
1525 fData.AppendValue(asym);
1528 errorp = 2.0/((fp+bp)*(fp+bp))*TMath::Sqrt(bp*bp*efp*efp+ebp*ebp*fp*fp);
1532 errorm = 2.0/((fm+bm)*(fm+bm))*TMath::Sqrt(bm*bm*efm*efm+ebm*ebm*fm*fm);
1535 error = TMath::Sqrt(errorp*errorp+errorm*errorm);
1536 fData.AppendErrorValue(error);
1553 for (Int_t i=0; i<
fMsrInfo->GetNoOfFuncs(); i++) {
1558 UInt_t size = runData->
GetDataBin(histoNo[0])->size();
1561 fData.SetTheoryTimeStart(
fData.GetDataTimeStart());
1563 fData.SetTheoryTimeStep(
fData.GetDataTimeStep());
1567 fData.SetTheoryTimeStep(
fData.GetDataTimeStep()/(Double_t)factor);
1571 for (UInt_t i=0; i<size; i++) {
1572 time =
fData.GetTheoryTimeStart() +
static_cast<Double_t
>(i)*
fData.GetTheoryTimeStep();
1574 if (fabs(value) > 10.0) {
1577 fData.AppendTheoryValue(value);
1614 size_t size = 2*forwardHistoNo.size();
1615 if (backwardHistoNo.size() > forwardHistoNo.size())
1616 size = 2*backwardHistoNo.size();
1618 for (UInt_t i=0; i<
fT0s.size(); i++) {
1623 for (UInt_t i=0; i<
fRunInfo->GetT0BinSize(); i++) {
1629 if (
fT0s[i] == -1) {
1635 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1636 if (
fT0s[2*i] == -1.0)
1637 if (runData->
GetT0Bin(forwardHistoNo[i]) > 0.0) {
1642 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1643 if (
fT0s[2*i+1] == -1.0)
1644 if (runData->
GetT0Bin(backwardHistoNo[i]) > 0.0) {
1651 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1652 if (
fT0s[2*i] == -1.0) {
1656 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1657 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1658 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << runData->
GetT0BinEstimated(forwardHistoNo[i]);
1659 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1660 std::cerr << std::endl;
1663 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1664 if (
fT0s[2*i+1] == -1.0) {
1668 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1669 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName()->Data();
1670 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[i]);
1671 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1672 std::cerr << std::endl;
1677 for (UInt_t i=0; i<forwardHistoNo.size(); i++) {
1678 if ((
fT0s[2*i] < 0) || (
fT0s[2*i] >
static_cast<Int_t
>(runData->
GetDataBin(forwardHistoNo[i])->size()))) {
1679 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **ERROR** t0 data bin (" <<
fT0s[2*i] <<
") doesn't make any sense!";
1680 std::cerr << std::endl <<
">> forwardHistoNo " << forwardHistoNo[i];
1681 std::cerr << std::endl;
1685 for (UInt_t i=0; i<backwardHistoNo.size(); i++) {
1686 if ((
fT0s[2*i+1] < 0) || (
fT0s[2*i+1] >
static_cast<Int_t
>(runData->
GetDataBin(backwardHistoNo[i])->size()))) {
1687 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::PrepareData(): **ERROR** t0 data bin (" <<
fT0s[2*i+1] <<
") doesn't make any sense!";
1688 std::cerr << std::endl <<
">> backwardHistoNo " << backwardHistoNo[i];
1689 std::cerr << std::endl;
1695 if (
fRunInfo->GetRunNameSize() > 1) {
1698 for (UInt_t i=1; i<
fRunInfo->GetRunNameSize(); i++) {
1701 if (addRunData == 0) {
1702 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **ERROR** Couldn't get addrun " <<
fRunInfo->GetRunName(i)->Data() <<
"!";
1703 std::cerr << std::endl;
1710 fAddT0s[i-1].resize(2*forwardHistoNo.size());
1711 for (UInt_t j=0; j<
fAddT0s[i-1].size(); j++) {
1716 for (Int_t j=0; j<
fRunInfo->GetAddT0BinSize(i-1); j++) {
1721 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1722 if (
fAddT0s[i-1][2*j] == -1.0)
1723 if (addRunData->
GetT0Bin(forwardHistoNo[j]) > 0.0) {
1728 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1729 if (
fAddT0s[i-1][2*j+1] == -1.0)
1730 if (addRunData->
GetT0Bin(backwardHistoNo[j]) > 0.0) {
1737 for (UInt_t j=0; j<forwardHistoNo.size(); j++) {
1738 if (
fAddT0s[i-1][2*j] == -1.0) {
1742 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1743 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1744 std::cerr << std::endl <<
">> will try the estimated one: forward t0 = " << addRunData->
GetT0BinEstimated(forwardHistoNo[j]);
1745 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1746 std::cerr << std::endl;
1749 for (UInt_t j=0; j<backwardHistoNo.size(); j++) {
1750 if (
fAddT0s[i-1][2*j+1] == -1.0) {
1754 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperT0(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!";
1755 std::cerr << std::endl <<
">> run: " <<
fRunInfo->GetRunName(i)->Data();
1756 std::cerr << std::endl <<
">> will try the estimated one: backward t0 = " << runData->
GetT0BinEstimated(backwardHistoNo[j]);
1757 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS OK!! For instance for LEM this is almost for sure rubbish!";
1758 std::cerr << std::endl;
1789 if (start[0] == -1) {
1790 start[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(0);
1792 if (start[1] == -1) {
1793 start[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(2);
1796 end[0] =
fMsrInfo->GetMsrGlobal()->GetDataRange(1);
1799 end[1] =
fMsrInfo->GetMsrGlobal()->GetDataRange(3);
1802 Double_t t0[2] = {
fT0s[0],
fT0s[1]};
1807 start[0] =
static_cast<Int_t
>(t0[0])+offset;
1808 fRunInfo->SetDataRange(start[0], 0);
1809 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[0] <<
".";
1810 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1811 std::cerr << std::endl;
1814 start[1] =
static_cast<Int_t
>(t0[1])+offset;
1815 fRunInfo->SetDataRange(start[1], 2);
1816 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range start = t0+" << offset <<
"(=10ns) = " << start[1] <<
".";
1817 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1818 std::cerr << std::endl;
1821 end[0] = runData->
GetDataBin(histoNo[0])->size();
1823 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (forward) was not provided, will try data range end = " << end[0] <<
".";
1824 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1825 std::cerr << std::endl;
1828 end[1] = runData->
GetDataBin(histoNo[1])->size();
1830 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** data range (backward) was not provided, will try data range end = " << end[1] <<
".";
1831 std::cerr << std::endl <<
">> NO GUARANTEE THAT THIS DOES MAKE ANY SENSE.";
1832 std::cerr << std::endl;
1837 for (UInt_t i=0; i<2; i++) {
1838 if (end[i] < start[i]) {
1839 Int_t keep = end[i];
1844 if ((start[i] < 0) || (start[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1845 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **ERROR** start data bin doesn't make any sense!";
1846 std::cerr << std::endl;
1851 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **ERROR** end data bin (" << end[i] <<
") doesn't make any sense!";
1852 std::cerr << std::endl;
1855 if (end[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())) {
1856 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **WARNING** end data bin (" << end[i] <<
") > histo length (" <<
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()) <<
").";
1857 std::cerr << std::endl <<
">> Will set end = (histo length - 1). Consider to change it in the msr-file." << std::endl;
1858 std::cerr << std::endl;
1859 end[i] =
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size())-1;
1862 if ((t0[i] < 0) || (t0[i] >
static_cast<Int_t
>(runData->
GetDataBin(histoNo[i])->size()))) {
1863 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange(): **ERROR** t0 data bin doesn't make any sense!";
1864 std::cerr << std::endl;
1870 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) > fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1871 start[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(start[0]) - t0[0]);
1872 end[1] =
static_cast<Int_t
>(t0[1] +
static_cast<Double_t
>(end[0]) - t0[0]);
1873 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange **WARNING** needed to shift backward data range.";
1874 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(2) <<
", " <<
fRunInfo->GetDataRange(3);
1875 std::cerr << std::endl <<
">> used : " << start[1] <<
", " << end[1];
1876 std::cerr << std::endl;
1878 if (fabs(
static_cast<Double_t
>(start[0])-t0[0]) < fabs(
static_cast<Double_t
>(start[1])-t0[1])){
1879 start[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(start[1]) - t0[1]);
1880 end[0] =
static_cast<Int_t
>(t0[0] +
static_cast<Double_t
>(end[1]) - t0[1]);
1881 std::cerr << std::endl <<
">> PRunAsymmetryBNMR::GetProperDataRange **WARNING** needed to shift forward data range.";
1882 std::cerr << std::endl <<
">> given: " <<
fRunInfo->GetDataRange(0) <<
", " <<
fRunInfo->GetDataRange(1);
1883 std::cerr << std::endl <<
">> used : " << start[0] <<
", " << end[0];
1884 std::cerr << std::endl;
1943 std::cerr <<
">> PRunSingleHisto::GetProperFitRange(): **WARNING** Couldn't get fit start/end time!" << std::endl;
1944 std::cerr <<
">> Will set it to fgb/lgb which given in time is: " <<
fFitStartTime <<
"..." <<
fFitEndTime <<
" (usec)" << std::endl;
1968 Double_t SumF[2] = {0.0, 0.0};
1969 Double_t SumB[2] = {0.0, 0.0};
1974 for (Int_t i=0; i<
fForwardp.size(); i++) {
1986 if ( (SumF[0]+SumF[1]) == 0) {
1989 alpha = (SumB[0]+SumB[1])/(SumF[0]+SumF[1]);
1991 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)
static std::vector< std::string > Split(const std::string &str, const std::string &delimiters)