634 Int_t usedParams = 0;
635 for (UInt_t i=0; i<error.size(); i++) {
639 UInt_t ndf =
static_cast<int>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
640 Double_t val = (*fFitterFcn)(param);
643 Double_t totalExpectedChisq = 0.0;
645 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedChisq, expectedChisqPerRun);
647 std::vector<Double_t> chisqPerRun;
648 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
652 std::cout << std::endl << std::endl <<
">> chisq = " << val <<
", NDF = " << ndf <<
", chisq/NDF = " << val/ndf;
654 if (totalExpectedChisq != 0.0) {
655 std::cout << std::endl <<
">> expected chisq = " << totalExpectedChisq <<
", NDF = " << ndf <<
", expected chisq/NDF = " << totalExpectedChisq/ndf;
657 for (UInt_t i=0; i<expectedChisqPerRun.size(); i++) {
660 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq/red.chisq_e) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
"/" << expectedChisqPerRun[i]/ndf_run <<
")";
662 }
else if (chisqPerRun.size() > 0) {
664 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
667 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
")";
673 expectedChisqPerRun.clear();
677 secFitRange.resize(1);
678 for (UInt_t k=0; k<
fSector.size(); k++) {
680 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
681 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
684 val = (*fFitterFcn)(param);
686 ndf =
static_cast<UInt_t
>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
688 totalExpectedChisq = 0.0;
689 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedChisq, expectedChisqPerRun);
691 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
695 std::cout << std::endl;
696 std::cout <<
"++++" << std::endl;
697 std::cout <<
">> Sector " << k+1 <<
": FitRange: " << secFitRange[0].first <<
", " << secFitRange[0].second << std::endl;
698 std::cout <<
">> chisq = " << val <<
", NDF = " << ndf <<
", chisq/NDF = " << val/ndf;
700 if (totalExpectedChisq != 0.0) {
701 std::cout << std::endl <<
">> expected chisq = " << totalExpectedChisq <<
", NDF = " << ndf <<
", expected chisq/NDF = " << totalExpectedChisq/ndf;
703 for (UInt_t i=0; i<expectedChisqPerRun.size(); i++) {
706 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq/red.chisq_e) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
"/" << expectedChisqPerRun[i]/ndf_run <<
")";
708 }
else if (chisqPerRun.size() > 0) {
710 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
713 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
")";
718 expectedChisqPerRun.clear();
723 Double_t totalExpectedMaxLH = 0.0;
724 std::vector<Double_t> expectedMaxLHPerRun;
725 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedMaxLH, expectedMaxLHPerRun);
727 std::vector<Double_t> maxLHPerRun;
728 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
732 std::cout << std::endl << std::endl <<
">> maxLH = " << val <<
", NDF = " << ndf <<
", maxLH/NDF = " << val/ndf;
734 if (totalExpectedMaxLH != 0.0) {
735 std::cout << std::endl <<
">> expected maxLH = " << totalExpectedMaxLH <<
", NDF = " << ndf <<
", expected maxLH/NDF = " << totalExpectedMaxLH/ndf;
737 for (UInt_t i=0; i<expectedMaxLHPerRun.size(); i++) {
740 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.maxLH/red.maxLH_e) = (" << ndf_run <<
"/" << maxLHPerRun[i]/ndf_run <<
"/" << expectedMaxLHPerRun[i]/ndf_run <<
")";
746 expectedMaxLHPerRun.clear();
750 secFitRange.resize(1);
751 for (UInt_t k=0; k<
fSector.size(); k++) {
753 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
754 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
757 val = (*fFitterFcn)(param);
759 ndf =
static_cast<int>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
761 totalExpectedMaxLH = 0.0;
762 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedMaxLH, expectedMaxLHPerRun);
764 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
768 std::cout << std::endl;
769 std::cout <<
"++++" << std::endl;
770 std::cout <<
">> Sector " << k+1 <<
": FitRange: " << secFitRange[0].first <<
", " << secFitRange[0].second << std::endl;
771 std::cout <<
">> maxLH = " << val <<
", NDF = " << ndf <<
", maxLH/NDF = " << val/ndf;
773 if (totalExpectedMaxLH != 0.0) {
774 std::cout << std::endl <<
">> expected maxLH = " << totalExpectedMaxLH <<
", NDF = " << ndf <<
", expected maxLH/NDF = " << totalExpectedMaxLH/ndf;
776 for (UInt_t i=0; i<expectedMaxLHPerRun.size(); i++) {
779 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.maxLH/red.maxLH_e) = (" << ndf_run <<
"/" << maxLHPerRun[i]/ndf_run <<
"/" << expectedMaxLHPerRun[i]/ndf_run <<
")";
785 expectedMaxLHPerRun.clear();
789 std::cout << std::endl << std::endl;
795 std::cout << std::endl <<
">> Number of available threads for the function optimization: " << omp_get_max_threads() << std::endl;
800 std::cout << std::endl <<
">> Chi Square fit will be executed" << std::endl;
802 std::cout << std::endl <<
">> Maximum Likelihood fit will be executed" << std::endl;
806 for (UInt_t i=0; i<
fParams.size(); i++) {
807 fRunInfo->SetMsrParamPosErrorPresent(i,
false);
811 Bool_t firstSave =
true;
812 for (UInt_t i=0; i<
fCmdList.size(); i++) {
815 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command INTERACTIVE is not yet implemented.";
816 std::cerr << std::endl;
828 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command EIGEN is not yet implemented.";
829 std::cerr << std::endl;
835 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command MACHINE_PRECISION is not yet implemented.";
836 std::cerr << std::endl;
871 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command USER_COVARIANCE is not yet implemented.";
872 std::cerr << std::endl;
875 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command USER_PARAM_STATE is not yet implemented.";
876 std::cerr << std::endl;
882 std::cerr << std::endl <<
"**PANIC ERROR**: PFitter::DoFit(): You should never have reached this point";
883 std::cerr << std::endl;
893 fRunInfo->GetMsrStatistic()->fValid =
true;
895 fRunInfo->GetMsrStatistic()->fValid =
false;
940 PMsrLines::iterator it;
941 UInt_t cmdLineNo = 0;
952 pos = line.First(
'#');
954 line.Remove(pos,line.Length()-pos);
956 if (line.Contains(
"COMMANDS", TString::kIgnoreCase)) {
958 }
else if (line.Contains(
"SET BATCH", TString::kIgnoreCase)) {
960 }
else if (line.Contains(
"END RETURN", TString::kIgnoreCase)) {
962 }
else if (line.Contains(
"CHI_SQUARE", TString::kIgnoreCase)) {
964 }
else if (line.Contains(
"MAX_LIKELIHOOD", TString::kIgnoreCase)) {
966 }
else if (line.Contains(
"SCALE_N0_BKG", TString::kIgnoreCase)) {
968 }
else if (line.Contains(
"INTERACTIVE", TString::kIgnoreCase)) {
970 cmd.second = cmdLineNo;
972 }
else if (line.Contains(
"CONTOURS", TString::kIgnoreCase)) {
974 cmd.second = cmdLineNo;
977 std::vector<std::string> tokens;
981 tokens = PStringUtils::Split(line.Data(),
", \t");
983 for (Int_t i=0; i<static_cast<int>(tokens.size()); i++) {
984 str = tokens[i].c_str();
986 if ((i==1) || (i==2)) {
988 if (!str.IsDigit()) {
989 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
990 std::cerr << std::endl <<
">> " << line.Data();
991 std::cerr << std::endl <<
">> parameter number is not number!";
992 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
993 std::cerr << std::endl;
999 if ((ival < 1) || (ival >
fParams.size())) {
1000 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1001 std::cerr << std::endl <<
">> " << line.Data();
1002 std::cerr << std::endl <<
">> parameter number is out of range [1," <<
fParams.size() <<
"]!";
1003 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1004 std::cerr << std::endl;
1015 if (!str.IsDigit()) {
1016 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1017 std::cerr << std::endl <<
">> " << line.Data();
1018 std::cerr << std::endl <<
">> number of points is not number!";
1019 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1020 std::cerr << std::endl;
1025 if ((ival < 1) || (ival > 100)) {
1026 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1027 std::cerr << std::endl <<
">> " << line.Data();
1028 std::cerr << std::endl <<
">> number of scan points is out of range [1,100]!";
1029 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1030 std::cerr << std::endl;
1038 }
else if (line.Contains(
"EIGEN", TString::kIgnoreCase)) {
1040 cmd.second = cmdLineNo;
1042 }
else if (line.Contains(
"FIT_RANGE", TString::kIgnoreCase)) {
1049 std::vector<std::string> tokens;
1052 tokens = PStringUtils::Split(line.Data(),
", \t");
1054 if (
static_cast<int>(tokens.size()) == 2) {
1055 str = tokens[1].c_str();
1056 if (str.Contains(
"RESET", TString::kIgnoreCase)) {
1058 cmd.second = cmdLineNo;
1061 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1062 std::cerr << std::endl <<
">> " << line.Data();
1063 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE start end | FIT_RANGE s1 e1 s2 e2 .. sN eN,";
1064 std::cerr << std::endl <<
">> with N the number of runs in the msr-file." << std::endl;
1065 std::cerr << std::endl <<
">> Found " << str.Data() <<
", instead of RESET" << std::endl;
1069 }
else if ((
static_cast<int>(tokens.size()) > 1) && (
static_cast<UInt_t
>(
static_cast<int>(tokens.size())) % 2) == 1) {
1070 if ((
static_cast<int>(tokens.size()) > 3) && ((
static_cast<UInt_t
>(
static_cast<int>(tokens.size()))-1)) != 2*
fRunInfo->GetMsrRunList()->size()) {
1071 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1072 std::cerr << std::endl <<
">> " << line.Data();
1073 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE <start> <end> | FIT_RANGE <s1> <e1> <s2> <e2> .. <sN> <eN> |";
1074 std::cerr << std::endl <<
">> FIT_RANGE fgb+<n0> lgb-<n1> | FIT_RANGE fgb+<n00> lgb-<n01> fgb+<n10> lgb-<n11> ... fgb+<nN0> lgb-<nN1>,";
1075 std::cerr << std::endl <<
">> with N the number of runs in the msr-file.";
1076 std::cerr << std::endl <<
">> Found N=" << (
static_cast<int>(tokens.size())-1)/2 <<
", # runs in msr-file=" <<
fRunInfo->GetMsrRunList()->size() << std::endl;
1082 for (Int_t n=1; n<static_cast<int>(tokens.size()); n++) {
1083 str = tokens[n].c_str();
1084 if (!str.IsFloat()) {
1085 if ((n%2 == 1) && (!str.Contains(
"fgb", TString::kIgnoreCase)))
1087 if ((n%2 == 0) && (!str.Contains(
"lgb", TString::kIgnoreCase)))
1096 cmd.second = cmdLineNo;
1099 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1100 std::cerr << std::endl <<
">> " << line.Data();
1101 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE <start> <end> | FIT_RANGE <s1> <e1> <s2> <e2> .. <sN> <eN> |";
1102 std::cerr << std::endl <<
">> FIT_RANGE fgb+<n0> lgb-<n1> | FIT_RANGE fgb+<n00> lgb-<n01> fgb+<n10> lgb-<n11> ... fgb+<nN0> lgb-<nN1>,";
1103 std::cerr << std::endl <<
">> with N the number of runs in the msr-file.";
1104 std::cerr << std::endl <<
">> Found token '" << str.Data() <<
"', which is not a floating point number." << std::endl;
1110 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1111 std::cerr << std::endl <<
">> " << line.Data();
1112 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE <start> <end> | FIT_RANGE <s1> <e1> <s2> <e2> .. <sN> <eN> |";
1113 std::cerr << std::endl <<
">> FIT_RANGE fgb+<n0> lgb-<n1> | FIT_RANGE fgb+<n00> lgb-<n01> fgb+<n10> lgb-<n11> ... fgb+<nN0> lgb-<nN1>,";
1114 std::cerr << std::endl <<
">> with N the number of runs in the msr-file.";
1119 }
else if (line.Contains(
"FIX", TString::kIgnoreCase)) {
1121 std::vector<std::string> tokens;
1125 tokens = PStringUtils::Split(line.Data(),
", \t");
1127 for (Int_t i=1; i<static_cast<int>(tokens.size()); i++) {
1128 str = tokens[i].c_str();
1130 if (str.IsDigit()) {
1134 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1135 std::cerr << std::endl <<
">> " << line.Data();
1136 std::cerr << std::endl <<
">> Parameter " << ival <<
" is out of the Parameter Range [1," <<
fParams.size() <<
"]";
1137 std::cerr << std::endl;
1143 Bool_t found =
false;
1144 for (UInt_t j=0; j<
fParams.size(); j++) {
1145 if (
fParams[j].fName.CompareTo(str, TString::kIgnoreCase) == 0) {
1151 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1152 std::cerr << std::endl <<
">> " << line.Data();
1153 std::cerr << std::endl <<
">> Parameter '" << str.Data() <<
"' is NOT present as a parameter name";
1154 std::cerr << std::endl;
1164 cmd.second = cmdLineNo;
1166 }
else if (line.Contains(
"HESSE", TString::kIgnoreCase)) {
1169 cmd.second = cmdLineNo;
1171 }
else if (line.Contains(
"MACHINE_PRECISION", TString::kIgnoreCase)) {
1173 cmd.second = cmdLineNo;
1175 }
else if (line.Contains(
"MIGRAD", TString::kIgnoreCase)) {
1178 cmd.second = cmdLineNo;
1180 }
else if (line.Contains(
"MINIMIZE", TString::kIgnoreCase)) {
1183 cmd.second = cmdLineNo;
1185 }
else if (line.Contains(
"MINOS", TString::kIgnoreCase)) {
1188 cmd.second = cmdLineNo;
1190 }
else if (line.Contains(
"MNPLOT", TString::kIgnoreCase)) {
1192 cmd.second = cmdLineNo;
1194 }
else if (line.Contains(
"PRINT_LEVEL", TString::kIgnoreCase)) {
1196 cmd.second = cmdLineNo;
1198 }
else if (line.Contains(
"RELEASE", TString::kIgnoreCase)) {
1200 std::vector<std::string> tokens;
1204 tokens = PStringUtils::Split(line.Data(),
", \t");
1206 for (Int_t i=1; i<static_cast<int>(tokens.size()); i++) {
1207 str = tokens[i].c_str();
1209 if (str.IsDigit()) {
1213 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1214 std::cerr << std::endl <<
">> " << line.Data();
1215 std::cerr << std::endl <<
">> Parameter " << ival <<
" is out of the Parameter Range [1," <<
fParams.size() <<
"]";
1216 std::cerr << std::endl;
1222 Bool_t found =
false;
1223 for (UInt_t j=0; j<
fParams.size(); j++) {
1224 if (
fParams[j].fName.CompareTo(str, TString::kIgnoreCase) == 0) {
1230 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1231 std::cerr << std::endl <<
">> " << line.Data();
1232 std::cerr << std::endl <<
">> Parameter '" << str.Data() <<
"' is NOT present as a parameter name";
1233 std::cerr << std::endl;
1241 cmd.second = cmdLineNo;
1243 }
else if (line.Contains(
"RESTORE", TString::kIgnoreCase)) {
1245 cmd.second = cmdLineNo;
1247 }
else if (line.Contains(
"SAVE", TString::kIgnoreCase)) {
1249 cmd.second = cmdLineNo;
1251 }
else if (line.Contains(
"SCAN", TString::kIgnoreCase)) {
1253 cmd.second = cmdLineNo;
1256 std::vector<std::string> tokens;
1260 tokens = PStringUtils::Split(line.Data(),
", \t");
1262 for (Int_t i=0; i<static_cast<int>(tokens.size()); i++) {
1263 str = tokens[i].c_str();
1266 if (!str.IsDigit()) {
1267 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1268 std::cerr << std::endl <<
">> " << line.Data();
1269 std::cerr << std::endl <<
">> parameter number is not number!";
1270 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1271 std::cerr << std::endl;
1277 if ((ival < 1) || (ival >
fParams.size())) {
1278 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1279 std::cerr << std::endl <<
">> " << line.Data();
1280 std::cerr << std::endl <<
">> parameter number is out of range [1," <<
fParams.size() <<
"]!";
1281 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1282 std::cerr << std::endl;
1293 if (!str.IsDigit()) {
1294 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1295 std::cerr << std::endl <<
">> " << line.Data();
1296 std::cerr << std::endl <<
">> number of points is not number!";
1297 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1298 std::cerr << std::endl;
1303 if ((ival < 1) || (ival > 100)) {
1304 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1305 std::cerr << std::endl <<
">> " << line.Data();
1306 std::cerr << std::endl <<
">> number of scan points is out of range [1,100]!";
1307 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1308 std::cerr << std::endl;
1317 if (!str.IsFloat()) {
1318 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1319 std::cerr << std::endl <<
">> " << line.Data();
1320 std::cerr << std::endl <<
">> low is not a floating point number!";
1321 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1322 std::cerr << std::endl;
1331 if (!str.IsFloat()) {
1332 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1333 std::cerr << std::endl <<
">> " << line.Data();
1334 std::cerr << std::endl <<
">> high is not a floating point number!";
1335 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1336 std::cerr << std::endl;
1344 }
else if (line.Contains(
"SIMPLEX", TString::kIgnoreCase)) {
1346 cmd.second = cmdLineNo;
1348 }
else if (line.Contains(
"STRATEGY", TString::kIgnoreCase)) {
1349 std::vector<std::string> tokens;
1352 tokens = PStringUtils::Split(line.Data(),
" \t");
1353 if (
static_cast<int>(tokens.size()) == 2) {
1354 str = tokens[1].c_str();
1355 if (str.CompareTo(
"0") == 0) {
1357 }
else if (str.CompareTo(
"1") == 0) {
1359 }
else if (str.CompareTo(
"2") == 0) {
1361 }
else if (str.CompareTo(
"LOW") == 0) {
1363 }
else if (str.CompareTo(
"DEFAULT") == 0) {
1365 }
else if (str.CompareTo(
"HIGH") == 0) {
1370 }
else if (line.Contains(
"USER_COVARIANCE", TString::kIgnoreCase)) {
1372 cmd.second = cmdLineNo;
1374 }
else if (line.Contains(
"USER_PARAM_STATE", TString::kIgnoreCase)) {
1376 cmd.second = cmdLineNo;
1378 }
else if (line.Contains(
"SECTOR", TString::kIgnoreCase)) {
1381 cmd.second = cmdLineNo;
1385 std::vector<std::string> tokens;
1388 tokens = PStringUtils::Split(line.Data(),
" ,\t");
1390 if (
static_cast<int>(tokens.size()) == 1) {
1391 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo;
1392 std::cerr << std::endl <<
">> " << line.Data();
1393 std::cerr << std::endl <<
">> At least one sector time stamp is expected.";
1394 std::cerr << std::endl <<
">> Will stop ...";
1395 std::cerr << std::endl;
1402 for (Int_t i=1; i<static_cast<int>(tokens.size()); i++) {
1406 str = tokens[i].c_str();
1407 if (str.IsFloat()) {
1412 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo;
1413 std::cerr << std::endl <<
">> " << line.Data();
1414 std::cerr << std::endl <<
">> The sector time stamp " << dval <<
" is > as the lgb time stamp (" <<
fOriginalFitRange[j].second <<
") of run " << j <<
".";
1415 std::cerr << std::endl <<
">> Will stop ...";
1416 std::cerr << std::endl;
1426 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo;
1427 std::cerr << std::endl <<
">> " << line.Data();
1428 std::cerr << std::endl <<
">> The sector time stamp '" << str <<
"' is not a number.";
1429 std::cerr << std::endl <<
">> Will stop ...";
1430 std::cerr << std::endl;
1438 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo <<
" an unkown command is found:";
1439 std::cerr << std::endl <<
">> " << line.Data();
1440 std::cerr << std::endl <<
">> Will stop ...";
1441 std::cerr << std::endl;
1449 Bool_t fixFlag =
false;
1450 Bool_t releaseFlag =
false;
1451 Bool_t minimizerFlag =
false;
1453 if (line.Contains(
"FIX", TString::kIgnoreCase))
1455 else if (line.Contains(
"RELEASE", TString::kIgnoreCase) ||
1456 line.Contains(
"RESTORE", TString::kIgnoreCase))
1458 else if (line.Contains(
"MINIMIZE", TString::kIgnoreCase) ||
1459 line.Contains(
"MIGRAD", TString::kIgnoreCase) ||
1460 line.Contains(
"SIMPLEX", TString::kIgnoreCase)) {
1462 minimizerFlag =
true;
1463 }
else if (line.Contains(
"MINOS", TString::kIgnoreCase)) {
1464 if (fixFlag && releaseFlag && !minimizerFlag) {
1465 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **WARNING** RELEASE/RESTORE command present";
1466 std::cerr << std::endl <<
">> without minimizer command (MINIMIZE/MIGRAD/SIMPLEX) between";
1467 std::cerr << std::endl <<
">> RELEASE/RESTORE and MINOS. Behaviour might be different to the";
1468 std::cerr << std::endl <<
">> expectation of the user ?!?" << std::endl;
1471 releaseFlag =
false;
1472 minimizerFlag =
false;
2098 std::cout << std::endl <<
">> PFitter::ExecuteSave(): nothing to be saved ...";
2102 ROOT::Minuit2::MnUserParameterState mnState =
fFcnMin->UserState();
2105 if (!mnState.IsValid()) {
2106 std::cerr << std::endl <<
">> PFitter::ExecuteSave: **WARNING** Minuit2 User Parameter State is not valid, i.e. nothing to be saved";
2107 std::cerr << std::endl;
2115 std::vector<Double_t> param;
2116 std::vector<Double_t> err;
2117 Double_t totalExpectedChisq = 0.0;
2118 std::vector<Double_t> expectedchisqPerRun;
2119 std::vector<UInt_t> ndfPerHisto;
2121 for (UInt_t i=0; i<
fParams.size(); i++) {
2122 param.push_back(
fParams[i].fValue);
2123 err.push_back(
fParams[i].fStep);
2131 fFitterFcn->CalcExpectedChiSquare(par_r, totalExpectedChisq, expectedchisqPerRun);
2134 std::vector<Double_t> chisqPerRun;
2135 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
2142 if (totalExpectedChisq != 0.0) {
2145 for (UInt_t i=0; i<expectedchisqPerRun.size(); i++) {
2147 ndfPerHisto.push_back(ndf_run);
2158 }
else if (chisqPerRun.size() > 1) {
2160 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
2162 ndfPerHisto.push_back(ndf_run);
2176 for (UInt_t i=0; i<
fParams.size(); i++)
2177 error.push_back(
fParams[i].fStep);
2184 expectedchisqPerRun.clear();
2185 ndfPerHisto.clear();
2186 chisqPerRun.clear();
2188 std::cout <<
">> PFitter::ExecuteSave(): will write minuit2 output file ..." << std::endl;
2194 fout.open(
"MINUIT2.OUTPUT", std::iostream::out);
2196 fout.open(
"MINUIT2.OUTPUT", std::iostream::out | std::iostream::app);
2198 if (!fout.is_open()) {
2199 std::cerr << std::endl <<
"**ERROR** PFitter::ExecuteSave() couldn't open MINUIT2.OUTPUT file";
2200 std::cerr << std::endl;
2206 fout << std::endl <<
"*************************************************************************";
2207 fout << std::endl <<
" musrfit MINUIT2 output file from " <<
fRunInfo->GetFileName().Data() <<
" - " << dt.AsSQLString();
2208 fout << std::endl <<
"*************************************************************************";
2212 fout << std::endl <<
" elapsed times:";
2217 fout << std::endl <<
"*************************************************************************";
2222 fout << std::endl <<
" Fval() = " << mnState.Fval() <<
", Edm() = " << mnState.Edm() <<
", NFcn() = " << mnState.NFcn();
2224 fout << std::endl <<
"*************************************************************************";
2228 Int_t maxLength = 10;
2229 for (UInt_t i=0; i<
fParams.size(); i++) {
2230 if (
fParams[i].fName.Length() > maxLength)
2231 maxLength =
fParams[i].fName.Length() + 1;
2236 fout << std::endl <<
" PARAMETERS";
2237 fout << std::endl <<
"-------------------------------------------------------------------------";
2238 fout << std::endl <<
" ";
2239 for (Int_t j=0; j<=maxLength-4; j++)
2241 fout <<
"Parabolic Minos";
2242 fout << std::endl <<
" No Name";
2243 for (Int_t j=0; j<=maxLength-4; j++)
2245 fout <<
"Value Error Negative Positive Limits";
2246 for (UInt_t i=0; i<
fParams.size(); i++) {
2248 fout.setf(std::ios::right, std::ios::adjustfield);
2250 fout << std::endl << i+1 <<
" ";
2252 fout <<
fParams[i].fName.Data();
2253 for (Int_t j=0; j<=maxLength-
fParams[i].fName.Length(); j++)
2256 fout.setf(std::ios::left, std::ios::adjustfield);
2259 fout <<
fParams[i].fValue <<
" ";
2261 fout.setf(std::ios::left, std::ios::adjustfield);
2269 if (
fParams[i].fPosErrorPresent) {
2270 fout.setf(std::ios::left, std::ios::adjustfield);
2274 fout.setf(std::ios::left, std::ios::adjustfield);
2277 fout <<
fParams[i].fPosError <<
" ";
2279 fout.setf(std::ios::left, std::ios::adjustfield);
2282 fout.setf(std::ios::left, std::ios::adjustfield);
2287 if (
fParams[i].fNoOfParams > 5) {
2288 fout.setf(std::ios::left, std::ios::adjustfield);
2290 if (
fParams[i].fLowerBoundaryPresent)
2291 fout <<
fParams[i].fLowerBoundary;
2294 fout.setf(std::ios::left, std::ios::adjustfield);
2296 if (
fParams[i].fUpperBoundaryPresent)
2297 fout <<
fParams[i].fUpperBoundary;
2301 fout.setf(std::ios::left, std::ios::adjustfield);
2304 fout.setf(std::ios::left, std::ios::adjustfield);
2310 fout << std::endl <<
"*************************************************************************";
2313 fout << std::endl <<
" COVARIANCE MATRIX";
2314 fout << std::endl <<
"-------------------------------------------------------------------------";
2315 if (mnState.HasCovariance()) {
2316 ROOT::Minuit2::MnUserCovariance cov = mnState.Covariance();
2317 fout << std::endl <<
"from " << cov.Nrow() <<
" free parameters";
2318 for (UInt_t i=0; i<cov.Nrow(); i++) {
2320 for (UInt_t j=0; j<i; j++) {
2321 fout.setf(std::ios::left, std::ios::adjustfield);
2323 if (cov(i,j) > 0.0) {
2333 fout << std::endl <<
" no covariance matrix available";
2336 fout << std::endl <<
"*************************************************************************";
2339 fout << std::endl <<
" CORRELATION COEFFICIENTS";
2340 fout << std::endl <<
"-------------------------------------------------------------------------";
2341 if (mnState.IsValid() && mnState.HasCovariance()) {
2342 ROOT::Minuit2::MnGlobalCorrelationCoeff corr = mnState.GlobalCC();
2343 ROOT::Minuit2::MnUserCovariance cov = mnState.Covariance();
2345 fout << std::endl <<
" No Global ";
2346 for (UInt_t i=0; i<
fParams.size(); i++) {
2349 fout.setf(std::ios::left, std::ios::adjustfield);
2356 if (parNo.size() != cov.Nrow()) {
2357 std::cerr << std::endl <<
"**SEVERE ERROR** in PFitter::ExecuteSave(): minuit2 and musrfit book keeping to not correspond! Unable to write correlation matrix.";
2358 std::cerr << std::endl;
2360 TString title(
"Minuit2 Output Correlation Matrix for ");
2363 title += dt.AsSQLString();
2364 std::unique_ptr<TCanvas> ccorr = std::make_unique<TCanvas>(
"ccorr",
"title", 500, 500);
2365 std::unique_ptr<TH2D> hcorr = std::make_unique<TH2D>(
"hcorr", title, cov.Nrow(), 0.0, cov.Nrow(), cov.Nrow(), 0.0, cov.Nrow());
2367 for (UInt_t i=0; i<cov.Nrow(); i++) {
2369 fout << std::endl <<
" ";
2370 fout.setf(std::ios::left, std::ios::adjustfield);
2374 fout.setf(std::ios::left, std::ios::adjustfield);
2377 fout << corr.GlobalCC()[i];
2379 for (UInt_t j=0; j<cov.Nrow(); j++) {
2380 fout.setf(std::ios::left, std::ios::adjustfield);
2385 hcorr->Fill((Double_t)i,(Double_t)i,1.0);
2389 std::cerr << std::endl <<
"**SEVERE ERROR** in PFitter::ExecuteSave(): parameter no " << parNo[i]+1 <<
" has an error == 0. Cannot correctly handle the correlation matrix.";
2390 std::cerr << std::endl;
2393 std::cerr << std::endl <<
"**SEVERE ERROR** in PFitter::ExecuteSave(): parameter no " << parNo[j]+1 <<
" has an error == 0. Cannot correctly handle the correlation matrix.";
2394 std::cerr << std::endl;
2399 hcorr->Fill((Double_t)i,(Double_t)j,dval);
2401 if (dval < 1.0e-2) {
2413 fout << dval <<
" ";
2418 TFile ff(
"MINUIT2.root",
"recreate");
2420 if (cov.Nrow() <= 6)
2421 hcorr->Draw(
"COLZTEXT");
2423 hcorr->Draw(
"COLZ");
2424 ccorr->Write(
"ccorr", TObject::kOverwrite,
sizeof(ccorr));
2425 hcorr->Write(
"hcorr", TObject::kOverwrite,
sizeof(hcorr));
2435 std::string yaml_filename(
fRunInfo->GetFileName().Data());
2436 const std::string msr_ext(
".msr");
2437 yaml_filename.replace(yaml_filename.find(msr_ext), msr_ext.length(),
2441 const std::string yaml_indent(
" ");
2444 std::ofstream yaml_file(yaml_filename);
2447 yaml_file << std::scientific << std::setprecision(16);
2450 yaml_file <<
"values:\n";
2451 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2452 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
": "
2457 yaml_file <<
"errors:\n";
2458 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2459 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
": "
2464 yaml_file <<
"mnerrors:\n";
2465 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2468 boost::variant<double, std::string> positive_error, negative_error;
2469 if (
fParams[i].fPosErrorPresent) {
2470 positive_error =
fParams[i].fPosError;
2471 negative_error =
fParams[i].fStep;
2473 positive_error =
"null";
2474 negative_error =
"null";
2477 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
":\n";
2478 yaml_file << yaml_indent << yaml_indent
2479 <<
"positive: " << positive_error <<
"\n";
2480 yaml_file << yaml_indent << yaml_indent
2481 <<
"negative: " << negative_error <<
"\n";
2485 yaml_file <<
"limits:\n";
2486 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2489 boost::variant<double, std::string> upper_limit, lower_limit;
2490 if (
fParams[i].fLowerBoundaryPresent) {
2491 lower_limit =
fParams[i].fLowerBoundary;
2493 lower_limit =
"null";
2495 if (
fParams[i].fUpperBoundaryPresent) {
2496 upper_limit =
fParams[i].fUpperBoundary;
2498 upper_limit =
"null";
2501 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
":\n";
2502 yaml_file << yaml_indent << yaml_indent <<
"lower: " << lower_limit
2504 yaml_file << yaml_indent << yaml_indent <<
"upper: " << upper_limit
2509 yaml_file <<
"fixed:\n";
2510 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2511 std::string is_fixed =
fParams[i].fStep == 0.0 ?
"true" :
"false";
2512 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
": " << is_fixed
2517 yaml_file <<
"covariance:\n";
2518 for (
unsigned int i = 0; i < cov.Nrow(); ++i) {
2519 yaml_file << yaml_indent << mnState.Name(parNo[i]) <<
":\n";
2520 for (
unsigned int j = 0; j < cov.Nrow(); ++j) {
2521 yaml_file << yaml_indent << yaml_indent << mnState.Name(parNo[j])
2522 <<
": " << cov(i, j) <<
"\n";
2527 yaml_file <<
"correlation:\n";
2528 for (
unsigned int i = 0; i < cov.Nrow(); ++i) {
2529 yaml_file << yaml_indent << mnState.Name(parNo[i]) <<
":\n";
2530 for (
unsigned int j = 0; j < cov.Nrow(); ++j) {
2531 double correlation =
2535 yaml_file << yaml_indent << yaml_indent << mnState.Name(parNo[j])
2536 <<
": " << correlation <<
"\n";
2546 fout << std::endl <<
" no correlation coefficients available";
2550 fout << std::endl <<
"*************************************************************************";
2551 fout << std::endl <<
" chisq/maxLH RESULT ";
2552 fout << std::endl <<
"*************************************************************************";
2563 fitStartTime = run->at(0).GetFitRange(0);
2564 fitEndTime = run->at(0).GetFitRange(1);
2566 fout.setf(std::ios::fixed, std::ios::floatfield);
2567 fout << std::endl <<
" Time Range: " << fitStartTime <<
", " << fitEndTime << std::endl;
2569 fout.setf(std::ios::fixed, std::ios::floatfield);
2570 fout << std::endl <<
" chisq = " << std::setprecision(4) << statistics->
fMin <<
", NDF = " << statistics->
fNdf <<
", chisq/NDF = " << std::setprecision(6) << statistics->
fMin/statistics->
fNdf;
2572 fout << std::endl <<
" chisq_e = " << std::setprecision(4) << statistics->
fMinExpected <<
", NDF = " << statistics->
fNdf <<
", chisq_e/NDF = " << std::setprecision(6) << statistics->
fMinExpected/statistics->
fNdf;
2574 fout.setf(std::ios::fixed, std::ios::floatfield);
2575 fout << std::endl <<
" maxLH = " << std::setprecision(4) << statistics->
fMin <<
", NDF = " << statistics->
fNdf <<
", maxLH/NDF = " << std::setprecision(6) << statistics->
fMin/statistics->
fNdf;
2577 fout << std::endl <<
" maxLH_e = " << std::setprecision(4) << statistics->
fMinExpected <<
", NDF = " << statistics->
fNdf <<
", maxLH_e/NDF = " << std::setprecision(6) << statistics->
fMinExpected/statistics->
fNdf;
2584 fout << std::endl <<
"*************************************************************************";
2585 fout << std::endl <<
" DONE ";
2586 fout << std::endl <<
"*************************************************************************";
2587 fout << std::endl << std::endl;
2685 Int_t usedParams = 0;
2686 for (UInt_t i=0; i<error.size(); i++) {
2687 if (error[i] != 0.0)
2692 secFitRange.resize(1);
2695 Double_t totalExpectedChisq = 0.0;
2698 for (UInt_t k=0; k<
fSector.size(); k++) {
2700 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
2701 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
2704 val = (*fFitterFcn)(param);
2707 ndf =
static_cast<UInt_t
>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
2710 totalExpectedChisq = 0.0;
2711 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedChisq, expectedChisqPerRun);
2712 fSector[k].SetExpectedChisq(totalExpectedChisq);
2714 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
2716 fSector[k].SetChisq(chisqPerRun[i], i);
2717 fSector[k].SetExpectedChisq(expectedChisqPerRun[i], i);
2720 if (totalExpectedChisq != 0.0) {
2722 for (UInt_t i=0; i<expectedChisqPerRun.size(); i++) {
2725 fSector[k].SetNDF(ndf_run, i);
2728 }
else if (chisqPerRun.size() > 0) {
2730 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
2733 fSector[k].SetNDF(ndf_run, i);
2738 chisqPerRun.clear();
2739 expectedChisqPerRun.clear();
2742 Double_t totalExpectedMaxLH = 0.0;
2745 for (UInt_t k=0; k<
fSector.size(); k++) {
2747 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
2748 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
2751 val = (*fFitterFcn)(param);
2754 ndf =
static_cast<UInt_t
>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
2757 totalExpectedMaxLH = 0.0;
2758 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedMaxLH, expectedMaxLHPerRun);
2759 fSector[k].SetExpectedChisq(totalExpectedMaxLH);
2761 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
2763 fSector[k].SetChisq(maxLHPerRun[i], i);
2764 fSector[k].SetExpectedChisq(expectedMaxLHPerRun[i], i);
2767 if (totalExpectedMaxLH != 0.0) {
2769 for (UInt_t i=0; i<expectedMaxLHPerRun.size(); i++) {
2772 fSector[k].SetNDF(ndf_run, i);
2778 maxLHPerRun.clear();
2779 expectedMaxLHPerRun.clear();