781 const TString alpha(
"alpha"), beta(
"beta"), norm(
"norm"), bkgfit(
"bkgfit"), lifetime(
"lifetime");
783 std::ostringstream strInfile;
799 std::ostringstream tempRunNumber;
800 tempRunNumber.fill(
'0');
801 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
803 tempRunNumber << tempRun;
805 std::string tempRunName;
807 tempRunName = msrRunList->at(i).GetRunName()->Data();
808 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
809 if ( loc == std::string::npos ) {
810 std::cerr << std::endl <<
">> msr2data: **ERROR** A template run file number does not match the \"file index\"";
811 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the template file!";
812 std::cerr << std::endl;
817 std::cout << std::endl <<
">> msr2data: **INFO** Generating new global input msr file " << msrOutFile << std::endl;
820 std::ostringstream titleStream;
821 titleStream <<
"Global msr file for the runs: ";
827 fMsrHandler->SetMsrTitle(TString(titleStream.str()));
832 std::string tempParamName;
833 for (
unsigned int i(0); i < msrParamList->size(); ++i) {
834 tempParamName = msrParamList->at(i).fName.Data();
835 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
837 msrParamList->at(i).fIsGlobal =
false;
840 msrParamList->at(i).fIsGlobal =
true;
847 std::cout <<
">> msr2data: **ERROR** found NO run specific parameter, hence the GLOBAL option doesn't make sense." << std::endl;
848 std::cout <<
">> msr2data: Could it be, that your run specific labling is < 4 digits? Please check your msr-Input-File." << std::endl;
854 bool wasSorted(
true);
856 if(!msrParamList->at(i).fIsGlobal) {
863 std::vector<int> *tempMap;
865 std::vector<std::string> tempVec;
866 std::string line, tempString;
876 bool mapExists(
false);
877 for (
unsigned int i(0); i < tempLines->size(); ++i) {
878 line = (*tempLines)[i].fLine.Data();
879 split( tempVec, line, is_any_of(
" \t"), token_compress_on );
880 for (
unsigned int j(1); j < tempVec.size(); ++j) {
882 tempPar = boost::lexical_cast<unsigned int>(tempVec[j]);
884 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
885 if (tempPar == msrParamList->at(k).fNo) {
886 if (msrParamList->at(k).fIsGlobal) {
887 tempVec[j] = boost::lexical_cast<std::string>(k + 1);
889 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(k).fName.Data() \
890 <<
" is recognized as run specific!";
891 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template THEORY block.";
892 std::cerr << std::endl <<
">> msr2data: **WARNING** The THEORY block entry will be substituted by a mapped parameter.";
893 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
894 std::cerr << std::endl;
897 tempMap = msrRunList->at(0).GetMap();
898 while (l < tempMap->size()) {
899 if ((*tempMap)[l] == tempPar) {
902 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
917 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
920 for (l = 0; l < tempMap->size(); ++l) {
921 if (!(*tempMap)[l]) {
926 msrRunList->at(m).SetMap(tempPar, l);
929 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
936 catch(boost::bad_lexical_cast &) {
941 (*tempLines)[i].fLine.Clear();
942 for (
unsigned int j(0); j < tempVec.size(); ++j) {
943 (*tempLines)[i].fLine += TString(tempVec[j]) + TString(
" ");
949 std::string::size_type pos(0);
951 for (
unsigned int i(0); i < tempLines->size(); ++i) {
952 line = (*tempLines)[i].fLine.Data();
953 split( tempVec, line, is_any_of(
" ()+-*/=\t,") );
954 for (
unsigned int j(1); j < tempVec.size(); ++j) {
955 if (!tempVec[j].substr(0,3).compare(
"par")) {
957 tempPar = boost::lexical_cast<unsigned int>(tempVec[j].substr(3));
959 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
960 if (tempPar == msrParamList->at(k).fNo) {
961 if (msrParamList->at(k).fIsGlobal) {
962 pos = line.find(tempVec[j], pos);
963 if ( pos != std::string::npos ) {
965 tempString.append(boost::lexical_cast<std::string>(k + 1));
966 line.replace(pos, tempVec[j].length(), tempString);
968 std::cerr << std::endl <<
">> msr2data: **ERROR** A previously identified parameter in the FUNCTIONS block is not found any more!";
969 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
970 std::cerr << std::endl;
973 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(k).fName.Data() \
974 <<
" is recognized as run specific!";
975 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template FUNCTIONS block.";
976 std::cerr << std::endl <<
">> msr2data: **WARNING** The FUNCTIONS block entry will be substituted by a mapped parameter.";
977 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
978 std::cerr << std::endl;
981 tempMap = msrRunList->at(0).GetMap();
982 while (l < tempMap->size()) {
983 if ((*tempMap)[l] == tempPar) {
986 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
1000 for (l = 0; l < tempMap->size(); ++l) {
1001 if (!(*tempMap)[l]) {
1006 msrRunList->at(m).SetMap(tempPar, l);
1009 pos = line.find(tempVec[j], pos);
1010 if ( pos != std::string::npos ) {
1012 tempString.append(boost::lexical_cast<std::string>(l + 1));
1013 line.replace(pos, tempVec[j].length(), tempString);
1015 std::cerr << std::endl <<
">> msr2data: **ERROR** A previously identified parameter in the FUNCTIONS block is not found any more!";
1016 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1017 std::cerr << std::endl;
1025 catch(boost::bad_lexical_cast &) {
1026 std::cerr << std::endl <<
">> msr2data: **ERROR** Something is wrong with the parameters used in the FUNCTIONS block!";
1027 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - function parsing should have failed earlier!";
1028 std::cerr << std::endl;
1035 (*tempLines)[i].fLine = TString(line);
1047 tempPar = msrRunList->at(i).GetNormParamNo();
1050 for (l = 0; l < msrParamList->size(); ++l) {
1051 if (tempPar == msrParamList->at(l).fNo) {
1052 msrRunList->at(i).SetNormParamNo(l + 1);
1056 if (l > msrParamList->size()) {
1057 std::cerr << std::endl <<
">> msr2data: **ERROR** The norm parameter specified in RUN block " << i + 1 <<
" does not exist!";
1058 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
1059 std::cerr << std::endl;
1063 tempPar = msrRunList->at(i).GetBkgFitParamNo();
1066 for (l = 0; l < msrParamList->size(); ++l) {
1067 if (tempPar == msrParamList->at(l).fNo) {
1068 msrRunList->at(i).SetBkgFitParamNo(l + 1);
1072 if (l > msrParamList->size()) {
1073 std::cerr << std::endl <<
">> msr2data: **ERROR** The backgr.fit parameter specified in RUN block " << i + 1 <<
" does not exist!";
1074 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
1075 std::cerr << std::endl;
1079 tempPar = msrRunList->at(i).GetAlphaParamNo();
1082 for (l = 0; l < msrParamList->size(); ++l) {
1083 if (tempPar == msrParamList->at(l).fNo) {
1084 msrRunList->at(i).SetAlphaParamNo(l + 1);
1088 if (l > msrParamList->size()) {
1089 std::cerr << std::endl <<
">> msr2data: **ERROR** The alpha parameter specified in RUN block " << i + 1 <<
" does not exist!";
1090 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
1091 std::cerr << std::endl;
1095 tempPar = msrRunList->at(i).GetBetaParamNo();
1098 for (l = 0; l < msrParamList->size(); ++l) {
1099 if (tempPar == msrParamList->at(l).fNo) {
1100 msrRunList->at(i).SetBetaParamNo(l + 1);
1104 if (l > msrParamList->size()) {
1105 std::cerr << std::endl <<
">> msr2data: **ERROR** The beta parameter specified in RUN block " << i + 1 <<
" does not exist!";
1106 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
1107 std::cerr << std::endl;
1111 tempPar = msrRunList->at(i).GetLifetimeParamNo();
1114 for (l = 0; l < msrParamList->size(); ++l) {
1115 if (tempPar == msrParamList->at(l).fNo) {
1116 msrRunList->at(i).SetLifetimeParamNo(l + 1);
1120 if (l > msrParamList->size()) {
1121 std::cerr << std::endl <<
">> msr2data: **ERROR** The lifetime parameter specified in RUN block " << i + 1 <<
" does not exist!";
1122 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
1123 std::cerr << std::endl;
1127 tempMap = msrRunList->at(i).GetMap();
1128 for (
unsigned int j(0); j < tempMap->size(); ++j) {
1129 tempPar = (*tempMap)[j];
1132 for (l = 0; l < msrParamList->size(); ++l) {
1133 if (tempPar == msrParamList->at(l).fNo) {
1134 msrRunList->at(i).SetMap(l + 1, j);
1144 if (
fMsrHandler->GetMsrFourierList()->fPhaseParamNo.size() > 0) {
1146 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
1147 if (tempPar == msrParamList->at(k).fNo) {
1148 fMsrHandler->GetMsrFourierList()->fPhaseParamNo.push_back(k + 1);
1155 for (
unsigned int i(0); i <
fMsrHandler->GetMsrPlotList()->size(); ++i) {
1156 tempPar =
fMsrHandler->GetMsrPlotList()->at(i).fRRFPhaseParamNo;
1159 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
1160 if (tempPar == msrParamList->at(k).fNo) {
1161 fMsrHandler->GetMsrPlotList()->at(i).fRRFPhaseParamNo = k + 1;
1169 for (l = 0; l < msrParamList->size(); ++l) {
1170 msrParamList->at(l).fNo = l + 1;
1173 bool lineChanged(
false), mapExists(
false);
1176 for (
unsigned int i(0); i < tempLines->size(); ++i) {
1177 line = (*tempLines)[i].fLine.Data();
1178 split( tempVec, line, is_any_of(
" \t"), token_compress_on );
1180 for (
unsigned int j(1); j < tempVec.size(); ++j) {
1182 tempPar = boost::lexical_cast<unsigned int>(tempVec[j]);
1183 if (!msrParamList->at(tempPar - 1).fIsGlobal) {
1184 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(tempPar - 1).fName.Data() \
1185 <<
" is recognized as run specific!";
1186 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template THEORY block.";
1187 std::cerr << std::endl <<
">> msr2data: **WARNING** The THEORY block entry will be substituted by a mapped parameter.";
1188 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
1189 std::cerr << std::endl;
1192 tempMap = msrRunList->at(0).GetMap();
1193 while (l < tempMap->size()) {
1194 if ((*tempMap)[l] == tempPar) {
1197 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
1212 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
1216 for (l = 0; l < tempMap->size(); ++l) {
1217 if (!(*tempMap)[l]) {
1222 msrRunList->at(m).SetMap(tempPar, l);
1225 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
1230 catch(boost::bad_lexical_cast &) {
1236 (*tempLines)[i].fLine.Clear();
1237 for (
unsigned int j(0); j < tempVec.size(); ++j) {
1238 (*tempLines)[i].fLine += TString(tempVec[j]) + TString(
" ");
1240 lineChanged =
false;
1247 std::string::size_type pos(0);
1248 for (
unsigned int i(0); i < tempLines->size(); ++i) {
1249 line = (*tempLines)[i].fLine.Data();
1250 split( tempVec, line, is_any_of(
" ()+-*/=\t,") );
1251 for (
unsigned int j(1); j < tempVec.size(); ++j) {
1252 if (!tempVec[j].substr(0,3).compare(
"par")) {
1254 tempPar = boost::lexical_cast<unsigned int>(tempVec[j].substr(3));
1256 if (!msrParamList->at(tempPar - 1).fIsGlobal) {
1258 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(tempPar - 1).fName.Data() \
1259 <<
" is recognized as run specific!";
1260 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template FUNCTIONS block.";
1261 std::cerr << std::endl <<
">> msr2data: **WARNING** The FUNCTIONS block entry will be substituted by a mapped parameter.";
1262 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
1263 std::cerr << std::endl;
1266 tempMap = msrRunList->at(0).GetMap();
1267 while (l < tempMap->size()) {
1268 if ((*tempMap)[l] == tempPar) {
1271 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
1285 for (l = 0; l < tempMap->size(); ++l) {
1286 if (!(*tempMap)[l]) {
1291 msrRunList->at(m).SetMap(tempPar, l);
1294 pos = line.find(tempVec[j], pos);
1295 if ( pos != std::string::npos ) {
1297 tempString.append(boost::lexical_cast<std::string>(l + 1));
1298 line.replace(pos, tempVec[j].length(), tempString);
1300 std::cerr << std::endl <<
">> msr2data: **ERROR** A previously identified parameter in the FUNCTIONS block is not found any more!";
1301 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1302 std::cerr << std::endl;
1309 catch(boost::bad_lexical_cast &) {
1310 std::cerr << std::endl <<
">> msr2data: **ERROR** Something is wrong with the parameters used in the FUNCTIONS block!";
1311 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - function parsing should have failed earlier!";
1312 std::cerr << std::endl;
1320 (*tempLines)[i].fLine = TString(line);
1321 lineChanged =
false;
1331 tempPar = msrRunList->at(i).GetNormParamNo();
1333 if (msrParamList->at(tempPar-1).fIsGlobal) {
1334 msrRunList->at(i).SetParGlobal(norm, 1);
1336 msrRunList->at(i).SetParGlobal(norm, 0);
1339 tempPar = msrRunList->at(i).GetBkgFitParamNo();
1341 if (msrParamList->at(tempPar-1).fIsGlobal) {
1342 msrRunList->at(i).SetParGlobal(bkgfit, 1);
1344 msrRunList->at(i).SetParGlobal(bkgfit, 0);
1347 tempPar = msrRunList->at(i).GetAlphaParamNo();
1349 if (msrParamList->at(tempPar-1).fIsGlobal) {
1350 msrRunList->at(i).SetParGlobal(alpha, 1);
1352 msrRunList->at(i).SetParGlobal(alpha, 0);
1355 tempPar = msrRunList->at(i).GetBetaParamNo();
1357 if (msrParamList->at(tempPar-1).fIsGlobal) {
1358 msrRunList->at(i).SetParGlobal(beta, 1);
1360 msrRunList->at(i).SetParGlobal(beta, 0);
1363 tempPar = msrRunList->at(i).GetLifetimeParamNo();
1365 if (msrParamList->at(tempPar-1).fIsGlobal) {
1366 msrRunList->at(i).SetParGlobal(lifetime, 1);
1368 msrRunList->at(i).SetParGlobal(lifetime, 0);
1371 tempMap = msrRunList->at(i).GetMap();
1372 for (
unsigned int j(0); j < tempMap->size(); ++j) {
1373 tempPar = (*tempMap)[j];
1375 if (msrParamList->at(tempPar-1).fIsGlobal) {
1376 msrRunList->at(i).SetMapGlobal(j, 1);
1378 msrRunList->at(i).SetMapGlobal(j, 0);
1391 unsigned int oldTempRun(0);
1392 bool firstrun(
true);
1396 if (firstrun || (globalPlus == 1))
1405 std::cout << std::endl <<
">> msr2data: **ERROR** Input file generation has not been successful! Quitting..." << std::endl;
1411 std::string path(
"");
1412 bool pathSet(
false);
1413 char *pathPtr(getenv(
"MUSRFITPATH"));
1415 path = boost::lexical_cast<std::string>(pathPtr);
1416 if (!path.empty()) {
1422 std::cerr << std::endl <<
">> msr2data: **WARNING** The MUSRFITPATH environment variable is not set!";
1423 std::cerr << std::endl <<
">> msr2data: **WARNING** Please set it or at least ensure that musrfit can be found on the PATH!" << std::endl;
1425 std::ostringstream oss;
1427 std::cout << std::endl <<
">> msr2data: **INFO** Calling " << oss.str() << std::endl;
1428 if (system(oss.str().c_str()) == -1) {
1429 std::cerr << std::endl <<
"**ERROR** system call: " << oss.str().c_str() <<
" failed." << std::endl;
1437 std::cout << std::endl <<
">> msr2data: **INFO** Continuing with the generation of the global input msr file " << msrOutFile << std::endl;
1444 singleRunMsrFile =
nullptr;
1446 std::map<UInt_t, TString> commentsP, commentsR;
1448 std::ostringstream newRunNumber;
1449 newRunNumber.fill(
'0');
1450 newRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1456 if (newRunNumber.str().compare(tempRunNumber.str())) {
1460 if (singleRunMsrFile ==
nullptr)
1465 for (
unsigned int l(
fNumGlobalParam); l < msrParamList->size(); ++l) {
1466 tempParamName = msrParamList->at(l).fName.Data();
1467 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
1468 if ( loc != std::string::npos ) {
1470 msrParamList->at(l).fName = tempParamName;
1471 if (globalPlus && singleRunMsrFile) {
1476 std::cerr << std::endl <<
">> msr2data: **ERROR** The indices of the run specific parameters do not match the template run number!";
1477 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1478 std::cerr << std::endl;
1481 if (singleRunMsrFile) {
1482 delete singleRunMsrFile;
1483 singleRunMsrFile =
nullptr;
1488 tempRunName = msrRunList->at(i).GetRunName()->Data();
1489 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
1490 if ( loc != std::string::npos ) {
1492 tempTstr = TString(tempRunName);
1493 msrRunList->at(i).SetRunName(tempTstr, 0);
1495 std::cerr << std::endl <<
">> msr2data: **ERROR** A template run file number does not match the \"file index\"";
1496 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the template file!";
1497 std::cerr << std::endl;
1503 std::ostringstream tempStrStr;
1507 commentsP[1] = TString(
"Common parameters for all runs");
1512 tempTstr = tempStrStr.str();
1518 tempTstr = tempStrStr.str();
1519 commentsR[1] = tempTstr;
1524 UInt_t runcounter(0);
1525 std::map<TString, Int_t> *runParGlobal(
nullptr);
1526 std::map<TString, Int_t>::iterator iter;
1530 tempRunNumber.str(newRunNumber.str());
1531 newRunNumber.str(
"");
1532 newRunNumber.clear();
1533 newRunNumber.fill(
'0');
1534 newRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1541 if (singleRunMsrFile ==
nullptr)
1548 tempParamName = msrParamList->back().fName.Data();
1549 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
1550 if ( loc != std::string::npos ) {
1552 msrParamList->back().fName = tempParamName;
1554 if (globalPlus && singleRunMsrFile) {
1559 std::cerr << std::endl <<
">> msr2data: **ERROR** Something went wrong when appending new parameters!";
1560 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1561 std::cerr << std::endl;
1564 if (singleRunMsrFile) {
1565 delete singleRunMsrFile;
1566 singleRunMsrFile =
nullptr;
1572 tempRunName = msrRunList->back().GetRunName()->Data();
1573 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
1574 if ( loc != std::string::npos ) {
1576 tempTstr = TString(tempRunName);
1577 msrRunList->back().SetRunName(tempTstr, 0);
1579 std::cerr << std::endl <<
">> msr2data: **ERROR** Something went wrong when appending new RUN blocks!";
1580 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1581 std::cerr << std::endl;
1585 runParGlobal = msrRunList->back().GetParGlobal();
1586 iter = runParGlobal->find(norm);
1587 if (iter != runParGlobal->end()) {
1589 msrRunList->back().SetNormParamNo(msrRunList->back().GetNormParamNo() +
fNumSpecParam);
1591 iter = runParGlobal->find(bkgfit);
1592 if (iter != runParGlobal->end()) {
1594 msrRunList->back().SetBkgFitParamNo(msrRunList->back().GetBkgFitParamNo() +
fNumSpecParam);
1596 iter = runParGlobal->find(alpha);
1597 if (iter != runParGlobal->end()) {
1599 msrRunList->back().SetAlphaParamNo(msrRunList->back().GetAlphaParamNo() +
fNumSpecParam);
1601 iter = runParGlobal->find(beta);
1602 if (iter != runParGlobal->end()) {
1604 msrRunList->back().SetBetaParamNo(msrRunList->back().GetBetaParamNo() +
fNumSpecParam);
1606 iter = runParGlobal->find(lifetime);
1607 if (iter != runParGlobal->end()) {
1609 msrRunList->back().SetLifetimeParamNo(msrRunList->back().GetLifetimeParamNo() +
fNumSpecParam);
1611 runMapGlobal = msrRunList->back().GetMapGlobal();
1612 for (
unsigned int l(0); l < runMapGlobal->size(); ++l) {
1613 if (!(*runMapGlobal)[l])
1614 msrRunList->back().SetMap(msrRunList->back().GetMap()->at(l) +
fNumSpecParam, l);
1624 tempTstr = tempStrStr.str();
1630 tempTstr = tempStrStr.str();
1641 status =
fMsrHandler->WriteMsrFile(msrOutFile.c_str(), &commentsP,
nullptr,
nullptr, &commentsR);
1644 std::cerr << std::endl <<
">> msr2data: **ERROR** Writing the new msr-file has not been successful!";
1645 std::cerr << std::endl;
1652 msrParamList =
nullptr;
1653 msrRunList =
nullptr;
1776 unsigned int withHeader,
bool global,
unsigned int counter)
const
1779 for (
unsigned int i=0; i<paramList.size(); i++) {
1780 if (paramList[i] >
fMsrHandler->GetMsrParamList()->size()) {
1781 std::cerr <<
"msr2data: **ERROR** found parameter " << paramList[i] <<
" which is out of bound (>" <<
fMsrHandler->GetMsrParamList()->size() <<
")." << std::endl;
1786 if (!to_lower_copy(outfile).compare(
"none")) {
1791 std::ostringstream curRunNumber;
1792 curRunNumber.fill(
'0');
1793 curRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1797 std::string msrTitle(
fMsrHandler->GetMsrTitle()->Data());
1798 std::string msrFileName(
fMsrHandler->GetFileName().Data());
1799 unsigned int msrNoOfParams(
fMsrHandler->GetNoOfParams());
1807 std::ostringstream tempRunNumber;
1808 std::string tempName;
1810 tempRunNumber.fill(
'0');
1811 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1816 for (
unsigned int i(0); i < msrParamList->size(); ++i) {
1817 tempName = msrParamList->at(i).fName.Data();
1818 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1831 for (
unsigned int i(0); i < msrRunList->size(); ++i) {
1832 tempName = msrRunList->at(i).GetRunName()->Data();
1833 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1834 if ( loc != std::string::npos ) {
1848 bool okP(
true), okR(
true);
1856 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of parameters or their grouping is not consistent with the specified run list!";
1857 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file!";
1858 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1859 std::cerr << std::endl;
1870 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of RUN blocks or their grouping is not consistent with the specified run list!";
1871 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file!";
1872 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1873 std::cerr << std::endl;
1878 for (
unsigned int a(0); a <
fRunVector.size(); ++a) {
1879 tempRunNumber.clear();
1880 tempRunNumber.str(
"");
1881 tempRunNumber.fill(
'0');
1882 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1888 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1900 std::cerr << std::endl <<
">> msr2data: **ERROR** The run specific parameter names are not consistent with the specified run list!";
1901 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file and the run list!";
1902 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1903 std::cerr << std::endl;
1907 for (
unsigned int a(0); a <
fRunVector.size(); ++a) {
1908 tempRunNumber.clear();
1909 tempRunNumber.str(
"");
1910 tempRunNumber.fill(
'0');
1911 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1917 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1918 if (loc == std::string::npos) {
1929 std::cerr << std::endl <<
">> msr2data: **ERROR** The run names in the RUN blocks are not consistent with the specified run list!";
1930 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file and the run list!";
1931 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1932 std::cerr << std::endl;
1937 std::vector<std::string> dataParamNames;
1938 std::vector<std::string> dataParamLabels;
1939 std::vector<double> dataParam, dataParamErr;
1946 rawRunData =
fDataHandler->GetRunData((*msrRunList)[0].GetRunName()->Data());
1949 if (rawRunData ==
nullptr)
1954 dataParamNames.push_back(
"dataT");
1955 dataParamLabels.push_back(
"T (K)");
1960 std::ostringstream oss;
1962 oss <<
"dataT" << i;
1963 dataParamNames.push_back(oss.str());
1965 oss <<
"T" << i <<
" (K)";
1966 dataParamLabels.push_back(oss.str());
1977 dataParamNames.push_back(
"dataB");
1978 dataParamLabels.push_back(
"B (G)");
1979 dataParam.push_back(value);
1984 dataParamNames.push_back(
"dataE");
1985 dataParamLabels.push_back(
"Implantation Energy (keV)");
1986 dataParam.push_back(value);
1991 dataParamNames.push_back(
"dataTr");
1992 dataParamLabels.push_back(
"Transport (kV)");
1993 dataParam.push_back(value);
1997 if (ra.size() > 1) {
1999 dataParamNames.push_back(
"dataRALRAR");
2000 dataParamLabels.push_back(
"RAL-RAR (kV)");
2001 dataParam.push_back(ra[0]-ra[1]);
2004 if (ra.size() == 4) {
2006 dataParamNames.push_back(
"dataRATRAB");
2007 dataParamLabels.push_back(
"RAT-RAB (kV)");
2008 dataParam.push_back(ra[2]-ra[3]);
2014 dataParamNames.push_back(
"dataSpinRot");
2015 dataParamLabels.push_back(
"Spin Rotation Angle (degree)");
2016 dataParam.push_back(value);
2019 rawRunData =
nullptr;
2027 std::vector<std::string> splitVec;
2030 std::istringstream strLine;
2036 else if (line.at(0) ==
'#' || !to_lower_copy(line.substr(0,3)).compare(
"run"))
2039 split( splitVec, line, is_any_of(
"#") );
2041 strLine.str(splitVec[0]);
2044 std::cerr << std::endl <<
">> msr2data: **ERROR** The run number in the runlist file does not match the one which should be processed...";
2045 std::cerr << std::endl <<
">> msr2data: **ERROR** Something is very strange... Please report this bug!";
2046 std::cerr << std::endl;
2050 while (strLine >> val) {
2051 indVarValues.push_back(val);
2053 if (indVarValues.size() !=
fIndVar.size()) {
2054 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of data entries in the runlist file for the run number " << runNo;
2055 std::cerr << std::endl <<
">> msr2data: **ERROR** does not match the number of labels given in the RUN-line! Please check the file!";
2056 std::cerr << std::endl;
2067 if (!msrStatistic->
fValid) {
2068 std::cerr << std::endl <<
">> msr2data: **WARNING** The fit of run " << *
fRunVectorIter <<
" has not converged!";
2069 std::cerr << std::endl <<
">> msr2data: **WARNING** Its parameter data have not been appended to the output file " << outfile;
2070 std::cerr << std::endl;
2074 dataParamNames.clear();
2075 dataParamLabels.clear();
2077 dataParamErr.clear();
2078 indVarValues.clear();
2084 std::fstream outFile;
2085 outFile.open(outfile.c_str(), std::ios::in | std::ios::out | std::ios::ate);
2086 if (outFile.is_open()) {
2087 if (((withHeader == 0) || (withHeader == 1)) && !
fHeaderWritten) {
2090 outFile.seekp(0, std::ios::end);
2095 int size(outFile.tellg());
2098 for (
int i(1); i<=size; ++i) {
2099 outFile.seekg(-i, std::ios::end);
2100 getline(outFile, s);
2111 outFile.seekp(0, std::ios::cur);
2117 outFile.open(outfile.c_str(), std::ios::out);
2118 if (!outFile.is_open()) {
2119 std::cerr << std::endl <<
">> msr2data: **ERROR** The output file " << outfile <<
" cannot be opened! Please check!";
2120 std::cerr << std::endl;
2129 std::cout << std::endl <<
">> msr2data: **INFO** Write a new DB file header to " << outfile << std::endl;
2131 outFile <<
"TITLE" << std::endl;
2132 outFile <<
">>>Put your title here<<<" << std::endl << std::endl;
2133 outFile <<
"Abstract" << std::endl;
2134 outFile <<
">>>Put your abstract here<<<" << std::endl << std::endl;
2135 outFile <<
"LABELS" << std::endl;
2138 for (
unsigned int i(0); i < dataParamLabels.size(); ++i) {
2139 outFile << dataParamLabels[i] << std::endl;
2144 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2145 outFile <<
fIndVar[i] << std::endl;
2151 std::string tempName;
2154 outFile << (*msrParamList)[i].fName.Data() << std::endl;
2159 std::string::size_type loc = tempName.rfind(curRunNumber.str());
2161 outFile << tempName.substr(0, loc) << std::endl;
2163 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2164 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2165 std::cerr << std::endl;
2170 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2172 outFile << (*msrParamList)[i].fName.Data() << std::endl;
2176 if (msrStatistic->
fChisq)
2177 outFile <<
"CHISQ" << std::endl;
2179 outFile <<
"maxLH" << std::endl;
2181 outFile <<
"NDF" << std::endl;
2183 if (msrStatistic->
fChisq)
2184 outFile <<
"CHISQred" << std::endl;
2186 outFile <<
"maxLHred" << std::endl;
2188 outFile <<
"RUN" << std::endl;
2190 outFile << std::endl <<
"Data";
2193 for (
unsigned int i(0); i < dataParamNames.size(); ++i) {
2194 outFile <<
" " << dataParamNames[i];
2199 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2206 std::string tempName;
2209 outFile <<
" " << (*msrParamList)[i].fName.Data();
2214 std::string::size_type loc = tempName.rfind(curRunNumber.str());
2216 outFile <<
" " << tempName.substr(0, loc);
2218 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2219 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2220 std::cerr << std::endl;
2225 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2227 outFile <<
" " << (*msrParamList)[i].fName.Data();
2231 if (msrStatistic->
fChisq)
2232 outFile <<
" " <<
"CHISQ";
2234 outFile <<
" " <<
"maxLH";
2236 outFile <<
" " <<
"NDF";
2238 if (msrStatistic->
fChisq)
2239 outFile <<
" " <<
"CHISQred";
2241 outFile <<
" " <<
"maxLHred";
2243 outFile <<
" " <<
"RUN" << std::endl;
2245 outFile <<
"\\-e" << std::endl;
2251 for (
unsigned int i(0); i < dataParam.size(); ++i) {
2252 if (i < dataParamErr.size())
2253 outFile << dataParamNames[i] <<
" = " << dataParam[i] <<
", " \
2254 << dataParamErr[i] <<
", " << dataParamErr[i] <<
",\\" << std::endl;
2256 outFile << dataParamNames[i] <<
" = " << dataParam[i] <<
", 0, 0,\\" << std::endl;
2261 for (
unsigned int i(0); i < indVarValues.size(); ++i) {
2262 outFile <<
fIndVar[i] <<
" = " << indVarValues[i] <<
", 0, 0,\\" << std::endl;
2268 std::string tempName;
2272 outFile << (*msrParamList)[i].fName.Data() <<
" = ";
2273 if ((*msrParamList)[i].fPosErrorPresent) {
2274 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
2277 outFile << (*msrParamList)[i].fValue <<
", ";
2280 if ((*msrParamList)[i].fPosErrorPresent)
2281 outFile << (*msrParamList)[i].fPosError <<
", ";
2283 outFile << fabs((*msrParamList)[i].fStep) <<
", ";
2284 outFile << fabs((*msrParamList)[i].fStep) <<
",\\" << std::endl;
2290 tempName = (*msrParamList)[idx].fName.Data();
2291 std::string::size_type loc = tempName.rfind(curRunNumber.str());
2293 outFile << tempName.substr(0, loc) <<
" = ";
2294 if ((*msrParamList)[idx].fPosErrorPresent) {
2295 WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, outFile.width(), db);
2298 outFile << (*msrParamList)[idx].fValue <<
", ";
2300 if ((*msrParamList)[idx].fPosErrorPresent) {
2301 WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, outFile.width(), db);
2304 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
2307 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
2308 outFile <<
",\\" << std::endl;
2313 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2315 outFile << (*msrParamList)[i].fName.Data() <<
" = ";
2316 if ((*msrParamList)[i].fPosErrorPresent) {
2317 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
2320 WriteValue(outFile, (*msrParamList)[i].fValue, fabs((*msrParamList)[i].fStep), outFile.width(), db);
2323 if ((*msrParamList)[i].fPosErrorPresent) {
2324 WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, outFile.width(), db);
2327 WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
2330 WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
2331 outFile <<
",\\" << std::endl;
2336 if (msrStatistic->
fChisq)
2337 outFile <<
"CHISQ = " << msrStatistic->
fMin <<
", 0, 0,\\" << std::endl;
2339 outFile <<
"maxLH = " << msrStatistic->
fMin <<
", 0, 0,\\" << std::endl;
2341 outFile <<
"NDF = " << msrStatistic->
fNdf <<
", 0, 0,\\" << std::endl;
2343 if (msrStatistic->
fChisq)
2344 outFile <<
"CHISQred = " << msrStatistic->
fMin/msrStatistic->
fNdf <<
", 0, 0,\\" << std::endl;
2346 outFile <<
"maxLHred = " << msrStatistic->
fMin/msrStatistic->
fNdf <<
", 0, 0,\\" << std::endl;
2352 unsigned int length(0), maxlength(12);
2353 for (
unsigned int i(0); i < dataParamNames.size(); ++i) {
2354 length = dataParamNames[i].length();
2355 if (length > maxlength)
2358 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2360 if (length > maxlength)
2368 s = (*msrParamList)[i].fName.Data();
2369 length = s.length();
2370 if (length > maxlength)
2378 s = (*msrParamList)[idx].fName.Data();
2379 std::string::size_type loc = s.rfind(curRunNumber.str());
2382 if (length > maxlength)
2385 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2386 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2387 std::cerr << std::endl;
2392 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2394 s = (*msrParamList)[i].fName.Data();
2395 length = s.length();
2396 if (length > maxlength)
2407 std::cout << std::endl <<
">> msr2data: **INFO** Write a new simple-ASCII file header to " << outfile << std::endl;
2410 for (
unsigned int i(0); i < dataParamNames.size(); ++i) {
2411 s = dataParamNames[i];
2412 if (i < dataParamErr.size()) {
2413 outFile << std::setw(maxlength) << std::left << s << std::setw(maxlength + 3) << std::left << s +
"Err";
2415 outFile << std::setw(maxlength) << std::left << s;
2420 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2421 outFile << std::setw(maxlength) << std::left <<
fIndVar[i];
2429 s = (*msrParamList)[i].fName.Data();
2430 outFile << std::setw(maxlength) << std::left << s \
2431 << std::setw(maxlength + 6) << std::left << s +
"PosErr" \
2432 << std::setw(maxlength + 6) << std::left << s +
"NegErr";
2439 s = (*msrParamList)[idx].fName.Data();
2440 std::string::size_type loc = s.rfind(curRunNumber.str());
2442 s = s.substr(0, loc);
2443 outFile << std::setw(maxlength) << std::left << s \
2444 << std::setw(maxlength + 6) << std::left << s +
"PosErr" \
2445 << std::setw(maxlength + 6) << std::left << s +
"NegErr";
2447 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2448 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2449 std::cerr << std::endl;
2454 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2456 s = (*msrParamList)[i].fName.Data();
2457 outFile << std::setw(maxlength) << std::left << s \
2458 << std::setw(maxlength + 6) << std::left << s +
"PosErr" \
2459 << std::setw(maxlength + 6) << std::left << s +
"NegErr";
2465 if (msrStatistic->
fChisq)
2466 outFile << std::setw(maxlength) << std::left <<
"CHISQ";
2468 outFile << std::setw(maxlength) << std::left <<
"maxLH";
2470 outFile << std::setw(maxlength) << std::left <<
"NDF";
2472 if (msrStatistic->
fChisq)
2473 outFile << std::setw(maxlength) << std::left <<
"CHISQred";
2475 outFile << std::setw(maxlength) << std::left <<
"maxLHred";
2477 outFile << std::setw(maxlength) << std::left <<
"RUN" << std::endl;
2483 for (
unsigned int i(0); i < dataParam.size(); ++i) {
2484 if (i < dataParamErr.size()) {
2485 WriteValue(outFile, dataParam[i], maxlength);
2486 WriteValue(outFile, dataParamErr[i], maxlength + 3);
2488 WriteValue(outFile, dataParam[i], maxlength);
2494 for (
unsigned int i(0); i < indVarValues.size(); ++i) {
2495 WriteValue(outFile, indVarValues[i], maxlength);
2503 if ((*msrParamList)[i].fPosErrorPresent)
2504 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
2506 WriteValue(outFile, (*msrParamList)[i].fValue, maxlength);
2508 if ((*msrParamList)[i].fPosErrorPresent)
2509 WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
2511 WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db);
2513 WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db);
2520 if ((*msrParamList)[idx].fPosErrorPresent)
2521 WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, maxlength, db);
2523 WriteValue(outFile, (*msrParamList)[idx].fValue, maxlength);
2525 if ((*msrParamList)[idx].fPosErrorPresent)
2526 WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, maxlength, db);
2528 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
2530 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
2534 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2536 if ((*msrParamList)[i].fPosErrorPresent)
2537 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
2539 WriteValue(outFile, (*msrParamList)[i].fValue, fabs((*msrParamList)[i].fStep), maxlength, db);
2541 if ((*msrParamList)[i].fPosErrorPresent)
2542 WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
2544 WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
2546 WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
2558 outFile << std::endl;
2563 std::cout << std::endl <<
">> msr2data: **INFO** Parameter data of run " << *
fRunVectorIter <<
" of file " << msrFileName \
2564 <<
" have been appended to " << outfile << std::endl;
2566 std::cout << std::endl <<
">> msr2data: **INFO** Parameter data of file " << msrFileName <<
" have been appended to " << outfile << std::endl;
2577 msrParamList =
nullptr;
2578 msrRunList =
nullptr;
2581 dataParamNames.clear();
2582 dataParamLabels.clear();
2584 dataParamErr.clear();
2585 indVarValues.clear();