4 #include "TPaletteAxis.h"
18 TDirectoryFile(name.c_str(), name.c_str(), option.c_str(), motherDir),
31 if (!hist || std::string(hist->GetName()).empty() ) {
36 std::string hist_name(hist->GetName());
39 TVX_WARNING(
"Replacing existing histogram %s", hist_name.c_str());
41 fHs[hist_name].reset(hist);
55 static TCanvas canvas(
"canvas",
"canvas", 1200, 600);
56 canvas.UseCurrentStyle();
57 canvas.SetGridx(
true);
58 canvas.SetGridy(
true);
60 for (
auto& iHist :
fHs)
62 std::string histName = iHist.first;
63 std::unique_ptr<TH1>& hist = iHist.second;
65 char* opts = (
char*) hist->GetOption();
67 if (strstr(opts,
"XX")) canvas.SetLogx(
true);
68 else canvas.SetLogx(
false);
70 if (strstr(opts,
"XY")) canvas.SetLogy(
true);
71 else canvas.SetLogy(
false);
73 if (strstr(opts,
"XZ")) canvas.SetLogz(
true);
74 else canvas.SetLogz(
false);
78 TColor *color =
nullptr;
81 if (strstr(opts,
"whit_zro")) {
82 hist->GetZaxis()->SetRangeUser(-1,1);
85 TPaletteAxis *palette = (TPaletteAxis*) hist->GetListOfFunctions()->FindObject(
"palette");
86 color = gROOT->GetColor( palette->GetValueColor(0) );
87 color->GetRGB(r, g, b);
88 color->SetRGB(255, 255, 255);
92 TList* sub_list = hist->GetListOfFunctions();
95 while ( TObject *iObj = (TObject*) next() )
97 if ( !iObj )
continue;
101 std::string sFileName = prefix +
"/" + histName +
"." + img_format;
102 canvas.SaveAs(sFileName.c_str());
105 if (color) color->SetRGB(r, g, b);
HistContainer(const std::string name, TDirectory *motherDir=nullptr, const std::string option="")
Creates an empty histogram container.
HistMap fHs
A container of unique pointers to TH1 objects indexed by names.
const TH1 * FindHist(const std::string &hist_name) const
Returns a raw pointer to the histogram with hist_name name or nullptr such histogram does not exist...
void SaveAllAs(std::string prefix="./", std::string img_format="png")
Saves all histograms from the container as png images in the prefix directory.
void Add(TH1 *hist)
This container assumes the ownership of the histogram and can modify it.