Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions hist/hist/src/TAxis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "snprintf.h"

#include <iostream>
#include <cmath>
#include <ctime>
#include <cassert>

Expand Down Expand Up @@ -779,10 +780,18 @@ void TAxis::SaveAttributes(std::ostream &out, const char *name, const char *subn

////////////////////////////////////////////////////////////////////////////////
/// Initialize axis with fix bins
///
/// An error is printed if xup or xlow are infinite/nan
/// (due to resulting undefined fixed bin width)
///
/// Set xup <= xlow to force the axis range and number of bins to be automatically
/// deduced after buffer is full or BufferEmpty is called

void TAxis::Set(Int_t nbins, Double_t xlow, Double_t xup)
{
fNbins = nbins;
if (!std::isfinite(xlow) || !std::isfinite(xup))
Error("TAxis::Set", "Axis limits need to be finite numbers");
fXmin = xlow;
fXmax = xup;
if (!fParent) SetDefaults();
Expand All @@ -791,17 +800,24 @@ void TAxis::Set(Int_t nbins, Double_t xlow, Double_t xup)

////////////////////////////////////////////////////////////////////////////////
/// Initialize axis with variable bins
///
/// An error is printed if bin edges are not in strictly increasing order
/// or if any of them is infinite or nan

void TAxis::Set(Int_t nbins, const Float_t *xbins)
{
Int_t bin;
fNbins = nbins;
fXbins.Set(fNbins+1);
for (bin=0; bin<= fNbins; bin++)
for (bin = 0; bin <= fNbins; bin++) {
if (!std::isfinite(xbins[bin])) {
Error("TAxis::Set", "Bin edges need to be finite numbers. Use a large number instead.");
}
fXbins.fArray[bin] = xbins[bin];
}
for (bin=1; bin<= fNbins; bin++)
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
Error("TAxis::Set", "bins must be in increasing order");
Error("TAxis::Set", "bin edges must be in increasing order");
fXmin = fXbins.fArray[0];
fXmax = fXbins.fArray[fNbins];
if (!fParent) SetDefaults();
Expand All @@ -819,7 +835,7 @@ void TAxis::Set(Int_t nbins, const Double_t *xbins)
fXbins.fArray[bin] = xbins[bin];
for (bin=1; bin<= fNbins; bin++)
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
Error("TAxis::Set", "bins must be in increasing order");
Error("TAxis::Set", "bin edges must be in increasing order");
fXmin = fXbins.fArray[0];
fXmax = fXbins.fArray[fNbins];
if (!fParent) SetDefaults();
Expand Down
2 changes: 1 addition & 1 deletion hist/hist/src/TH2Poly.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ times, it is better to divide into a small number of cells.

TH2Poly::TH2Poly()
{
Initialize(0., 0., 0., 0., 25, 25);
Initialize(0., 0., 0., 0., 25, 25); // automatic axis range calculation
SetName("NoName");
SetTitle("NoTitle");
SetFloat();
Expand Down
6 changes: 5 additions & 1 deletion hist/hist/test/test_TH1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,9 @@ TEST(TH1, SetBufferedSumw2)
// https://github.com/root-project/root/issues/20185
TEST(TAxis, EqualBinEdges)
{
ROOT_EXPECT_ERROR(TAxis _({1, 1}), "TAxis::Set", "bins must be in increasing order");
ROOT_EXPECT_ERROR(TAxis _({1, 1}), "TAxis::Set", "bin edges must be in increasing order");
ROOT_EXPECT_ERROR(TAxis _(1, -std::numeric_limits<double>::infinity(), 0), "TAxis::Set", "Axis limits need to be finite numbers");
ROOT_EXPECT_ERROR(TAxis _(1, 0., std::numeric_limits<double>::infinity()), "TAxis::Set", "Axis limits need to be finite numbers");
ROOT_EXPECT_ERROR(TAxis _(1, std::numeric_limits<double>::quiet_NaN(), 0), "TAxis::Set", "Axis limits need to be finite numbers");
ROOT_EXPECT_ERROR(TAxis _(1, 0, std::numeric_limits<double>::quiet_NaN()), "TAxis::Set", "Axis limits need to be finite numbers");
}
16 changes: 8 additions & 8 deletions test/stressHistogram.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6269,26 +6269,26 @@ bool testMerge1DWithBuffer(bool allNoLimits)
// where different axis are used, BUT the largest bin width must be
// a multiple of the smallest bin width

double x1 = 1; double x2 = 0;
double x1 = 1; double x2 = 0; // i.e. automatic axis range calculation
if (!allNoLimits) {
// case when one of the histogram has limits (mix mode)
x1 = minRange; x2 = maxRange;
}

TH1D* h0 = new TH1D("h0", "h0-Title", numberOfBins, 1, 0);
TH1D* h1 = new TH1D("h1", "h1-Title", numberOfBins, x1, x2);
TH1D* h2 = new TH1D("h2", "h2-Title", 1,1,0);
TH1D* h3 = new TH1D("h3", "h3-Title", 1,1,0);
TH1D* h4 = new TH1D("h4", "h4-Title", numberOfBins, x1,x2);
TH1D* h2 = new TH1D("h2", "h2-Title", 1, 1, 0);
TH1D* h3 = new TH1D("h3", "h3-Title", 1, 1, 0);
TH1D* h4 = new TH1D("h4", "h4-Title", numberOfBins, x1, x2);

h0->Sumw2(); h1->Sumw2();h2->Sumw2();h4->Sumw2();
// The below histograms will be merged into h0, so they all need to fit into the buffer.
// Otherwise, the axis ranges will be computed already during the partial merge.
h0->SetBuffer(nEvents * 10);
h1->SetBuffer(nEvents*10);
h2->SetBuffer(nEvents*10);
h3->SetBuffer(nEvents*10);
h4->SetBuffer(nEvents*10);
h1->SetBuffer(nEvents * 10);
h2->SetBuffer(nEvents * 10);
h3->SetBuffer(nEvents * 10);
h4->SetBuffer(nEvents * 10);


for ( Int_t e = 0; e < nEvents; ++e ) {
Expand Down
Loading