modified: scratch/make_prettyplots.C set z min
This commit is contained in:
parent
88cf59bce3
commit
66fd758554
|
|
@ -27,7 +27,8 @@
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Style — called once before anything is drawn
|
// Style — called once before anything is drawn
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
void SetStyle() {
|
void SetStyle()
|
||||||
|
{
|
||||||
gROOT->SetStyle("Plain");
|
gROOT->SetStyle("Plain");
|
||||||
gStyle->SetOptStat(0);
|
gStyle->SetOptStat(0);
|
||||||
gStyle->SetOptTitle(0);
|
gStyle->SetOptTitle(0);
|
||||||
|
|
@ -65,26 +66,31 @@ void SetStyle() {
|
||||||
void make_prettyplots(const char *rootFile,
|
void make_prettyplots(const char *rootFile,
|
||||||
const char *histName,
|
const char *histName,
|
||||||
const char *xlabel = "",
|
const char *xlabel = "",
|
||||||
const char* ylabel = "") {
|
const char *ylabel = "",
|
||||||
|
double minZ = -9999.0)
|
||||||
|
{
|
||||||
|
|
||||||
SetStyle();
|
SetStyle();
|
||||||
|
|
||||||
// --- Open file ----------------------------------------------------------
|
// --- Open file ----------------------------------------------------------
|
||||||
TFile *f = TFile::Open(rootFile, "READ");
|
TFile *f = TFile::Open(rootFile, "READ");
|
||||||
if (!f || f->IsZombie()) {
|
if (!f || f->IsZombie())
|
||||||
|
{
|
||||||
std::cerr << "ERROR: Cannot open " << rootFile << "\n";
|
std::cerr << "ERROR: Cannot open " << rootFile << "\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TObject *obj = f->Get(histName);
|
TObject *obj = f->Get(histName);
|
||||||
if (!obj) {
|
if (!obj)
|
||||||
|
{
|
||||||
std::cerr << "ERROR: '" << histName << "' not found in " << rootFile << "\n";
|
std::cerr << "ERROR: '" << histName << "' not found in " << rootFile << "\n";
|
||||||
f->Close();
|
f->Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TObject *clone = obj->Clone(Form("%s_clone", histName));
|
TObject *clone = obj->Clone(Form("%s_clone", histName));
|
||||||
if (!clone) {
|
if (!clone)
|
||||||
|
{
|
||||||
std::cerr << "ERROR: Clone failed for '" << histName << "'\n";
|
std::cerr << "ERROR: Clone failed for '" << histName << "'\n";
|
||||||
f->Close();
|
f->Close();
|
||||||
return;
|
return;
|
||||||
|
|
@ -104,11 +110,20 @@ void make_prettyplots(const char* rootFile,
|
||||||
c.cd();
|
c.cd();
|
||||||
|
|
||||||
// Widen right margin for the colz palette bar
|
// Widen right margin for the colz palette bar
|
||||||
if (is2D) gPad->SetRightMargin(0.13);
|
if (is2D)
|
||||||
|
gPad->SetRightMargin(0.13);
|
||||||
|
|
||||||
if (is2D) {
|
if (is2D)
|
||||||
|
{
|
||||||
TH2 *h = (TH2 *)clone;
|
TH2 *h = (TH2 *)clone;
|
||||||
h->SetStats(0);
|
h->SetStats(0);
|
||||||
|
|
||||||
|
// --- Apply Minimum Z if provided ---
|
||||||
|
if (minZ != -9999.0)
|
||||||
|
{
|
||||||
|
h->SetMinimum(minZ);
|
||||||
|
}
|
||||||
|
|
||||||
h->GetXaxis()->SetTitle(xlabel);
|
h->GetXaxis()->SetTitle(xlabel);
|
||||||
h->GetYaxis()->SetTitle(ylabel);
|
h->GetYaxis()->SetTitle(ylabel);
|
||||||
h->GetXaxis()->SetTitleOffset(1);
|
h->GetXaxis()->SetTitleOffset(1);
|
||||||
|
|
@ -116,7 +131,9 @@ void make_prettyplots(const char* rootFile,
|
||||||
h->GetXaxis()->CenterTitle(true);
|
h->GetXaxis()->CenterTitle(true);
|
||||||
h->GetYaxis()->CenterTitle(true);
|
h->GetYaxis()->CenterTitle(true);
|
||||||
h->Draw("colz");
|
h->Draw("colz");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
TH1 *h = (TH1 *)clone;
|
TH1 *h = (TH1 *)clone;
|
||||||
h->SetStats(0);
|
h->SetStats(0);
|
||||||
h->SetLineColor(kAzure - 5);
|
h->SetLineColor(kAzure - 5);
|
||||||
|
|
@ -134,12 +151,14 @@ void make_prettyplots(const char* rootFile,
|
||||||
// Build output path: same directory as input file, named after the histogram
|
// Build output path: same directory as input file, named after the histogram
|
||||||
std::string inPath(rootFile);
|
std::string inPath(rootFile);
|
||||||
std::string dir = inPath.substr(0, inPath.find_last_of("/\\"));
|
std::string dir = inPath.substr(0, inPath.find_last_of("/\\"));
|
||||||
if (dir == inPath) dir = "."; // no directory component — use cwd
|
if (dir == inPath)
|
||||||
|
dir = "."; // no directory component — use cwd
|
||||||
|
|
||||||
std::string outPath = dir + "/" + std::string(histName) + ".png";
|
std::string outPath = dir + "/" + std::string(histName) + ".png";
|
||||||
// Replace any "/" inside histName (e.g. "folder/hist") with "_"
|
// Replace any "/" inside histName (e.g. "folder/hist") with "_"
|
||||||
for (char &ch : outPath)
|
for (char &ch : outPath)
|
||||||
if (ch == '/') ch = '_';
|
if (ch == '/')
|
||||||
|
ch = '_';
|
||||||
|
|
||||||
c.Modified();
|
c.Modified();
|
||||||
c.Update();
|
c.Update();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user