Th2 from array and setbin contents

I’m pulling my hair out trying to use an array to plot a th2f:

I define a histogram:

int ROWS = 16;
int COLUMNS = 50;
double a[ROWS][COLUMNS];

TH2F *optimizationSlice = new TH2F("optimizationSlice","optimizationSlice", COLUMNS, 0.3, 1.28, ROWS, 0.1454, 0.147);

I read my file and fill in my array with:

    a[currentrow][currentcolumn] = currentsignificance;
    if(currentrow == ROWS-1){
      currentrow = 0;
      currentcolumn++;
    }
    else{
      currentrow++;
    }

I fill the TH2F:

  for(Int_t i = 0;i<ROWS;i++){
    cout << endl;
    for(Int_t j = 0;j<COLUMNS;j++){
      currentbin = optimizationSlice->GetBin(j,i);
      cout << "Filling: " << currentbin << "with.." << endl;
      cout << "a["<<i<<"]["<<j<<"]=" << a[i][j] << endl;
      optimizationSlice->SetBinContent(currentbin,a[i][j]);
    }
  }

And my Result is appended. I figured filling an array would be the most straighforward way of doing this, but you’ll notice that I seem to be missing a row and column, and I think the results are wrong. I know that the 0th bin should be 0.9, and based on the scale, it doesn’t seem to be correct. Does anyone have a snippet that performs this task?

Thanks,
James


The convention for numbering bins is explained in the doc of TH1.
bin 0 is underflow
bin 1 is first bin
bin N is last bin
bin N+1 is overflow

Rene

I’m aware of this, and GetBin(x,y) accounts for this fact, yet I still have this problem. I’ll look into it more later.
james

to repeat my point, you should do

currentbin = optimizationSlice->GetBin(j+1,i+1); instead of

currentbin = optimizationSlice->GetBin(j,i);
Rene