Skip to content

Commit cb2c09e

Browse files
authored
[hist] raise error of badly sorted edges as with variable binwidth
1 parent 34f9d42 commit cb2c09e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hist/hist/src/TAxis.cxx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "snprintf.h"
2828

2929
#include <iostream>
30+
#include <cmath>
3031
#include <ctime>
3132
#include <cassert>
3233

@@ -779,10 +780,17 @@ void TAxis::SaveAttributes(std::ostream &out, const char *name, const char *subn
779780

780781
////////////////////////////////////////////////////////////////////////////////
781782
/// Initialize axis with fix bins
783+
///
784+
/// An error is printed if xup <= xlow
785+
/// or in any of them is infinite (due to resulting undefined fixed bin width)
782786

783787
void TAxis::Set(Int_t nbins, Double_t xlow, Double_t xup)
784788
{
785789
fNbins = nbins;
790+
if (xup <= xlow)
791+
Error("TAxis::Set", "upper edge must be strictly higher than lower edge");
792+
if (std::isinf(xlow) || std::isinf(xup))
793+
Error("TAxis::Set", "fixed binwidth not compatible with infinite lower/upper edges");
786794
fXmin = xlow;
787795
fXmax = xup;
788796
if (!fParent) SetDefaults();
@@ -791,6 +799,8 @@ void TAxis::Set(Int_t nbins, Double_t xlow, Double_t xup)
791799

792800
////////////////////////////////////////////////////////////////////////////////
793801
/// Initialize axis with variable bins
802+
///
803+
/// An error is printed if bin edges are not in strictly increasing order
794804

795805
void TAxis::Set(Int_t nbins, const Float_t *xbins)
796806
{
@@ -801,7 +811,7 @@ void TAxis::Set(Int_t nbins, const Float_t *xbins)
801811
fXbins.fArray[bin] = xbins[bin];
802812
for (bin=1; bin<= fNbins; bin++)
803813
if (fXbins.fArray[bin] <= fXbins.fArray[bin - 1])
804-
Error("TAxis::Set", "bins must be in increasing order");
814+
Error("TAxis::Set", "bin edges must be in increasing order");
805815
fXmin = fXbins.fArray[0];
806816
fXmax = fXbins.fArray[fNbins];
807817
if (!fParent) SetDefaults();

0 commit comments

Comments
 (0)