Problem with variable bin width histogram

Dear All,

     When comparing two different bin-edge arrays :
           (constant)
           double xBins_bjet_pt0[] = {150,200,250,300,350,400,450,500,550,600};
                   or
           (variable)
           double xBins_bjet_pt0[] = {150,200,250,300,350,400,450,500,600};

     I get quite some strange results :

ppe.gla.ac.uk/~ngutierrez/te … et_pt0.png
ppe.gla.ac.uk/~ngutierrez/te … et_pt0.png

      for some reason there is a change on the first two bins ... while I am only changing the last two ...

       Any ideas what may be wrong here ?

       Yours,
           Nicolas

P.S. I create histograms by doing :
double xBins_bjet_pt0[] = {150,200,250,300,350,400,450,500,600};
int nBins_bjet_pt0 = sizeof(xBins_bjet_pt0)/sizeof(*xBins_bjet_pt0)-1;

which are passed as arguments to a function :
TH1F* MyPlotVLQ::InitHist(string histname, string thetype, int nbins, double xBins[] … ) {
and then :
TH1F *hist = new TH1F(fullname.c_str(), fullname.c_str(),nbins, xBins);

The bullet point is a plain TH1F, while the coloured histograms are a THStack.

Hi,

I think there might be something not completely under control in some part of your code as the snippet you pasted is perfectly sane (see the trivial macro at the bottom).
If I could propose a strategy, I would start with one single histogram at the time and see what happens to the bins.

Cheers,
Danilo

{

double xBins_bjet_pt0[] = {150,200,250,300,350,400,450,500,550,600};
int nBins_bjet_pt0 = sizeof(xBins_bjet_pt0)/sizeof(*xBins_bjet_pt0)-1;
TH1F h0("h0", "h0", nBins_bjet_pt0, xBins_bjet_pt0);

double xBins_bjet_pt1[] = {150,200,250,300,350,400,450,500,600};
int nBins_bjet_pt1 = sizeof(xBins_bjet_pt1)/sizeof(*xBins_bjet_pt1)-1;
TH1F h1("h1", "h1", nBins_bjet_pt1, xBins_bjet_pt1);

TRandom3 rndm(5);
for (int i=0;i<1000;++i){
  double x = rndm.Uniform(0,600);
  h0.Fill(x);
  h1.Fill(x);
}

TCanvas c;
h0.Draw();
h0.GetYaxis()->SetRangeUser(0,200);
c.Print("h0.png");

h1.Draw();
h1.GetYaxis()->SetRangeUser(0,200);
c.Print("h1.png");
}

Hi,

  I found the problem. An custom auxiliary Fill(TH1..) function, meant to handle the overflow and underflow,
  was not properly designed for cases when the first and last bin have different widths.

  Thanks,
       Nicolas