The return number from function GetBin() is not equal to my setting number bins

ROOT Version: 6.22/08
Platform: Ubuntu 20.04
Dear experts,
I found the number obtained from “h->GetBin()” is not equal to my setting bin number.
As shown in the attachment, the bin value is 40 from GetBin() while I set 5*5 bins.
It’s strange and I don’t the reason, could you please help me check it?
Thank you very much.
rr.C (308 Bytes)

Best regards,
Jiechen

Hi,
I changed your macro a bit:

void rr()
{
        const int bin=5;
        TH2F *h=new TH2F("h","h",bin,0,50,bin,0,50);
        TRandom ran;
        double nn=20;
        for(int i=0;i<5000;i++)
                h->Fill(ran.Poisson(nn),ran.Poisson(nn));

        double N=h->GetBin(bin,bin);
        cout<<N<<endl;;
        for(int i=0;i<N;i++)
                cout<<i<<"\t"<<h->GetBinContent(i)<<endl;
        h->Draw("COLZ TEXT");
}

(you had the last loop starting from 1 instead of 0), and made the following picture explaining the bin numbering. Note there are underflows/overflows for each row, which increase the number of bins significantly:

Hi, Yus,

Very clear illustration, thank you very much.

Best regards,
Jiechen