43 #include <boost/algorithm/string/trim.hpp> 44 #include <boost/algorithm/string/case_conv.hpp> 45 #include <boost/algorithm/string/split.hpp> 48 #include <boost/lexical_cast.hpp> 58 PMsr2Data::PMsr2Data(
const std::string &ext) : fFileExtension(ext), fRunListFile(false), fNumGlobalParam(0), fNumSpecParam(0), fNumTempRunBlocks(0), fRunNumberDigits(4), fHeaderWritten(false)
97 std::ostringstream strInfile;
99 std::unique_ptr<std::ifstream> in = std::make_unique<std::ifstream>(strInfile.str().c_str());
100 if (!in->is_open()) {
102 std::string fileNameCopy(strInfile.str());
106 in.reset(
new std::ifstream(strInfile.str().c_str()));
107 if (!in->is_open()) {
108 std::cerr << std::endl <<
">> msr2data: **ERROR** Neither the file " << fileNameCopy <<
" nor the file " << strInfile.str() <<
" can be opened! Please check!";
109 std::cerr << std::endl;
116 std::cerr << std::endl <<
">> msr2data: **ERROR** None of the given msr-files can be opened! Please check!";
117 std::cerr << std::endl;
121 std::cerr << std::endl <<
">> msr2data: **ERROR** The given template " << strInfile.str() <<
" cannot be opened! Please check!";
122 std::cerr << std::endl;
127 std::ostringstream tempRunNumber;
128 tempRunNumber.fill(
'0');
129 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
131 tempRunNumber << runNo;
135 std::string line, firstOnLine;
136 std::istringstream strLine;
138 while (getline(*in, line)) {
141 strLine >> firstOnLine;
142 if (!to_lower_copy(firstOnLine).compare(
"run")) {
144 strLine >> firstOnLine;
145 std::string::size_type loc = firstOnLine.rfind(tempRunNumber.str());
146 if ( loc != std::string::npos ) {
148 if (isdigit(firstOnLine.at(--loc))) {
158 std::cerr << std::endl <<
">> msr2data: **ERROR** The first processed run file number does not match the \"file index\"!";
159 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of digits to be used for formatting the run numbers cannot be determined!";
160 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the first msr-file that should be processed;";
161 std::cerr << std::endl <<
">> msr2data: **ERROR** this is either some template or the first existing file from the run list.";
162 std::cerr << std::endl;
168 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the first msr-file that should be processed;";
169 std::cerr << std::endl <<
">> msr2data: **ERROR** this is either some template or the first file from the run list.";
170 std::cerr << std::endl <<
">> msr2data: **ERROR** Obviously it contains no RUN block...";
171 std::cerr << std::endl;
189 double max(pow(static_cast<double>(10), static_cast<int>(
fRunNumberDigits+1)) - 1.0);
190 unsigned int max_UInt;
191 max >
static_cast<double>(std::numeric_limits<unsigned int>::max()) ? max_UInt = std::numeric_limits<unsigned int>::max()
192 : max_UInt =
static_cast<unsigned int>(max);
193 for (std::vector<unsigned int>::const_iterator iter(
fRunVector.begin()); iter !=
fRunVector.end(); ++iter) {
194 if (*iter > max_UInt) {
252 if ((runNoStart < 1) || (runNoEnd < 1))
256 if (runNoStart <= runNoEnd) {
257 for (
unsigned int i(runNoStart); i<=runNoEnd; ++i)
260 for (
unsigned int i(runNoStart); i>=runNoEnd; --i)
281 if (runListVector.empty())
284 for (std::vector<unsigned int>::const_iterator iter(runListVector.begin()); iter!=runListVector.end(); ++iter) {
310 std::ifstream in(runListFile.c_str());
312 std::cerr << std::endl <<
">> msr2data: **ERROR** The runlist file " << runListFile <<
" cannot be opened! Please check!";
313 std::cerr << std::endl;
317 std::string line, indvar;
318 std::istringstream strLine;
319 std::vector<std::string> splitVec;
320 unsigned int cntr(0);
323 while (getline(in, line)) {
327 else if (line.at(0) ==
'#')
332 split( splitVec, line, is_any_of(
"#") );
336 strLine.str(splitVec[0]);
338 if (to_lower_copy(indvar).compare(
"run")) {
339 std::cerr << std::endl <<
">> msr2data: **ERROR** The format of the runlist file " << runListFile <<
" is not correct! Please check!";
340 std::cerr << std::endl;
342 while (strLine >> indvar)
348 strLine.str(splitVec[0]);
387 std::cerr << std::endl <<
">> msr2data: **WARNING** Reading/parsing musrfit_startup.xml failed." << std::endl;
405 fMsrHandler = std::make_unique<PMsrHandler>(infile.c_str());
410 std::cerr << std::endl <<
">> msr2data: **ERROR** Could not find " << infile << std::endl;
413 std::cerr << std::endl <<
">> msr2data: **SYNTAX ERROR** in file " << infile <<
", full stop here." << std::endl;
416 std::cerr << std::endl <<
">> msr2data: **UNKOWN ERROR** when trying to read the msr-file" << std::endl;
434 std::ostringstream singleMsrInFile;
442 std::cerr << std::endl <<
">> msr2data: **ERROR** Could not find " << singleMsrInFile.str() << std::endl;
445 std::cerr << std::endl <<
">> msr2data: **SYNTAX ERROR** in file " << singleMsrInFile.str() <<
", full stop here." << std::endl;
448 std::cerr << std::endl <<
">> msr2data: **UNKOWN ERROR** when trying to read the msr-file" << std::endl;
454 return singleRunMsrFile;
476 std::cerr << std::endl <<
">> msr2data: **WARNING** Could not read all data files, will continue without the data file information..." << std::endl;
502 std::string globalTag(
"");
503 if (calledFromGlobalMode)
504 globalTag =
"-OneRunFit";
506 std::ostringstream strInfile;
509 std::ifstream in(strInfile.str().c_str());
511 std::cerr << std::endl <<
">> msr2data: **ERROR** The template msr-file " << strInfile.str() <<
" cannot be opened! Please check!";
512 std::cerr << std::endl;
515 std::ostringstream strOutfile;
517 std::ofstream out(strOutfile.str().c_str());
519 std::cerr << std::endl <<
">> msr2data: **ERROR** The new msr file " << strOutfile.str() <<
" cannot be opened! Please check!";
520 std::cerr << std::endl;
524 std::ostringstream tempRunNumber;
525 tempRunNumber.fill(
'0');
526 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
528 tempRunNumber << tempRun;
530 std::ostringstream newRunNumber;
531 newRunNumber.fill(
'0');
532 newRunNumber.setf(std::ios::internal, std::ios::adjustfield);
536 std::cout << std::endl <<
">> msr2data: **INFO** Generating new input msr file " << strOutfile.str() << std::endl;
538 std::string line, firstOnLine;
539 std::istringstream strLine;
540 unsigned int emptyLineCounter(0);
546 while (getline(in, line)) {
548 if (++emptyLineCounter < 3)
552 emptyLineCounter = 0;
554 if (!line.compare(
"SET BATCH") || !line.compare(
"END RETURN"))
559 strLine >> firstOnLine;
560 if (!to_lower_copy(firstOnLine).compare(
"run")) {
561 strLine >> firstOnLine;
562 std::string::size_type loc = firstOnLine.rfind(tempRunNumber.str());
563 if ( loc != std::string::npos ) {
566 std::cerr << std::endl <<
">> msr2data: **WARNING** The template run file number does not match the \"file index\"";
567 std::cerr << std::endl <<
">> msr2data: **WARNING** Unexpected things will happen... (for sure)";
568 std::cerr << std::endl;
570 out <<
"RUN " << firstOnLine;
571 while (strLine >> firstOnLine)
572 out <<
" " << firstOnLine;
574 }
else if (!to_lower_copy(firstOnLine).compare(
"chisq") || !to_lower_copy(firstOnLine).compare(
"maxlh")) {
575 out <<
"*** FIT DID NOT CONVERGE ***" << std::endl;
578 out << line << std::endl;
612 else if (par2.
fNo > par1.
fNo)
635 const TString alpha(
"alpha"), beta(
"beta"), norm(
"norm"), bkgfit(
"bkgfit"), lifetime(
"lifetime");
637 std::ostringstream strInfile;
653 std::ostringstream tempRunNumber;
654 tempRunNumber.fill(
'0');
655 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
657 tempRunNumber << tempRun;
659 std::string tempRunName;
661 tempRunName = msrRunList->at(i).GetRunName()->Data();
662 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
663 if ( loc == std::string::npos ) {
664 std::cerr << std::endl <<
">> msr2data: **ERROR** A template run file number does not match the \"file index\"";
665 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the template file!";
666 std::cerr << std::endl;
671 std::cout << std::endl <<
">> msr2data: **INFO** Generating new global input msr file " << msrOutFile << std::endl;
674 std::ostringstream titleStream;
675 titleStream <<
"Global msr file for the runs: ";
681 fMsrHandler->SetMsrTitle(TString(titleStream.str()));
686 std::string tempParamName;
687 for (
unsigned int i(0); i < msrParamList->size(); ++i) {
688 tempParamName = msrParamList->at(i).fName.Data();
689 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
691 msrParamList->at(i).fIsGlobal =
false;
694 msrParamList->at(i).fIsGlobal =
true;
701 bool wasSorted(
true);
703 if(!msrParamList->at(i).fIsGlobal) {
710 std::vector<int> *tempMap;
712 std::vector<std::string> tempVec;
713 std::string line, tempString;
723 bool mapExists(
false);
724 for (
unsigned int i(0); i < tempLines->size(); ++i) {
725 line = (*tempLines)[i].fLine.Data();
726 split( tempVec, line, is_any_of(
" \t"), token_compress_on );
727 for (
unsigned int j(1); j < tempVec.size(); ++j) {
729 tempPar = boost::lexical_cast<
unsigned int>(tempVec[j]);
731 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
732 if (tempPar == msrParamList->at(k).fNo) {
733 if (msrParamList->at(k).fIsGlobal) {
734 tempVec[j] = boost::lexical_cast<std::string>(k + 1);
736 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(k).fName.Data() \
737 <<
" is recognized as run specific!";
738 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template THEORY block.";
739 std::cerr << std::endl <<
">> msr2data: **WARNING** The THEORY block entry will be substituted by a mapped parameter.";
740 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
741 std::cerr << std::endl;
744 tempMap = msrRunList->at(0).GetMap();
745 while (l < tempMap->size()) {
746 if ((*tempMap)[l] == tempPar) {
749 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
764 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
767 for (l = 0; l < tempMap->size(); ++l) {
768 if (!(*tempMap)[l]) {
773 msrRunList->at(m).SetMap(tempPar, l);
776 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
783 catch(boost::bad_lexical_cast &) {
788 (*tempLines)[i].fLine.Clear();
789 for (
unsigned int j(0); j < tempVec.size(); ++j) {
790 (*tempLines)[i].fLine += TString(tempVec[j]) + TString(
" ");
796 std::string::size_type pos(0);
798 for (
unsigned int i(0); i < tempLines->size(); ++i) {
799 line = (*tempLines)[i].fLine.Data();
800 split( tempVec, line, is_any_of(
" ()+-*/=\t,") );
801 for (
unsigned int j(1); j < tempVec.size(); ++j) {
802 if (!tempVec[j].substr(0,3).compare(
"par")) {
804 tempPar = boost::lexical_cast<
unsigned int>(tempVec[j].substr(3));
806 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
807 if (tempPar == msrParamList->at(k).fNo) {
808 if (msrParamList->at(k).fIsGlobal) {
809 pos = line.find(tempVec[j], pos);
810 if ( pos != std::string::npos ) {
812 tempString.append(boost::lexical_cast<std::string>(k + 1));
813 line.replace(pos, tempVec[j].length(), tempString);
815 std::cerr << std::endl <<
">> msr2data: **ERROR** A previously identified parameter in the FUNCTIONS block is not found any more!";
816 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
817 std::cerr << std::endl;
820 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(k).fName.Data() \
821 <<
" is recognized as run specific!";
822 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template FUNCTIONS block.";
823 std::cerr << std::endl <<
">> msr2data: **WARNING** The FUNCTIONS block entry will be substituted by a mapped parameter.";
824 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
825 std::cerr << std::endl;
828 tempMap = msrRunList->at(0).GetMap();
829 while (l < tempMap->size()) {
830 if ((*tempMap)[l] == tempPar) {
833 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
847 for (l = 0; l < tempMap->size(); ++l) {
848 if (!(*tempMap)[l]) {
853 msrRunList->at(m).SetMap(tempPar, l);
856 pos = line.find(tempVec[j], pos);
857 if ( pos != std::string::npos ) {
859 tempString.append(boost::lexical_cast<std::string>(l + 1));
860 line.replace(pos, tempVec[j].length(), tempString);
862 std::cerr << std::endl <<
">> msr2data: **ERROR** A previously identified parameter in the FUNCTIONS block is not found any more!";
863 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
864 std::cerr << std::endl;
872 catch(boost::bad_lexical_cast &) {
873 std::cerr << std::endl <<
">> msr2data: **ERROR** Something is wrong with the parameters used in the FUNCTIONS block!";
874 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - function parsing should have failed earlier!";
875 std::cerr << std::endl;
882 (*tempLines)[i].fLine = TString(line);
894 tempPar = msrRunList->at(i).GetNormParamNo();
897 for (l = 0; l < msrParamList->size(); ++l) {
898 if (tempPar == msrParamList->at(l).fNo) {
899 msrRunList->at(i).SetNormParamNo(l + 1);
903 if (l > msrParamList->size()) {
904 std::cerr << std::endl <<
">> msr2data: **ERROR** The norm parameter specified in RUN block " << i + 1 <<
" does not exist!";
905 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
906 std::cerr << std::endl;
910 tempPar = msrRunList->at(i).GetBkgFitParamNo();
913 for (l = 0; l < msrParamList->size(); ++l) {
914 if (tempPar == msrParamList->at(l).fNo) {
915 msrRunList->at(i).SetBkgFitParamNo(l + 1);
919 if (l > msrParamList->size()) {
920 std::cerr << std::endl <<
">> msr2data: **ERROR** The backgr.fit parameter specified in RUN block " << i + 1 <<
" does not exist!";
921 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
922 std::cerr << std::endl;
926 tempPar = msrRunList->at(i).GetAlphaParamNo();
929 for (l = 0; l < msrParamList->size(); ++l) {
930 if (tempPar == msrParamList->at(l).fNo) {
931 msrRunList->at(i).SetAlphaParamNo(l + 1);
935 if (l > msrParamList->size()) {
936 std::cerr << std::endl <<
">> msr2data: **ERROR** The alpha parameter specified in RUN block " << i + 1 <<
" does not exist!";
937 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
938 std::cerr << std::endl;
942 tempPar = msrRunList->at(i).GetBetaParamNo();
945 for (l = 0; l < msrParamList->size(); ++l) {
946 if (tempPar == msrParamList->at(l).fNo) {
947 msrRunList->at(i).SetBetaParamNo(l + 1);
951 if (l > msrParamList->size()) {
952 std::cerr << std::endl <<
">> msr2data: **ERROR** The beta parameter specified in RUN block " << i + 1 <<
" does not exist!";
953 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
954 std::cerr << std::endl;
958 tempPar = msrRunList->at(i).GetLifetimeParamNo();
961 for (l = 0; l < msrParamList->size(); ++l) {
962 if (tempPar == msrParamList->at(l).fNo) {
963 msrRunList->at(i).SetLifetimeParamNo(l + 1);
967 if (l > msrParamList->size()) {
968 std::cerr << std::endl <<
">> msr2data: **ERROR** The lifetime parameter specified in RUN block " << i + 1 <<
" does not exist!";
969 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - file checks should have failed earlier!";
970 std::cerr << std::endl;
974 tempMap = msrRunList->at(i).GetMap();
975 for (
unsigned int j(0); j < tempMap->size(); ++j) {
976 tempPar = (*tempMap)[j];
979 for (l = 0; l < msrParamList->size(); ++l) {
980 if (tempPar == msrParamList->at(l).fNo) {
981 msrRunList->at(i).SetMap(l + 1, j);
991 if (
fMsrHandler->GetMsrFourierList()->fPhaseParamNo.size() > 0) {
993 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
994 if (tempPar == msrParamList->at(k).fNo) {
995 fMsrHandler->GetMsrFourierList()->fPhaseParamNo.push_back(k + 1);
1002 for (
unsigned int i(0); i <
fMsrHandler->GetMsrPlotList()->size(); ++i) {
1003 tempPar =
fMsrHandler->GetMsrPlotList()->at(i).fRRFPhaseParamNo;
1006 for (
unsigned int k(0); k < msrParamList->size(); ++k) {
1007 if (tempPar == msrParamList->at(k).fNo) {
1008 fMsrHandler->GetMsrPlotList()->at(i).fRRFPhaseParamNo = k + 1;
1016 for (l = 0; l < msrParamList->size(); ++l) {
1017 msrParamList->at(l).fNo = l + 1;
1020 bool lineChanged(
false), mapExists(
false);
1023 for (
unsigned int i(0); i < tempLines->size(); ++i) {
1024 line = (*tempLines)[i].fLine.Data();
1025 split( tempVec, line, is_any_of(
" \t"), token_compress_on );
1027 for (
unsigned int j(1); j < tempVec.size(); ++j) {
1029 tempPar = boost::lexical_cast<
unsigned int>(tempVec[j]);
1030 if (!msrParamList->at(tempPar - 1).fIsGlobal) {
1031 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(tempPar - 1).fName.Data() \
1032 <<
" is recognized as run specific!";
1033 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template THEORY block.";
1034 std::cerr << std::endl <<
">> msr2data: **WARNING** The THEORY block entry will be substituted by a mapped parameter.";
1035 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
1036 std::cerr << std::endl;
1039 tempMap = msrRunList->at(0).GetMap();
1040 while (l < tempMap->size()) {
1041 if ((*tempMap)[l] == tempPar) {
1044 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
1059 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
1063 for (l = 0; l < tempMap->size(); ++l) {
1064 if (!(*tempMap)[l]) {
1069 msrRunList->at(m).SetMap(tempPar, l);
1072 tempVec[j].append(boost::lexical_cast<std::string>(l + 1));
1077 catch(boost::bad_lexical_cast &) {
1083 (*tempLines)[i].fLine.Clear();
1084 for (
unsigned int j(0); j < tempVec.size(); ++j) {
1085 (*tempLines)[i].fLine += TString(tempVec[j]) + TString(
" ");
1087 lineChanged =
false;
1094 std::string::size_type pos(0);
1095 for (
unsigned int i(0); i < tempLines->size(); ++i) {
1096 line = (*tempLines)[i].fLine.Data();
1097 split( tempVec, line, is_any_of(
" ()+-*/=\t,") );
1098 for (
unsigned int j(1); j < tempVec.size(); ++j) {
1099 if (!tempVec[j].substr(0,3).compare(
"par")) {
1101 tempPar = boost::lexical_cast<
unsigned int>(tempVec[j].substr(3));
1103 if (!msrParamList->at(tempPar - 1).fIsGlobal) {
1105 std::cerr << std::endl <<
">> msr2data: **WARNING** The parameter " << msrParamList->at(tempPar - 1).fName.Data() \
1106 <<
" is recognized as run specific!";
1107 std::cerr << std::endl <<
">> msr2data: **WARNING** Still it appears directly (un-mapped) in the template FUNCTIONS block.";
1108 std::cerr << std::endl <<
">> msr2data: **WARNING** The FUNCTIONS block entry will be substituted by a mapped parameter.";
1109 std::cerr << std::endl <<
">> msr2data: **WARNING** In case, this is not what has been intended, please review the new msr-file!";
1110 std::cerr << std::endl;
1113 tempMap = msrRunList->at(0).GetMap();
1114 while (l < tempMap->size()) {
1115 if ((*tempMap)[l] == tempPar) {
1118 if (msrRunList->at(m).GetMap()->at(l) != tempPar) {
1132 for (l = 0; l < tempMap->size(); ++l) {
1133 if (!(*tempMap)[l]) {
1138 msrRunList->at(m).SetMap(tempPar, l);
1141 pos = line.find(tempVec[j], pos);
1142 if ( pos != std::string::npos ) {
1144 tempString.append(boost::lexical_cast<std::string>(l + 1));
1145 line.replace(pos, tempVec[j].length(), tempString);
1147 std::cerr << std::endl <<
">> msr2data: **ERROR** A previously identified parameter in the FUNCTIONS block is not found any more!";
1148 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1149 std::cerr << std::endl;
1156 catch(boost::bad_lexical_cast &) {
1157 std::cerr << std::endl <<
">> msr2data: **ERROR** Something is wrong with the parameters used in the FUNCTIONS block!";
1158 std::cerr << std::endl <<
">> msr2data: **ERROR** Please report a bug - function parsing should have failed earlier!";
1159 std::cerr << std::endl;
1167 (*tempLines)[i].fLine = TString(line);
1168 lineChanged =
false;
1178 tempPar = msrRunList->at(i).GetNormParamNo();
1180 if (msrParamList->at(tempPar-1).fIsGlobal) {
1181 msrRunList->at(i).SetParGlobal(norm, 1);
1183 msrRunList->at(i).SetParGlobal(norm, 0);
1186 tempPar = msrRunList->at(i).GetBkgFitParamNo();
1188 if (msrParamList->at(tempPar-1).fIsGlobal) {
1189 msrRunList->at(i).SetParGlobal(bkgfit, 1);
1191 msrRunList->at(i).SetParGlobal(bkgfit, 0);
1194 tempPar = msrRunList->at(i).GetAlphaParamNo();
1196 if (msrParamList->at(tempPar-1).fIsGlobal) {
1197 msrRunList->at(i).SetParGlobal(alpha, 1);
1199 msrRunList->at(i).SetParGlobal(alpha, 0);
1202 tempPar = msrRunList->at(i).GetBetaParamNo();
1204 if (msrParamList->at(tempPar-1).fIsGlobal) {
1205 msrRunList->at(i).SetParGlobal(beta, 1);
1207 msrRunList->at(i).SetParGlobal(beta, 0);
1210 tempPar = msrRunList->at(i).GetLifetimeParamNo();
1212 if (msrParamList->at(tempPar-1).fIsGlobal) {
1213 msrRunList->at(i).SetParGlobal(lifetime, 1);
1215 msrRunList->at(i).SetParGlobal(lifetime, 0);
1218 tempMap = msrRunList->at(i).GetMap();
1219 for (
unsigned int j(0); j < tempMap->size(); ++j) {
1220 tempPar = (*tempMap)[j];
1222 if (msrParamList->at(tempPar-1).fIsGlobal) {
1223 msrRunList->at(i).SetMapGlobal(j, 1);
1225 msrRunList->at(i).SetMapGlobal(j, 0);
1238 unsigned int oldTempRun(0);
1239 bool firstrun(
true);
1243 if (firstrun || (globalPlus == 1))
1252 std::cout << std::endl <<
">> msr2data: **ERROR** Input file generation has not been successful! Quitting..." << std::endl;
1258 std::string path(
"");
1259 bool pathSet(
false);
1260 char *pathPtr(getenv(
"MUSRFITPATH"));
1262 path = boost::lexical_cast<std::string>(pathPtr);
1263 if (!path.empty()) {
1269 std::cerr << std::endl <<
">> msr2data: **WARNING** The MUSRFITPATH environment variable is not set!";
1270 std::cerr << std::endl <<
">> msr2data: **WARNING** Please set it or at least ensure that musrfit can be found on the PATH!" << std::endl;
1272 std::ostringstream oss;
1274 std::cout << std::endl <<
">> msr2data: **INFO** Calling " << oss.str() << std::endl;
1275 if (system(oss.str().c_str()) == -1) {
1276 std::cerr << std::endl <<
"**ERROR** system call: " << oss.str().c_str() <<
" failed." << std::endl;
1284 std::cout << std::endl <<
">> msr2data: **INFO** Continuing with the generation of the global input msr file " << msrOutFile << std::endl;
1291 singleRunMsrFile =
nullptr;
1293 std::map<UInt_t, TString> commentsP, commentsR;
1295 std::ostringstream newRunNumber;
1296 newRunNumber.fill(
'0');
1297 newRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1303 if (newRunNumber.str().compare(tempRunNumber.str())) {
1307 if (singleRunMsrFile ==
nullptr)
1312 for (
unsigned int l(
fNumGlobalParam); l < msrParamList->size(); ++l) {
1313 tempParamName = msrParamList->at(l).fName.Data();
1314 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
1315 if ( loc != std::string::npos ) {
1317 msrParamList->at(l).fName = tempParamName;
1318 if (globalPlus && singleRunMsrFile) {
1323 std::cerr << std::endl <<
">> msr2data: **ERROR** The indices of the run specific parameters do not match the template run number!";
1324 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1325 std::cerr << std::endl;
1328 if (singleRunMsrFile) {
1329 delete singleRunMsrFile;
1330 singleRunMsrFile =
nullptr;
1335 tempRunName = msrRunList->at(i).GetRunName()->Data();
1336 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
1337 if ( loc != std::string::npos ) {
1339 tempTstr = TString(tempRunName);
1340 msrRunList->at(i).SetRunName(tempTstr, 0);
1342 std::cerr << std::endl <<
">> msr2data: **ERROR** A template run file number does not match the \"file index\"";
1343 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the template file!";
1344 std::cerr << std::endl;
1350 std::ostringstream tempStrStr;
1354 commentsP[1] = TString(
"Common parameters for all runs");
1359 tempTstr = tempStrStr.str();
1365 tempTstr = tempStrStr.str();
1366 commentsR[1] = tempTstr;
1371 UInt_t runcounter(0);
1372 std::map<TString, Int_t> *runParGlobal(
nullptr);
1373 std::map<TString, Int_t>::iterator iter;
1377 tempRunNumber.str(newRunNumber.str());
1378 newRunNumber.str(
"");
1379 newRunNumber.clear();
1380 newRunNumber.fill(
'0');
1381 newRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1388 if (singleRunMsrFile ==
nullptr)
1395 tempParamName = msrParamList->back().fName.Data();
1396 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
1397 if ( loc != std::string::npos ) {
1399 msrParamList->back().fName = tempParamName;
1401 if (globalPlus && singleRunMsrFile) {
1406 std::cerr << std::endl <<
">> msr2data: **ERROR** Something went wrong when appending new parameters!";
1407 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1408 std::cerr << std::endl;
1411 if (singleRunMsrFile) {
1412 delete singleRunMsrFile;
1413 singleRunMsrFile =
nullptr;
1419 tempRunName = msrRunList->back().GetRunName()->Data();
1420 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
1421 if ( loc != std::string::npos ) {
1423 tempTstr = TString(tempRunName);
1424 msrRunList->back().SetRunName(tempTstr, 0);
1426 std::cerr << std::endl <<
">> msr2data: **ERROR** Something went wrong when appending new RUN blocks!";
1427 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1428 std::cerr << std::endl;
1432 runParGlobal = msrRunList->back().GetParGlobal();
1433 iter = runParGlobal->find(norm);
1434 if (iter != runParGlobal->end()) {
1436 msrRunList->back().SetNormParamNo(msrRunList->back().GetNormParamNo() +
fNumSpecParam);
1438 iter = runParGlobal->find(bkgfit);
1439 if (iter != runParGlobal->end()) {
1441 msrRunList->back().SetBkgFitParamNo(msrRunList->back().GetBkgFitParamNo() +
fNumSpecParam);
1443 iter = runParGlobal->find(alpha);
1444 if (iter != runParGlobal->end()) {
1446 msrRunList->back().SetAlphaParamNo(msrRunList->back().GetAlphaParamNo() +
fNumSpecParam);
1448 iter = runParGlobal->find(beta);
1449 if (iter != runParGlobal->end()) {
1451 msrRunList->back().SetBetaParamNo(msrRunList->back().GetBetaParamNo() +
fNumSpecParam);
1453 iter = runParGlobal->find(lifetime);
1454 if (iter != runParGlobal->end()) {
1456 msrRunList->back().SetLifetimeParamNo(msrRunList->back().GetLifetimeParamNo() +
fNumSpecParam);
1458 runMapGlobal = msrRunList->back().GetMapGlobal();
1459 for (
unsigned int l(0); l < runMapGlobal->size(); ++l) {
1460 if (!(*runMapGlobal)[l])
1461 msrRunList->back().SetMap(msrRunList->back().GetMap()->at(l) +
fNumSpecParam, l);
1471 tempTstr = tempStrStr.str();
1477 tempTstr = tempStrStr.str();
1488 status =
fMsrHandler->WriteMsrFile(msrOutFile.c_str(), &commentsP,
nullptr,
nullptr, &commentsR);
1491 std::cerr << std::endl <<
">> msr2data: **ERROR** Writing the new msr-file has not been successful!";
1492 std::cerr << std::endl;
1499 msrParamList =
nullptr;
1500 msrRunList =
nullptr;
1527 std::ostringstream tempRunNumber;
1528 tempRunNumber.fill(
'0');
1529 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1531 tempRunNumber << tempRun;
1533 std::ostringstream newRunNumber;
1534 newRunNumber.fill(
'0');
1535 newRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1539 std::string tempParamName, tempRunName;
1542 std::ostringstream msrOutFile;
1544 std::cout << std::endl <<
">> msr2data: **INFO** Generating new input msr file " << msrOutFile.str() << std::endl;
1546 tempTstr = TString(newRunNumber.str());
1550 for (
unsigned int l(
fNumGlobalParam); l < msrParamList->size(); ++l) {
1551 tempParamName = msrParamList->at(l).fName.Data();
1552 std::string::size_type loc = tempParamName.rfind(tempRunNumber.str());
1553 if ( loc != std::string::npos ) {
1554 tempParamName.erase(loc);
1555 msrParamList->at(l).fName = tempParamName;
1557 std::cerr << std::endl <<
">> msr2data: **ERROR** The indices of the run specific parameters do not match the template run number!";
1558 std::cerr << std::endl <<
">> msr2data: **ERROR** This should not happen! Please report a bug!";
1559 std::cerr << std::endl;
1563 if (newRunNumber.str().compare(tempRunNumber.str())) {
1566 tempRunName = msrRunList->at(i).GetRunName()->Data();
1567 std::string::size_type loc = tempRunName.rfind(tempRunNumber.str());
1568 if ( loc != std::string::npos ) {
1570 tempTstr = TString(tempRunName);
1571 msrRunList->at(i).SetRunName(tempTstr, 0);
1573 std::cerr << std::endl <<
">> msr2data: **ERROR** A template run file number does not match the \"file index\"";
1574 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check the template file!";
1575 std::cerr << std::endl;
1588 *msrParamList = paramListCopy;
1589 *msrRunList = runListCopy;
1592 paramListCopy.clear();
1593 runListCopy.clear();
1597 std::cerr << std::endl <<
">> msr2data: **ERROR** Writing the new msr file has not been successful!";
1598 std::cerr << std::endl;
1623 unsigned int withHeader,
bool global,
unsigned int counter)
const 1626 for (
unsigned int i=0; i<paramList.size(); i++) {
1627 if (paramList[i] >
fMsrHandler->GetMsrParamList()->size()) {
1628 std::cerr <<
"msr2data: **ERROR** found parameter " << paramList[i] <<
" which is out of bound (>" <<
fMsrHandler->GetMsrParamList()->size() <<
")." << std::endl;
1633 if (!to_lower_copy(outfile).compare(
"none")) {
1638 std::ostringstream curRunNumber;
1639 curRunNumber.fill(
'0');
1640 curRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1644 std::string msrTitle(
fMsrHandler->GetMsrTitle()->Data());
1645 std::string msrFileName(
fMsrHandler->GetFileName().Data());
1646 unsigned int msrNoOfParams(
fMsrHandler->GetNoOfParams());
1654 std::ostringstream tempRunNumber;
1655 std::string tempName;
1657 tempRunNumber.fill(
'0');
1658 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1663 for (
unsigned int i(0); i < msrParamList->size(); ++i) {
1664 tempName = msrParamList->at(i).fName.Data();
1665 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1678 for (
unsigned int i(0); i < msrRunList->size(); ++i) {
1679 tempName = msrRunList->at(i).GetRunName()->Data();
1680 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1681 if ( loc != std::string::npos ) {
1695 bool okP(
true), okR(
true);
1703 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of parameters or their grouping is not consistent with the specified run list!";
1704 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file!";
1705 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1706 std::cerr << std::endl;
1717 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of RUN blocks or their grouping is not consistent with the specified run list!";
1718 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file!";
1719 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1720 std::cerr << std::endl;
1725 for (
unsigned int a(0); a <
fRunVector.size(); ++a) {
1726 tempRunNumber.clear();
1727 tempRunNumber.str(
"");
1728 tempRunNumber.fill(
'0');
1729 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1735 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1747 std::cerr << std::endl <<
">> msr2data: **ERROR** The run specific parameter names are not consistent with the specified run list!";
1748 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file and the run list!";
1749 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1750 std::cerr << std::endl;
1754 for (
unsigned int a(0); a <
fRunVector.size(); ++a) {
1755 tempRunNumber.clear();
1756 tempRunNumber.str(
"");
1757 tempRunNumber.fill(
'0');
1758 tempRunNumber.setf(std::ios::internal, std::ios::adjustfield);
1764 std::string::size_type loc = tempName.rfind(tempRunNumber.str());
1765 if (loc == std::string::npos) {
1776 std::cerr << std::endl <<
">> msr2data: **ERROR** The run names in the RUN blocks are not consistent with the specified run list!";
1777 std::cerr << std::endl <<
">> msr2data: **ERROR** Please check carefully the integrity of the msr file and the run list!";
1778 std::cerr << std::endl <<
">> msr2data: **ERROR** No output will be written!";
1779 std::cerr << std::endl;
1784 std::vector<std::string> dataParamNames;
1785 std::vector<std::string> dataParamLabels;
1786 std::vector<double> dataParam, dataParamErr;
1793 rawRunData =
fDataHandler->GetRunData((*msrRunList)[0].GetRunName()->Data());
1798 dataParamNames.push_back(
"dataT");
1799 dataParamLabels.push_back(
"T (K)");
1804 std::ostringstream oss;
1806 oss <<
"dataT" << i;
1807 dataParamNames.push_back(oss.str());
1809 oss <<
"T" << i <<
" (K)";
1810 dataParamLabels.push_back(oss.str());
1821 dataParamNames.push_back(
"dataB");
1822 dataParamLabels.push_back(
"B (G)");
1823 dataParam.push_back(value);
1828 dataParamNames.push_back(
"dataE");
1829 dataParamLabels.push_back(
"Implantation Energy (keV)");
1830 dataParam.push_back(value);
1835 dataParamNames.push_back(
"dataTr");
1836 dataParamLabels.push_back(
"Transport (kV)");
1837 dataParam.push_back(value);
1841 if (ra.size() > 1) {
1843 dataParamNames.push_back(
"dataRALRAR");
1844 dataParamLabels.push_back(
"RAL-RAR (kV)");
1845 dataParam.push_back(ra[0]-ra[1]);
1848 if (ra.size() == 4) {
1850 dataParamNames.push_back(
"dataRATRAB");
1851 dataParamLabels.push_back(
"RAT-RAB (kV)");
1852 dataParam.push_back(ra[2]-ra[3]);
1858 dataParamNames.push_back(
"dataSpinRot");
1859 dataParamLabels.push_back(
"Spin Rotation Angle (degree)");
1860 dataParam.push_back(value);
1863 rawRunData =
nullptr;
1871 std::vector<std::string> splitVec;
1874 std::istringstream strLine;
1880 else if (line.at(0) ==
'#' || !to_lower_copy(line.substr(0,3)).compare(
"run"))
1883 split( splitVec, line, is_any_of(
"#") );
1885 strLine.str(splitVec[0]);
1888 std::cerr << std::endl <<
">> msr2data: **ERROR** The run number in the runlist file does not match the one which should be processed...";
1889 std::cerr << std::endl <<
">> msr2data: **ERROR** Something is very strange... Please report this bug!";
1890 std::cerr << std::endl;
1894 while (strLine >> val) {
1895 indVarValues.push_back(val);
1897 if (indVarValues.size() !=
fIndVar.size()) {
1898 std::cerr << std::endl <<
">> msr2data: **ERROR** The number of data entries in the runlist file for the run number " << runNo;
1899 std::cerr << std::endl <<
">> msr2data: **ERROR** does not match the number of labels given in the RUN-line! Please check the file!";
1900 std::cerr << std::endl;
1911 if (!msrStatistic->fValid) {
1912 std::cerr << std::endl <<
">> msr2data: **WARNING** The fit of run " << *
fRunVectorIter <<
" has not converged!";
1913 std::cerr << std::endl <<
">> msr2data: **WARNING** Its parameter data have not been appended to the output file " << outfile;
1914 std::cerr << std::endl;
1918 dataParamNames.clear();
1919 dataParamLabels.clear();
1921 dataParamErr.clear();
1922 indVarValues.clear();
1928 std::fstream outFile;
1929 outFile.open(outfile.c_str(), std::ios::in | std::ios::out | std::ios::ate);
1930 if (outFile.is_open()) {
1931 if (((withHeader == 0) || (withHeader == 1)) && !
fHeaderWritten) {
1934 outFile.seekp(0, std::ios::end);
1939 int size(outFile.tellg());
1942 for (
int i(1); i<=size; ++i) {
1943 outFile.seekg(-i, std::ios::end);
1944 getline(outFile, s);
1955 outFile.seekp(0, std::ios::cur);
1961 outFile.open(outfile.c_str(), std::ios::out);
1962 if (!outFile.is_open()) {
1963 std::cerr << std::endl <<
">> msr2data: **ERROR** The output file " << outfile <<
" cannot be opened! Please check!";
1964 std::cerr << std::endl;
1973 std::cout << std::endl <<
">> msr2data: **INFO** Write a new DB file header to " << outfile << std::endl;
1975 outFile <<
"TITLE" << std::endl;
1976 outFile <<
">>>Put your title here<<<" << std::endl << std::endl;
1977 outFile <<
"Abstract" << std::endl;
1978 outFile <<
">>>Put your abstract here<<<" << std::endl << std::endl;
1979 outFile <<
"LABELS" << std::endl;
1982 for (
unsigned int i(0); i < dataParamLabels.size(); ++i) {
1983 outFile << dataParamLabels[i] << std::endl;
1988 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
1989 outFile <<
fIndVar[i] << std::endl;
1995 std::string tempName;
1998 outFile << (*msrParamList)[i].fName.Data() << std::endl;
2003 std::string::size_type loc = tempName.rfind(curRunNumber.str());
2005 outFile << tempName.substr(0, loc) << std::endl;
2007 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2008 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2009 std::cerr << std::endl;
2014 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2016 outFile << (*msrParamList)[i].fName.Data() << std::endl;
2020 if (msrStatistic->fChisq)
2021 outFile <<
"CHISQ" << std::endl;
2023 outFile <<
"maxLH" << std::endl;
2025 outFile <<
"NDF" << std::endl;
2027 if (msrStatistic->fChisq)
2028 outFile <<
"CHISQred" << std::endl;
2030 outFile <<
"maxLHred" << std::endl;
2032 outFile <<
"RUN" << std::endl;
2034 outFile << std::endl <<
"Data";
2037 for (
unsigned int i(0); i < dataParamNames.size(); ++i) {
2038 outFile <<
" " << dataParamNames[i];
2043 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2050 std::string tempName;
2053 outFile <<
" " << (*msrParamList)[i].fName.Data();
2058 std::string::size_type loc = tempName.rfind(curRunNumber.str());
2060 outFile <<
" " << tempName.substr(0, loc);
2062 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2063 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2064 std::cerr << std::endl;
2069 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2071 outFile <<
" " << (*msrParamList)[i].fName.Data();
2075 if (msrStatistic->fChisq)
2076 outFile <<
" " <<
"CHISQ";
2078 outFile <<
" " <<
"maxLH";
2080 outFile <<
" " <<
"NDF";
2082 if (msrStatistic->fChisq)
2083 outFile <<
" " <<
"CHISQred";
2085 outFile <<
" " <<
"maxLHred";
2087 outFile <<
" " <<
"RUN" << std::endl;
2089 outFile <<
"\\-e" << std::endl;
2095 for (
unsigned int i(0); i < dataParam.size(); ++i) {
2096 if (i < dataParamErr.size())
2097 outFile << dataParamNames[i] <<
" = " << dataParam[i] <<
", " \
2098 << dataParamErr[i] <<
", " << dataParamErr[i] <<
",\\" << std::endl;
2100 outFile << dataParamNames[i] <<
" = " << dataParam[i] <<
", 0, 0,\\" << std::endl;
2105 for (
unsigned int i(0); i < indVarValues.size(); ++i) {
2106 outFile <<
fIndVar[i] <<
" = " << indVarValues[i] <<
", 0, 0,\\" << std::endl;
2112 std::string tempName;
2116 outFile << (*msrParamList)[i].fName.Data() <<
" = ";
2117 if ((*msrParamList)[i].fPosErrorPresent) {
2118 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
2121 outFile << (*msrParamList)[i].fValue <<
", ";
2124 if ((*msrParamList)[i].fPosErrorPresent)
2125 outFile << (*msrParamList)[i].fPosError <<
", ";
2127 outFile << fabs((*msrParamList)[i].fStep) <<
", ";
2128 outFile << fabs((*msrParamList)[i].fStep) <<
",\\" << std::endl;
2134 tempName = (*msrParamList)[idx].fName.Data();
2135 std::string::size_type loc = tempName.rfind(curRunNumber.str());
2137 outFile << tempName.substr(0, loc) <<
" = ";
2138 if ((*msrParamList)[idx].fPosErrorPresent) {
2139 WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, outFile.width(), db);
2142 outFile << (*msrParamList)[idx].fValue <<
", ";
2144 if ((*msrParamList)[idx].fPosErrorPresent) {
2145 WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, outFile.width(), db);
2148 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
2151 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, outFile.width(), db);
2152 outFile <<
",\\" << std::endl;
2157 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2159 outFile << (*msrParamList)[i].fName.Data() <<
" = ";
2160 if ((*msrParamList)[i].fPosErrorPresent) {
2161 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, outFile.width(), db);
2164 WriteValue(outFile, (*msrParamList)[i].fValue, fabs((*msrParamList)[i].fStep), outFile.width(), db);
2167 if ((*msrParamList)[i].fPosErrorPresent) {
2168 WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, outFile.width(), db);
2171 WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
2174 WriteValue(outFile, (*msrParamList)[i].fStep, (*msrParamList)[i].fStep, outFile.width(), db);
2175 outFile <<
",\\" << std::endl;
2180 if (msrStatistic->fChisq)
2181 outFile <<
"CHISQ = " << msrStatistic->fMin <<
", 0, 0,\\" << std::endl;
2183 outFile <<
"maxLH = " << msrStatistic->fMin <<
", 0, 0,\\" << std::endl;
2185 outFile <<
"NDF = " << msrStatistic->fNdf <<
", 0, 0,\\" << std::endl;
2187 if (msrStatistic->fChisq)
2188 outFile <<
"CHISQred = " << msrStatistic->fMin/msrStatistic->fNdf <<
", 0, 0,\\" << std::endl;
2190 outFile <<
"maxLHred = " << msrStatistic->fMin/msrStatistic->fNdf <<
", 0, 0,\\" << std::endl;
2196 unsigned int length(0), maxlength(12);
2197 for (
unsigned int i(0); i < dataParamNames.size(); ++i) {
2198 length = dataParamNames[i].length();
2199 if (length > maxlength)
2202 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2204 if (length > maxlength)
2212 s = (*msrParamList)[i].fName.Data();
2213 length = s.length();
2214 if (length > maxlength)
2222 s = (*msrParamList)[idx].fName.Data();
2223 std::string::size_type loc = s.rfind(curRunNumber.str());
2226 if (length > maxlength)
2229 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2230 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2231 std::cerr << std::endl;
2236 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2238 s = (*msrParamList)[i].fName.Data();
2239 length = s.length();
2240 if (length > maxlength)
2251 std::cout << std::endl <<
">> msr2data: **INFO** Write a new simple-ASCII file header to " << outfile << std::endl;
2254 for (
unsigned int i(0); i < dataParamNames.size(); ++i) {
2255 s = dataParamNames[i];
2256 if (i < dataParamErr.size()) {
2257 outFile << std::setw(maxlength) << std::left << s << std::setw(maxlength + 3) << std::left << s +
"Err";
2259 outFile << std::setw(maxlength) << std::left << s;
2264 for (
unsigned int i(0); i <
fIndVar.size(); ++i) {
2265 outFile << std::setw(maxlength) << std::left <<
fIndVar[i];
2273 s = (*msrParamList)[i].fName.Data();
2274 outFile << std::setw(maxlength) << std::left << s \
2275 << std::setw(maxlength + 6) << std::left << s +
"PosErr" \
2276 << std::setw(maxlength + 6) << std::left << s +
"NegErr";
2283 s = (*msrParamList)[idx].fName.Data();
2284 std::string::size_type loc = s.rfind(curRunNumber.str());
2286 s = s.substr(0, loc);
2287 outFile << std::setw(maxlength) << std::left << s \
2288 << std::setw(maxlength + 6) << std::left << s +
"PosErr" \
2289 << std::setw(maxlength + 6) << std::left << s +
"NegErr";
2291 std::cerr << std::endl <<
">> msr2data: **ERROR** The run index of some parameter does not match the run number being processed!";
2292 std::cerr << std::endl <<
">> msr2data: **ERROR** The output will be flawed!";
2293 std::cerr << std::endl;
2298 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2300 s = (*msrParamList)[i].fName.Data();
2301 outFile << std::setw(maxlength) << std::left << s \
2302 << std::setw(maxlength + 6) << std::left << s +
"PosErr" \
2303 << std::setw(maxlength + 6) << std::left << s +
"NegErr";
2309 if (msrStatistic->fChisq)
2310 outFile << std::setw(maxlength) << std::left <<
"CHISQ";
2312 outFile << std::setw(maxlength) << std::left <<
"maxLH";
2314 outFile << std::setw(maxlength) << std::left <<
"NDF";
2316 if (msrStatistic->fChisq)
2317 outFile << std::setw(maxlength) << std::left <<
"CHISQred";
2319 outFile << std::setw(maxlength) << std::left <<
"maxLHred";
2321 outFile << std::setw(maxlength) << std::left <<
"RUN" << std::endl;
2327 for (
unsigned int i(0); i < dataParam.size(); ++i) {
2328 if (i < dataParamErr.size()) {
2329 WriteValue(outFile, dataParam[i], maxlength);
2330 WriteValue(outFile, dataParamErr[i], maxlength + 3);
2332 WriteValue(outFile, dataParam[i], maxlength);
2338 for (
unsigned int i(0); i < indVarValues.size(); ++i) {
2339 WriteValue(outFile, indVarValues[i], maxlength);
2347 if ((*msrParamList)[i].fPosErrorPresent)
2348 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
2350 WriteValue(outFile, (*msrParamList)[i].fValue, maxlength);
2352 if ((*msrParamList)[i].fPosErrorPresent)
2353 WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
2355 WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db);
2357 WriteValue(outFile, fabs((*msrParamList)[i].fStep), (*msrParamList)[i].fStep, maxlength, db);
2364 if ((*msrParamList)[idx].fPosErrorPresent)
2365 WriteValue(outFile, (*msrParamList)[idx].fValue, (*msrParamList)[idx].fPosError, maxlength, db);
2367 WriteValue(outFile, (*msrParamList)[idx].fValue, maxlength);
2369 if ((*msrParamList)[idx].fPosErrorPresent)
2370 WriteValue(outFile, (*msrParamList)[idx].fPosError, (*msrParamList)[idx].fPosError, maxlength, db);
2372 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
2374 WriteValue(outFile, (*msrParamList)[idx].fStep, (*msrParamList)[idx].fStep, maxlength, db);
2378 for (
unsigned int i(0); i < msrNoOfParams; ++i) {
2380 if ((*msrParamList)[i].fPosErrorPresent)
2381 WriteValue(outFile, (*msrParamList)[i].fValue, (*msrParamList)[i].fPosError, maxlength, db);
2383 WriteValue(outFile, (*msrParamList)[i].fValue, fabs((*msrParamList)[i].fStep), maxlength, db);
2385 if ((*msrParamList)[i].fPosErrorPresent)
2386 WriteValue(outFile, (*msrParamList)[i].fPosError, (*msrParamList)[i].fPosError, maxlength, db);
2388 WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
2390 WriteValue(outFile, fabs((*msrParamList)[i].fStep), fabs((*msrParamList)[i].fStep), maxlength, db);
2395 WriteValue(outFile, msrStatistic->fMin, maxlength);
2397 WriteValue(outFile, msrStatistic->fNdf, maxlength);
2399 WriteValue(outFile, msrStatistic->fMin/msrStatistic->fNdf, maxlength);
2402 outFile << std::endl;
2407 std::cout << std::endl <<
">> msr2data: **INFO** Parameter data of run " << *
fRunVectorIter <<
" of file " << msrFileName \
2408 <<
" have been appended to " << outfile << std::endl;
2410 std::cout << std::endl <<
">> msr2data: **INFO** Parameter data of file " << msrFileName <<
" have been appended to " << outfile << std::endl;
2421 msrParamList =
nullptr;
2422 msrRunList =
nullptr;
2425 dataParamNames.clear();
2426 dataParamLabels.clear();
2428 dataParamErr.clear();
2429 indVarValues.clear();
2445 if ((fabs(value) >= 1.0e6) || ((fabs(value) < 1.0e-4) && (fabs(value) > 0.0)))
2446 outFile << std::scientific << std::setprecision(width - 8);
2448 outFile.unsetf(std::ios::floatfield);
2449 outFile << std::setw(width) << std::left << value;
2463 void PMsr2Data::WriteValue(std::fstream &outFile,
const double &value,
const double &errValue,
const unsigned int &width,
const bool &db)
const 2465 Int_t previous_prec = outFile.precision();
2469 if (fabs(value) > 0.0)
2470 prec +=
static_cast<int>(log10(fabs(value)));
2472 if ((fabs(value) >= 1.0e6) || ((fabs(value) < 1.0e-4) && (fabs(value) > 0)))
2473 outFile << std::scientific;
2475 outFile.unsetf(std::ios::floatfield);
2477 outFile.precision(prec);
2478 outFile << std::setw(width) << std::left << value;
2479 outFile.precision(previous_prec);
2502 double dval = value;
2504 if (fabs(dval) >= 1.0)
2508 }
while ((i<20) && !done);
2529 if (paramList.size() == 0)
2532 for (
unsigned int i=0; i<paramList.size(); i++) {
2533 if (paramValue+1 == paramList[i])
std::unique_ptr< PRunDataHandler > fDataHandler
unsigned int fNumGlobalParam
unsigned int fNumTempRunBlocks
unsigned int fRunNumberDigits
int ParseXmlStartupFile()
int DetermineRunNumberDigits(unsigned int, bool) const
int CheckRunNumbersInRange() const
std::vector< PMsrRunBlock > PMsrRunList
bool PrepareGlobalInputFile(unsigned int, const std::string &, unsigned int) const
PMsrHandler * GetSingleRunMsrFile() const
virtual const Double_t GetTempError(const UInt_t idx)
virtual const PDoublePairVector * GetTemperature() const
int WriteOutput(const std::string &, const std::vector< unsigned int > &, bool, unsigned int, bool global=false, unsigned int counter=0) const
std::unique_ptr< PStartupHandler > fStartupHandler
std::string fFileExtension
int parseXmlFile(TSAXParser *, const char *)
std::unique_ptr< TSAXParser > fSaxParser
#define PMUSR_MSR_FILE_NOT_FOUND
std::unique_ptr< std::ifstream > fRunListFileStream
std::vector< Int_t > PIntVector
std::vector< PMsrParamStructure > PMsrParamList
std::vector< Double_t > PDoubleVector
#define MSR_PARAM_FUN_OFFSET
virtual const PDoubleVector GetRingAnode()
Int_t fNo
parameter number
std::vector< std::string > fIndVar
std::vector< unsigned int > fRunVector
int ReadMsrFile(const std::string &) const
int SetRunNumbers(unsigned int)
bool PrepareNewSortedInputFile(unsigned int) const
const char * startup_path_name
bool InParameterList(const unsigned int ¶mValue, const std::vector< unsigned int > &) const
unsigned int fNumSpecParam
std::vector< PMsrLineStructure > PMsrLines
unsigned int GetPresentRun() const
virtual const Double_t GetField()
int GetFirstSignificantDigit(const double &value) const
virtual const Double_t GetMuonSpinAngle()
void WriteValue(std::fstream &outFile, const double &value, const unsigned int &width) const
PMsr2Data(const std::string &)
Bool_t fIsGlobal
flag showing if the parameter is a global one (used for msr2data global)
virtual Int_t ReadMsrFile()
virtual const UInt_t GetNoOfTemperatures()
#define PMUSR_MSR_SYNTAX_ERROR
virtual const Double_t GetEnergy()
virtual const Double_t GetTransport()
virtual PMsrParamList * GetMsrParamList()
bool compare_parameters(const PMsrParamStructure &par1, const PMsrParamStructure &par2)
std::vector< unsigned int >::const_iterator fRunVectorIter
std::unique_ptr< PMsrHandler > fMsrHandler
bool PrepareNewInputFile(unsigned int, bool) const