# Filling a TH2 by bin number, rather than coordinates

As the title suggests, I’d like to know if it is possible to fill a 2D histogram by what bin number I want to fill, rather than the coordinate (x,y).

i.e. I want to fill the bin say, (1,1), in a way other than filling it by h1.Fill( x coordinate of bin (1,1), y coordinate of bin (1,1)).

This comes about since I have this algorithm that tries to do this:

```SigMap.Fill(xmin + (float(iBinSig)/float(nBinsX))*(xmax - xmin),ymin + (f\ loat(jBinSig)/float(nBinsY))*(ymax - ymin),sigarray[iBinSig-1][jBinSig-1]); ```

where xmin, xmax are the beginning and end points on the x-axis of the histogram, similarly for ymin and ymax, iBinSig and jBinSig are the variables that loop over the number of bins in the x and y directions respectively, nBinsX and nBinsY are the total number of bins in the x and y directions respectively. I’m weighting the entry with a value in an array.

What is intended to happen from doing this is depending on what bin the code is up to, iBinSig will take a value between 1 and nBinsX, and the x-coordinate to fill will be given by the minimum value + a fraction of the way to the maximum value, which can be seen by the histogram fill (xmin + (iBinSig/nBinsX)*(xmax - xmin)). In principle this should work, however I find in the final product that some of the bins overlap - it must not be clear to the code that I’m looking to fill each bin separately, and what I think is happening is that two different x-coordinates are corresponding to the same bin.

I have included the plot showing this, and you can clearly see the binning error. Just to clarify, the value in each bin should be between 0 and 1. In some areas, it’s ~4, and most of the time between 1 and 2.

So if anyone could help me out I would appreciate it!