9 if (h1->Integral() == 0)
return;
10 int nn = h1->GetNbinsX();
12 while (h1->GetBinContent(bin_lo) == 0) bin_lo++;
14 while (h1->GetBinContent(bin_hi) == 0) bin_hi--;
19 int nn = h1->GetNbinsX();
24 if (bin_lo < 1) bin_lo = 1;
25 if (bin_hi > nn) bin_hi = nn;
26 h1->GetXaxis()->SetRange(bin_lo, bin_hi);
31 TH1* h1 = h2->ProjectionX(
"h1_auto_set_range_x");
32 int nn = h1->GetNbinsX();
38 if (bin_lo < 1) bin_lo = 1;
39 if (bin_hi > nn) bin_hi = nn;
40 h2->GetXaxis()->SetRange(bin_lo, bin_hi);
45 TH1* h1 = h2->ProjectionY(
"h1_auto_set_range_y");
46 int nn = h1->GetNbinsX();
52 if (bin_lo < 1) bin_lo = 1;
53 if (bin_hi > nn) bin_hi = nn;
54 h2->GetYaxis()->SetRange(bin_lo, bin_hi);
void FindFilledRange(TH1 *h1, int &bin_lo, int &bin_hi)
Find the lowest and highest bins ("bin_lo" and "bin_hi") out of non-empty bins of "h1".
void AutoSetRangeX(TH2 *h2, const int margin_lo=5, const int margin_hi=5)
void AutoSetRange(TH1 *h1, const int margin_lo=5, const int margin_hi=5)
Adjust the axis range via "h1->GetXaxis()->SetRange(bin_lo, bin_hi)" to zoom up non-empty bins.
void AutoSetRangeY(TH2 *h2, const int margin_lo=5, const int margin_hi=5)