1189 int iMarkerStyle = 20;
1190 gStyle->SetFrameBorderMode(0);
1191 gStyle->SetFrameFillColor(0);
1192 gStyle->SetCanvasBorderMode(0);
1193 gStyle->SetPadBorderMode(0);
1194 gStyle->SetPadColor(0);
1195 gStyle->SetCanvasColor(0);
1196 gStyle->SetTitleColor(0);
1197 gStyle->SetStatColor(0);
1198 gStyle->SetFillColor(1);
1199 gStyle->SetPalette(1, 0);
1200 gStyle->SetTitleFontSize(0.06);
1201 gStyle->SetTitleH(0.06);
1202 gStyle->SetMarkerStyle(iMarkerStyle);
1203 gStyle->SetOptStat(111100);
1204 gStyle->SetStatBorderSize(0);
1205 gStyle->SetStatX(0.99);
1206 gStyle->SetStatY(0.99);
1207 gStyle->SetStatW(0.2);
1208 gStyle->SetStatH(0.1);
1214 TImage* img =
nullptr;
1218 std::string pathname(groupDir->GetPath());
1220 bool WasCollectionReference =
false;
1222 bool LookForDisplay;
1223 if (file_version == 1) {
1224 LookForDisplay =
containsDir(
"Config/annotations/display", (pathname +
"/" + nameHis +
"_"));
1225 if (LookForDisplay) {
1226 display =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/display", file_version);
1228 }
else if (file_version == 2) {
1229 std::optional<std::string> JSON_content;
1230 LookForDisplay =
containsDir((nameHis +
"_"), pathname);
1231 if (LookForDisplay) {
1232 JSON_content =
containsKeyInJSON(
"/annotations/display",
"Config", (pathname +
"/" + nameHis +
"_"));
1234 LookForDisplay =
true;
1236 LookForDisplay =
false;
1239 if (LookForDisplay) {
1240 display = JSON_content.value();
1244 bool PlotOverflows = (
display.find(
"PlotUnderOverflow") != std::string::npos);
1247 std::string drawopt =
"";
1248 while (
found != std::string::npos) {
1249 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1250 if (found1 != std::string::npos) {
1251 drawopt += boost::algorithm::to_lower_copy(
display.substr(
found + 5, found1 -
found - 5));
1259 std::string drawrefopt =
"";
1260 while (
found != std::string::npos) {
1261 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1262 if (found1 != std::string::npos) {
1263 drawrefopt += boost::algorithm::to_lower_copy(
display.substr(
found + 8, found1 -
found - 8));
1269 if (drawrefopt ==
"") {
1270 drawrefopt = drawopt;
1274 std::string drawrefopt2D =
"";
1275 while (
found != std::string::npos) {
1276 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1277 if (found1 != std::string::npos) {
1278 drawrefopt2D += boost::algorithm::to_lower_copy(
display.substr(
found + 10, found1 -
found - 10));
1280 drawrefopt2D += boost::algorithm::to_lower_copy(
display.substr(
found + 10,
display.size()));
1287 std::string datatitle;
1288 if (
found == std::string::npos) {
1291 while (
found != std::string::npos) {
1292 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1293 if (found1 != std::string::npos) {
1301 TKey* hkey = groupDir->FindKey(nameHis.c_str());
1303 std::cerr <<
"Did not find TKey for \"" << nameHis <<
"\", will not save this histogram.\n";
1304 return std::pair<std::string, std::string>{
1309 TObject* hobj = hkey->ReadObj();
1312 TEfficiency* eRef(0);
1314 std::vector<TH1*> hRefs;
1315 std::vector<TEfficiency*> eRefs;
1316 bool hasPlotted(
false);
1317 TH1*
h =
dynamic_cast<TH1*
>(hobj);
1318 TH2* h2 =
dynamic_cast<TH2*
>(
h);
1319 TGraph*
g =
dynamic_cast<TGraph*
>(hobj);
1320 TEfficiency*
e =
dynamic_cast<TEfficiency*
>(hobj);
1322 std::string
name = nameHis;
1329 std::string AlgoName(
"");
1330 AlgoName =
getStringName(pathname +
"/" + nameHis +
"_/Config/name", file_version);
1334 if (
found != std::string::npos) {
1335 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1341 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
1349 gPad->SetGridx(
display.find(
"SetGridx") != std::string::npos);
1350 gPad->SetGridy(
display.find(
"SetGridy") != std::string::npos);
1352 if (
found != std::string::npos) {
1353 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
1354 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
1355 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
1356 int n1 = std::strtol(cn.c_str(), NULL, 0);
1357 gStyle->SetPalette((Int_t)
n1);
1360 if (
found != std::string::npos) {
1361 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
1362 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
1363 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
1364 int n1 = std::strtol(cn.c_str(), NULL, 0);
1365 gStyle->SetGridStyle((Style_t)
n1);
1370 if (
found != std::string::npos) {
1371 Double_t minstat = 0.;
1372 std::size_t fpos1, fpos2, fpos;
1373 fpos =
display.find(
"MinStat");
1374 if (fpos != std::string::npos) {
1375 fpos1 =
display.find(
'(', fpos + 1);
1376 if (fpos1 != std::string::npos) {
1377 fpos2 =
display.find(
')', fpos1 + 1);
1378 if (fpos2 != std::string::npos) {
1379 std::string s_minstat =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
1380 minstat = std::strtod(s_minstat.c_str(), NULL);
1384 std::string fitopt(
"");
1385 fpos =
display.find(
"FitOption");
1386 if (fpos != std::string::npos) {
1387 fpos1 =
display.find(
'(', fpos + 1);
1388 if (fpos1 != std::string::npos) {
1389 fpos2 =
display.find(
')', fpos1 + 1);
1390 if (fpos2 != std::string::npos) {
1391 fitopt =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
1396 std::size_t found1 =
display.find(
"doublegaus");
1397 if (found1 != std::string::npos) {
1398 std::size_t found2 =
display.find(
'(', found1 + 1);
1399 if (found2 != std::string::npos) {
1400 std::size_t found3 =
display.find(
')', found2 + 1);
1401 if (found3 != std::string::npos) {
1402 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1403 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1404 std::size_t found4 =
display.find(
',', found2 + 1);
1405 if (found4 != std::string::npos) {
1406 range =
display.substr(found4 + 1, found3 - found4 - 1);
1407 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1411 f1->GetParameters(
par);
1412 TF1* func =
new TF1(
"func",
"gaus(0)+gaus(3)",
xmin,
xmax);
1413 func->SetParameters(
par);
1414 func->SetParameter(3,
h->GetBinContent(
h->GetMaximumBin()));
1415 func->SetParameter(4,
h->GetMean());
1416 func->SetParameter(5,
par[2]);
1417 func->SetLineColor(kRed);
1418 func->SetLineWidth(2);
1419 if (
h->GetEffectiveEntries() > minstat) {
1420 h->Fit(func, (
"rq" + fitopt).c_str());
1429 std::size_t found1 =
display.find(
"gauspluspol1");
1430 if (found1 != std::string::npos) {
1431 std::size_t found2 =
display.find(
'(', found1 + 1);
1432 if (found2 != std::string::npos) {
1433 std::size_t found3 =
display.find(
')', found2 + 1);
1434 if (found3 != std::string::npos) {
1435 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1436 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1437 std::size_t found4 =
display.find(
',', found2 + 1);
1438 if (found4 != std::string::npos) {
1439 range =
display.substr(found4 + 1, found3 - found4 - 1);
1440 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1441 TF1* func =
new TF1(
"func",
"gaus(0)+pol1(3)",
xmin,
xmax);
1442 func->SetLineColor(kRed);
1443 func->SetLineWidth(2);
1444 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
1445 if (
h->GetEffectiveEntries() > minstat) {
1446 h->Fit(func, (
"rq" + fitopt).c_str());
1454 found1 =
display.find(
"gausplusexpo");
1455 if (found1 != std::string::npos) {
1456 std::size_t found2 =
display.find(
'(', found1 + 1);
1457 if (found2 != std::string::npos) {
1458 std::size_t found3 =
display.find(
')', found2 + 1);
1459 if (found3 != std::string::npos) {
1460 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1461 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1462 std::size_t found4 =
display.find(
',', found2 + 1);
1463 if (found4 != std::string::npos) {
1464 range =
display.substr(found4 + 1, found3 - found4 - 1);
1465 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1467 TF1* func =
new TF1(
"func",
"gaus(0)+expo(3)",
xmin,
xmax);
1468 func->SetLineColor(kRed);
1469 func->SetLineWidth(2);
1470 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
1471 if (
h->GetEffectiveEntries() > minstat) {
1472 h->Fit(func, (
"rq" + fitopt).c_str());
1481 if (found2 != std::string::npos) {
1482 std::size_t found3 =
display.find(
')', found2 + 1);
1483 if (found3 != std::string::npos) {
1484 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1485 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1486 std::size_t found4 =
display.find(
',', found2 + 1);
1487 if (found4 != std::string::npos) {
1488 range =
display.substr(found4 + 1, found3 - found4 - 1);
1489 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1490 TF1* func =
new TF1(
"func",
"gaus",
xmin,
xmax);
1491 func->SetLineColor(kRed);
1492 func->SetLineWidth(2);
1493 if (
h->GetEffectiveEntries() > minstat) {
1494 h->Fit(func, (
"rq" + fitopt).c_str());
1507 if (h2->GetMinimum() >= 0 && h2->GetMaximum() > 0.) {
1508 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1509 gPad->SetLogz(
display.find(
"LogZ") != std::string::npos);
1512 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1514 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax()) {
1515 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
1516 <<
"Inconsistent x-axis settings: min=" <<
h->GetXaxis()->GetXmin() <<
", "
1517 <<
"max=" <<
h->GetXaxis()->GetXmax() <<
", "
1518 <<
"Will not save this histogram.\n";
1519 return std::pair<std::string, std::string>{
1523 if (
h->GetYaxis()->GetXmin() >=
h->GetYaxis()->GetXmax()) {
1524 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
1525 <<
"Inconsistent y-axis settings: min=" <<
h->GetYaxis()->GetXmin() <<
", "
1526 <<
"max=" <<
h->GetYaxis()->GetXmax() <<
", "
1527 <<
"Will not save this histogram.\n";
1528 return std::pair<std::string, std::string>{
1533 if (drawopt ==
"") {
1537 if (file_version == 1) {
1538 groupDir->cd((nameHis +
"_/Results").c_str());
1540 }
else if (file_version == 2) {
1541 if (groupDir->GetDirectory((nameHis +
"_").c_str()) != 0) {
1542 groupDir->cd((nameHis +
"_").c_str());
1546 h2Ref =
dynamic_cast<TH2*
>(
ref);
1547 TCollection* colln =
dynamic_cast<TCollection*
>(
ref);
1549 h2Ref =
dynamic_cast<TH2*
>(colln->MakeIterator()->Next());
1551 if (h2Ref && (drawrefopt2D !=
"")) {
1553 h2Ref->Draw(drawrefopt2D.c_str());
1556 h2->Draw((
"SAME" + drawopt).c_str());
1558 if (drawopt.find(
"lego") == std::string::npos) {
1566 t.SetTextSize(0.03);
1567 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1570 tt.SetTextSize(0.03);
1573 }
else if (
h != 0) {
1575 if (
display.find(
"StatBox") != std::string::npos) {
1578 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax()) {
1579 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
1580 <<
"Inconsistent x-axis settings: min=" <<
h->GetXaxis()->GetXmin() <<
", "
1581 <<
"max=" <<
h->GetXaxis()->GetXmax() <<
", "
1582 <<
"Will not save this histogram.\n";
1583 return std::pair<std::string, std::string>{
1587 h->SetLineColor(kBlack);
1588 h->SetMarkerColor(1);
1595 if (file_version == 1) {
1596 groupDir->cd((nameHis +
"_/Results").c_str());
1598 }
else if (file_version == 2) {
1599 if (groupDir->GetDirectory((nameHis +
"_").c_str()) != 0) {
1600 groupDir->cd((nameHis +
"_").c_str());
1604 hRef =
dynamic_cast<TH1*
>(
ref);
1606 hRefs.push_back(hRef);
1608 TCollection* colln =
dynamic_cast<TCollection*
>(
ref);
1610 WasCollectionReference =
true;
1611 std::unique_ptr<TIterator> icolln(colln->MakeIterator());
1613 while ((ref2 = icolln->Next())) {
1614 hRef =
dynamic_cast<TH1*
>(ref2);
1616 if (hRef->GetDimension() ==
h->GetDimension()) {
1617 hRefs.push_back(hRef);
1619 }
else std::cout <<
"hRef cast failed!!!" << std::endl;
1626 if (hRefs.size() > 0) {
1627 legend =
new TLegend(0.55, 0.77, 0.87, 0.87);
1631 legend->SetBorderSize(0);
1632 legend->AddEntry(
h, datatitle.c_str());
1634 for (
auto hRef : hRefs) {
1640 hRef->SetMarkerColor(local_color);
1643 hRef->SetLineColor(local_color);
1644 hRef->SetLineWidth(2);
1645 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
1646 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
1648 if (PlotOverflows) {
1663 bool isLogY = (
display.find(
"LogY") != std::string::npos);
1669 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
1672 std::cerr <<
"ymin is <0. and LogY requested for histogram \"" << pathname +
"/" + nameHis
1673 <<
"\", ymin=" <<
ymin << std::endl;
1676 double yMargin = (
ymax -
ymin) * 0.05;
1677 h->SetAxisRange(
ymin - yMargin,
ymax + yMargin,
"Y");
1679 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
1680 hRef->GetXaxis()->SetRangeUser(
xmin,
xmax);
1682 if (
h->GetMinimum() >= 0. && hRef->GetMinimum() >= 0. &&
h->GetMaximum() > 0. &&
1683 hRef->GetMaximum() > 0.) {
1684 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1687 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1690 h->Draw(drawopt.c_str());
1693 hRef->Draw((
"SAME" + drawrefopt).c_str());
1696 if (
display.find(
"ScaleRef") != std::string::npos) {
1698 }
else if (
h->Integral(
"width") > 0.0 && hRef->Integral(
"width") > 0.0 &&
1699 (AlgoName.find(
"BinContentComp") == std::string::npos) &&
1700 (
display.find(
"NoNorm") == std::string::npos)) {
1701 scale =
h->Integral(
"width") / hRef->Integral(
"width");
1706 hRef->SetMarkerColor(local_color);
1708 hRef->SetLineColor(local_color);
1709 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
1710 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
1712 if (PlotOverflows) {
1729 bool isLogY = (
display.find(
"LogY") != std::string::npos);
1737 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
"Y");
1740 std::cerr <<
"ymin is <=0. and LogY requested for histogram \"" << pathname +
"/" + nameHis
1741 <<
"\", ymin=" <<
ymin << std::endl;
1745 h->SetAxisRange(
ymin - yDiff * 0.05,
ymax + yDiff * 0.05,
"Y");
1748 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
1749 hRef->GetXaxis()->SetRangeUser(
xmin,
xmax);
1751 if (
h->GetMinimum() >= 0 && hRef->GetMinimum() >= 0 &&
h->GetMaximum() > 0. && hRef->GetMaximum() > 0.) {
1752 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1755 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1759 h->Draw(drawopt.c_str());
1762 hRef->Draw((
"SAME" + drawrefopt).c_str());
1764 if (WasCollectionReference) {
1765 legend->AddEntry(hRef, hRef->GetName());
1767 std::string refInfo(
"");
1768 refInfo =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/refInfo", file_version);
1769 legend->AddEntry(hRef, refInfo !=
"Undefined" ? refInfo.c_str() :
"Reference");
1772 h->Draw((
"SAME" + drawopt).c_str());
1776 if (
h->GetMinimum() >= 0) {
1777 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1780 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1783 h->Draw(drawopt.c_str());
1797 t.SetTextSize(0.03);
1798 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1801 tt.SetTextSize(0.03);
1810 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
1812 if (
g->GetMinimum() >= 0. &&
g->GetMaximum() > 0.) {
1813 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1821 g->Draw((std::string(
"AP") + drawopt).c_str());
1825 t.SetTextSize(0.03);
1826 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1829 tt.SetTextSize(0.03);
1839 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
1841 if (drawopt ==
"") {
1842 if (
e->GetDimension() == 1) {
1849 if (file_version == 1) {
1850 groupDir->cd((nameHis +
"_/Results").c_str());
1852 }
else if (file_version == 2) {
1853 if (groupDir->cd((nameHis +
"_").c_str())) {
1857 eRef =
dynamic_cast<TEfficiency*
>(
ref);
1859 eRefs.push_back(eRef);
1861 TCollection* colln =
dynamic_cast<TCollection*
>(
ref);
1863 WasCollectionReference =
true;
1864 TIterator* icolln = colln->MakeIterator();
1866 while ((ref2 = icolln->Next())) {
1867 eRef =
dynamic_cast<TEfficiency*
>(ref2);
1869 if (eRef->GetDimension() ==
e->GetDimension()) {
1870 eRefs.push_back(eRef);
1872 }
else std::cout <<
"eRef cast failed!!!" << std::endl;
1878 if (eRefs.size() > 0) {
1879 legend =
new TLegend(0.55, 0.77, 0.87, 0.87);
1883 legend->SetBorderSize(0);
1884 legend->AddEntry(
e, datatitle.c_str());
1886 for (
auto eRef : eRefs) {
1896 eRef->SetMarkerColor(local_color);
1897 eRef->SetLineColor(local_color);
1900 e->Draw(drawopt.c_str());
1906 if (WasCollectionReference) {
1907 legend->AddEntry(eRef, eRef->GetName());
1909 std::string refInfo(
"");
1910 refInfo =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/refInfo", file_version);
1911 legend->AddEntry(eRef, refInfo !=
"Undefined" ? refInfo.c_str() :
"Reference");
1917 e->Draw(drawopt.c_str());
1922 e->GetPaintedGraph()->GetXaxis()->SetTitleColor();
1928 t.SetTextSize(0.03);
1929 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1932 tt.SetTextSize(0.03);
1939 if (
x)
rv.assign(
x,
y);
1942 std::pair<std::string, std::string> rvPair {