11 #include <TBufferJSON.h>
13 #include <TDirectory.h>
14 #include <TEfficiency.h>
18 #include <TGraphAsymmErrors.h>
23 #include <TIterator.h>
34 #include <TImageDump.h>
47 #include "TPluginManager.h"
49 #define BINLOEDGE(h, n) h->GetXaxis()->GetBinLowEdge(n)
50 #define BINWIDTH(h, n) h->GetXaxis()->GetBinWidth(n)
64 Double_t getScaleVal(std::string&
display) {
66 std::size_t found2 =
display.find_first_of(
',',
found + 1);
69 double resultVal = 0.0;
70 auto [
ptr, ec] = std::from_chars(valueStr.data(), valueStr.data() + valueStr.size(), resultVal);
71 if (ec != std::errc()) {
72 std::cerr <<
"Unable to cast scaling value " << valueStr <<
" to double" << std::endl;
86 kBlue, kRed, kGray, kOrange, kViolet, kGreen + 1
92 if ((
h = gROOT->GetPluginManager()->FindHandler(
"TVirtualPS",
"image"))) {
93 if (
h->LoadPlugin() == -1)
return;
103 if ((
h = gROOT->GetPluginManager()->FindHandler(
"TVirtualPS",
"image"))) {
104 if (
h->LoadPlugin() == -1)
return;
120 if (
dir == 0)
return;
123 std::string
name(
dir->GetName());
124 if (
name ==
"Config" ||
name ==
"Results") {
129 std::string::size_type
i =
name.find_last_of(
'_');
130 if (
i == (
name.size() - 1)) {
136 dirmap.insert(std::move(dirmapVal));
138 DirMap_t::value_type dirmapVal(
"<top_level>",
dir);
139 dirmap.insert(std::move(dirmapVal));
144 TIter
next(
dir->GetListOfKeys());
146 while ((
key =
dynamic_cast<TKey*
>(
next())) != 0) {
148 TObject*
obj =
key->ReadObj();
149 TDirectory*
subdir =
dynamic_cast<TDirectory*
>(
obj);
151 std::string subdirName(
subdir->GetName());
152 std::string
fName(
"");
166 if (
obj ==
nullptr)
return;
169 TString obj_type =
obj->ClassName();
172 if (obj_type ==
"TDirectoryFile" || obj_type ==
"TDirectory" || obj_type ==
"TFile") {
173 dir =
static_cast<TDirectory*
> (
obj);
174 std::string
name(
dir->GetName());
175 if (
name ==
"Config" ||
name ==
"Results") {
180 std::string::size_type
i =
name.find_last_of(
'_');
181 if (
i == (
name.size() - 1)) {
185 DirStrMap_t::value_type dirstrmapVal(objName,
obj);
186 dirstrmap.insert(std::move(dirstrmapVal));
188 DirStrMap_t::value_type dirstrmapVal(objName,
obj);
189 dirstrmap.insert(std::move(dirstrmapVal));
192 DirStrMap_t::value_type dirstrmapVal(
"<top_level>",
obj);
193 dirstrmap.insert(std::move(dirstrmapVal));
196 if (obj_type ==
"TDirectoryFile" || obj_type ==
"TDirectory" || obj_type ==
"TFile") {
197 dir =
static_cast<TDirectory*
> (
obj);
199 TIter
next(
dir->GetListOfKeys());
201 while ((
key =
dynamic_cast<TKey*
>(
next())) != 0) {
203 std::string
fName(
"");
204 TObject* obj_in_dir =
key->ReadObj();
205 TString obj_in_dir_type = obj_in_dir->ClassName();
207 if (obj_in_dir_type ==
"TDirectoryFile" || obj_in_dir_type ==
"TDirectory" || obj_in_dir_type ==
"TFile" ||
208 obj_in_dir_type ==
"TObjString") {
209 std::string obj_in_dirName;
210 obj_in_dirName =
key->GetName();
216 fName += obj_in_dirName;
217 if (obj_in_dirName !=
"Config" && obj_in_dirName !=
"Results" && obj_in_dirName !=
"Version_name") {
234 std::string::size_type
i =
235 obj_in_dirName.find_last_of(
'_');
236 if (
i != (obj_in_dirName.size() - 1)) {
252 TIter
next(
dir->GetListOfKeys());
254 while ((
key =
dynamic_cast<TKey*
>(
next())) != 0) {
255 TObject*
obj =
key->ReadObj();
256 if (
dynamic_cast<TH1*
>(
obj) ||
dynamic_cast<TGraph*
>(
obj) ||
dynamic_cast<TEfficiency*
>(
obj)) {
257 const char*
path(
dir->GetPath());
258 std::string assName(
obj->GetName());
259 AssMap_t::value_type AssmapVal(assName,
path);
260 dirmap.insert(std::move(AssmapVal));
269 for (nlohmann::json::const_iterator
it = j.begin();
it != j.end(); ++
it) {
270 std::string sName = location;
271 std::string keyname =
it.key();
272 if (keyname !=
"Config" && keyname !=
"Results") {
274 std::string::size_type
i = keyname.find_last_of(
'_');
275 if (
i != (keyname.size() - 1)) {
276 if (location !=
"") {
280 std::cout <<
"name: " << sName <<
", path: " << path_to_file << sName <<
"\n";
281 valuestring =
it.value();
290 std::string stringName(
"Undefined");
291 if (file_version == 1) {
294 if (gROOT->cd(location.c_str()) == 0) {
300 while ((
key =
dynamic_cast<TKey*
>(mylist.Next())) != 0) {
301 TObject*
obj =
key->ReadObj();
302 stringName = (
obj->GetName());
306 }
else if (file_version == 2) {
309 std::size_t split_point = 0;
310 std::string JSON_name(
"");
311 std::string path_inTDir(
"");
312 std::string path_inJSON(
"");
313 if ((split_point = location.find(
"/Results/")) != std::string::npos) {
314 JSON_name =
"Results";
315 path_inTDir = location.substr(0, split_point);
316 path_inJSON = location.substr(split_point + 8);
317 }
else if ((split_point = location.find(
"/Config/")) != std::string::npos) {
318 JSON_name =
"Config";
319 path_inTDir = location.substr(0, split_point);
320 path_inJSON = location.substr(split_point + 7);
323 if (gROOT->cd(path_inTDir.c_str()) == 0) {
327 TObjString* JSON_obj =
dynamic_cast<TObjString*
>(
gDirectory->GetKey(JSON_name.c_str())->ReadObj());
329 std::cerr <<
"HanOutputFile::getStringName : dynamic cast failed\n";
332 std::string JSON_str = (JSON_obj->GetName());
334 nlohmann::json::json_pointer JSON_ptr(path_inJSON);
338 auto val = j.at(JSON_ptr);
339 if (!(
val.is_null())) stringName =
val.get<std::string>();
364 TDirectory* dirobj(0);
367 dirobj =
dynamic_cast<TDirectory*
>(
obj);
370 if (
found != std::string::npos) {
383 const std::string& pathInJSON,
const std::string& jsonName,
const std::string& path_to_JSON) {
384 gROOT->cd(path_to_JSON.c_str());
394 if (pathInJSON ==
"") {
396 return "JSON exists";
398 if (pathInJSON ==
"/") {
403 nlohmann::ordered_json::json_pointer
p1(pathInJSON);
404 std::string return_string;
408 if (
val1.type() == nlohmann::json::value_t::string) {
409 val1.get_to(return_string);
411 return_string =
val1.dump();
413 std::cout <<
"Warning: Strange part of JSON" << std::endl;
426 return return_string;
431 std::cerr <<
"HanOutputFile::getNEntries(): "
432 <<
"No input file is open\n";
436 double Nentries = 0.0;
437 m_file->cd(location.c_str());
442 Nentries =
h->GetEntries();
448 Nentries =
g->GetN();
454 Nentries =
e->GetCopyTotalHisto()->GetEntries();
462 if (
const TH1*
h =
dynamic_cast<const TH1*
>(
obj)) {
463 return h->GetEntries();
464 }
else if (
const TGraph*
g =
dynamic_cast<const TGraph*
>(
obj)) {
466 }
else if (
const TEfficiency*
e =
dynamic_cast<const TEfficiency*
>(
obj)) {
467 return e->GetCopyTotalHisto()->GetEntries();
469 std::cerr <<
"HanOutputFile::getNEntries(): "
470 <<
"provided object is not a histogram or graph\n";
477 std::string
value(
"");
478 if (file_version == 1) {
479 gROOT->cd(location.c_str());
482 while ((
key =
dynamic_cast<TKey*
>(mylist.Next())) != 0) {
483 TObject*
obj =
key->ReadObj();
484 TDirectory*
subdir =
dynamic_cast<TDirectory*
>(
obj);
486 std::string name_subdir =
subdir->GetName();
487 gROOT->cd((location +
"/" + name_subdir).c_str());
490 while ((
key1 =
dynamic_cast<TKey*
>(mylist1.Next())) != 0) {
491 TObject* obj1 =
key1->ReadObj();
492 TDirectory* subsubdir =
dynamic_cast<TDirectory*
>(obj1);
493 if (subsubdir != 0) {
494 std::string name_subsubdir = obj1->GetName();
495 gROOT->cd((location +
"/" + name_subdir +
"/" + name_subsubdir).c_str());
498 while ((
key2 =
dynamic_cast<TKey*
>(mylist2.Next())) != 0) {
500 TDirectory* finaldir =
dynamic_cast<TDirectory*
>(
obj2);
502 std::string name_finaldir =
obj2->GetName();
503 gROOT->cd((location +
"/" + name_subdir +
"/" + name_subsubdir +
"/" + name_finaldir).c_str());
506 while ((key3 =
dynamic_cast<TKey*
>(mylist3.Next())) != 0) {
507 TObject* obj3 = key3->ReadObj();
508 std::string value_info = obj3->GetName();
509 value += (name_subsubdir + name_finaldir +
": " + value_info +
" ");
512 gROOT->cd((location +
"/" + name_subdir +
"/" + name_subsubdir).c_str());
513 }
else if (name_subsubdir !=
"name" && name_subsubdir !=
"Status" && name_subsubdir !=
"display") {
515 std::string value_info =
obj2->GetName();
516 value += (name_subsubdir +
": " + value_info +
" ");
520 gROOT->cd((location +
"/" + name_subdir).c_str());
521 }
else if (name_subdir !=
"name" && name_subdir !=
"Status") {
522 std::string value_info = obj1->GetName();
523 value += (name_subdir +
": " + value_info +
" ");
527 gROOT->cd((location).c_str());
531 }
else if (file_version == 2) {
533 std::string JSON_name(
"");
534 std::string TDir_path(
"");
535 std::string path_inJSON(
"");
536 std::size_t split_point = 0;
537 if ((split_point = location.rfind(
"/Results")) != std::string::npos) {
538 JSON_name =
"Results";
539 TDir_path = location.substr(0, split_point);
540 path_inJSON = location.substr(split_point + 8);
541 }
else if ((split_point = location.rfind(
"/Config")) != std::string::npos) {
542 JSON_name =
"Config";
543 TDir_path = location.substr(0, split_point);
544 path_inJSON = location.substr(split_point + 7);
547 if (gROOT->cd(TDir_path.c_str()) == 0) {
551 std::unique_ptr<TObjString> JSON_obj(
dynamic_cast<TObjString*
>(
gDirectory->GetKey(JSON_name.c_str())->ReadObj()));
553 std::cerr <<
"HanOutputFile::getInfo : dynamic cast failed\n";
556 std::string JSON_str = (JSON_obj->GetName());
558 nlohmann::ordered_json json_in_j;
559 if (path_inJSON !=
"") {
560 nlohmann::ordered_json::json_pointer JSON_ptr(path_inJSON);
563 json_in_j = j.at(JSON_ptr);
568 std::cout <<
"Wrong path: " << location <<
"\n";
572 json_in_j = std::move(j);
581 std::string
value(
"");
588 std::string
value(
"");
589 for (nlohmann::ordered_json::const_iterator
it = j.begin();
it != j.end(); ++
it) {
590 const auto&
key =
it.key();
591 auto val =
it.value();
592 if (strcmp(
val.type_name(),
"object") == 0) {
593 for (nlohmann::ordered_json::const_iterator it1 =
val.begin(); it1 !=
val.end(); ++it1) {
594 const auto&
key1 = it1.key();
595 auto val1 = it1.value();
596 if (strcmp(
val1.type_name(),
"object") == 0) {
597 for (nlohmann::ordered_json::const_iterator it2 =
val1.begin(); it2 !=
val1.end(); ++it2) {
598 const auto&
key2 = it2.key();
599 auto val2 = it2.value();
603 }
else if (
key1 !=
"name" &&
key1 !=
"Status" &&
key1 !=
"display") {
608 }
else if (
key !=
"name" &&
key !=
"Status") {
613 (
key +
": " +
val.get<std::string>() +
" ");
621 std::string space = leadingSpace;
622 std::string::size_type
i =
pathName.find_first_of(
'/');
623 if (
i != std::string::npos) {
624 std::string subPath(
pathName,
i + 1, std::string::npos);
636 if (
m_file != 0)
return true;
643 std::cerr <<
"HanOutputFile::getFileVersion(): "
644 <<
"No input file is open\n";
648 m_file->cd(
"HanMetadata_");
655 while ((
key = (TKey*)
next())) {
656 TString key_name =
key->GetName();
657 if (key_name ==
"V.2.3") {
671 std::cerr <<
"HanOutputFile::printAllGroupDirs(): "
672 <<
"No input file is open\n";
676 if (file_version == 1) {
681 DirMap_t::const_iterator idirend =
m_indirMap.end();
682 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
683 std::string idirName = idir->first;
684 const char*
path(idir->second->GetPath());
685 std::cout <<
"name: " << idirName <<
", path: " <<
path <<
"\n";
687 }
else if (file_version == 2) {
691 const char* path_to_file =
m_file->GetPath();
693 for (DirStrMap_t::const_iterator idir =
m_indirstrMap.begin(); idir != idirend; ++idir) {
694 std::string idirName = idir->first;
695 TDirectory* dirobj =
dynamic_cast<TDirectory*
>(idir->second);
697 std::string pathname(dirobj->GetPath());
698 std::cout <<
"name: " << idirName <<
", path: " << pathname <<
"\n";
700 std::cout <<
"name: " << idirName <<
", path: " << path_to_file << idirName <<
"\n";
701 TObjString* strobj =
dynamic_cast<TObjString*
>(idir->second);
703 std::cerr <<
"HanOutputFile::printAllGroupDirs(): dynamic cast failed\n";
706 std::string
content = strobj->GetName();
722 std::cerr <<
"HanOutputFile::stringListSystemPaths(): "
723 <<
"No input file is open\n";
733 DirMap_t::const_iterator idirend =
m_indirMap.end();
734 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
735 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
738 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
739 aMapIter =
m_assessMap.insert(std::move(aMapVal)).first;
743 AssMap_t::const_iterator ias = aMapIter->second->begin();
744 if (ias != aMapIter->second->end()) {
745 std::string hisPath = ias->second;
746 std::string::size_type sepi = hisPath.find(
':');
747 if (sepi != std::string::npos) {
748 hisPath = std::string(hisPath, sepi + 1, std::string::npos);
750 std::string completeDir(location);
751 completeDir += hisPath;
760 std::ostringstream
result;
766 std::ostringstream
result;
772 std::ostringstream
result;
779 std::cerr <<
"HanOutputFile::streamAllDQAssessments(): "
780 <<
"No input file is open\n";
786 if ((file_version == 1) || (file_version == 2)) {
791 DirMap_t::const_iterator idirend =
m_indirMap.end();
792 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
793 std::string idirName = idir->first;
794 std::string pathname(idir->second->GetPath());
795 std::string::size_type
i = pathname.find_last_of(
'/');
796 if (
i != (pathname.size() - 1)) {
799 std::string pathnameS = pathname +
"Results/Status";
800 std::string pathnameA = pathname +
"Config/name";
801 std::string idirStatus =
getStringName(pathnameS, file_version);
802 std::string idirAlg =
getStringName(pathnameA, file_version);
805 std::string::size_type idirNamei = idirName.find_last_of(
'/');
806 if (idirNamei != std::string::npos) {
807 idirName = std::string(idirName, idirNamei + 1, std::string::npos);
810 std::string formattedName(
indent);
811 formattedName += idirName;
814 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
818 o << formattedName <<
" ";
820 o.setf(std::ios_base::right, std::ios_base::adjustfield);
822 o << idirStatus <<
" ";
832 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
835 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
836 aMapIter =
m_assessMap.insert(std::move(aMapVal)).first;
840 AssMap_t::const_iterator aend = aMapIter->second->end();
841 std::string info1(
"");
842 std::string info2(
"");
843 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
844 std::string hisName = ias->first;
845 std::string hisPath = ias->second;
846 std::string Path1 = hisPath +
"/" + hisName +
"_/Results";
847 std::string Path2 = hisPath +
"/" + hisName +
"_/Config";
849 info1 =
getInfo(Path1, file_version);
851 info2 =
getInfo(Path2, file_version);
853 std::string formattedHistName(
indent);
855 std::string algo =
getStringName(Path2 +
"/name", file_version);
856 formattedHistName +=
" ";
857 formattedHistName += hisName;
859 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
863 o << formattedHistName <<
" ";
865 o.setf(std::ios_base::right, std::ios_base::adjustfield);
876 std::string hisTitle =
h->GetTitle();
880 if ((
h1 =
dynamic_cast<TH1*
>(
h)) &&
h1->GetDimension() == 1) {
881 o <<
" Underflow: " <<
h1->GetBinContent(0) <<
" Overflow: " <<
h1->GetBinContent(
h1->GetNbinsX() + 1)
884 if (info1 !=
"" && info2 !=
"") {
886 <<
"Config " << info2 <<
" Results "
887 <<
"Results " << info1 <<
" title " << hisTitle <<
"\n";
888 }
else if (info1 !=
"") {
889 o <<
"Results Results " << info1 <<
" title " << hisTitle <<
"\n";
890 }
else if (info2 !=
"") {
891 o <<
"Config Config " << info2 <<
" title " << hisTitle <<
"\n";
893 o <<
" title " << hisTitle <<
"\n";
907 std::cerr <<
"HanOutputFile::streamHistoAssessments(): "
908 <<
"No input file is open\n";
916 DirMap_t::const_iterator idirend =
m_indirMap.end();
917 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
918 std::string idirName = idir->first;
919 std::string pathname(idir->second->GetPath());
920 std::string::size_type
i = pathname.find_last_of(
'/');
921 if (
i != (pathname.size() - 1)) {
924 std::string idirStatus =
"Undefined";
925 std::string idirAlg =
"Undefined";
928 std::string::size_type idirNamei = idirName.find_last_of(
'/');
929 if (idirNamei != std::string::npos) {
930 idirName = std::string(idirName, idirNamei + 1, std::string::npos);
933 std::string formattedName;
934 formattedName += idirName;
936 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
939 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
940 aMapIter =
m_assessMap.insert(std::move(aMapVal)).first;
944 AssMap_t::const_iterator aend = aMapIter->second->end();
945 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
946 std::string hisName = ias->first;
947 std::string hisPath = ias->second;
948 std::string formattedHistName;
953 std::string hisTitle(
h->GetTitle());
954 formattedHistName +=
"";
955 formattedHistName += hisName;
957 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
961 o << hisPath <<
"/" << formattedHistName <<
" "
973 std::cerr <<
"HanOutputFile::streamAllDQAssessments(): "
974 <<
"No input file is open\n";
982 DirMap_t::const_iterator idirend =
m_indirMap.end();
983 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
984 std::string idirName = idir->first;
985 std::string pathname(idir->second->GetPath());
986 std::string::size_type
i = pathname.find_last_of(
'/');
987 if (
i != (pathname.size() - 1)) {
990 std::string idirStatus =
"Undefined";
991 std::string idirAlg =
"Undefined";
994 std::string::size_type idirNamei = idirName.find_last_of(
'/');
995 if (idirNamei != std::string::npos) {
996 idirName = std::string(idirName, idirNamei + 1, std::string::npos);
999 std::string formattedName(
indent);
1000 formattedName += idirName;
1003 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
1006 o << formattedName <<
" ";
1008 o.setf(std::ios_base::right, std::ios_base::adjustfield);
1010 o << idirStatus <<
" ";
1018 o.flags(savedFlags);
1020 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
1023 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
1024 aMapIter =
m_assessMap.insert(std::move(aMapVal)).first;
1028 AssMap_t::const_iterator aend = aMapIter->second->end();
1029 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
1030 std::string hisName = ias->first;
1031 std::string hisPath = ias->second;
1034 std::string info1, info2;
1037 std::string formattedHistName(
indent);
1038 std::string
status =
"Undefined";
1039 std::string algo =
"Undefined";
1044 std::string hisTitle(
h->GetTitle());
1045 formattedHistName +=
" ";
1046 formattedHistName += hisName;
1048 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
1051 o << formattedHistName <<
" ";
1053 o.setf(std::ios_base::right, std::ios_base::adjustfield);
1060 if (info1 !=
"" && info2 !=
"") {
1062 <<
"Config " << info2 <<
" Results "
1063 <<
"Results " << info1 <<
" title " << hisTitle <<
"\n";
1064 }
else if (info1 !=
"") {
1065 o <<
"Results Results " << info1 <<
" title " << hisTitle <<
"\n";
1066 }
else if (info2 !=
"") {
1067 o <<
"Config Config " << info2 <<
" title " << hisTitle <<
"\n";
1069 o <<
" title " << hisTitle <<
"\n";
1074 o.flags(savedFlags);
1082 std::cerr <<
"HanOutputFile::saveAllHistograms(): "
1083 <<
"No input file is open\n";
1093 DirMap_t::const_iterator idirend =
m_indirMap.end();
1094 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
1095 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
1098 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
1099 aMapIter =
m_assessMap.insert(std::move(aMapVal)).first;
1102 AssMap_t::const_iterator aend = aMapIter->second->end();
1103 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
1104 std::string hisName = ias->first;
1105 std::string hisPath = ias->second;
1106 std::string::size_type sepi = hisPath.find(
':');
1107 if (sepi != std::string::npos) {
1108 hisPath = std::string(hisPath, sepi + 1, std::string::npos);
1110 std::string completeDir(location);
1111 completeDir += hisPath;
1113 std::cout <<
"Saving " << completeDir <<
" " << hisName << std::endl;
1117 hisName, std::move(completeDir), idir->second, drawRefs, run_min_LB, (hisPath +
"/" + hisName), cnvsType);
1118 if (isSaved) ++nSaved;
1122 std::cerr <<
"Exception caught: " <<
e.what() << std::endl;
1130 gVirtualPS->Open(myC->GetName(), 114);
1132 auto pImgDump =
dynamic_cast<TImageDump*
>(gVirtualPS);
1134 (*img) = pImgDump->GetImage();
1136 (*img)->GetImageBuffer(
x,
y, TImage::kPng);
1142 bool drawRefs,
const std::string& run_min_LB,
const std::string&
pathName,
1144 std::pair<std::string, std::string> pngAndJson =
1147 if (pngAndJson.first ==
"" && pngAndJson.second ==
"") {
1150 std::string namePNG = nameHis;
1151 std::string nameJSON = nameHis;
1154 nameJSON +=
".json";
1156 std::string::size_type
i = location.find_last_of(
'/');
1157 if (
i != (location.size() - 1)) {
1161 namePNG = location + namePNG;
1162 nameJSON = location + nameJSON;
1163 return saveFile(cnvsType, namePNG, pngAndJson.first, nameJSON, pngAndJson.second);
1167 const std::string& nameHis, TDirectory* groupDir,
bool drawRefs,
const std::string& run_min_LB,
1175 const std::string& nameHis, TDirectory* groupDir,
bool drawRefs,
const std::string& run_min_LB,
1183 bool drawRefs,
const std::string& run_min_LB,
1184 const std::string&
pathName,
int cnvsType) {
1188 int iMarkerStyle = 20;
1189 gStyle->SetFrameBorderMode(0);
1190 gStyle->SetFrameFillColor(0);
1191 gStyle->SetCanvasBorderMode(0);
1192 gStyle->SetPadBorderMode(0);
1193 gStyle->SetPadColor(0);
1194 gStyle->SetCanvasColor(0);
1195 gStyle->SetTitleColor(0);
1196 gStyle->SetStatColor(0);
1197 gStyle->SetFillColor(1);
1198 gStyle->SetPalette(1, 0);
1199 gStyle->SetTitleFontSize(0.06);
1200 gStyle->SetTitleH(0.06);
1201 gStyle->SetMarkerStyle(iMarkerStyle);
1202 gStyle->SetOptStat(111100);
1203 gStyle->SetStatBorderSize(0);
1204 gStyle->SetStatX(0.99);
1205 gStyle->SetStatY(0.99);
1206 gStyle->SetStatW(0.2);
1207 gStyle->SetStatH(0.1);
1213 TImage* img =
nullptr;
1217 std::string pathname(groupDir->GetPath());
1219 bool WasCollectionReference =
false;
1221 bool LookForDisplay;
1222 if (file_version == 1) {
1223 LookForDisplay =
containsDir(
"Config/annotations/display", (pathname +
"/" + nameHis +
"_"));
1224 if (LookForDisplay) {
1225 display =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/display", file_version);
1227 }
else if (file_version == 2) {
1228 std::optional<std::string> JSON_content;
1229 LookForDisplay =
containsDir((nameHis +
"_"), pathname);
1230 if (LookForDisplay) {
1231 JSON_content =
containsKeyInJSON(
"/annotations/display",
"Config", (pathname +
"/" + nameHis +
"_"));
1233 LookForDisplay =
true;
1235 LookForDisplay =
false;
1238 if (LookForDisplay) {
1239 display = JSON_content.value();
1243 bool PlotOverflows = (
display.find(
"PlotUnderOverflow") != std::string::npos);
1246 std::string drawopt =
"";
1247 while (
found != std::string::npos) {
1248 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1256 std::string drawrefopt =
"";
1257 while (
found != std::string::npos) {
1258 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1264 if (drawrefopt ==
"") {
1265 drawrefopt = drawopt;
1269 std::string drawrefopt2D =
"";
1270 while (
found != std::string::npos) {
1271 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1274 drawrefopt2D += temp;
1280 std::string datatitle;
1281 if (
found == std::string::npos) {
1284 while (
found != std::string::npos) {
1285 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1286 if (found1 != std::string::npos) {
1294 TKey* hkey = groupDir->FindKey(nameHis.c_str());
1296 std::cerr <<
"Did not find TKey for \"" << nameHis <<
"\", will not save this histogram.\n";
1297 return std::pair<std::string, std::string>{
1302 TObject* hobj = hkey->ReadObj();
1305 TEfficiency* eRef(0);
1307 std::vector<TH1*> hRefs;
1308 std::vector<TEfficiency*> eRefs;
1309 bool hasPlotted(
false);
1310 TH1*
h =
dynamic_cast<TH1*
>(hobj);
1311 TH2* h2 =
dynamic_cast<TH2*
>(
h);
1312 TGraph*
g =
dynamic_cast<TGraph*
>(hobj);
1313 TEfficiency*
e =
dynamic_cast<TEfficiency*
>(hobj);
1315 std::string
name = nameHis;
1322 std::string AlgoName(
"");
1323 AlgoName =
getStringName(pathname +
"/" + nameHis +
"_/Config/name", file_version);
1327 if (
found != std::string::npos) {
1328 std::size_t found1 =
display.find_first_of(
',',
found + 1);
1334 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
1342 gPad->SetGridx(
display.find(
"SetGridx") != std::string::npos);
1343 gPad->SetGridy(
display.find(
"SetGridy") != std::string::npos);
1345 if (
found != std::string::npos) {
1346 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
1347 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
1348 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
1349 int n1 = std::strtol(cn.c_str(), NULL, 0);
1350 gStyle->SetPalette((Int_t)
n1);
1353 if (
found != std::string::npos) {
1354 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
1355 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
1356 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
1357 int n1 = std::strtol(cn.c_str(), NULL, 0);
1358 gStyle->SetGridStyle((Style_t)
n1);
1363 if (
found != std::string::npos) {
1364 Double_t minstat = 0.;
1365 std::size_t fpos1, fpos2, fpos;
1366 fpos =
display.find(
"MinStat");
1367 if (fpos != std::string::npos) {
1368 fpos1 =
display.find(
'(', fpos + 1);
1369 if (fpos1 != std::string::npos) {
1370 fpos2 =
display.find(
')', fpos1 + 1);
1371 if (fpos2 != std::string::npos) {
1372 std::string s_minstat =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
1373 minstat = std::strtod(s_minstat.c_str(), NULL);
1377 std::string fitopt(
"");
1378 fpos =
display.find(
"FitOption");
1379 if (fpos != std::string::npos) {
1380 fpos1 =
display.find(
'(', fpos + 1);
1381 if (fpos1 != std::string::npos) {
1382 fpos2 =
display.find(
')', fpos1 + 1);
1383 if (fpos2 != std::string::npos) {
1384 fitopt =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
1389 std::size_t found1 =
display.find(
"doublegaus");
1390 if (found1 != std::string::npos) {
1391 std::size_t found2 =
display.find(
'(', found1 + 1);
1392 if (found2 != std::string::npos) {
1393 std::size_t found3 =
display.find(
')', found2 + 1);
1394 if (found3 != std::string::npos) {
1395 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1396 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1397 std::size_t found4 =
display.find(
',', found2 + 1);
1398 if (found4 != std::string::npos) {
1399 range =
display.substr(found4 + 1, found3 - found4 - 1);
1400 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1404 f1->GetParameters(
par);
1405 TF1* func =
new TF1(
"func",
"gaus(0)+gaus(3)",
xmin,
xmax);
1406 func->SetParameters(
par);
1407 func->SetParameter(3,
h->GetBinContent(
h->GetMaximumBin()));
1408 func->SetParameter(4,
h->GetMean());
1409 func->SetParameter(5,
par[2]);
1410 func->SetLineColor(kRed);
1411 func->SetLineWidth(2);
1412 if (
h->GetEffectiveEntries() > minstat) {
1413 h->Fit(func, (
"rq" + fitopt).c_str());
1422 std::size_t found1 =
display.find(
"gauspluspol1");
1423 if (found1 != std::string::npos) {
1424 std::size_t found2 =
display.find(
'(', found1 + 1);
1425 if (found2 != std::string::npos) {
1426 std::size_t found3 =
display.find(
')', found2 + 1);
1427 if (found3 != std::string::npos) {
1428 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1429 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1430 std::size_t found4 =
display.find(
',', found2 + 1);
1431 if (found4 != std::string::npos) {
1432 range =
display.substr(found4 + 1, found3 - found4 - 1);
1433 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1434 TF1* func =
new TF1(
"func",
"gaus(0)+pol1(3)",
xmin,
xmax);
1435 func->SetLineColor(kRed);
1436 func->SetLineWidth(2);
1437 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
1438 if (
h->GetEffectiveEntries() > minstat) {
1439 h->Fit(func, (
"rq" + fitopt).c_str());
1447 found1 =
display.find(
"gausplusexpo");
1448 if (found1 != std::string::npos) {
1449 std::size_t found2 =
display.find(
'(', found1 + 1);
1450 if (found2 != std::string::npos) {
1451 std::size_t found3 =
display.find(
')', found2 + 1);
1452 if (found3 != std::string::npos) {
1453 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1454 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1455 std::size_t found4 =
display.find(
',', found2 + 1);
1456 if (found4 != std::string::npos) {
1457 range =
display.substr(found4 + 1, found3 - found4 - 1);
1458 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1460 TF1* func =
new TF1(
"func",
"gaus(0)+expo(3)",
xmin,
xmax);
1461 func->SetLineColor(kRed);
1462 func->SetLineWidth(2);
1463 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
1464 if (
h->GetEffectiveEntries() > minstat) {
1465 h->Fit(func, (
"rq" + fitopt).c_str());
1474 if (found2 != std::string::npos) {
1475 std::size_t found3 =
display.find(
')', found2 + 1);
1476 if (found3 != std::string::npos) {
1477 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
1478 Double_t
xmin = std::strtod(
range.c_str(), NULL);
1479 std::size_t found4 =
display.find(
',', found2 + 1);
1480 if (found4 != std::string::npos) {
1481 range =
display.substr(found4 + 1, found3 - found4 - 1);
1482 Double_t
xmax = std::strtod(
range.c_str(), NULL);
1483 TF1* func =
new TF1(
"func",
"gaus",
xmin,
xmax);
1484 func->SetLineColor(kRed);
1485 func->SetLineWidth(2);
1486 if (
h->GetEffectiveEntries() > minstat) {
1487 h->Fit(func, (
"rq" + fitopt).c_str());
1500 if (h2->GetMinimum() >= 0 && h2->GetMaximum() > 0.) {
1501 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1502 gPad->SetLogz(
display.find(
"LogZ") != std::string::npos);
1505 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1507 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax()) {
1508 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
1509 <<
"Inconsistent x-axis settings: min=" <<
h->GetXaxis()->GetXmin() <<
", "
1510 <<
"max=" <<
h->GetXaxis()->GetXmax() <<
", "
1511 <<
"Will not save this histogram.\n";
1512 return std::pair<std::string, std::string>{
1516 if (
h->GetYaxis()->GetXmin() >=
h->GetYaxis()->GetXmax()) {
1517 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
1518 <<
"Inconsistent y-axis settings: min=" <<
h->GetYaxis()->GetXmin() <<
", "
1519 <<
"max=" <<
h->GetYaxis()->GetXmax() <<
", "
1520 <<
"Will not save this histogram.\n";
1521 return std::pair<std::string, std::string>{
1526 if (drawopt ==
"") {
1530 if (file_version == 1) {
1531 groupDir->cd((nameHis +
"_/Results").c_str());
1533 }
else if (file_version == 2) {
1534 if (groupDir->GetDirectory((nameHis +
"_").c_str()) != 0) {
1535 groupDir->cd((nameHis +
"_").c_str());
1539 h2Ref =
dynamic_cast<TH2*
>(
ref);
1540 TCollection* colln =
dynamic_cast<TCollection*
>(
ref);
1542 h2Ref =
dynamic_cast<TH2*
>(colln->MakeIterator()->Next());
1544 if (h2Ref && (drawrefopt2D !=
"")) {
1546 h2Ref->Draw(drawrefopt2D.c_str());
1549 h2->Draw((
"SAME" + drawopt).c_str());
1551 if (drawopt.find(
"lego") == std::string::npos) {
1559 t.SetTextSize(0.03);
1560 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1563 tt.SetTextSize(0.03);
1566 }
else if (
h != 0) {
1568 if (
display.find(
"StatBox") != std::string::npos) {
1571 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax()) {
1572 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
1573 <<
"Inconsistent x-axis settings: min=" <<
h->GetXaxis()->GetXmin() <<
", "
1574 <<
"max=" <<
h->GetXaxis()->GetXmax() <<
", "
1575 <<
"Will not save this histogram.\n";
1576 return std::pair<std::string, std::string>{
1580 h->SetLineColor(kBlack);
1581 h->SetMarkerColor(1);
1588 if (file_version == 1) {
1589 groupDir->cd((nameHis +
"_/Results").c_str());
1591 }
else if (file_version == 2) {
1592 if (groupDir->GetDirectory((nameHis +
"_").c_str()) != 0) {
1593 groupDir->cd((nameHis +
"_").c_str());
1597 hRef =
dynamic_cast<TH1*
>(
ref);
1599 hRefs.push_back(hRef);
1601 TCollection* colln =
dynamic_cast<TCollection*
>(
ref);
1603 WasCollectionReference =
true;
1604 std::unique_ptr<TIterator> icolln(colln->MakeIterator());
1606 while ((ref2 = icolln->Next())) {
1607 hRef =
dynamic_cast<TH1*
>(ref2);
1609 if (hRef->GetDimension() ==
h->GetDimension()) {
1610 hRefs.push_back(hRef);
1612 }
else std::cout <<
"hRef cast failed!!!" << std::endl;
1619 if (hRefs.size() > 0) {
1620 legend =
new TLegend(0.55, 0.77, 0.87, 0.87);
1624 legend->SetBorderSize(0);
1625 legend->AddEntry(
h, datatitle.c_str());
1627 for (
auto hRef : hRefs) {
1633 hRef->SetMarkerColor(local_color);
1636 hRef->SetLineColor(local_color);
1637 hRef->SetLineWidth(2);
1638 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
1639 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
1641 if (PlotOverflows) {
1656 bool isLogY = (
display.find(
"LogY") != std::string::npos);
1662 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
1665 std::cerr <<
"ymin is <0. and LogY requested for histogram \"" << pathname +
"/" + nameHis
1666 <<
"\", ymin=" <<
ymin << std::endl;
1669 double yMargin = (
ymax -
ymin) * 0.05;
1670 h->SetAxisRange(
ymin - yMargin,
ymax + yMargin,
"Y");
1672 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
1673 hRef->GetXaxis()->SetRangeUser(
xmin,
xmax);
1675 if (
h->GetMinimum() >= 0. && hRef->GetMinimum() >= 0. &&
h->GetMaximum() > 0. &&
1676 hRef->GetMaximum() > 0.) {
1677 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1680 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1683 h->Draw(drawopt.c_str());
1686 hRef->Draw((
"SAME" + drawrefopt).c_str());
1689 if (
display.find(
"ScaleRef") != std::string::npos) {
1691 }
else if (
h->Integral(
"width") > 0.0 && hRef->Integral(
"width") > 0.0 &&
1692 (AlgoName.find(
"BinContentComp") == std::string::npos) &&
1693 (
display.find(
"NoNorm") == std::string::npos)) {
1694 scale =
h->Integral(
"width") / hRef->Integral(
"width");
1699 hRef->SetMarkerColor(local_color);
1701 hRef->SetLineColor(local_color);
1702 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
1703 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
1705 if (PlotOverflows) {
1722 bool isLogY = (
display.find(
"LogY") != std::string::npos);
1730 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
"Y");
1733 std::cerr <<
"ymin is <=0. and LogY requested for histogram \"" << pathname +
"/" + nameHis
1734 <<
"\", ymin=" <<
ymin << std::endl;
1738 h->SetAxisRange(
ymin - yDiff * 0.05,
ymax + yDiff * 0.05,
"Y");
1741 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
1742 hRef->GetXaxis()->SetRangeUser(
xmin,
xmax);
1744 if (
h->GetMinimum() >= 0 && hRef->GetMinimum() >= 0 &&
h->GetMaximum() > 0. && hRef->GetMaximum() > 0.) {
1745 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1748 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1752 h->Draw(drawopt.c_str());
1755 hRef->Draw((
"SAME" + drawrefopt).c_str());
1757 if (WasCollectionReference) {
1758 legend->AddEntry(hRef, hRef->GetName());
1760 std::string refInfo(
"");
1761 refInfo =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/refInfo", file_version);
1762 legend->AddEntry(hRef, refInfo !=
"Undefined" ? refInfo.c_str() :
"Reference");
1765 h->Draw((
"SAME" + drawopt).c_str());
1769 if (
h->GetMinimum() >= 0) {
1770 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1773 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
1776 h->Draw(drawopt.c_str());
1790 t.SetTextSize(0.03);
1791 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1794 tt.SetTextSize(0.03);
1803 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
1805 if (
g->GetMinimum() >= 0. &&
g->GetMaximum() > 0.) {
1806 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
1814 g->Draw((std::string(
"AP") + drawopt).c_str());
1818 t.SetTextSize(0.03);
1819 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1822 tt.SetTextSize(0.03);
1832 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
1834 if (drawopt ==
"") {
1835 if (
e->GetDimension() == 1) {
1842 if (file_version == 1) {
1843 groupDir->cd((nameHis +
"_/Results").c_str());
1845 }
else if (file_version == 2) {
1846 if (groupDir->cd((nameHis +
"_").c_str())) {
1850 eRef =
dynamic_cast<TEfficiency*
>(
ref);
1852 eRefs.push_back(eRef);
1854 TCollection* colln =
dynamic_cast<TCollection*
>(
ref);
1856 WasCollectionReference =
true;
1857 TIterator* icolln = colln->MakeIterator();
1859 while ((ref2 = icolln->Next())) {
1860 eRef =
dynamic_cast<TEfficiency*
>(ref2);
1862 if (eRef->GetDimension() ==
e->GetDimension()) {
1863 eRefs.push_back(eRef);
1865 }
else std::cout <<
"eRef cast failed!!!" << std::endl;
1871 if (eRefs.size() > 0) {
1872 legend =
new TLegend(0.55, 0.77, 0.87, 0.87);
1876 legend->SetBorderSize(0);
1877 legend->AddEntry(
e, datatitle.c_str());
1879 for (
auto eRef : eRefs) {
1889 eRef->SetMarkerColor(local_color);
1890 eRef->SetLineColor(local_color);
1893 e->Draw(drawopt.c_str());
1899 if (WasCollectionReference) {
1900 legend->AddEntry(eRef, eRef->GetName());
1902 std::string refInfo(
"");
1903 refInfo =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/refInfo", file_version);
1904 legend->AddEntry(eRef, refInfo !=
"Undefined" ? refInfo.c_str() :
"Reference");
1910 e->Draw(drawopt.c_str());
1915 e->GetPaintedGraph()->GetXaxis()->SetTitleColor();
1921 t.SetTextSize(0.03);
1922 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
1925 tt.SetTextSize(0.03);
1932 if (
x)
rv.assign(
x,
y);
1935 std::pair<std::string, std::string> rvPair {
1947 TDirectory* groupDir1,
1948 TDirectory* groupDir2,
bool drawRefs,
1949 const std::string& run_min_LB,
const std::string&
pathName,
1953 gStyle->SetFrameBorderMode(0);
1954 gStyle->SetFrameFillColor(0);
1955 gStyle->SetCanvasBorderMode(0);
1956 gStyle->SetPadBorderMode(0);
1957 gStyle->SetPadColor(0);
1958 gStyle->SetCanvasColor(0);
1959 gStyle->SetTitleColor(0);
1960 gStyle->SetStatColor(0);
1961 gStyle->SetFillColor(1);
1962 gStyle->SetPalette(1, 0);
1963 gStyle->SetTitleFontSize(0.06);
1964 gStyle->SetTitleH(0.06);
1965 gStyle->SetMarkerStyle(20);
1966 gStyle->SetOptStat(111100);
1967 gStyle->SetStatBorderSize(0);
1968 gStyle->SetStatX(0.99);
1969 gStyle->SetStatY(0.99);
1970 gStyle->SetStatW(0.2);
1971 gStyle->SetStatH(0.1);
1974 std::string pathname(groupDir1->GetPath());
1977 bool LookForDisplay;
1978 if (file_version == 1) {
1979 LookForDisplay =
containsDir(
"Config/annotations/display", (pathname +
"/" + nameHis +
"_"));
1980 if (LookForDisplay) {
1981 display =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/display", file_version);
1983 }
else if (file_version == 2) {
1984 std::optional<std::string> JSON_content;
1985 LookForDisplay =
containsDir((nameHis +
"_"), pathname);
1986 if (LookForDisplay) {
1987 JSON_content =
containsKeyInJSON(
"/annotations/display",
"Config", (pathname +
"/" + nameHis +
"_"));
1989 LookForDisplay =
true;
1991 LookForDisplay =
false;
1994 if (LookForDisplay) {
1995 display = JSON_content.value();
2001 std::string drawopt =
"";
2002 while (
found != std::string::npos) {
2003 std::size_t found1 =
display.find_first_of(
',',
found + 1);
2011 TKey* hkey = groupDir1->FindKey(nameHis.c_str());
2013 TKey* hkey2 = groupDir2->FindKey(nameHis.c_str());
2014 if (hkey == 0 || hkey2 == 0) {
2015 std::cerr <<
"Did not find TKey for \"" << nameHis <<
"\", will not save this histogram.\n";
2020 TObject* hobj = hkey->ReadObj();
2021 TObject* hobj2 = hkey2->ReadObj();
2024 TH2* h2(0), *h2_2(0), *h2Diff(0);
2025 TGraph*
g(0), *
g2(0);
2026 TEfficiency*
e(0), *
e2(0);
2029 std::string nameJSON = nameHis;
2030 std::string namePNG = nameHis;
2032 nameJSON +=
".json";
2033 std::string::size_type
i = location.find_last_of(
'/');
2034 if (
i != (location.size() - 1)) {
2037 namePNG = location + namePNG;
2038 nameJSON = location + nameJSON;
2039 std::string AlgoName =
getStringName(pathname +
"/" + nameHis +
"_/Config/name", file_version);
2043 if (
found != std::string::npos) {
2044 std::size_t found1 =
display.find_first_of(
',',
found + 1);
2050 if ((
h =
dynamic_cast<TH1*
>(hobj)) != 0 && (
hist2 =
dynamic_cast<TH1*
>(hobj2)) != 0) {
2051 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
2057 std::string tmpdraw(drawopt);
2058 if ((h2 =
dynamic_cast<TH2*
>(
h)) != 0 && ((h2_2 =
dynamic_cast<TH2*
>(
hist2)) != 0)) {
2060 h2Diff = (TH2*) h2->Clone(
"difference");
2071 h2Diff->Add(h2, h2_2, 1.0, -1.0);
2072 h2Diff->SetLineColor(2);
2073 h2Diff->SetMarkerColor(2);
2074 if (!
drawH2(myC.get(), h2Diff, tmpdraw,
display))
return false;
2078 t.SetTextSize(0.03);
2079 t.DrawLatex(0.02, 0.04, (run_min_LB +
" difference").c_str());
2082 tt.SetTextSize(0.03);
2086 }
else if (
h != 0 &&
hist2 != 0) {
2089 if (
display.find(
"ScaleRef") != std::string::npos) {
2091 }
else if (
h->Integral(
"width") > 0.0 &&
hist2->Integral(
"width") > 0.0 &&
2092 (AlgoName.find(
"BinContentComp") == std::string::npos) &&
2093 (
display.find(
"NoNorm") == std::string::npos)) {
2094 scale =
h->Integral(
"width") /
hist2->Integral(
"width");
2097 double ymin = (
hist2->GetMinimum() <
h->GetMinimum()) ?
hist2->GetMinimum() :
h->GetMinimum();
2098 double ymax = (
hist2->GetMaximum() >
h->GetMaximum()) ?
hist2->GetMaximum() :
h->GetMaximum();
2099 double yMargin = (
ymax -
ymin) * 0.05;
2100 h->SetAxisRange(
ymin - yMargin,
ymax + yMargin,
"Y");
2102 h->SetMarkerColor(1);
2105 hist2->SetMarkerColor(4);
2106 hist2->SetLineColor(4);
2107 hist2->SetFillStyle(0);
2108 hist2->SetLineWidth(2);
2110 if (file_version == 1) {
2111 groupDir1->cd((nameHis +
"_/Results").c_str());
2113 groupDir1->cd((nameHis +
"_").c_str());
2118 if (!
drawH1(myC.get(),
h, hRef, tmpdraw,
display, AlgoName))
return false;
2123 legend =
new TLegend(0.55, 0.77, 0.87, 0.87);
2127 legend->SetBorderSize(0);
2129 std::size_t foundN1 = run_min_LB.find_first_of(
"-");
2130 std::size_t foundN2 = run_min_LB.find_first_of(
',');
2132 legend->AddEntry(
h, (
"Run " + run_min_LB.substr(5, foundN1 - 5)).c_str());
2133 legend->AddEntry(
hist2, (
"Run " + run_min_LB.substr(foundN1 + 1, foundN2 - foundN1 - 1)).c_str());
2135 legend->AddEntry(hRef,
"Reference");
2141 t.SetTextSize(0.03);
2142 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2145 tt.SetTextSize(0.03);
2155 if (((
g =
dynamic_cast<TGraph*
>(hobj)) != 0) && ((
g2 =
dynamic_cast<TGraph*
>(hobj2)) != 0)) {
2156 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
2158 if (
g->GetMinimum() >= 0. &&
g2->GetMinimum() >= 0. &&
g->GetMaximum() > 0. &&
g2->GetMaximum() > 0.) {
2159 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2163 g->Draw((std::string(
"AP") + drawopt).c_str());
2165 g2->SetMarkerColor(2);
2166 g2->SetLineColor(2);
2167 g2->Draw((std::string(
"P") + drawopt +
" same").c_str());
2170 t.SetTextSize(0.03);
2171 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2174 tt.SetTextSize(0.03);
2182 if (((
e =
dynamic_cast<TEfficiency*
>(hobj)) != 0) && ((
e2 =
dynamic_cast<TEfficiency*
>(hobj2)) != 0)) {
2183 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
2188 e->Draw((std::string(
"AP") + drawopt).c_str());
2192 e->GetPaintedGraph()->GetXaxis()->SetTitleColor();
2195 e2->SetMarkerColor(2);
2196 e2->SetLineColor(2);
2197 e2->Draw((std::string(
"P") + drawopt +
" same").c_str());
2200 t.SetTextSize(0.03);
2201 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2204 tt.SetTextSize(0.03);
2220 std::string drawopt(drawop);
2222 if (h2->GetMinimum() >= 0 && h2->GetMaximum() > 0) {
2223 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2224 gPad->SetLogz(
display.find(
"LogZ") != std::string::npos);
2226 gPad->SetLogy(
false);
2229 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2231 gPad->SetLogx(
false);
2234 if (h2->GetXaxis()->GetXmin() >= h2->GetXaxis()->GetXmax()) {
2235 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
2236 <<
"Inconsistent x-axis settings: min=" << h2->GetXaxis()->GetXmin() <<
", "
2237 <<
"max=" << h2->GetXaxis()->GetXmax() <<
", "
2238 <<
"Will not save this histogram.\n";
2241 if (h2->GetYaxis()->GetXmin() >= h2->GetYaxis()->GetXmax()) {
2242 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
2243 <<
"Inconsistent y-axis settings: min=" << h2->GetYaxis()->GetXmin() <<
", "
2244 <<
"max=" << h2->GetYaxis()->GetXmax() <<
", "
2245 <<
"Will not save this histogram.\n";
2249 if (drawopt ==
"") {
2252 h2->Draw(drawopt.c_str());
2262 gPad->SetGridx(
display.find(
"SetGridx") != std::string::npos);
2263 gPad->SetGridy(
display.find(
"SetGridy") != std::string::npos);
2265 if (
found != std::string::npos) {
2266 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
2267 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
2268 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
2269 int n1 = std::strtol(cn.c_str(), NULL, 0);
2270 gStyle->SetPalette((Int_t)
n1);
2273 if (
found != std::string::npos) {
2274 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
2275 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
2276 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
2277 int n1 = std::strtol(cn.c_str(), NULL, 0);
2278 gStyle->SetGridStyle((Style_t)
n1);
2280 if (!drawopt.empty()) {
2288 if (
found != std::string::npos) {
2289 Double_t minstat = 0.;
2290 std::size_t fpos1, fpos2, fpos;
2291 fpos =
display.find(
"MinStat");
2292 if (fpos != std::string::npos) {
2293 fpos1 =
display.find(
'(', fpos + 1);
2294 if (fpos1 != std::string::npos) {
2295 fpos2 =
display.find(
')', fpos1 + 1);
2296 if (fpos2 != std::string::npos) {
2297 std::string s_minstat =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
2298 minstat = std::strtod(s_minstat.c_str(), NULL);
2302 std::string fitopt(
"");
2303 fpos =
display.find(
"FitOption");
2304 if (fpos != std::string::npos) {
2305 fpos1 =
display.find(
'(', fpos + 1);
2306 if (fpos1 != std::string::npos) {
2307 fpos2 =
display.find(
')', fpos1 + 1);
2308 if (fpos2 != std::string::npos) {
2309 fitopt =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
2314 std::size_t found1 =
display.find(
"doublegaus");
2315 if (found1 != std::string::npos) {
2316 std::size_t found2 =
display.find(
'(', found1 + 1);
2317 if (found2 != std::string::npos) {
2318 std::size_t found3 =
display.find(
')', found2 + 1);
2319 if (found3 != std::string::npos) {
2320 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2321 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2322 std::size_t found4 =
display.find(
',', found2 + 1);
2323 if (found4 != std::string::npos) {
2324 range =
display.substr(found4 + 1, found3 - found4 - 1);
2325 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2329 f1->GetParameters(
par);
2330 TF1* func =
new TF1(
"func",
"gaus(0)+gaus(3)",
xmin,
xmax);
2331 func->SetParameters(
par);
2332 func->SetParameter(3,
h->GetBinContent(
h->GetMaximumBin()));
2333 func->SetParameter(4,
h->GetMean());
2334 func->SetParameter(5,
par[2]);
2335 func->SetLineColor(kRed);
2336 func->SetLineWidth(2);
2337 if (
h->GetEffectiveEntries() > minstat) {
2338 h->Fit(func, (
"rq" + fitopt).c_str());
2347 std::size_t found1 =
display.find(
"gauspluspol1");
2348 if (found1 != std::string::npos) {
2349 std::size_t found2 =
display.find(
'(', found1 + 1);
2350 if (found2 != std::string::npos) {
2351 std::size_t found3 =
display.find(
')', found2 + 1);
2352 if (found3 != std::string::npos) {
2353 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2354 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2355 std::size_t found4 =
display.find(
',', found2 + 1);
2356 if (found4 != std::string::npos) {
2357 range =
display.substr(found4 + 1, found3 - found4 - 1);
2358 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2359 TF1* func =
new TF1(
"func",
"gaus(0)+pol1(3)",
xmin,
xmax);
2360 func->SetLineColor(kRed);
2361 func->SetLineWidth(2);
2362 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
2363 if (
h->GetEffectiveEntries() > minstat) {
2364 h->Fit(func, (
"rq" + fitopt).c_str());
2372 found1 =
display.find(
"gausplusexpo");
2373 if (found1 != std::string::npos) {
2374 std::size_t found2 =
display.find(
'(', found1 + 1);
2375 if (found2 != std::string::npos) {
2376 std::size_t found3 =
display.find(
')', found2 + 1);
2377 if (found3 != std::string::npos) {
2378 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2379 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2380 std::size_t found4 =
display.find(
',', found2 + 1);
2381 if (found4 != std::string::npos) {
2382 range =
display.substr(found4 + 1, found3 - found4 - 1);
2383 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2385 TF1* func =
new TF1(
"func",
"gaus(0)+expo(3)",
xmin,
xmax);
2386 func->SetLineColor(kRed);
2387 func->SetLineWidth(2);
2388 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
2389 if (
h->GetEffectiveEntries() > minstat) {
2390 h->Fit(func, (
"rq" + fitopt).c_str());
2399 if (found2 != std::string::npos) {
2400 std::size_t found3 =
display.find(
')', found2 + 1);
2401 if (found3 != std::string::npos) {
2402 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2403 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2404 std::size_t found4 =
display.find(
',', found2 + 1);
2405 if (found4 != std::string::npos) {
2406 range =
display.substr(found4 + 1, found3 - found4 - 1);
2407 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2408 TF1* func =
new TF1(
"func",
"gaus",
xmin,
xmax);
2409 func->SetLineColor(kRed);
2410 func->SetLineWidth(2);
2411 if (
h->GetEffectiveEntries() > minstat) {
2412 h->Fit(func, (
"rq" + fitopt).c_str());
2422 if (!drawopt.empty()) {
2428 TCanvas* myC, TH1*
h, TH1* hRef, std::string& drawopt, std::string&
display, std::string& AlgoName) {
2430 if (
display.find(
"StatBox") != std::string::npos) {
2433 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax()) {
2434 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
2435 <<
"Inconsistent x-axis settings: min=" <<
h->GetXaxis()->GetXmin() <<
", "
2436 <<
"max=" <<
h->GetXaxis()->GetXmax() <<
", "
2437 <<
"Will not save this histogram.\n";
2445 if (
h->GetMinimum() >= 0 &&
h->GetMaximum() > 0.) {
2446 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2448 gPad->SetLogy(
false);
2451 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2453 gPad->SetLogx(
false);
2456 h->Draw(drawopt.c_str());
2465 TCanvas* myC, TH1* hRef, TH1*
h, std::string& drawopt, std::string&
display, std::string& AlgoName) {
2469 hRef->SetMarkerColor(2);
2470 hRef->SetLineColor(2);
2471 hRef->SetLineWidth(2);
2472 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
2473 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
2486 bool isLogY = (
display.find(
"LogY") != std::string::npos);
2492 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
"Y");
2495 std::cerr <<
"ymin is <0. and LogY requested for histogram \"" <<
h->GetName() <<
" "
2496 <<
h->GetDirectory()->GetPath() <<
"\", ymin=" <<
ymin << std::endl;
2499 double yMargin = (
ymax -
ymin) * 0.05;
2500 h->SetAxisRange(
ymin - yMargin,
ymax + yMargin,
"Y");
2503 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
2505 if (
h->GetMinimum() >= 0 && hRef->GetMinimum() >= 0 &&
h->GetMaximum() > 0 && hRef->GetMaximum() > 0) {
2506 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2509 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2511 h->Draw(drawopt.c_str());
2512 hRef->Draw((
"SAME" + drawopt).c_str());
2513 h->Draw((
"SAME" + drawopt).c_str());
2516 if (
display.find(
"ScaleRef") != std::string::npos) {
2518 }
else if (
h->Integral(
"width") > 0.0 && hRef->Integral(
"width") > 0.0 &&
2519 (AlgoName.find(
"BinContentComp") == std::string::npos) &&
2520 (
display.find(
"NoNorm") == std::string::npos)) {
2521 scale =
h->Integral(
"width") / hRef->Integral(
"width");
2524 hRef->SetMarkerColor(15);
2525 hRef->SetFillColor(15);
2526 hRef->SetLineColor(15);
2527 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
2528 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
2540 bool isLogY = (
display.find(
"LogY") != std::string::npos);
2548 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
"Y");
2551 std::cerr <<
"ymin is <=0. and LogY requested for histogram \"" <<
h->GetName() <<
" "
2552 <<
h->GetDirectory()->GetPath() <<
"\", ymin=" <<
ymin << std::endl;
2556 h->SetAxisRange(
ymin - yDiff * 0.05,
ymax + yDiff * 0.05,
"Y");
2560 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
2562 if (
h->GetMinimum() >= 0. && hRef->GetMinimum() >= 0. &&
h->GetMaximum() > 0. && hRef->GetMaximum() > 0.) {
2563 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2566 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2569 h->Draw(drawopt.c_str());
2570 hRef->Draw((
"SAME" + drawopt).c_str());
2571 h->Draw((
"SAME" + drawopt).c_str());
2581 std::size_t
found =
str.find(
"AxisRange");
2582 while (
found != std::string::npos) {
2587 std::string coordinates, cx1, cy1 =
"";
2588 std::size_t found1 =
str.find_first_of(
')',
found + 1);
2589 std::size_t found2 =
str.find_first_of(
"\'",
found + 1);
2590 if (found2 != std::string::npos) {
2591 found2 =
str.find_first_of(
"\'", found2 + 1);
2592 if (found1 < found2) {
2593 found1 =
str.find_first_of(
')', found2 + 1);
2627 if (found1 != std::string::npos) {
2629 found1 = coordinates.find_first_of(
',');
2630 if (found1 != std::string::npos) {
2631 cx1 = coordinates.substr(0, found1);
2632 double x1 = std::strtod(cx1.c_str(), NULL);
2633 found2 = coordinates.find_first_of(
',', found1 + 1);
2634 if (found2 != std::string::npos) {
2635 cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2636 double y1 = std::strtod(cy1.c_str(), NULL);
2637 std::string txt = coordinates.substr(found2 + 2, coordinates.size());
2639 if (txt ==
"X" &&
x1 <
y1) {
2640 h->GetXaxis()->SetRangeUser(
x1,
y1);
2642 if (txt ==
"Y" &&
x1 <
y1) {
2643 h->SetAxisRange(
x1,
y1,
"Y");
2645 if (txt ==
"Z" &&
x1 <
y1) {
2646 h->SetAxisRange(
x1,
y1,
"Z");
2649 std::string txt = coordinates.substr(found1 + 2, coordinates.size());
2651 if (txt[1] ==
'M') {
2652 if (txt ==
"XMax") {
2654 h->GetXaxis()->SetRangeUser(
xmin,
x1);
2656 if (txt ==
"XMin") {
2658 h->GetXaxis()->SetRangeUser(
x1,
xmax);
2660 if (txt ==
"YMax") {
2661 double ymin =
h->GetMinimum();
2662 h->SetAxisRange(
ymin,
x1,
"Y");
2664 if (txt ==
"YMin") {
2665 double ymax =
h->GetMaximum();
2666 h->SetAxisRange(
x1,
ymax,
"Y");
2681 if (
display.find(
"RatioPad") == std::string::npos)
return;
2683 unsigned int ww = myC_upperpad->GetWw();
2684 unsigned int wh = myC_upperpad->GetWh();
2685 std::string padname =
"PAD";
2686 std::string padname_ratio =
"PAD_main";
2687 auto myC_ratiopad = std::make_unique<TCanvas>(padname_ratio.c_str(),
"myC_ratiopad", ww,
wh);
2688 auto myC_main = std::make_unique<TCanvas>(padname.c_str(),
"myC_main", ww,
wh);
2692 myC_ratiopad->SetTopMargin(0);
2693 myC_ratiopad->SetLogx(
display.find(
"LogX") != std::string::npos);
2702 std::unique_ptr<TH1F> clonehist;
2703 std::unique_ptr<TH1F> clonehistref;
2706 clonehist.reset((
TH1F*) ph->ProjectionX());
2708 clonehist.reset((
TH1F*)
h->Clone());
2709 if (!clonehist->GetSumw2()) {
2714 clonehistref.reset((
TH1F*) phRef->ProjectionX());
2716 clonehistref.reset((
TH1F*) hRef->Clone());
2717 if (!clonehistref->GetSumw2()) {
2718 clonehistref->Sumw2();
2721 if (!clonehist or !clonehistref) {
2724 clonehist->SetBit(kCanDelete);
2725 clonehist->Divide(clonehistref.get());
2729 formatTH1(myC_ratiopad.get(), clonehist.get());
2730 clonehist->SetTitle(
"");
2733 double delta = 0.75;
2734 if (
display.find(
"delta(") != std::string::npos) {
2737 clonehist->SetAxisRange(1. - delta, 1. + delta,
"Y");
2739 clonehist->GetYaxis()->SetNdivisions(3,
true);
2740 clonehist->SetMarkerStyle(1);
2741 clonehist->Draw(
"E");
2742 clonehist->GetXaxis()->SetTitleSize(0.11);
2743 clonehist->GetXaxis()->SetLabelSize(0.11);
2744 clonehist->GetYaxis()->SetTitleSize(0.11);
2745 clonehist->GetYaxis()->SetLabelSize(0.11);
2747 TPad* lowerPad =
new TPad(
"lowerPad",
"lowerPad", .005, .060, .995, .250);
2748 lowerPad->SetTopMargin(0);
2749 lowerPad->SetFillStyle(0);
2751 TPad* upperPad =
new TPad(
"upperPad",
"upperPad", .005, .250, .995, .995);
2752 upperPad->SetBottomMargin(0);
2753 upperPad->SetFillStyle(0);
2757 myC_ratiopad->DrawClonePad();
2760 line.SetLineColor(kRed);
2761 line.SetLineWidth(1);
2763 double xmin = clonehist->GetXaxis()->GetXmin();
2764 double xmax = clonehist->GetXaxis()->GetXmax();
2769 myC_upperpad->SetBottomMargin(0);
2770 myC_upperpad->SetFillStyle(0);
2771 h->GetXaxis()->SetLabelSize(0.);
2772 h->GetXaxis()->SetTitleSize(0.);
2773 myC_upperpad->DrawClonePad();
2775 myC_upperpad->Clear();
2776 myC_main->DrawClonePad();
2782 for (TObject* o : *(myC_main->GetListOfPrimitives())) {
2783 o->SetBit(kCanDelete);
2784 if (
auto*
o2 =
dynamic_cast<TPad*
>(o)) {
2785 for (
auto* o3: *(
o2->GetListOfPrimitives())) {
2786 if (!
dynamic_cast<TFrame*
>(o3)) {
2787 o3->SetBit(kCanDelete);
2796 for (TObject* o : *(myC_upperpad->GetListOfPrimitives())) {
2797 o->SetBit(kCanDelete);
2798 if (
auto*
o2 =
dynamic_cast<TPad*
>(o)) {
2799 for (
auto* o3: *(
o2->GetListOfPrimitives())) {
2800 if (!
dynamic_cast<TFrame*
>(o3)) {
2801 o3->SetBit(kCanDelete);
2809 if (
display.find(
"Ref2DRatio") == std::string::npos &&
display.find(
"Ref2DSignif") == std::string::npos)
return;
2812 std::make_unique<TCanvas>(
"canvas_bottom",
"canvas_bottom", canvas_top->GetWw(), canvas_top->GetWh());
2813 auto canvas_all = std::make_unique<TCanvas>(
"canvas_all",
"canvas_all", canvas_top->GetWw(), canvas_top->GetWh());
2816 canvas_bot->SetTopMargin(0);
2818 h2Ref->Scale(h2->Integral() / h2Ref->Integral());
2820 TH2* comparison = (TH2*) (h2->Clone());
2821 comparison->Divide(h2, h2Ref, 1.0, 1.0);
2822 comparison->SetTitle(
"");
2823 formatTH2(canvas_bot.get(), comparison);
2825 if (
display.find(
"Ref2DRatio") != std::string::npos) {
2826 comparison->GetZaxis()->SetTitle(
"ratio to ref.");
2827 comparison->SetAxisRange(0.0, 2.0,
"Z");
2828 }
else if (
display.find(
"Ref2DSignif") != std::string::npos) {
2829 comparison->GetZaxis()->SetTitle(
"difference to ref. (#sigma)");
2830 comparison->SetAxisRange(-4.5, 4.5,
"Z");
2838 for (
int binx = 0; binx <= comparison->GetNbinsX(); binx++) {
2839 for (
int biny = 0; biny <= comparison->GetNbinsY(); biny++) {
2840 value_a = h2->GetBinContent(binx, biny);
2841 value_b = h2Ref->GetBinContent(binx, biny);
2843 sigma_a = h2->GetBinError(binx, biny);
2844 sigma_b = h2Ref->GetBinError(binx, biny);
2846 if (sigma_a == 0 && sigma_b == 0) signif = 0;
2847 else signif = (value_a - value_b) / sqrt((sigma_a * sigma_a + sigma_b * sigma_b));
2849 comparison->SetBinContent(binx, biny, signif);
2854 comparison->Draw(
"colz");
2857 TPad* pad_bot =
new TPad(
"pad_bot",
"pad_bot", 0.005, 0.060, 0.995, 0.550);
2858 TPad* pad_top =
new TPad(
"pad_top",
"pad_top", 0.005, 0.550, 0.995, 0.995);
2860 pad_bot->SetTopMargin(0);
2861 pad_top->SetBottomMargin(0);
2863 pad_bot->SetFillStyle(0);
2864 pad_top->SetFillStyle(0);
2870 canvas_bot->DrawClonePad();
2873 canvas_top->SetBottomMargin(0);
2874 canvas_top->SetFillStyle(0);
2875 h2->GetXaxis()->SetLabelSize(0.);
2876 h2->GetXaxis()->SetTitleSize(0.);
2877 canvas_top->DrawClonePad();
2879 canvas_top->Clear();
2881 canvas_all->DrawClonePad();
2886 double xmin =
h->GetXaxis()->GetXmin();
2887 double xmax =
h->GetXaxis()->GetXmax();
2889 std::size_t
found =
str.find(
"polynomial(");
2890 while (
found != std::string::npos) {
2891 std::size_t endpos =
str.find_first_of(
')',
found + 1);
2892 std::cout <<
"found;" <<
found <<
" endpos;" << endpos <<
"count "
2894 std::string inp_str =
str.substr(
found + 11, endpos -
found - 11);
2895 std::size_t found1 = 0;
2896 std::size_t found2 = inp_str.find_first_of(
',', found1);
2897 TF1* func =
new TF1(
"func",
"pol9",
xmin,
xmax);
2898 for (
int j = 0; j < 10; j++) {
2899 std::string value_str = inp_str.substr(found1, found2 - found1);
2900 double value_double = std::strtod(value_str.c_str(), NULL);
2901 func->SetParameter(j, value_double);
2902 if (found2 == std::string::npos) {
2905 found1 = found2 + 1;
2906 found2 = inp_str.find_first_of(
',', found1);
2916 std::size_t
found =
str.find(
"TLine");
2917 while (
found != std::string::npos) {
2918 std::size_t found1 =
str.find_first_of(
')',
found + 1);
2919 if (found1 != std::string::npos) {
2920 std::string coordinates =
str.substr(
found + 6, found1 -
found - 6);
2922 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
2925 found1 = coordinates.find_first_of(
',');
2926 if (found1 != std::string::npos) {
2927 std::string cx1 = coordinates.substr(0, found1);
2928 double x1 = std::strtod(cx1.c_str(), NULL);
2929 std::size_t found2 = coordinates.find_first_of(
',', found1 + 1);
2930 if (found2 != std::string::npos) {
2931 std::string cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2932 double y1 = std::strtod(cy1.c_str(), NULL);
2933 found1 = coordinates.find_first_of(
',', found2 + 1);
2934 if (found1 != std::string::npos) {
2935 std::string cx2 = coordinates.substr(found2 + 1, found1 - found2 - 1);
2936 double x2 = std::strtod(cx2.c_str(), NULL);
2937 std::string cy2 = coordinates.substr(found1 + 1, coordinates.size());
2938 double y2 = std::strtod(cy2.c_str(), NULL);
2940 TLine*
L =
new TLine;
2942 if (x1 <= 1.0 && x1 >= 0.0 && x2 <= 1.0 && x2 >= 0.0 && y1 <= 1.0 && y1 >= 0.0 &&
y2 <= 1.0 &&
2957 while (
found != std::string::npos) {
2958 std::string coordinates, cx1, cy1 =
"";
2959 std::size_t found1 =
str.find_first_of(
')',
found + 1);
2960 std::size_t found2 =
str.find_first_of(
'\'',
found + 1);
2961 if (found2 != std::string::npos) {
2962 found2 =
str.find_first_of(
'\"', found2 + 1);
2963 if (found2 != std::string::npos && found1 < found2) {
2964 found1 =
str.find_first_of(
')', found2 + 1);
2967 if (found1 != std::string::npos) {
2970 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
2973 found1 = coordinates.find_first_of(
',');
2974 if (found1 != std::string::npos) {
2975 cx1 = coordinates.substr(0, found1);
2976 double x1 = std::strtod(cx1.c_str(), NULL);
2977 found2 = coordinates.find_first_of(
',', found1 + 1);
2978 if (found2 != std::string::npos) {
2979 cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2980 double y1 = std::strtod(cy1.c_str(), NULL);
2981 std::string txt = coordinates.substr(found2 + 2, coordinates.size());
2984 TText* T =
new TText;
2986 if (x1 <= 1.0 && x1 >= 0.0 && y1 <= 1.0 && y1 >= 0.0) {
2987 T->DrawTextNDC(
x1,
y1, txt.c_str());
2990 T->DrawText(
x1,
y1, txt.c_str());
2999 while (
found != std::string::npos) {
3000 std::size_t found1 =
str.find_first_of(
')',
found + 1);
3001 if (found1 != std::string::npos) {
3002 std::string coordinates =
str.substr(
found + 6, found1 -
found - 6);
3004 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
3007 found1 = coordinates.find_first_of(
',');
3008 if (found1 != std::string::npos) {
3009 std::string cx1 = coordinates.substr(0, found1);
3010 double x1 = std::strtod(cx1.c_str(), NULL);
3011 std::size_t found2 = coordinates.find_first_of(
',', found1 + 1);
3012 if (found2 != std::string::npos) {
3013 std::string cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
3014 double y1 = std::strtod(cy1.c_str(), NULL);
3015 found1 = coordinates.find_first_of(
',', found2 + 1);
3016 if (found1 != std::string::npos) {
3017 std::string cx2 = coordinates.substr(found2 + 1, found1 - found2 - 1);
3018 double x2 = std::strtod(cx2.c_str(), NULL);
3019 std::string cy2 = coordinates.substr(found1 + 1, coordinates.size());
3020 double y2 = std::strtod(cy2.c_str(), NULL);
3022 TLine*
L =
new TLine;
3025 if (x1 <= 1.0 && x1 >= 0.0 && x2 <= 1.0 && x2 >= 0.0 && y1 <= 1.0 && y1 >= 0.0 &&
y2 <= 1.0 &&
3040 while (
found != std::string::npos) {
3041 std::string coordinates, cx1, cy1, txtsize =
"";
3042 std::size_t found1 =
str.find_first_of(
')',
found + 1);
3043 std::size_t found2 =
str.find_first_of(
'\'',
found + 1);
3044 if (found2 != std::string::npos) {
3045 found2 =
str.find_first_of(
'\"', found2 + 1);
3046 if (found2 != std::string::npos && found1 < found2) {
3047 found1 =
str.find_first_of(
')', found2 + 1);
3050 if (found1 != std::string::npos) {
3053 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
3056 found1 = coordinates.find_first_of(
',');
3057 if (found1 != std::string::npos) {
3058 cx1 = coordinates.substr(0, found1);
3059 double x1 = std::strtod(cx1.c_str(), NULL);
3060 found2 = coordinates.find_first_of(
',', found1 + 1);
3061 if (found2 != std::string::npos) {
3062 cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
3063 double y1 = std::strtod(cy1.c_str(), NULL);
3064 std::size_t found3 = coordinates.find_first_of(
',', found2 + 1);
3065 if (found3 != std::string::npos) {
3066 txtsize = coordinates.substr(found2 + 1, found3 - found2 - 1);
3067 double size = std::strtod(txtsize.c_str(), NULL);
3068 std::string txt = coordinates.substr(found3 + 2, coordinates.size());
3071 TText* T =
new TText;
3072 T->SetTextSize(
size / 100);
3074 if (x1 <= 1.0 && x1 >= 0.0 && y1 <= 1.0 && y1 >= 0.0) {
3075 T->DrawTextNDC(
x1,
y1, txt.c_str());
3078 T->DrawText(
x1,
y1, txt.c_str());
3089 if (
c == 0 ||
h == 0)
return;
3091 c->SetLeftMargin(0.15);
3092 c->SetRightMargin(0.13);
3093 c->SetBottomMargin(0.15);
3094 c->SetTopMargin(0.12);
3096 h->SetStats(kFALSE);
3097 h->SetLabelSize(0.04,
"X");
3098 h->SetLabelSize(0.04,
"Y");
3099 h->SetLabelFont(62,
"X");
3100 h->SetLabelFont(62,
"Y");
3101 h->SetTitleSize(0.04,
"X");
3102 h->SetTitleSize(0.04,
"Y");
3103 h->GetXaxis()->SetTitleFont(62);
3104 h->GetXaxis()->SetTitleSize(0.04);
3105 h->GetYaxis()->SetTitleFont(62);
3106 h->GetYaxis()->SetTitleSize(0.04);
3107 h->SetMarkerStyle(20);
3108 h->SetMarkerSize(0.8);
3110 h->SetTitleOffset(1.5,
"y");
3111 h->SetTitleOffset(0.9,
"x");
3113 h->SetNdivisions(504,
"X");
3114 h->SetNdivisions(504,
"Y");
3118 if (
c == 0 ||
h == 0)
return;
3120 c->SetLeftMargin(0.15);
3121 c->SetRightMargin(0.13);
3122 c->SetBottomMargin(0.15);
3123 c->SetTopMargin(0.12);
3125 h->SetStats(kFALSE);
3127 h->SetLabelSize(0.04,
"X");
3128 h->SetLabelSize(0.04,
"Y");
3129 h->SetLabelSize(0.04,
"Z");
3130 h->SetLabelFont(62,
"X");
3131 h->SetLabelFont(62,
"Y");
3132 h->SetLabelFont(62,
"Z");
3133 h->SetTitleSize(0.04,
"X");
3134 h->SetTitleSize(0.04,
"Y");
3135 h->SetTitleSize(0.04,
"Z");
3136 h->GetXaxis()->SetTitleFont(62);
3137 h->GetXaxis()->SetTitleSize(0.04);
3138 h->GetYaxis()->SetTitleFont(62);
3139 h->GetYaxis()->SetTitleSize(0.04);
3141 h->SetTitleOffset(1.5,
"y");
3142 h->SetTitleOffset(0.9,
"x");
3144 h->SetNdivisions(504,
"X");
3145 h->SetNdivisions(504,
"Y");
3149 if (
c == 0 ||
g == 0)
return;
3151 c->SetLeftMargin(0.15);
3152 c->SetRightMargin(0.13);
3153 c->SetBottomMargin(0.15);
3154 c->SetTopMargin(0.12);
3156 g->SetMarkerStyle(20);
3160 if (
c == 0 ||
e == 0)
return;
3162 c->SetLeftMargin(0.15);
3163 c->SetRightMargin(0.13);
3164 c->SetBottomMargin(0.15);
3165 c->SetTopMargin(0.12);
3183 DirToAssMap_t::const_iterator assessMapEnd =
m_assessMap.end();
3184 for (DirToAssMap_t::const_iterator
i =
m_assessMap.begin();
i != assessMapEnd; ++
i) {
3195 std::cerr <<
"Error writing file to " <<
fname << std::endl;
3205 if (img) getImageBuffer(img, myC,
x,
y);
3208 json = TBufferJSON::ConvertToJSON(myC);
3213 const std::string& nameJSON) {
3215 myC->SaveAs(namePNG.c_str());
3218 std::string
json = std::string(TBufferJSON::ConvertToJSON(myC));
3224 int cnvsType,
const std::string& pngfName,
const std::string& pngContent,
const std::string& jsonfName,
3225 const std::string& jsonfContent) {
3235 return(png ||
json);