11 #include <TBufferJSON.h>
13 #include <TDirectory.h>
14 #include <TEfficiency.h>
18 #include <TGraphAsymmErrors.h>
23 #include <TIterator.h>
34 #include <TImageDump.h>
37 #include <boost/algorithm/string/case_conv.hpp>
38 #include <boost/lexical_cast.hpp>
46 #include "TPluginManager.h"
48 #define BINLOEDGE(h, n) h->GetXaxis()->GetBinLowEdge(n)
49 #define BINWIDTH(h, n) h->GetXaxis()->GetBinWidth(n)
63 Double_t getScaleVal(std::string&
display) {
65 std::size_t found2 =
display.find_first_of(
',',
found + 1);
69 return boost::lexical_cast<Double_t>(
display.substr(
found + 9, found2 -
found - 9));
71 catch (boost::bad_lexical_cast
const&)
73 std::cerr <<
"Unable to cast scaling value " <<
display.substr(
found + 9, found2 -
found - 9) <<
" to double"
87 kBlue, kRed, kGray, kOrange, kViolet, kGreen + 1
93 if ((
h = gROOT->GetPluginManager()->FindHandler(
"TVirtualPS",
"image"))) {
94 if (
h->LoadPlugin() == -1)
return;
104 if ((
h = gROOT->GetPluginManager()->FindHandler(
"TVirtualPS",
"image"))) {
105 if (
h->LoadPlugin() == -1)
return;
121 if (
dir == 0)
return;
124 std::string
name(
dir->GetName());
125 if (
name ==
"Config" ||
name ==
"Results") {
130 std::string::size_type
i =
name.find_last_of(
'_');
131 if (
i == (
name.size() - 1)) {
136 DirMap_t::value_type dirmapVal(dirName,
dir);
137 dirmap.insert(dirmapVal);
139 DirMap_t::value_type dirmapVal(
"<top_level>",
dir);
140 dirmap.insert(dirmapVal);
145 TIter
next(
dir->GetListOfKeys());
147 while ((
key =
dynamic_cast<TKey*
>(
next())) != 0) {
149 TObject*
obj =
key->ReadObj();
150 TDirectory*
subdir =
dynamic_cast<TDirectory*
>(
obj);
152 std::string subdirName(
subdir->GetName());
153 std::string
fName(
"");
167 if (
obj ==
nullptr)
return;
170 TString obj_type =
obj->ClassName();
173 if (obj_type ==
"TDirectoryFile" || obj_type ==
"TDirectory" || obj_type ==
"TFile") {
175 std::string
name(
dir->GetName());
176 if (
name ==
"Config" ||
name ==
"Results") {
181 std::string::size_type
i =
name.find_last_of(
'_');
182 if (
i == (
name.size() - 1)) {
186 DirStrMap_t::value_type dirstrmapVal(objName,
obj);
187 dirstrmap.insert(dirstrmapVal);
189 DirStrMap_t::value_type dirstrmapVal(objName,
obj);
190 dirstrmap.insert(dirstrmapVal);
193 DirStrMap_t::value_type dirstrmapVal(
"<top_level>",
obj);
194 dirstrmap.insert(dirstrmapVal);
197 if (obj_type ==
"TDirectoryFile" || obj_type ==
"TDirectory" || obj_type ==
"TFile") {
200 TIter
next(
dir->GetListOfKeys());
202 while ((
key =
dynamic_cast<TKey*
>(
next())) != 0) {
204 std::string
fName(
"");
205 TObject* obj_in_dir =
key->ReadObj();
206 TString obj_in_dir_type = obj_in_dir->ClassName();
208 if (obj_in_dir_type ==
"TDirectoryFile" || obj_in_dir_type ==
"TDirectory" || obj_in_dir_type ==
"TFile" ||
209 obj_in_dir_type ==
"TObjString") {
210 std::string obj_in_dirName;
211 obj_in_dirName =
key->GetName();
217 fName += obj_in_dirName;
218 if (obj_in_dirName !=
"Config" && obj_in_dirName !=
"Results" && obj_in_dirName !=
"Version_name") {
235 std::string::size_type
i =
236 obj_in_dirName.find_last_of(
'_');
237 if (
i != (obj_in_dirName.size() - 1)) {
253 TIter
next(
dir->GetListOfKeys());
255 while ((
key =
dynamic_cast<TKey*
>(
next())) != 0) {
256 TObject*
obj =
key->ReadObj();
257 if (
dynamic_cast<TH1*
>(
obj) ||
dynamic_cast<TGraph*
>(
obj) ||
dynamic_cast<TEfficiency*
>(
obj)) {
258 const char*
path(
dir->GetPath());
259 std::string assName(
obj->GetName());
260 AssMap_t::value_type AssmapVal(assName,
path);
261 dirmap.insert(AssmapVal);
270 for (nlohmann::json::const_iterator
it = j.begin();
it != j.end(); ++
it) {
271 std::string sName = location;
272 std::string keyname =
it.key();
273 if (keyname !=
"Config" && keyname !=
"Results") {
275 std::string::size_type
i = keyname.find_last_of(
'_');
276 if (
i != (keyname.size() - 1)) {
277 if (location !=
"") {
281 std::cout <<
"name: " << sName <<
", path: " << path_to_file << sName <<
"\n";
282 valuestring =
it.value();
291 std::string stringName(
"Undefined");
292 if (file_version == 1) {
295 if (gROOT->cd(location.c_str()) == 0) {
301 while ((
key =
dynamic_cast<TKey*
>(mylist.Next())) != 0) {
302 TObject*
obj =
key->ReadObj();
303 stringName = (
obj->GetName());
307 }
else if (file_version == 2) {
310 std::size_t split_point = 0;
311 std::string JSON_name(
"");
312 std::string path_inTDir(
"");
313 std::string path_inJSON(
"");
314 if ((split_point = location.find(
"/Results/")) != std::string::npos) {
315 JSON_name =
"Results";
316 path_inTDir = location.substr(0, split_point);
317 path_inJSON = location.substr(split_point + 8);
318 }
else if ((split_point = location.find(
"/Config/")) != std::string::npos) {
319 JSON_name =
"Config";
320 path_inTDir = location.substr(0, split_point);
321 path_inJSON = location.substr(split_point + 7);
324 if (gROOT->cd(path_inTDir.c_str()) == 0) {
328 TObjString* JSON_obj =
dynamic_cast<TObjString*
>(
gDirectory->GetKey(JSON_name.c_str())->ReadObj());
330 std::cerr <<
"HanOutputFile::getStringName : dynamic cast failed\n";
333 std::string JSON_str = (JSON_obj->GetName());
335 nlohmann::json::json_pointer JSON_ptr(path_inJSON);
339 auto val = j.at(JSON_ptr);
340 if (!(
val.is_null())) stringName =
val.get<std::string>();
365 TDirectory* dirobj(0);
368 dirobj =
dynamic_cast<TDirectory*
>(
obj);
371 if (
found != std::string::npos) {
384 const std::string& pathInJSON,
const std::string& jsonName,
const std::string& path_to_JSON) {
385 gROOT->cd(path_to_JSON.c_str());
395 if (pathInJSON ==
"") {
397 return "JSON exists";
399 if (pathInJSON ==
"/") {
404 nlohmann::ordered_json::json_pointer
p1(pathInJSON);
405 std::string return_string;
408 auto val1 = j.at(
p1);
409 if (val1.type() == nlohmann::json::value_t::string) {
410 val1.get_to(return_string);
412 return_string = val1.dump();
414 std::cout <<
"Warning: Strange part of JSON" << std::endl;
427 return return_string;
432 std::cerr <<
"HanOutputFile::getNEntries(): "
433 <<
"No input file is open\n";
437 double Nentries = 0.0;
438 m_file->cd(location.c_str());
443 Nentries =
h->GetEntries();
449 Nentries =
g->GetN();
455 Nentries =
e->GetCopyTotalHisto()->GetEntries();
463 if (
const TH1*
h =
dynamic_cast<const TH1*
>(
obj)) {
464 return h->GetEntries();
465 }
else if (
const TGraph*
g =
dynamic_cast<const TGraph*
>(
obj)) {
467 }
else if (
const TEfficiency*
e =
dynamic_cast<const TEfficiency*
>(
obj)) {
468 return e->GetCopyTotalHisto()->GetEntries();
470 std::cerr <<
"HanOutputFile::getNEntries(): "
471 <<
"provided object is not a histogram or graph\n";
478 std::string
value(
"");
479 if (file_version == 1) {
480 gROOT->cd(location.c_str());
483 while ((
key =
dynamic_cast<TKey*
>(mylist.Next())) != 0) {
484 TObject*
obj =
key->ReadObj();
485 TDirectory*
subdir =
dynamic_cast<TDirectory*
>(
obj);
487 std::string name_subdir =
subdir->GetName();
488 gROOT->cd((location +
"/" + name_subdir).c_str());
491 while ((
key1 =
dynamic_cast<TKey*
>(mylist1.Next())) != 0) {
492 TObject* obj1 =
key1->ReadObj();
493 TDirectory* subsubdir =
dynamic_cast<TDirectory*
>(obj1);
494 if (subsubdir != 0) {
495 std::string name_subsubdir = obj1->GetName();
496 gROOT->cd((location +
"/" + name_subdir +
"/" + name_subsubdir).c_str());
499 while ((
key2 =
dynamic_cast<TKey*
>(mylist2.Next())) != 0) {
501 TDirectory* finaldir =
dynamic_cast<TDirectory*
>(
obj2);
503 std::string name_finaldir =
obj2->GetName();
504 gROOT->cd((location +
"/" + name_subdir +
"/" + name_subsubdir +
"/" + name_finaldir).c_str());
507 while ((key3 =
dynamic_cast<TKey*
>(mylist3.Next())) != 0) {
508 TObject* obj3 = key3->ReadObj();
509 std::string value_info = obj3->GetName();
510 value += (name_subsubdir + name_finaldir +
": " + value_info +
" ");
513 gROOT->cd((location +
"/" + name_subdir +
"/" + name_subsubdir).c_str());
514 }
else if (name_subsubdir !=
"name" && name_subsubdir !=
"Status" && name_subsubdir !=
"display") {
516 std::string value_info =
obj2->GetName();
517 value += (name_subsubdir +
": " + value_info +
" ");
521 gROOT->cd((location +
"/" + name_subdir).c_str());
522 }
else if (name_subdir !=
"name" && name_subdir !=
"Status") {
523 std::string value_info = obj1->GetName();
524 value += (name_subdir +
": " + value_info +
" ");
528 gROOT->cd((location).c_str());
532 }
else if (file_version == 2) {
534 std::string JSON_name(
"");
535 std::string TDir_path(
"");
536 std::string path_inJSON(
"");
537 std::size_t split_point = 0;
538 if ((split_point = location.rfind(
"/Results")) != std::string::npos) {
539 JSON_name =
"Results";
540 TDir_path = location.substr(0, split_point);
541 path_inJSON = location.substr(split_point + 8);
542 }
else if ((split_point = location.rfind(
"/Config")) != std::string::npos) {
543 JSON_name =
"Config";
544 TDir_path = location.substr(0, split_point);
545 path_inJSON = location.substr(split_point + 7);
548 if (gROOT->cd(TDir_path.c_str()) == 0) {
552 std::unique_ptr<TObjString> JSON_obj(
dynamic_cast<TObjString*
>(
gDirectory->GetKey(JSON_name.c_str())->ReadObj()));
554 std::cerr <<
"HanOutputFile::getInfo : dynamic cast failed\n";
557 std::string JSON_str = (JSON_obj->GetName());
559 nlohmann::ordered_json json_in_j;
560 if (path_inJSON !=
"") {
561 nlohmann::ordered_json::json_pointer JSON_ptr(path_inJSON);
564 json_in_j = j.at(JSON_ptr);
569 std::cout <<
"Wrong path: " << location <<
"\n";
573 json_in_j = std::move(j);
582 std::string
value(
"");
589 std::string
value(
"");
590 for (nlohmann::ordered_json::const_iterator
it = j.begin();
it != j.end(); ++
it) {
591 const auto&
key =
it.key();
592 auto val =
it.value();
593 if (strcmp(
val.type_name(),
"object") == 0) {
594 for (nlohmann::ordered_json::const_iterator
it1 =
val.begin();
it1 !=
val.end(); ++
it1) {
596 auto val1 =
it1.value();
597 if (strcmp(val1.type_name(),
"object") == 0) {
598 for (nlohmann::ordered_json::const_iterator it2 = val1.begin(); it2 != val1.end(); ++it2) {
599 const auto&
key2 = it2.key();
600 auto val2 = it2.value();
604 }
else if (
key1 !=
"name" &&
key1 !=
"Status" &&
key1 !=
"display") {
605 value += (
key1 +
": " + val1.get<std::string>() +
609 }
else if (
key !=
"name" &&
key !=
"Status") {
614 (
key +
": " +
val.get<std::string>() +
" ");
622 std::string space = leadingSpace;
623 std::string::size_type
i =
pathName.find_first_of(
'/');
624 if (
i != std::string::npos) {
625 std::string subPath(
pathName,
i + 1, std::string::npos);
637 if (
m_file != 0)
return true;
644 std::cerr <<
"HanOutputFile::getFileVersion(): "
645 <<
"No input file is open\n";
649 m_file->cd(
"HanMetadata_");
656 while ((
key = (TKey*)
next())) {
657 TString key_name =
key->GetName();
658 if (key_name ==
"V.2.3") {
672 std::cerr <<
"HanOutputFile::printAllGroupDirs(): "
673 <<
"No input file is open\n";
677 if (file_version == 1) {
682 DirMap_t::const_iterator idirend =
m_indirMap.end();
683 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
684 std::string idirName = idir->first;
685 const char*
path(idir->second->GetPath());
686 std::cout <<
"name: " << idirName <<
", path: " <<
path <<
"\n";
688 }
else if (file_version == 2) {
692 const char* path_to_file =
m_file->GetPath();
694 for (DirStrMap_t::const_iterator idir =
m_indirstrMap.begin(); idir != idirend; ++idir) {
695 std::string idirName = idir->first;
696 TDirectory* dirobj =
dynamic_cast<TDirectory*
>(idir->second);
698 std::string pathname(dirobj->GetPath());
699 std::cout <<
"name: " << idirName <<
", path: " << pathname <<
"\n";
701 std::cout <<
"name: " << idirName <<
", path: " << path_to_file << idirName <<
"\n";
702 TObjString* strobj =
dynamic_cast<TObjString*
>(idir->second);
704 std::cerr <<
"HanOutputFile::printAllGroupDirs(): dynamic cast failed\n";
707 std::string
content = strobj->GetName();
723 std::cerr <<
"HanOutputFile::stringListSystemPaths(): "
724 <<
"No input file is open\n";
734 DirMap_t::const_iterator idirend =
m_indirMap.end();
735 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
736 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
739 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
744 AssMap_t::const_iterator ias = aMapIter->second->begin();
745 if (ias != aMapIter->second->end()) {
746 std::string hisPath = ias->second;
747 std::string::size_type sepi = hisPath.find(
':');
748 if (sepi != std::string::npos) {
749 hisPath = std::string(hisPath, sepi + 1, std::string::npos);
751 std::string completeDir(location);
752 completeDir += hisPath;
761 std::ostringstream
result;
767 std::ostringstream
result;
773 std::ostringstream
result;
780 std::cerr <<
"HanOutputFile::streamAllDQAssessments(): "
781 <<
"No input file is open\n";
787 if ((file_version == 1) || (file_version == 2)) {
792 DirMap_t::const_iterator idirend =
m_indirMap.end();
793 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
794 std::string idirName = idir->first;
795 std::string pathname(idir->second->GetPath());
796 std::string::size_type
i = pathname.find_last_of(
'/');
797 if (
i != (pathname.size() - 1)) {
800 std::string pathnameS = pathname +
"Results/Status";
801 std::string pathnameA = pathname +
"Config/name";
802 std::string idirStatus =
getStringName(pathnameS, file_version);
803 std::string idirAlg =
getStringName(pathnameA, file_version);
806 std::string::size_type idirNamei = idirName.find_last_of(
'/');
807 if (idirNamei != std::string::npos) {
808 idirName = std::string(idirName, idirNamei + 1, std::string::npos);
811 std::string formattedName(
indent);
812 formattedName += idirName;
815 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
819 o << formattedName <<
" ";
821 o.setf(std::ios_base::right, std::ios_base::adjustfield);
823 o << idirStatus <<
" ";
833 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
836 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
841 AssMap_t::const_iterator aend = aMapIter->second->end();
842 std::string info1(
"");
843 std::string info2(
"");
844 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
845 std::string hisName = ias->first;
846 std::string hisPath = ias->second;
847 std::string Path1 = hisPath +
"/" + hisName +
"_/Results";
848 std::string Path2 = hisPath +
"/" + hisName +
"_/Config";
850 info1 =
getInfo(Path1, file_version);
852 info2 =
getInfo(Path2, file_version);
854 std::string formattedHistName(
indent);
856 std::string algo =
getStringName(Path2 +
"/name", file_version);
857 formattedHistName +=
" ";
858 formattedHistName += hisName;
860 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
864 o << formattedHistName <<
" ";
866 o.setf(std::ios_base::right, std::ios_base::adjustfield);
877 std::string hisTitle =
h->GetTitle();
881 if ((
h1 =
dynamic_cast<TH1*
>(
h)) &&
h1->GetDimension() == 1) {
882 o <<
" Underflow: " <<
h1->GetBinContent(0) <<
" Overflow: " <<
h1->GetBinContent(
h1->GetNbinsX() + 1)
885 if (info1 !=
"" && info2 !=
"") {
887 <<
"Config " << info2 <<
" Results "
888 <<
"Results " << info1 <<
" title " << hisTitle <<
"\n";
889 }
else if (info1 !=
"") {
890 o <<
"Results Results " << info1 <<
" title " << hisTitle <<
"\n";
891 }
else if (info2 !=
"") {
892 o <<
"Config Config " << info2 <<
" title " << hisTitle <<
"\n";
894 o <<
" title " << hisTitle <<
"\n";
908 std::cerr <<
"HanOutputFile::streamHistoAssessments(): "
909 <<
"No input file is open\n";
917 DirMap_t::const_iterator idirend =
m_indirMap.end();
918 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
919 std::string idirName = idir->first;
920 std::string pathname(idir->second->GetPath());
921 std::string::size_type
i = pathname.find_last_of(
'/');
922 if (
i != (pathname.size() - 1)) {
925 std::string idirStatus =
"Undefined";
926 std::string idirAlg =
"Undefined";
929 std::string::size_type idirNamei = idirName.find_last_of(
'/');
930 if (idirNamei != std::string::npos) {
931 idirName = std::string(idirName, idirNamei + 1, std::string::npos);
934 std::string formattedName;
935 formattedName += idirName;
937 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
940 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
945 AssMap_t::const_iterator aend = aMapIter->second->end();
946 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
947 std::string hisName = ias->first;
948 std::string hisPath = ias->second;
949 std::string formattedHistName;
954 std::string hisTitle(
h->GetTitle());
955 formattedHistName +=
"";
956 formattedHistName += hisName;
958 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
962 o << hisPath <<
"/" << formattedHistName <<
" "
974 std::cerr <<
"HanOutputFile::streamAllDQAssessments(): "
975 <<
"No input file is open\n";
983 DirMap_t::const_iterator idirend =
m_indirMap.end();
984 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
985 std::string idirName = idir->first;
986 std::string pathname(idir->second->GetPath());
987 std::string::size_type
i = pathname.find_last_of(
'/');
988 if (
i != (pathname.size() - 1)) {
991 std::string idirStatus =
"Undefined";
992 std::string idirAlg =
"Undefined";
995 std::string::size_type idirNamei = idirName.find_last_of(
'/');
996 if (idirNamei != std::string::npos) {
997 idirName = std::string(idirName, idirNamei + 1, std::string::npos);
1000 std::string formattedName(
indent);
1001 formattedName += idirName;
1004 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
1007 o << formattedName <<
" ";
1009 o.setf(std::ios_base::right, std::ios_base::adjustfield);
1011 o << idirStatus <<
" ";
1019 o.flags(savedFlags);
1021 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
1024 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
1029 AssMap_t::const_iterator aend = aMapIter->second->end();
1030 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
1031 std::string hisName = ias->first;
1032 std::string hisPath = ias->second;
1035 std::string info1, info2;
1038 std::string formattedHistName(
indent);
1039 std::string
status =
"Undefined";
1040 std::string algo =
"Undefined";
1045 std::string hisTitle(
h->GetTitle());
1046 formattedHistName +=
" ";
1047 formattedHistName += hisName;
1049 const std::ios_base::fmtflags savedFlags = o.setf(std::ios_base::left, std::ios_base::adjustfield);
1052 o << formattedHistName <<
" ";
1054 o.setf(std::ios_base::right, std::ios_base::adjustfield);
1061 if (info1 !=
"" && info2 !=
"") {
1063 <<
"Config " << info2 <<
" Results "
1064 <<
"Results " << info1 <<
" title " << hisTitle <<
"\n";
1065 }
else if (info1 !=
"") {
1066 o <<
"Results Results " << info1 <<
" title " << hisTitle <<
"\n";
1067 }
else if (info2 !=
"") {
1068 o <<
"Config Config " << info2 <<
" title " << hisTitle <<
"\n";
1070 o <<
" title " << hisTitle <<
"\n";
1075 o.flags(savedFlags);
1083 std::cerr <<
"HanOutputFile::saveAllHistograms(): "
1084 <<
"No input file is open\n";
1094 DirMap_t::const_iterator idirend =
m_indirMap.end();
1095 for (DirMap_t::const_iterator idir =
m_indirMap.begin(); idir != idirend; ++idir) {
1096 DirToAssMap_t::const_iterator aMapIter =
m_assessMap.find(idir->first);
1099 DirToAssMap_t::value_type aMapVal(idir->first, aMap);
1103 AssMap_t::const_iterator aend = aMapIter->second->end();
1104 for (AssMap_t::const_iterator ias = aMapIter->second->begin(); ias != aend; ++ias) {
1105 std::string hisName = ias->first;
1106 std::string hisPath = ias->second;
1107 std::string::size_type sepi = hisPath.find(
':');
1108 if (sepi != std::string::npos) {
1109 hisPath = std::string(hisPath, sepi + 1, std::string::npos);
1111 std::string completeDir(location);
1112 completeDir += hisPath;
1114 std::cout <<
"Saving " << completeDir <<
" " << hisName << std::endl;
1118 hisName, std::move(completeDir), idir->second, drawRefs, run_min_LB, (hisPath +
"/" + hisName), cnvsType);
1119 if (isSaved) ++nSaved;
1123 std::cerr <<
"Exception caught: " <<
e.what() << std::endl;
1131 gVirtualPS->Open(myC->GetName(), 114);
1133 auto pImgDump =
dynamic_cast<TImageDump*
>(gVirtualPS);
1135 (*img) = pImgDump->GetImage();
1137 (*img)->GetImageBuffer(
x,
y, TImage::kPng);
1143 bool drawRefs,
const std::string& run_min_LB,
const std::string&
pathName,
1145 std::pair<std::string, std::string> pngAndJson =
1148 if (pngAndJson.first ==
"" && pngAndJson.second ==
"") {
1151 std::string namePNG = nameHis;
1152 std::string nameJSON = nameHis;
1155 nameJSON +=
".json";
1157 std::string::size_type
i = location.find_last_of(
'/');
1158 if (
i != (location.size() - 1)) {
1162 namePNG = location + namePNG;
1163 nameJSON = location + nameJSON;
1164 return saveFile(cnvsType, namePNG, pngAndJson.first, nameJSON, pngAndJson.second);
1168 const std::string& nameHis, TDirectory* groupDir,
bool drawRefs,
const std::string& run_min_LB,
1176 const std::string& nameHis, TDirectory* groupDir,
bool drawRefs,
const std::string& run_min_LB,
1184 bool drawRefs,
const std::string& run_min_LB,
1185 const std::string&
pathName,
int cnvsType) {
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 {
1954 TDirectory* groupDir1,
1955 TDirectory* groupDir2,
bool drawRefs,
1956 const std::string& run_min_LB,
const std::string&
pathName,
1960 gStyle->SetFrameBorderMode(0);
1961 gStyle->SetFrameFillColor(0);
1962 gStyle->SetCanvasBorderMode(0);
1963 gStyle->SetPadBorderMode(0);
1964 gStyle->SetPadColor(0);
1965 gStyle->SetCanvasColor(0);
1966 gStyle->SetTitleColor(0);
1967 gStyle->SetStatColor(0);
1968 gStyle->SetFillColor(1);
1969 gStyle->SetPalette(1, 0);
1970 gStyle->SetTitleFontSize(0.06);
1971 gStyle->SetTitleH(0.06);
1972 gStyle->SetMarkerStyle(20);
1973 gStyle->SetOptStat(111100);
1974 gStyle->SetStatBorderSize(0);
1975 gStyle->SetStatX(0.99);
1976 gStyle->SetStatY(0.99);
1977 gStyle->SetStatW(0.2);
1978 gStyle->SetStatH(0.1);
1981 std::string pathname(groupDir1->GetPath());
1984 bool LookForDisplay;
1985 if (file_version == 1) {
1986 LookForDisplay =
containsDir(
"Config/annotations/display", (pathname +
"/" + nameHis +
"_"));
1987 if (LookForDisplay) {
1988 display =
getStringName(pathname +
"/" + nameHis +
"_/Config/annotations/display", file_version);
1990 }
else if (file_version == 2) {
1991 std::optional<std::string> JSON_content;
1992 LookForDisplay =
containsDir((nameHis +
"_"), pathname);
1993 if (LookForDisplay) {
1994 JSON_content =
containsKeyInJSON(
"/annotations/display",
"Config", (pathname +
"/" + nameHis +
"_"));
1996 LookForDisplay =
true;
1998 LookForDisplay =
false;
2001 if (LookForDisplay) {
2002 display = JSON_content.value();
2008 std::string drawopt =
"";
2009 while (
found != std::string::npos) {
2010 std::size_t found1 =
display.find_first_of(
',',
found + 1);
2011 if (found1 != std::string::npos) {
2012 drawopt += boost::algorithm::to_lower_copy(
display.substr(
found + 5, found1 -
found - 5));
2020 TKey* hkey = groupDir1->FindKey(nameHis.c_str());
2022 TKey* hkey2 = groupDir2->FindKey(nameHis.c_str());
2023 if (hkey == 0 || hkey2 == 0) {
2024 std::cerr <<
"Did not find TKey for \"" << nameHis <<
"\", will not save this histogram.\n";
2029 TObject* hobj = hkey->ReadObj();
2030 TObject* hobj2 = hkey2->ReadObj();
2033 TH2* h2(0), *h2_2(0), *h2Diff(0);
2034 TGraph*
g(0), *
g2(0);
2035 TEfficiency*
e(0), *
e2(0);
2038 std::string nameJSON = nameHis;
2039 std::string namePNG = nameHis;
2041 nameJSON +=
".json";
2042 std::string::size_type
i = location.find_last_of(
'/');
2043 if (
i != (location.size() - 1)) {
2046 namePNG = location + namePNG;
2047 nameJSON = location + nameJSON;
2048 std::string AlgoName =
getStringName(pathname +
"/" + nameHis +
"_/Config/name", file_version);
2052 if (
found != std::string::npos) {
2053 std::size_t found1 =
display.find_first_of(
',',
found + 1);
2059 if ((
h =
dynamic_cast<TH1*
>(hobj)) != 0 && (
hist2 =
dynamic_cast<TH1*
>(hobj2)) != 0) {
2060 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
2066 std::string tmpdraw(drawopt);
2067 if ((h2 =
dynamic_cast<TH2*
>(
h)) != 0 && ((h2_2 =
dynamic_cast<TH2*
>(
hist2)) != 0)) {
2069 h2Diff = (TH2*) h2->Clone(
"difference");
2080 h2Diff->Add(h2, h2_2, 1.0, -1.0);
2081 h2Diff->SetLineColor(2);
2082 h2Diff->SetMarkerColor(2);
2083 if (!
drawH2(myC.get(), h2Diff, tmpdraw,
display))
return false;
2087 t.SetTextSize(0.03);
2088 t.DrawLatex(0.02, 0.04, (run_min_LB +
" difference").c_str());
2091 tt.SetTextSize(0.03);
2095 }
else if (
h != 0 &&
hist2 != 0) {
2098 if (
display.find(
"ScaleRef") != std::string::npos) {
2100 }
else if (
h->Integral(
"width") > 0.0 &&
hist2->Integral(
"width") > 0.0 &&
2101 (AlgoName.find(
"BinContentComp") == std::string::npos) &&
2102 (
display.find(
"NoNorm") == std::string::npos)) {
2103 scale =
h->Integral(
"width") /
hist2->Integral(
"width");
2106 double ymin = (
hist2->GetMinimum() <
h->GetMinimum()) ?
hist2->GetMinimum() :
h->GetMinimum();
2107 double ymax = (
hist2->GetMaximum() >
h->GetMaximum()) ?
hist2->GetMaximum() :
h->GetMaximum();
2108 double yMargin = (
ymax -
ymin) * 0.05;
2109 h->SetAxisRange(
ymin - yMargin,
ymax + yMargin,
"Y");
2111 h->SetMarkerColor(1);
2114 hist2->SetMarkerColor(4);
2115 hist2->SetLineColor(4);
2116 hist2->SetFillStyle(0);
2117 hist2->SetLineWidth(2);
2119 if (file_version == 1) {
2120 groupDir1->cd((nameHis +
"_/Results").c_str());
2122 groupDir1->cd((nameHis +
"_").c_str());
2127 if (!
drawH1(myC.get(),
h, hRef, tmpdraw,
display, AlgoName))
return false;
2132 legend =
new TLegend(0.55, 0.77, 0.87, 0.87);
2136 legend->SetBorderSize(0);
2138 std::size_t foundN1 = run_min_LB.find_first_of(
"-");
2139 std::size_t foundN2 = run_min_LB.find_first_of(
',');
2141 legend->AddEntry(
h, (
"Run " + run_min_LB.substr(5, foundN1 - 5)).c_str());
2142 legend->AddEntry(
hist2, (
"Run " + run_min_LB.substr(foundN1 + 1, foundN2 - foundN1 - 1)).c_str());
2144 legend->AddEntry(hRef,
"Reference");
2150 t.SetTextSize(0.03);
2151 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2154 tt.SetTextSize(0.03);
2164 if (((
g =
dynamic_cast<TGraph*
>(hobj)) != 0) && ((
g2 =
dynamic_cast<TGraph*
>(hobj2)) != 0)) {
2165 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
2167 if (
g->GetMinimum() >= 0. &&
g2->GetMinimum() >= 0. &&
g->GetMaximum() > 0. &&
g2->GetMaximum() > 0.) {
2168 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2172 g->Draw((std::string(
"AP") + drawopt).c_str());
2174 g2->SetMarkerColor(2);
2175 g2->SetLineColor(2);
2176 g2->Draw((std::string(
"P") + drawopt +
" same").c_str());
2179 t.SetTextSize(0.03);
2180 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2183 tt.SetTextSize(0.03);
2191 if (((
e =
dynamic_cast<TEfficiency*
>(hobj)) != 0) && ((
e2 =
dynamic_cast<TEfficiency*
>(hobj2)) != 0)) {
2192 auto myC = std::make_unique<TCanvas>(nameHis.c_str(),
"myC", ww,
wh);
2197 e->Draw((std::string(
"AP") + drawopt).c_str());
2201 e->GetPaintedGraph()->GetXaxis()->SetTitleColor();
2204 e2->SetMarkerColor(2);
2205 e2->SetLineColor(2);
2206 e2->Draw((std::string(
"P") + drawopt +
" same").c_str());
2209 t.SetTextSize(0.03);
2210 t.DrawLatex(0.02, 0.04, run_min_LB.c_str());
2213 tt.SetTextSize(0.03);
2229 std::string drawopt(drawop);
2231 if (h2->GetMinimum() >= 0 && h2->GetMaximum() > 0) {
2232 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2233 gPad->SetLogz(
display.find(
"LogZ") != std::string::npos);
2235 gPad->SetLogy(
false);
2238 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2240 gPad->SetLogx(
false);
2243 if (h2->GetXaxis()->GetXmin() >= h2->GetXaxis()->GetXmax()) {
2244 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
2245 <<
"Inconsistent x-axis settings: min=" << h2->GetXaxis()->GetXmin() <<
", "
2246 <<
"max=" << h2->GetXaxis()->GetXmax() <<
", "
2247 <<
"Will not save this histogram.\n";
2250 if (h2->GetYaxis()->GetXmin() >= h2->GetYaxis()->GetXmax()) {
2251 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
2252 <<
"Inconsistent y-axis settings: min=" << h2->GetYaxis()->GetXmin() <<
", "
2253 <<
"max=" << h2->GetYaxis()->GetXmax() <<
", "
2254 <<
"Will not save this histogram.\n";
2258 if (drawopt ==
"") {
2261 h2->Draw(drawopt.c_str());
2271 gPad->SetGridx(
display.find(
"SetGridx") != std::string::npos);
2272 gPad->SetGridy(
display.find(
"SetGridy") != std::string::npos);
2274 if (
found != std::string::npos) {
2275 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
2276 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
2277 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
2278 int n1 = std::strtol(cn.c_str(), NULL, 0);
2279 gStyle->SetPalette((Int_t)
n1);
2282 if (
found != std::string::npos) {
2283 std::size_t found1 =
display.find_first_of(
'(',
found + 1);
2284 std::size_t found2 =
display.find_first_of(
",)",
found + 1);
2285 std::string cn =
display.substr(found1 + 1, found2 - found1 - 1);
2286 int n1 = std::strtol(cn.c_str(), NULL, 0);
2287 gStyle->SetGridStyle((Style_t)
n1);
2289 if (!drawopt.empty()) {
2297 if (
found != std::string::npos) {
2298 Double_t minstat = 0.;
2299 std::size_t fpos1, fpos2, fpos;
2300 fpos =
display.find(
"MinStat");
2301 if (fpos != std::string::npos) {
2302 fpos1 =
display.find(
'(', fpos + 1);
2303 if (fpos1 != std::string::npos) {
2304 fpos2 =
display.find(
')', fpos1 + 1);
2305 if (fpos2 != std::string::npos) {
2306 std::string s_minstat =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
2307 minstat = std::strtod(s_minstat.c_str(), NULL);
2311 std::string fitopt(
"");
2312 fpos =
display.find(
"FitOption");
2313 if (fpos != std::string::npos) {
2314 fpos1 =
display.find(
'(', fpos + 1);
2315 if (fpos1 != std::string::npos) {
2316 fpos2 =
display.find(
')', fpos1 + 1);
2317 if (fpos2 != std::string::npos) {
2318 fitopt =
display.substr(fpos1 + 1, fpos2 - fpos1 - 1);
2323 std::size_t found1 =
display.find(
"doublegaus");
2324 if (found1 != std::string::npos) {
2325 std::size_t found2 =
display.find(
'(', found1 + 1);
2326 if (found2 != std::string::npos) {
2327 std::size_t found3 =
display.find(
')', found2 + 1);
2328 if (found3 != std::string::npos) {
2329 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2330 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2331 std::size_t found4 =
display.find(
',', found2 + 1);
2332 if (found4 != std::string::npos) {
2333 range =
display.substr(found4 + 1, found3 - found4 - 1);
2334 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2338 f1->GetParameters(
par);
2339 TF1* func =
new TF1(
"func",
"gaus(0)+gaus(3)",
xmin,
xmax);
2340 func->SetParameters(
par);
2341 func->SetParameter(3,
h->GetBinContent(
h->GetMaximumBin()));
2342 func->SetParameter(4,
h->GetMean());
2343 func->SetParameter(5,
par[2]);
2344 func->SetLineColor(kRed);
2345 func->SetLineWidth(2);
2346 if (
h->GetEffectiveEntries() > minstat) {
2347 h->Fit(func, (
"rq" + fitopt).c_str());
2356 std::size_t found1 =
display.find(
"gauspluspol1");
2357 if (found1 != std::string::npos) {
2358 std::size_t found2 =
display.find(
'(', found1 + 1);
2359 if (found2 != std::string::npos) {
2360 std::size_t found3 =
display.find(
')', found2 + 1);
2361 if (found3 != std::string::npos) {
2362 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2363 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2364 std::size_t found4 =
display.find(
',', found2 + 1);
2365 if (found4 != std::string::npos) {
2366 range =
display.substr(found4 + 1, found3 - found4 - 1);
2367 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2368 TF1* func =
new TF1(
"func",
"gaus(0)+pol1(3)",
xmin,
xmax);
2369 func->SetLineColor(kRed);
2370 func->SetLineWidth(2);
2371 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
2372 if (
h->GetEffectiveEntries() > minstat) {
2373 h->Fit(func, (
"rq" + fitopt).c_str());
2381 found1 =
display.find(
"gausplusexpo");
2382 if (found1 != std::string::npos) {
2383 std::size_t found2 =
display.find(
'(', found1 + 1);
2384 if (found2 != std::string::npos) {
2385 std::size_t found3 =
display.find(
')', found2 + 1);
2386 if (found3 != std::string::npos) {
2387 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2388 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2389 std::size_t found4 =
display.find(
',', found2 + 1);
2390 if (found4 != std::string::npos) {
2391 range =
display.substr(found4 + 1, found3 - found4 - 1);
2392 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2394 TF1* func =
new TF1(
"func",
"gaus(0)+expo(3)",
xmin,
xmax);
2395 func->SetLineColor(kRed);
2396 func->SetLineWidth(2);
2397 func->SetParameters(
h->GetBinContent(
h->GetMaximumBin()),
h->GetMean(),
h->GetRMS());
2398 if (
h->GetEffectiveEntries() > minstat) {
2399 h->Fit(func, (
"rq" + fitopt).c_str());
2408 if (found2 != std::string::npos) {
2409 std::size_t found3 =
display.find(
')', found2 + 1);
2410 if (found3 != std::string::npos) {
2411 std::string
range =
display.substr(found2 + 1, found3 - found2 - 1);
2412 Double_t
xmin = std::strtod(
range.c_str(), NULL);
2413 std::size_t found4 =
display.find(
',', found2 + 1);
2414 if (found4 != std::string::npos) {
2415 range =
display.substr(found4 + 1, found3 - found4 - 1);
2416 Double_t
xmax = std::strtod(
range.c_str(), NULL);
2417 TF1* func =
new TF1(
"func",
"gaus",
xmin,
xmax);
2418 func->SetLineColor(kRed);
2419 func->SetLineWidth(2);
2420 if (
h->GetEffectiveEntries() > minstat) {
2421 h->Fit(func, (
"rq" + fitopt).c_str());
2431 if (!drawopt.empty()) {
2437 TCanvas* myC, TH1*
h, TH1* hRef, std::string& drawopt, std::string&
display, std::string& AlgoName) {
2439 if (
display.find(
"StatBox") != std::string::npos) {
2442 if (
h->GetXaxis()->GetXmin() >=
h->GetXaxis()->GetXmax()) {
2443 std::cerr <<
"HanOutputFile::saveHistogramToFile(): "
2444 <<
"Inconsistent x-axis settings: min=" <<
h->GetXaxis()->GetXmin() <<
", "
2445 <<
"max=" <<
h->GetXaxis()->GetXmax() <<
", "
2446 <<
"Will not save this histogram.\n";
2454 if (
h->GetMinimum() >= 0 &&
h->GetMaximum() > 0.) {
2455 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2457 gPad->SetLogy(
false);
2460 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2462 gPad->SetLogx(
false);
2465 h->Draw(drawopt.c_str());
2474 TCanvas* myC, TH1* hRef, TH1*
h, std::string& drawopt, std::string&
display, std::string& AlgoName) {
2478 hRef->SetMarkerColor(2);
2479 hRef->SetLineColor(2);
2480 hRef->SetLineWidth(2);
2481 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
2482 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
2495 bool isLogY = (
display.find(
"LogY") != std::string::npos);
2501 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
"Y");
2504 std::cerr <<
"ymin is <0. and LogY requested for histogram \"" <<
h->GetName() <<
" "
2505 <<
h->GetDirectory()->GetPath() <<
"\", ymin=" <<
ymin << std::endl;
2508 double yMargin = (
ymax -
ymin) * 0.05;
2509 h->SetAxisRange(
ymin - yMargin,
ymax + yMargin,
"Y");
2512 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
2514 if (
h->GetMinimum() >= 0 && hRef->GetMinimum() >= 0 &&
h->GetMaximum() > 0 && hRef->GetMaximum() > 0) {
2515 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2518 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2520 h->Draw(drawopt.c_str());
2521 hRef->Draw((
"SAME" + drawopt).c_str());
2522 h->Draw((
"SAME" + drawopt).c_str());
2525 if (
display.find(
"ScaleRef") != std::string::npos) {
2527 }
else if (
h->Integral(
"width") > 0.0 && hRef->Integral(
"width") > 0.0 &&
2528 (AlgoName.find(
"BinContentComp") == std::string::npos) &&
2529 (
display.find(
"NoNorm") == std::string::npos)) {
2530 scale =
h->Integral(
"width") / hRef->Integral(
"width");
2533 hRef->SetMarkerColor(15);
2534 hRef->SetFillColor(15);
2535 hRef->SetLineColor(15);
2536 double ymin = (hRef->GetMinimum() <
h->GetMinimum()) ? hRef->GetMinimum() :
h->GetMinimum();
2537 double ymax = (hRef->GetMaximum() >
h->GetMaximum()) ? hRef->GetMaximum() :
h->GetMaximum();
2549 bool isLogY = (
display.find(
"LogY") != std::string::npos);
2557 h->SetAxisRange(
exp(lymin - (lymax - lymin) * 0.05),
exp(lymax + (lymax - lymin) * 0.05),
"Y");
2560 std::cerr <<
"ymin is <=0. and LogY requested for histogram \"" <<
h->GetName() <<
" "
2561 <<
h->GetDirectory()->GetPath() <<
"\", ymin=" <<
ymin << std::endl;
2565 h->SetAxisRange(
ymin - yDiff * 0.05,
ymax + yDiff * 0.05,
"Y");
2569 h->GetXaxis()->SetRangeUser(
xmin,
xmax);
2571 if (
h->GetMinimum() >= 0. && hRef->GetMinimum() >= 0. &&
h->GetMaximum() > 0. && hRef->GetMaximum() > 0.) {
2572 gPad->SetLogy(
display.find(
"LogY") != std::string::npos);
2575 gPad->SetLogx(
display.find(
"LogX") != std::string::npos);
2578 h->Draw(drawopt.c_str());
2579 hRef->Draw((
"SAME" + drawopt).c_str());
2580 h->Draw((
"SAME" + drawopt).c_str());
2590 std::size_t
found =
str.find(
"AxisRange");
2591 while (
found != std::string::npos) {
2596 std::string coordinates, cx1, cy1 =
"";
2597 std::size_t found1 =
str.find_first_of(
')',
found + 1);
2598 std::size_t found2 =
str.find_first_of(
"\'",
found + 1);
2599 if (found2 != std::string::npos) {
2600 found2 =
str.find_first_of(
"\'", found2 + 1);
2601 if (found1 < found2) {
2602 found1 =
str.find_first_of(
')', found2 + 1);
2636 if (found1 != std::string::npos) {
2638 found1 = coordinates.find_first_of(
',');
2639 if (found1 != std::string::npos) {
2640 cx1 = coordinates.substr(0, found1);
2641 double x1 = std::strtod(cx1.c_str(), NULL);
2642 found2 = coordinates.find_first_of(
',', found1 + 1);
2643 if (found2 != std::string::npos) {
2644 cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2645 double y1 = std::strtod(cy1.c_str(), NULL);
2646 std::string txt = coordinates.substr(found2 + 2, coordinates.size());
2648 if (txt ==
"X" &&
x1 <
y1) {
2649 h->GetXaxis()->SetRangeUser(
x1,
y1);
2651 if (txt ==
"Y" &&
x1 <
y1) {
2652 h->SetAxisRange(
x1,
y1,
"Y");
2654 if (txt ==
"Z" &&
x1 <
y1) {
2655 h->SetAxisRange(
x1,
y1,
"Z");
2658 std::string txt = coordinates.substr(found1 + 2, coordinates.size());
2660 if (txt[1] ==
'M') {
2661 if (txt ==
"XMax") {
2663 h->GetXaxis()->SetRangeUser(
xmin,
x1);
2665 if (txt ==
"XMin") {
2667 h->GetXaxis()->SetRangeUser(
x1,
xmax);
2669 if (txt ==
"YMax") {
2670 double ymin =
h->GetMinimum();
2671 h->SetAxisRange(
ymin,
x1,
"Y");
2673 if (txt ==
"YMin") {
2674 double ymax =
h->GetMaximum();
2675 h->SetAxisRange(
x1,
ymax,
"Y");
2690 if (
display.find(
"RatioPad") == std::string::npos)
return;
2692 unsigned int ww = myC_upperpad->GetWw();
2693 unsigned int wh = myC_upperpad->GetWh();
2694 std::string padname =
"PAD";
2695 std::string padname_ratio =
"PAD_main";
2696 auto myC_ratiopad = std::make_unique<TCanvas>(padname_ratio.c_str(),
"myC_ratiopad", ww,
wh);
2697 auto myC_main = std::make_unique<TCanvas>(padname.c_str(),
"myC_main", ww,
wh);
2701 myC_ratiopad->SetTopMargin(0);
2702 myC_ratiopad->SetLogx(
display.find(
"LogX") != std::string::npos);
2711 std::unique_ptr<TH1F> clonehist;
2712 std::unique_ptr<TH1F> clonehistref;
2715 clonehist.reset((
TH1F*) ph->ProjectionX());
2717 clonehist.reset((
TH1F*)
h->Clone());
2718 if (!clonehist->GetSumw2()) {
2723 clonehistref.reset((
TH1F*) phRef->ProjectionX());
2725 clonehistref.reset((
TH1F*) hRef->Clone());
2726 if (!clonehistref->GetSumw2()) {
2727 clonehistref->Sumw2();
2730 if (!clonehist or !clonehistref) {
2733 clonehist->SetBit(kCanDelete);
2734 clonehist->Divide(clonehistref.get());
2738 formatTH1(myC_ratiopad.get(), clonehist.get());
2739 clonehist->SetTitle(
"");
2742 double delta = 0.75;
2743 if (
display.find(
"delta(") != std::string::npos) {
2746 clonehist->SetAxisRange(1. - delta, 1. + delta,
"Y");
2748 clonehist->GetYaxis()->SetNdivisions(3,
true);
2749 clonehist->SetMarkerStyle(1);
2750 clonehist->Draw(
"E");
2751 clonehist->GetXaxis()->SetTitleSize(0.11);
2752 clonehist->GetXaxis()->SetLabelSize(0.11);
2753 clonehist->GetYaxis()->SetTitleSize(0.11);
2754 clonehist->GetYaxis()->SetLabelSize(0.11);
2756 TPad* lowerPad =
new TPad(
"lowerPad",
"lowerPad", .005, .060, .995, .250);
2757 lowerPad->SetTopMargin(0);
2758 lowerPad->SetFillStyle(0);
2760 TPad* upperPad =
new TPad(
"upperPad",
"upperPad", .005, .250, .995, .995);
2761 upperPad->SetBottomMargin(0);
2762 upperPad->SetFillStyle(0);
2766 myC_ratiopad->DrawClonePad();
2769 line.SetLineColor(kRed);
2770 line.SetLineWidth(1);
2772 double xmin = clonehist->GetXaxis()->GetXmin();
2773 double xmax = clonehist->GetXaxis()->GetXmax();
2778 myC_upperpad->SetBottomMargin(0);
2779 myC_upperpad->SetFillStyle(0);
2780 h->GetXaxis()->SetLabelSize(0.);
2781 h->GetXaxis()->SetTitleSize(0.);
2782 myC_upperpad->DrawClonePad();
2784 myC_upperpad->Clear();
2785 myC_main->DrawClonePad();
2791 for (TObject* o : *(myC_main->GetListOfPrimitives())) {
2792 o->SetBit(kCanDelete);
2793 if (
auto*
o2 =
dynamic_cast<TPad*
>(o)) {
2794 for (
auto* o3: *(
o2->GetListOfPrimitives())) {
2795 if (!
dynamic_cast<TFrame*
>(o3)) {
2796 o3->SetBit(kCanDelete);
2805 for (TObject* o : *(myC_upperpad->GetListOfPrimitives())) {
2806 o->SetBit(kCanDelete);
2807 if (
auto*
o2 =
dynamic_cast<TPad*
>(o)) {
2808 for (
auto* o3: *(
o2->GetListOfPrimitives())) {
2809 if (!
dynamic_cast<TFrame*
>(o3)) {
2810 o3->SetBit(kCanDelete);
2818 if (
display.find(
"Ref2DRatio") == std::string::npos &&
display.find(
"Ref2DSignif") == std::string::npos)
return;
2821 std::make_unique<TCanvas>(
"canvas_bottom",
"canvas_bottom", canvas_top->GetWw(), canvas_top->GetWh());
2822 auto canvas_all = std::make_unique<TCanvas>(
"canvas_all",
"canvas_all", canvas_top->GetWw(), canvas_top->GetWh());
2825 canvas_bot->SetTopMargin(0);
2827 h2Ref->Scale(h2->Integral() / h2Ref->Integral());
2829 TH2* comparison = (TH2*) (h2->Clone());
2830 comparison->Divide(h2, h2Ref, 1.0, 1.0);
2831 comparison->SetTitle(
"");
2832 formatTH2(canvas_bot.get(), comparison);
2834 if (
display.find(
"Ref2DRatio") != std::string::npos) {
2835 comparison->GetZaxis()->SetTitle(
"ratio to ref.");
2836 comparison->SetAxisRange(0.0, 2.0,
"Z");
2837 }
else if (
display.find(
"Ref2DSignif") != std::string::npos) {
2838 comparison->GetZaxis()->SetTitle(
"difference to ref. (#sigma)");
2839 comparison->SetAxisRange(-4.5, 4.5,
"Z");
2847 for (
int binx = 0; binx <= comparison->GetNbinsX(); binx++) {
2848 for (
int biny = 0; biny <= comparison->GetNbinsY(); biny++) {
2849 value_a = h2->GetBinContent(binx, biny);
2850 value_b = h2Ref->GetBinContent(binx, biny);
2852 sigma_a = h2->GetBinError(binx, biny);
2853 sigma_b = h2Ref->GetBinError(binx, biny);
2855 if (sigma_a == 0 && sigma_b == 0) signif = 0;
2856 else signif = (value_a - value_b) / sqrt((sigma_a * sigma_a + sigma_b * sigma_b));
2858 comparison->SetBinContent(binx, biny, signif);
2863 comparison->Draw(
"colz");
2866 TPad* pad_bot =
new TPad(
"pad_bot",
"pad_bot", 0.005, 0.060, 0.995, 0.550);
2867 TPad* pad_top =
new TPad(
"pad_top",
"pad_top", 0.005, 0.550, 0.995, 0.995);
2869 pad_bot->SetTopMargin(0);
2870 pad_top->SetBottomMargin(0);
2872 pad_bot->SetFillStyle(0);
2873 pad_top->SetFillStyle(0);
2879 canvas_bot->DrawClonePad();
2882 canvas_top->SetBottomMargin(0);
2883 canvas_top->SetFillStyle(0);
2884 h2->GetXaxis()->SetLabelSize(0.);
2885 h2->GetXaxis()->SetTitleSize(0.);
2886 canvas_top->DrawClonePad();
2888 canvas_top->Clear();
2890 canvas_all->DrawClonePad();
2895 double xmin =
h->GetXaxis()->GetXmin();
2896 double xmax =
h->GetXaxis()->GetXmax();
2898 std::size_t
found =
str.find(
"polynomial(");
2899 while (
found != std::string::npos) {
2900 std::size_t endpos =
str.find_first_of(
')',
found + 1);
2901 std::cout <<
"found;" <<
found <<
" endpos;" << endpos <<
"count "
2903 std::string inp_str =
str.substr(
found + 11, endpos -
found - 11);
2904 std::size_t found1 = 0;
2905 std::size_t found2 = inp_str.find_first_of(
',', found1);
2906 TF1* func =
new TF1(
"func",
"pol9",
xmin,
xmax);
2907 for (
int j = 0; j < 10; j++) {
2908 std::string value_str = inp_str.substr(found1, found2 - found1);
2909 double value_double = std::strtod(value_str.c_str(), NULL);
2910 func->SetParameter(j, value_double);
2911 if (found2 == std::string::npos) {
2914 found1 = found2 + 1;
2915 found2 = inp_str.find_first_of(
',', found1);
2925 std::size_t
found =
str.find(
"TLine");
2926 while (
found != std::string::npos) {
2927 std::size_t found1 =
str.find_first_of(
')',
found + 1);
2928 if (found1 != std::string::npos) {
2929 std::string coordinates =
str.substr(
found + 6, found1 -
found - 6);
2931 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
2934 found1 = coordinates.find_first_of(
',');
2935 if (found1 != std::string::npos) {
2936 std::string cx1 = coordinates.substr(0, found1);
2937 double x1 = std::strtod(cx1.c_str(), NULL);
2938 std::size_t found2 = coordinates.find_first_of(
',', found1 + 1);
2939 if (found2 != std::string::npos) {
2940 std::string cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2941 double y1 = std::strtod(cy1.c_str(), NULL);
2942 found1 = coordinates.find_first_of(
',', found2 + 1);
2943 if (found1 != std::string::npos) {
2944 std::string cx2 = coordinates.substr(found2 + 1, found1 - found2 - 1);
2945 double x2 = std::strtod(cx2.c_str(), NULL);
2946 std::string cy2 = coordinates.substr(found1 + 1, coordinates.size());
2947 double y2 = std::strtod(cy2.c_str(), NULL);
2949 TLine* L =
new TLine;
2951 if (x1 <= 1.0 && x1 >= 0.0 && x2 <= 1.0 && x2 >= 0.0 && y1 <= 1.0 && y1 >= 0.0 &&
y2 <= 1.0 &&
2966 while (
found != std::string::npos) {
2967 std::string coordinates, cx1, cy1 =
"";
2968 std::size_t found1 =
str.find_first_of(
')',
found + 1);
2969 std::size_t found2 =
str.find_first_of(
'\'',
found + 1);
2970 if (found2 != std::string::npos) {
2971 found2 =
str.find_first_of(
'\"', found2 + 1);
2972 if (found2 != std::string::npos && found1 < found2) {
2973 found1 =
str.find_first_of(
')', found2 + 1);
2976 if (found1 != std::string::npos) {
2979 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
2982 found1 = coordinates.find_first_of(
',');
2983 if (found1 != std::string::npos) {
2984 cx1 = coordinates.substr(0, found1);
2985 double x1 = std::strtod(cx1.c_str(), NULL);
2986 found2 = coordinates.find_first_of(
',', found1 + 1);
2987 if (found2 != std::string::npos) {
2988 cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
2989 double y1 = std::strtod(cy1.c_str(), NULL);
2990 std::string txt = coordinates.substr(found2 + 2, coordinates.size());
2993 TText* T =
new TText;
2995 if (x1 <= 1.0 && x1 >= 0.0 && y1 <= 1.0 && y1 >= 0.0) {
2996 T->DrawTextNDC(
x1,
y1, txt.c_str());
2999 T->DrawText(
x1,
y1, txt.c_str());
3008 while (
found != std::string::npos) {
3009 std::size_t found1 =
str.find_first_of(
')',
found + 1);
3010 if (found1 != std::string::npos) {
3011 std::string coordinates =
str.substr(
found + 6, found1 -
found - 6);
3013 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
3016 found1 = coordinates.find_first_of(
',');
3017 if (found1 != std::string::npos) {
3018 std::string cx1 = coordinates.substr(0, found1);
3019 double x1 = std::strtod(cx1.c_str(), NULL);
3020 std::size_t found2 = coordinates.find_first_of(
',', found1 + 1);
3021 if (found2 != std::string::npos) {
3022 std::string cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
3023 double y1 = std::strtod(cy1.c_str(), NULL);
3024 found1 = coordinates.find_first_of(
',', found2 + 1);
3025 if (found1 != std::string::npos) {
3026 std::string cx2 = coordinates.substr(found2 + 1, found1 - found2 - 1);
3027 double x2 = std::strtod(cx2.c_str(), NULL);
3028 std::string cy2 = coordinates.substr(found1 + 1, coordinates.size());
3029 double y2 = std::strtod(cy2.c_str(), NULL);
3031 TLine* L =
new TLine;
3034 if (x1 <= 1.0 && x1 >= 0.0 && x2 <= 1.0 && x2 >= 0.0 && y1 <= 1.0 && y1 >= 0.0 &&
y2 <= 1.0 &&
3049 while (
found != std::string::npos) {
3050 std::string coordinates, cx1, cy1, txtsize =
"";
3051 std::size_t found1 =
str.find_first_of(
')',
found + 1);
3052 std::size_t found2 =
str.find_first_of(
'\'',
found + 1);
3053 if (found2 != std::string::npos) {
3054 found2 =
str.find_first_of(
'\"', found2 + 1);
3055 if (found2 != std::string::npos && found1 < found2) {
3056 found1 =
str.find_first_of(
')', found2 + 1);
3059 if (found1 != std::string::npos) {
3062 if (found1 <
str.size() - 3 &&
str.substr(found1 + 1, 3) ==
"NDC") {
3065 found1 = coordinates.find_first_of(
',');
3066 if (found1 != std::string::npos) {
3067 cx1 = coordinates.substr(0, found1);
3068 double x1 = std::strtod(cx1.c_str(), NULL);
3069 found2 = coordinates.find_first_of(
',', found1 + 1);
3070 if (found2 != std::string::npos) {
3071 cy1 = coordinates.substr(found1 + 1, found2 - found1 - 1);
3072 double y1 = std::strtod(cy1.c_str(), NULL);
3073 std::size_t found3 = coordinates.find_first_of(
',', found2 + 1);
3074 if (found3 != std::string::npos) {
3075 txtsize = coordinates.substr(found2 + 1, found3 - found2 - 1);
3076 double size = std::strtod(txtsize.c_str(), NULL);
3077 std::string txt = coordinates.substr(found3 + 2, coordinates.size());
3080 TText* T =
new TText;
3081 T->SetTextSize(
size / 100);
3083 if (x1 <= 1.0 && x1 >= 0.0 && y1 <= 1.0 && y1 >= 0.0) {
3084 T->DrawTextNDC(
x1,
y1, txt.c_str());
3087 T->DrawText(
x1,
y1, txt.c_str());
3098 if (
c == 0 ||
h == 0)
return;
3100 c->SetLeftMargin(0.15);
3101 c->SetRightMargin(0.13);
3102 c->SetBottomMargin(0.15);
3103 c->SetTopMargin(0.12);
3105 h->SetStats(kFALSE);
3106 h->SetLabelSize(0.04,
"X");
3107 h->SetLabelSize(0.04,
"Y");
3108 h->SetLabelFont(62,
"X");
3109 h->SetLabelFont(62,
"Y");
3110 h->SetTitleSize(0.04,
"X");
3111 h->SetTitleSize(0.04,
"Y");
3112 h->GetXaxis()->SetTitleFont(62);
3113 h->GetXaxis()->SetTitleSize(0.04);
3114 h->GetYaxis()->SetTitleFont(62);
3115 h->GetYaxis()->SetTitleSize(0.04);
3116 h->SetMarkerStyle(20);
3117 h->SetMarkerSize(0.8);
3119 h->SetTitleOffset(1.5,
"y");
3120 h->SetTitleOffset(0.9,
"x");
3122 h->SetNdivisions(504,
"X");
3123 h->SetNdivisions(504,
"Y");
3127 if (
c == 0 ||
h == 0)
return;
3129 c->SetLeftMargin(0.15);
3130 c->SetRightMargin(0.13);
3131 c->SetBottomMargin(0.15);
3132 c->SetTopMargin(0.12);
3134 h->SetStats(kFALSE);
3136 h->SetLabelSize(0.04,
"X");
3137 h->SetLabelSize(0.04,
"Y");
3138 h->SetLabelSize(0.04,
"Z");
3139 h->SetLabelFont(62,
"X");
3140 h->SetLabelFont(62,
"Y");
3141 h->SetLabelFont(62,
"Z");
3142 h->SetTitleSize(0.04,
"X");
3143 h->SetTitleSize(0.04,
"Y");
3144 h->SetTitleSize(0.04,
"Z");
3145 h->GetXaxis()->SetTitleFont(62);
3146 h->GetXaxis()->SetTitleSize(0.04);
3147 h->GetYaxis()->SetTitleFont(62);
3148 h->GetYaxis()->SetTitleSize(0.04);
3150 h->SetTitleOffset(1.5,
"y");
3151 h->SetTitleOffset(0.9,
"x");
3153 h->SetNdivisions(504,
"X");
3154 h->SetNdivisions(504,
"Y");
3158 if (
c == 0 ||
g == 0)
return;
3160 c->SetLeftMargin(0.15);
3161 c->SetRightMargin(0.13);
3162 c->SetBottomMargin(0.15);
3163 c->SetTopMargin(0.12);
3165 g->SetMarkerStyle(20);
3169 if (
c == 0 ||
e == 0)
return;
3171 c->SetLeftMargin(0.15);
3172 c->SetRightMargin(0.13);
3173 c->SetBottomMargin(0.15);
3174 c->SetTopMargin(0.12);
3192 DirToAssMap_t::const_iterator assessMapEnd =
m_assessMap.end();
3193 for (DirToAssMap_t::const_iterator
i =
m_assessMap.begin();
i != assessMapEnd; ++
i) {
3204 std::cerr <<
"Error writing file to " <<
fname << std::endl;
3214 if (img) getImageBuffer(img, myC,
x,
y);
3217 json = TBufferJSON::ConvertToJSON(myC);
3222 const std::string& nameJSON) {
3224 myC->SaveAs(namePNG.c_str());
3227 std::string
json = std::string(TBufferJSON::ConvertToJSON(myC));
3233 int cnvsType,
const std::string& pngfName,
const std::string& pngContent,
const std::string& jsonfName,
3234 const std::string& jsonfContent) {
3244 return(png ||
json);