656 Int_t usedParams = 0;
657 for (UInt_t i=0; i<error.size(); i++) {
661 UInt_t ndf =
static_cast<int>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
662 Double_t val = (*fFitterFcn)(param);
665 Double_t totalExpectedChisq = 0.0;
667 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedChisq, expectedChisqPerRun);
669 std::vector<Double_t> chisqPerRun;
670 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
674 std::cout << std::endl << std::endl <<
">> chisq = " << val <<
", NDF = " << ndf <<
", chisq/NDF = " << val/ndf;
676 if (totalExpectedChisq != 0.0) {
677 std::cout << std::endl <<
">> expected chisq = " << totalExpectedChisq <<
", NDF = " << ndf <<
", expected chisq/NDF = " << totalExpectedChisq/ndf;
679 for (UInt_t i=0; i<expectedChisqPerRun.size(); i++) {
682 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq/red.chisq_e) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
"/" << expectedChisqPerRun[i]/ndf_run <<
")";
684 }
else if (chisqPerRun.size() > 0) {
686 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
689 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
")";
695 expectedChisqPerRun.clear();
699 secFitRange.resize(1);
700 for (UInt_t k=0; k<
fSector.size(); k++) {
702 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
703 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
706 val = (*fFitterFcn)(param);
708 ndf =
static_cast<UInt_t
>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
710 totalExpectedChisq = 0.0;
711 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedChisq, expectedChisqPerRun);
713 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
717 std::cout << std::endl;
718 std::cout <<
"++++" << std::endl;
719 std::cout <<
">> Sector " << k+1 <<
": FitRange: " << secFitRange[0].first <<
", " << secFitRange[0].second << std::endl;
720 std::cout <<
">> chisq = " << val <<
", NDF = " << ndf <<
", chisq/NDF = " << val/ndf;
722 if (totalExpectedChisq != 0.0) {
723 std::cout << std::endl <<
">> expected chisq = " << totalExpectedChisq <<
", NDF = " << ndf <<
", expected chisq/NDF = " << totalExpectedChisq/ndf;
725 for (UInt_t i=0; i<expectedChisqPerRun.size(); i++) {
728 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq/red.chisq_e) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
"/" << expectedChisqPerRun[i]/ndf_run <<
")";
730 }
else if (chisqPerRun.size() > 0) {
732 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
735 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.chisq) = (" << ndf_run <<
"/" << chisqPerRun[i]/ndf_run <<
")";
740 expectedChisqPerRun.clear();
745 Double_t totalExpectedMaxLH = 0.0;
746 std::vector<Double_t> expectedMaxLHPerRun;
747 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedMaxLH, expectedMaxLHPerRun);
749 std::vector<Double_t> maxLHPerRun;
750 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
754 std::cout << std::endl << std::endl <<
">> maxLH = " << val <<
", NDF = " << ndf <<
", maxLH/NDF = " << val/ndf;
756 if (totalExpectedMaxLH != 0.0) {
757 std::cout << std::endl <<
">> expected maxLH = " << totalExpectedMaxLH <<
", NDF = " << ndf <<
", expected maxLH/NDF = " << totalExpectedMaxLH/ndf;
759 for (UInt_t i=0; i<expectedMaxLHPerRun.size(); i++) {
762 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.maxLH/red.maxLH_e) = (" << ndf_run <<
"/" << maxLHPerRun[i]/ndf_run <<
"/" << expectedMaxLHPerRun[i]/ndf_run <<
")";
768 expectedMaxLHPerRun.clear();
772 secFitRange.resize(1);
773 for (UInt_t k=0; k<
fSector.size(); k++) {
775 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
776 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
779 val = (*fFitterFcn)(param);
781 ndf =
static_cast<int>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
783 totalExpectedMaxLH = 0.0;
784 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedMaxLH, expectedMaxLHPerRun);
786 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
790 std::cout << std::endl;
791 std::cout <<
"++++" << std::endl;
792 std::cout <<
">> Sector " << k+1 <<
": FitRange: " << secFitRange[0].first <<
", " << secFitRange[0].second << std::endl;
793 std::cout <<
">> maxLH = " << val <<
", NDF = " << ndf <<
", maxLH/NDF = " << val/ndf;
795 if (totalExpectedMaxLH != 0.0) {
796 std::cout << std::endl <<
">> expected maxLH = " << totalExpectedMaxLH <<
", NDF = " << ndf <<
", expected maxLH/NDF = " << totalExpectedMaxLH/ndf;
798 for (UInt_t i=0; i<expectedMaxLHPerRun.size(); i++) {
801 std::cout << std::endl <<
">> run block " << i+1 <<
": (NDF/red.maxLH/red.maxLH_e) = (" << ndf_run <<
"/" << maxLHPerRun[i]/ndf_run <<
"/" << expectedMaxLHPerRun[i]/ndf_run <<
")";
807 expectedMaxLHPerRun.clear();
811 std::cout << std::endl << std::endl;
817 std::cout << std::endl <<
">> Number of available threads for the function optimization: " << omp_get_max_threads() << std::endl;
822 std::cout << std::endl <<
">> Chi Square fit will be executed" << std::endl;
824 std::cout << std::endl <<
">> Maximum Likelihood fit will be executed" << std::endl;
828 for (UInt_t i=0; i<
fParams.size(); i++) {
829 fRunInfo->SetMsrParamPosErrorPresent(i,
false);
833 Bool_t firstSave =
true;
834 for (UInt_t i=0; i<
fCmdList.size(); i++) {
837 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command INTERACTIVE is not yet implemented.";
838 std::cerr << std::endl;
850 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command EIGEN is not yet implemented.";
851 std::cerr << std::endl;
857 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command MACHINE_PRECISION is not yet implemented.";
858 std::cerr << std::endl;
893 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command USER_COVARIANCE is not yet implemented.";
894 std::cerr << std::endl;
897 std::cerr << std::endl <<
"**WARNING** from PFitter::DoFit() : the command USER_PARAM_STATE is not yet implemented.";
898 std::cerr << std::endl;
904 std::cerr << std::endl <<
"**PANIC ERROR**: PFitter::DoFit(): You should never have reached this point";
905 std::cerr << std::endl;
915 fRunInfo->GetMsrStatistic()->fValid =
true;
917 fRunInfo->GetMsrStatistic()->fValid =
false;
962 PMsrLines::iterator it;
963 UInt_t cmdLineNo = 0;
974 pos = line.First(
'#');
976 line.Remove(pos,line.Length()-pos);
978 if (line.Contains(
"COMMANDS", TString::kIgnoreCase)) {
980 }
else if (line.Contains(
"SET BATCH", TString::kIgnoreCase)) {
982 }
else if (line.Contains(
"END RETURN", TString::kIgnoreCase)) {
984 }
else if (line.Contains(
"CHI_SQUARE", TString::kIgnoreCase)) {
986 }
else if (line.Contains(
"MAX_LIKELIHOOD", TString::kIgnoreCase)) {
988 }
else if (line.Contains(
"SCALE_N0_BKG", TString::kIgnoreCase)) {
990 }
else if (line.Contains(
"INTERACTIVE", TString::kIgnoreCase)) {
992 cmd.second = cmdLineNo;
994 }
else if (line.Contains(
"CONTOURS", TString::kIgnoreCase)) {
996 cmd.second = cmdLineNo;
999 TObjArray *tokens =
nullptr;
1004 tokens = line.Tokenize(
", \t");
1006 for (Int_t i=0; i<tokens->GetEntries(); i++) {
1007 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
1008 str = ostr->GetString();
1010 if ((i==1) || (i==2)) {
1012 if (!str.IsDigit()) {
1013 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1014 std::cerr << std::endl <<
">> " << line.Data();
1015 std::cerr << std::endl <<
">> parameter number is not number!";
1016 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1017 std::cerr << std::endl;
1027 if ((ival < 1) || (ival >
fParams.size())) {
1028 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1029 std::cerr << std::endl <<
">> " << line.Data();
1030 std::cerr << std::endl <<
">> parameter number is out of range [1," <<
fParams.size() <<
"]!";
1031 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1032 std::cerr << std::endl;
1047 if (!str.IsDigit()) {
1048 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1049 std::cerr << std::endl <<
">> " << line.Data();
1050 std::cerr << std::endl <<
">> number of points is not number!";
1051 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1052 std::cerr << std::endl;
1061 if ((ival < 1) || (ival > 100)) {
1062 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1063 std::cerr << std::endl <<
">> " << line.Data();
1064 std::cerr << std::endl <<
">> number of scan points is out of range [1,100]!";
1065 std::cerr << std::endl <<
">> command syntax for CONTOURS is: CONTOURS parameter-X parameter-Y [# of points]";
1066 std::cerr << std::endl;
1082 }
else if (line.Contains(
"EIGEN", TString::kIgnoreCase)) {
1084 cmd.second = cmdLineNo;
1086 }
else if (line.Contains(
"FIT_RANGE", TString::kIgnoreCase)) {
1093 TObjArray *tokens =
nullptr;
1097 tokens = line.Tokenize(
", \t");
1099 if (tokens->GetEntries() == 2) {
1100 ostr =
dynamic_cast<TObjString*
>(tokens->At(1));
1101 str = ostr->GetString();
1102 if (str.Contains(
"RESET", TString::kIgnoreCase)) {
1104 cmd.second = cmdLineNo;
1107 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1108 std::cerr << std::endl <<
">> " << line.Data();
1109 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE start end | FIT_RANGE s1 e1 s2 e2 .. sN eN,";
1110 std::cerr << std::endl <<
">> with N the number of runs in the msr-file." << std::endl;
1111 std::cerr << std::endl <<
">> Found " << str.Data() <<
", instead of RESET" << std::endl;
1119 }
else if ((tokens->GetEntries() > 1) && (
static_cast<UInt_t
>(tokens->GetEntries()) % 2) == 1) {
1120 if ((tokens->GetEntries() > 3) && ((
static_cast<UInt_t
>(tokens->GetEntries())-1)) != 2*
fRunInfo->GetMsrRunList()->size()) {
1121 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1122 std::cerr << std::endl <<
">> " << line.Data();
1123 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE <start> <end> | FIT_RANGE <s1> <e1> <s2> <e2> .. <sN> <eN> |";
1124 std::cerr << std::endl <<
">> FIT_RANGE fgb+<n0> lgb-<n1> | FIT_RANGE fgb+<n00> lgb-<n01> fgb+<n10> lgb-<n11> ... fgb+<nN0> lgb-<nN1>,";
1125 std::cerr << std::endl <<
">> with N the number of runs in the msr-file.";
1126 std::cerr << std::endl <<
">> Found N=" << (tokens->GetEntries()-1)/2 <<
", # runs in msr-file=" <<
fRunInfo->GetMsrRunList()->size() << std::endl;
1136 for (Int_t n=1; n<tokens->GetEntries(); n++) {
1137 ostr =
dynamic_cast<TObjString*
>(tokens->At(n));
1138 str = ostr->GetString();
1139 if (!str.IsFloat()) {
1140 if ((n%2 == 1) && (!str.Contains(
"fgb", TString::kIgnoreCase)))
1142 if ((n%2 == 0) && (!str.Contains(
"lgb", TString::kIgnoreCase)))
1151 cmd.second = cmdLineNo;
1154 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1155 std::cerr << std::endl <<
">> " << line.Data();
1156 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE <start> <end> | FIT_RANGE <s1> <e1> <s2> <e2> .. <sN> <eN> |";
1157 std::cerr << std::endl <<
">> FIT_RANGE fgb+<n0> lgb-<n1> | FIT_RANGE fgb+<n00> lgb-<n01> fgb+<n10> lgb-<n11> ... fgb+<nN0> lgb-<nN1>,";
1158 std::cerr << std::endl <<
">> with N the number of runs in the msr-file.";
1159 std::cerr << std::endl <<
">> Found token '" << str.Data() <<
"', which is not a floating point number." << std::endl;
1169 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1170 std::cerr << std::endl <<
">> " << line.Data();
1171 std::cerr << std::endl <<
">> Syntax: FIT_RANGE RESET | FIT_RANGE <start> <end> | FIT_RANGE <s1> <e1> <s2> <e2> .. <sN> <eN> |";
1172 std::cerr << std::endl <<
">> FIT_RANGE fgb+<n0> lgb-<n1> | FIT_RANGE fgb+<n00> lgb-<n01> fgb+<n10> lgb-<n11> ... fgb+<nN0> lgb-<nN1>,";
1173 std::cerr << std::endl <<
">> with N the number of runs in the msr-file.";
1186 }
else if (line.Contains(
"FIX", TString::kIgnoreCase)) {
1188 TObjArray *tokens =
nullptr;
1193 tokens = line.Tokenize(
", \t");
1195 for (Int_t i=1; i<tokens->GetEntries(); i++) {
1196 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
1197 str = ostr->GetString();
1199 if (str.IsDigit()) {
1203 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1204 std::cerr << std::endl <<
">> " << line.Data();
1205 std::cerr << std::endl <<
">> Parameter " << ival <<
" is out of the Parameter Range [1," <<
fParams.size() <<
"]";
1206 std::cerr << std::endl;
1216 Bool_t found =
false;
1217 for (UInt_t j=0; j<
fParams.size(); j++) {
1218 if (
fParams[j].fName.CompareTo(str, TString::kIgnoreCase) == 0) {
1224 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1225 std::cerr << std::endl <<
">> " << line.Data();
1226 std::cerr << std::endl <<
">> Parameter '" << str.Data() <<
"' is NOT present as a parameter name";
1227 std::cerr << std::endl;
1245 cmd.second = cmdLineNo;
1247 }
else if (line.Contains(
"HESSE", TString::kIgnoreCase)) {
1250 cmd.second = cmdLineNo;
1252 }
else if (line.Contains(
"MACHINE_PRECISION", TString::kIgnoreCase)) {
1254 cmd.second = cmdLineNo;
1256 }
else if (line.Contains(
"MIGRAD", TString::kIgnoreCase)) {
1259 cmd.second = cmdLineNo;
1261 }
else if (line.Contains(
"MINIMIZE", TString::kIgnoreCase)) {
1264 cmd.second = cmdLineNo;
1266 }
else if (line.Contains(
"MINOS", TString::kIgnoreCase)) {
1269 cmd.second = cmdLineNo;
1271 }
else if (line.Contains(
"MNPLOT", TString::kIgnoreCase)) {
1273 cmd.second = cmdLineNo;
1275 }
else if (line.Contains(
"PRINT_LEVEL", TString::kIgnoreCase)) {
1277 cmd.second = cmdLineNo;
1279 }
else if (line.Contains(
"RELEASE", TString::kIgnoreCase)) {
1281 TObjArray *tokens =
nullptr;
1286 tokens = line.Tokenize(
", \t");
1288 for (Int_t i=1; i<tokens->GetEntries(); i++) {
1289 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
1290 str = ostr->GetString();
1292 if (str.IsDigit()) {
1296 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1297 std::cerr << std::endl <<
">> " << line.Data();
1298 std::cerr << std::endl <<
">> Parameter " << ival <<
" is out of the Parameter Range [1," <<
fParams.size() <<
"]";
1299 std::cerr << std::endl;
1309 Bool_t found =
false;
1310 for (UInt_t j=0; j<
fParams.size(); j++) {
1311 if (
fParams[j].fName.CompareTo(str, TString::kIgnoreCase) == 0) {
1317 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1318 std::cerr << std::endl <<
">> " << line.Data();
1319 std::cerr << std::endl <<
">> Parameter '" << str.Data() <<
"' is NOT present as a parameter name";
1320 std::cerr << std::endl;
1336 cmd.second = cmdLineNo;
1338 }
else if (line.Contains(
"RESTORE", TString::kIgnoreCase)) {
1340 cmd.second = cmdLineNo;
1342 }
else if (line.Contains(
"SAVE", TString::kIgnoreCase)) {
1344 cmd.second = cmdLineNo;
1346 }
else if (line.Contains(
"SCAN", TString::kIgnoreCase)) {
1348 cmd.second = cmdLineNo;
1351 TObjArray *tokens =
nullptr;
1356 tokens = line.Tokenize(
", \t");
1358 for (Int_t i=0; i<tokens->GetEntries(); i++) {
1359 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
1360 str = ostr->GetString();
1363 if (!str.IsDigit()) {
1364 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1365 std::cerr << std::endl <<
">> " << line.Data();
1366 std::cerr << std::endl <<
">> parameter number is not number!";
1367 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1368 std::cerr << std::endl;
1378 if ((ival < 1) || (ival >
fParams.size())) {
1379 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1380 std::cerr << std::endl <<
">> " << line.Data();
1381 std::cerr << std::endl <<
">> parameter number is out of range [1," <<
fParams.size() <<
"]!";
1382 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1383 std::cerr << std::endl;
1398 if (!str.IsDigit()) {
1399 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1400 std::cerr << std::endl <<
">> " << line.Data();
1401 std::cerr << std::endl <<
">> number of points is not number!";
1402 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1403 std::cerr << std::endl;
1412 if ((ival < 1) || (ival > 100)) {
1413 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1414 std::cerr << std::endl <<
">> " << line.Data();
1415 std::cerr << std::endl <<
">> number of scan points is out of range [1,100]!";
1416 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1417 std::cerr << std::endl;
1430 if (!str.IsFloat()) {
1431 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1432 std::cerr << std::endl <<
">> " << line.Data();
1433 std::cerr << std::endl <<
">> low is not a floating point number!";
1434 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1435 std::cerr << std::endl;
1448 if (!str.IsFloat()) {
1449 std::cerr << std::endl <<
">> PFitter::CheckCommands: **ERROR** in line " << it->fLineNo;
1450 std::cerr << std::endl <<
">> " << line.Data();
1451 std::cerr << std::endl <<
">> high is not a floating point number!";
1452 std::cerr << std::endl <<
">> command syntax for SCAN is: SCAN [parameter no [# of points [low high]]]";
1453 std::cerr << std::endl;
1469 }
else if (line.Contains(
"SIMPLEX", TString::kIgnoreCase)) {
1471 cmd.second = cmdLineNo;
1473 }
else if (line.Contains(
"STRATEGY", TString::kIgnoreCase)) {
1474 TObjArray *tokens =
nullptr;
1478 tokens = line.Tokenize(
" \t");
1479 if (tokens->GetEntries() == 2) {
1480 ostr =
dynamic_cast<TObjString*
>(tokens->At(1));
1481 str = ostr->GetString();
1482 if (str.CompareTo(
"0") == 0) {
1484 }
else if (str.CompareTo(
"1") == 0) {
1486 }
else if (str.CompareTo(
"2") == 0) {
1488 }
else if (str.CompareTo(
"LOW") == 0) {
1490 }
else if (str.CompareTo(
"DEFAULT") == 0) {
1492 }
else if (str.CompareTo(
"HIGH") == 0) {
1501 }
else if (line.Contains(
"USER_COVARIANCE", TString::kIgnoreCase)) {
1503 cmd.second = cmdLineNo;
1505 }
else if (line.Contains(
"USER_PARAM_STATE", TString::kIgnoreCase)) {
1507 cmd.second = cmdLineNo;
1509 }
else if (line.Contains(
"SECTOR", TString::kIgnoreCase)) {
1512 cmd.second = cmdLineNo;
1516 TObjArray *tokens =
nullptr;
1520 tokens = line.Tokenize(
" ,\t");
1522 if (tokens->GetEntries() == 1) {
1523 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo;
1524 std::cerr << std::endl <<
">> " << line.Data();
1525 std::cerr << std::endl <<
">> At least one sector time stamp is expected.";
1526 std::cerr << std::endl <<
">> Will stop ...";
1527 std::cerr << std::endl;
1539 for (Int_t i=1; i<tokens->GetEntries(); i++) {
1543 ostr =
dynamic_cast<TObjString*
>(tokens->At(i));
1544 str = ostr->GetString();
1545 if (str.IsFloat()) {
1550 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo;
1551 std::cerr << std::endl <<
">> " << line.Data();
1552 std::cerr << std::endl <<
">> The sector time stamp " << dval <<
" is > as the lgb time stamp (" <<
fOriginalFitRange[j].second <<
") of run " << j <<
".";
1553 std::cerr << std::endl <<
">> Will stop ...";
1554 std::cerr << std::endl;
1569 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo;
1570 std::cerr << std::endl <<
">> " << line.Data();
1571 std::cerr << std::endl <<
">> The sector time stamp '" << str <<
"' is not a number.";
1572 std::cerr << std::endl <<
">> Will stop ...";
1573 std::cerr << std::endl;
1590 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **FATAL ERROR** in line " << it->fLineNo <<
" an unkown command is found:";
1591 std::cerr << std::endl <<
">> " << line.Data();
1592 std::cerr << std::endl <<
">> Will stop ...";
1593 std::cerr << std::endl;
1601 Bool_t fixFlag =
false;
1602 Bool_t releaseFlag =
false;
1603 Bool_t minimizerFlag =
false;
1605 if (line.Contains(
"FIX", TString::kIgnoreCase))
1607 else if (line.Contains(
"RELEASE", TString::kIgnoreCase) ||
1608 line.Contains(
"RESTORE", TString::kIgnoreCase))
1610 else if (line.Contains(
"MINIMIZE", TString::kIgnoreCase) ||
1611 line.Contains(
"MIGRAD", TString::kIgnoreCase) ||
1612 line.Contains(
"SIMPLEX", TString::kIgnoreCase)) {
1614 minimizerFlag =
true;
1615 }
else if (line.Contains(
"MINOS", TString::kIgnoreCase)) {
1616 if (fixFlag && releaseFlag && !minimizerFlag) {
1617 std::cerr << std::endl <<
">> PFitter::CheckCommands(): **WARNING** RELEASE/RESTORE command present";
1618 std::cerr << std::endl <<
">> without minimizer command (MINIMIZE/MIGRAD/SIMPLEX) between";
1619 std::cerr << std::endl <<
">> RELEASE/RESTORE and MINOS. Behaviour might be different to the";
1620 std::cerr << std::endl <<
">> expectation of the user ?!?" << std::endl;
1623 releaseFlag =
false;
1624 minimizerFlag =
false;
2276 std::cout << std::endl <<
">> PFitter::ExecuteSave(): nothing to be saved ...";
2280 ROOT::Minuit2::MnUserParameterState mnState =
fFcnMin->UserState();
2283 if (!mnState.IsValid()) {
2284 std::cerr << std::endl <<
">> PFitter::ExecuteSave: **WARNING** Minuit2 User Parameter State is not valid, i.e. nothing to be saved";
2285 std::cerr << std::endl;
2293 std::vector<Double_t> param;
2294 std::vector<Double_t> err;
2295 Double_t totalExpectedChisq = 0.0;
2296 std::vector<Double_t> expectedchisqPerRun;
2297 std::vector<UInt_t> ndfPerHisto;
2299 for (UInt_t i=0; i<
fParams.size(); i++) {
2300 param.push_back(
fParams[i].fValue);
2301 err.push_back(
fParams[i].fStep);
2309 fFitterFcn->CalcExpectedChiSquare(par_r, totalExpectedChisq, expectedchisqPerRun);
2312 std::vector<Double_t> chisqPerRun;
2313 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
2320 if (totalExpectedChisq != 0.0) {
2323 for (UInt_t i=0; i<expectedchisqPerRun.size(); i++) {
2325 ndfPerHisto.push_back(ndf_run);
2336 }
else if (chisqPerRun.size() > 1) {
2338 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
2340 ndfPerHisto.push_back(ndf_run);
2354 for (UInt_t i=0; i<
fParams.size(); i++)
2355 error.push_back(
fParams[i].fStep);
2362 expectedchisqPerRun.clear();
2363 ndfPerHisto.clear();
2364 chisqPerRun.clear();
2366 std::cout <<
">> PFitter::ExecuteSave(): will write minuit2 output file ..." << std::endl;
2372 fout.open(
"MINUIT2.OUTPUT", std::iostream::out);
2374 fout.open(
"MINUIT2.OUTPUT", std::iostream::out | std::iostream::app);
2376 if (!fout.is_open()) {
2377 std::cerr << std::endl <<
"**ERROR** PFitter::ExecuteSave() couldn't open MINUIT2.OUTPUT file";
2378 std::cerr << std::endl;
2384 fout << std::endl <<
"*************************************************************************";
2385 fout << std::endl <<
" musrfit MINUIT2 output file from " <<
fRunInfo->GetFileName().Data() <<
" - " << dt.AsSQLString();
2386 fout << std::endl <<
"*************************************************************************";
2390 fout << std::endl <<
" elapsed times:";
2395 fout << std::endl <<
"*************************************************************************";
2400 fout << std::endl <<
" Fval() = " << mnState.Fval() <<
", Edm() = " << mnState.Edm() <<
", NFcn() = " << mnState.NFcn();
2402 fout << std::endl <<
"*************************************************************************";
2406 Int_t maxLength = 10;
2407 for (UInt_t i=0; i<
fParams.size(); i++) {
2408 if (
fParams[i].fName.Length() > maxLength)
2409 maxLength =
fParams[i].fName.Length() + 1;
2414 fout << std::endl <<
" PARAMETERS";
2415 fout << std::endl <<
"-------------------------------------------------------------------------";
2416 fout << std::endl <<
" ";
2417 for (Int_t j=0; j<=maxLength-4; j++)
2419 fout <<
"Parabolic Minos";
2420 fout << std::endl <<
" No Name";
2421 for (Int_t j=0; j<=maxLength-4; j++)
2423 fout <<
"Value Error Negative Positive Limits";
2424 for (UInt_t i=0; i<
fParams.size(); i++) {
2426 fout.setf(std::ios::right, std::ios::adjustfield);
2428 fout << std::endl << i+1 <<
" ";
2430 fout <<
fParams[i].fName.Data();
2431 for (Int_t j=0; j<=maxLength-
fParams[i].fName.Length(); j++)
2434 fout.setf(std::ios::left, std::ios::adjustfield);
2437 fout <<
fParams[i].fValue <<
" ";
2439 fout.setf(std::ios::left, std::ios::adjustfield);
2447 if (
fParams[i].fPosErrorPresent) {
2448 fout.setf(std::ios::left, std::ios::adjustfield);
2452 fout.setf(std::ios::left, std::ios::adjustfield);
2455 fout <<
fParams[i].fPosError <<
" ";
2457 fout.setf(std::ios::left, std::ios::adjustfield);
2460 fout.setf(std::ios::left, std::ios::adjustfield);
2465 if (
fParams[i].fNoOfParams > 5) {
2466 fout.setf(std::ios::left, std::ios::adjustfield);
2468 if (
fParams[i].fLowerBoundaryPresent)
2469 fout <<
fParams[i].fLowerBoundary;
2472 fout.setf(std::ios::left, std::ios::adjustfield);
2474 if (
fParams[i].fUpperBoundaryPresent)
2475 fout <<
fParams[i].fUpperBoundary;
2479 fout.setf(std::ios::left, std::ios::adjustfield);
2482 fout.setf(std::ios::left, std::ios::adjustfield);
2488 fout << std::endl <<
"*************************************************************************";
2491 fout << std::endl <<
" COVARIANCE MATRIX";
2492 fout << std::endl <<
"-------------------------------------------------------------------------";
2493 if (mnState.HasCovariance()) {
2494 ROOT::Minuit2::MnUserCovariance cov = mnState.Covariance();
2495 fout << std::endl <<
"from " << cov.Nrow() <<
" free parameters";
2496 for (UInt_t i=0; i<cov.Nrow(); i++) {
2498 for (UInt_t j=0; j<i; j++) {
2499 fout.setf(std::ios::left, std::ios::adjustfield);
2501 if (cov(i,j) > 0.0) {
2511 fout << std::endl <<
" no covariance matrix available";
2514 fout << std::endl <<
"*************************************************************************";
2517 fout << std::endl <<
" CORRELATION COEFFICIENTS";
2518 fout << std::endl <<
"-------------------------------------------------------------------------";
2519 if (mnState.IsValid() && mnState.HasCovariance()) {
2520 ROOT::Minuit2::MnGlobalCorrelationCoeff corr = mnState.GlobalCC();
2521 ROOT::Minuit2::MnUserCovariance cov = mnState.Covariance();
2523 fout << std::endl <<
" No Global ";
2524 for (UInt_t i=0; i<
fParams.size(); i++) {
2527 fout.setf(std::ios::left, std::ios::adjustfield);
2534 if (parNo.size() != cov.Nrow()) {
2535 std::cerr << std::endl <<
"**SEVERE ERROR** in PFitter::ExecuteSave(): minuit2 and musrfit book keeping to not correspond! Unable to write correlation matrix.";
2536 std::cerr << std::endl;
2538 TString title(
"Minuit2 Output Correlation Matrix for ");
2541 title += dt.AsSQLString();
2542 std::unique_ptr<TCanvas> ccorr = std::make_unique<TCanvas>(
"ccorr",
"title", 500, 500);
2543 std::unique_ptr<TH2D> hcorr = std::make_unique<TH2D>(
"hcorr", title, cov.Nrow(), 0.0, cov.Nrow(), cov.Nrow(), 0.0, cov.Nrow());
2545 for (UInt_t i=0; i<cov.Nrow(); i++) {
2547 fout << std::endl <<
" ";
2548 fout.setf(std::ios::left, std::ios::adjustfield);
2552 fout.setf(std::ios::left, std::ios::adjustfield);
2555 fout << corr.GlobalCC()[i];
2557 for (UInt_t j=0; j<cov.Nrow(); j++) {
2558 fout.setf(std::ios::left, std::ios::adjustfield);
2563 hcorr->Fill((Double_t)i,(Double_t)i,1.0);
2567 std::cerr << std::endl <<
"**SEVERE ERROR** in PFitter::ExecuteSave(): parameter no " << parNo[i]+1 <<
" has an error == 0. Cannot correctly handle the correlation matrix.";
2568 std::cerr << std::endl;
2571 std::cerr << std::endl <<
"**SEVERE ERROR** in PFitter::ExecuteSave(): parameter no " << parNo[j]+1 <<
" has an error == 0. Cannot correctly handle the correlation matrix.";
2572 std::cerr << std::endl;
2577 hcorr->Fill((Double_t)i,(Double_t)j,dval);
2579 if (dval < 1.0e-2) {
2591 fout << dval <<
" ";
2596 TFile ff(
"MINUIT2.root",
"recreate");
2598 if (cov.Nrow() <= 6)
2599 hcorr->Draw(
"COLZTEXT");
2601 hcorr->Draw(
"COLZ");
2602 ccorr->Write(
"ccorr", TObject::kOverwrite,
sizeof(ccorr));
2603 hcorr->Write(
"hcorr", TObject::kOverwrite,
sizeof(hcorr));
2613 std::string yaml_filename(
fRunInfo->GetFileName().Data());
2614 const std::string msr_ext(
".msr");
2615 yaml_filename.replace(yaml_filename.find(msr_ext), msr_ext.length(),
2619 const std::string yaml_indent(
" ");
2622 std::ofstream yaml_file(yaml_filename);
2625 yaml_file << std::scientific << std::setprecision(16);
2628 yaml_file <<
"values:\n";
2629 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2630 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
": "
2635 yaml_file <<
"errors:\n";
2636 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2637 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
": "
2642 yaml_file <<
"mnerrors:\n";
2643 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2646 boost::variant<double, std::string> positive_error, negative_error;
2647 if (
fParams[i].fPosErrorPresent) {
2648 positive_error =
fParams[i].fPosError;
2649 negative_error =
fParams[i].fStep;
2651 positive_error =
"null";
2652 negative_error =
"null";
2655 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
":\n";
2656 yaml_file << yaml_indent << yaml_indent
2657 <<
"positive: " << positive_error <<
"\n";
2658 yaml_file << yaml_indent << yaml_indent
2659 <<
"negative: " << negative_error <<
"\n";
2663 yaml_file <<
"limits:\n";
2664 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2667 boost::variant<double, std::string> upper_limit, lower_limit;
2668 if (
fParams[i].fLowerBoundaryPresent) {
2669 lower_limit =
fParams[i].fLowerBoundary;
2671 lower_limit =
"null";
2673 if (
fParams[i].fUpperBoundaryPresent) {
2674 upper_limit =
fParams[i].fUpperBoundary;
2676 upper_limit =
"null";
2679 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
":\n";
2680 yaml_file << yaml_indent << yaml_indent <<
"lower: " << lower_limit
2682 yaml_file << yaml_indent << yaml_indent <<
"upper: " << upper_limit
2687 yaml_file <<
"fixed:\n";
2688 for (
unsigned int i = 0; i <
fParams.size(); ++i) {
2689 std::string is_fixed =
fParams[i].fStep == 0.0 ?
"true" :
"false";
2690 yaml_file << yaml_indent <<
fParams[i].fName.Data() <<
": " << is_fixed
2695 yaml_file <<
"covariance:\n";
2696 for (
unsigned int i = 0; i < cov.Nrow(); ++i) {
2697 yaml_file << yaml_indent << mnState.Name(parNo[i]) <<
":\n";
2698 for (
unsigned int j = 0; j < cov.Nrow(); ++j) {
2699 yaml_file << yaml_indent << yaml_indent << mnState.Name(parNo[j])
2700 <<
": " << cov(i, j) <<
"\n";
2705 yaml_file <<
"correlation:\n";
2706 for (
unsigned int i = 0; i < cov.Nrow(); ++i) {
2707 yaml_file << yaml_indent << mnState.Name(parNo[i]) <<
":\n";
2708 for (
unsigned int j = 0; j < cov.Nrow(); ++j) {
2709 double correlation =
2713 yaml_file << yaml_indent << yaml_indent << mnState.Name(parNo[j])
2714 <<
": " << correlation <<
"\n";
2724 fout << std::endl <<
" no correlation coefficients available";
2728 fout << std::endl <<
"*************************************************************************";
2729 fout << std::endl <<
" chisq/maxLH RESULT ";
2730 fout << std::endl <<
"*************************************************************************";
2741 fitStartTime = run->at(0).GetFitRange(0);
2742 fitEndTime = run->at(0).GetFitRange(1);
2744 fout.setf(std::ios::fixed, std::ios::floatfield);
2745 fout << std::endl <<
" Time Range: " << fitStartTime <<
", " << fitEndTime << std::endl;
2747 fout.setf(std::ios::fixed, std::ios::floatfield);
2748 fout << std::endl <<
" chisq = " << std::setprecision(4) << statistics->
fMin <<
", NDF = " << statistics->
fNdf <<
", chisq/NDF = " << std::setprecision(6) << statistics->
fMin/statistics->
fNdf;
2750 fout << std::endl <<
" chisq_e = " << std::setprecision(4) << statistics->
fMinExpected <<
", NDF = " << statistics->
fNdf <<
", chisq_e/NDF = " << std::setprecision(6) << statistics->
fMinExpected/statistics->
fNdf;
2752 fout.setf(std::ios::fixed, std::ios::floatfield);
2753 fout << std::endl <<
" maxLH = " << std::setprecision(4) << statistics->
fMin <<
", NDF = " << statistics->
fNdf <<
", maxLH/NDF = " << std::setprecision(6) << statistics->
fMin/statistics->
fNdf;
2755 fout << std::endl <<
" maxLH_e = " << std::setprecision(4) << statistics->
fMinExpected <<
", NDF = " << statistics->
fNdf <<
", maxLH_e/NDF = " << std::setprecision(6) << statistics->
fMinExpected/statistics->
fNdf;
2762 fout << std::endl <<
"*************************************************************************";
2763 fout << std::endl <<
" DONE ";
2764 fout << std::endl <<
"*************************************************************************";
2765 fout << std::endl << std::endl;
2863 Int_t usedParams = 0;
2864 for (UInt_t i=0; i<error.size(); i++) {
2865 if (error[i] != 0.0)
2870 secFitRange.resize(1);
2873 Double_t totalExpectedChisq = 0.0;
2876 for (UInt_t k=0; k<
fSector.size(); k++) {
2878 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
2879 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
2882 val = (*fFitterFcn)(param);
2885 ndf =
static_cast<UInt_t
>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
2888 totalExpectedChisq = 0.0;
2889 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedChisq, expectedChisqPerRun);
2890 fSector[k].SetExpectedChisq(totalExpectedChisq);
2892 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
2894 fSector[k].SetChisq(chisqPerRun[i], i);
2895 fSector[k].SetExpectedChisq(expectedChisqPerRun[i], i);
2898 if (totalExpectedChisq != 0.0) {
2900 for (UInt_t i=0; i<expectedChisqPerRun.size(); i++) {
2903 fSector[k].SetNDF(ndf_run, i);
2906 }
else if (chisqPerRun.size() > 0) {
2908 for (UInt_t i=0; i<chisqPerRun.size(); i++) {
2911 fSector[k].SetNDF(ndf_run, i);
2916 chisqPerRun.clear();
2917 expectedChisqPerRun.clear();
2920 Double_t totalExpectedMaxLH = 0.0;
2923 for (UInt_t k=0; k<
fSector.size(); k++) {
2925 secFitRange[0].first =
fSector[k].GetTimeRangeFirst(0);
2926 secFitRange[0].second =
fSector[k].GetTimeRangeLast();
2929 val = (*fFitterFcn)(param);
2932 ndf =
static_cast<UInt_t
>(
fFitterFcn->GetTotalNoOfFittedBins()) - usedParams;
2935 totalExpectedMaxLH = 0.0;
2936 fFitterFcn->CalcExpectedChiSquare(param, totalExpectedMaxLH, expectedMaxLHPerRun);
2937 fSector[k].SetExpectedChisq(totalExpectedMaxLH);
2939 for (UInt_t i=0; i<
fRunInfo->GetMsrRunList()->size(); i++) {
2941 fSector[k].SetChisq(maxLHPerRun[i], i);
2942 fSector[k].SetExpectedChisq(expectedMaxLHPerRun[i], i);
2945 if (totalExpectedMaxLH != 0.0) {
2947 for (UInt_t i=0; i<expectedMaxLHPerRun.size(); i++) {
2950 fSector[k].SetNDF(ndf_run, i);
2956 maxLHPerRun.clear();
2957 expectedMaxLHPerRun.clear();