TH2I with all bins equal

Goodmorning,
this is my first post around here so sorry if I made any mistake.
I am using a TH2I and I’m a little confused about the following code:

{

int i, j, k;
gStyle->SetPalette(1);
gStyle->SetOptStat(000000);
TH2I *oDOWN = new TH2I("","",4,1,5,4,1,5);

oDOWN->GetXaxis()->SetBinLabel(1,"1");
oDOWN->GetXaxis()->SetBinLabel(2,"2");
oDOWN->GetXaxis()->SetBinLabel(3,"3");
oDOWN->GetXaxis()->SetBinLabel(4,"4");
oDOWN->GetYaxis()->SetBinLabel(1,"4");
oDOWN->GetYaxis()->SetBinLabel(2,"3");
oDOWN->GetYaxis()->SetBinLabel(3,"2");
oDOWN->GetYaxis()->SetBinLabel(4,"1");

for (i= 1; i< 5; i++)
{
	for (j= 1; j< 5; j++)
	{
	cout << "Filling " << i << ", " << j << endl;
	oDOWN->Fill(i,j);
	}
}

//oDOWN->SetMinimum(-1); 

oDOWN->Draw("text" "colz");
}

this creates a 4X4 histo and fill each cell with a single event. So I would expect to see a “1” everywhere and to see all the cells of the same color. What happens, instead, is that the plot is all white and there is no “Z” column, so the plot seems empty. I tried to fill all the cells with any number of events, but as long as they are all filled with the same number, the plot will result white. The only workaround I found was to set the Minimum to (-1) (see commented line) but this is not optimal I wonder if there is a way to tell the plot to color the bins even if they are all at the same value.

Any help would be appreciated.

Paolo

The COL option maps the bins’ contents on a color map. When the histogram minimum and maximum are the same it is not possible to do a just mapping. A protection is done in the COL option painting function. It starts with:

   Double_t dz = zmax - zmin;
   if (dz <= 0) return;

I will update the documentation with this information.

see my comments in the code below

Rene

[code]{

int i, j, k;
gStyle->SetPalette(1);
gStyle->SetOptStat(000000);
TH2I *oDOWN = new TH2I("","",4,1,5,4,1,5);

oDOWN->GetXaxis()->SetBinLabel(1,“1”);
oDOWN->GetXaxis()->SetBinLabel(2,“2”);
oDOWN->GetXaxis()->SetBinLabel(3,“3”);
oDOWN->GetXaxis()->SetBinLabel(4,“4”);
oDOWN->GetYaxis()->SetBinLabel(1,“4”);
oDOWN->GetYaxis()->SetBinLabel(2,“3”);
oDOWN->GetYaxis()->SetBinLabel(3,“2”);
oDOWN->GetYaxis()->SetBinLabel(4,“1”);

for (i= 1; i< 5; i++)
{
for (j= 1; j< 5; j++)
{
cout << "Filling " << i << ", " << j << endl;
oDOWN->Fill(i+0.5,j+0.5); //<===never fill at bin boundaries!
}
}

oDOWN->SetMinimum(0); //<=== set correct minimum

oDOWN->Draw(“text” “colz”);
}
[/code]

[quote=“couet”]The COL option maps the bins’ contents on a color map. When the histogram minimum and maximum are the same it is not possible to do a just mapping. A protection is done in the COL option painting function. It starts with:

   Double_t dz = zmax - zmin;
   if (dz <= 0) return;

I will update the documentation with this information.[/quote]

Thanks for the replies and for the corrections to the code.
Is there any (easy) way to do what I’m looking, i.e. have the bins colored of the same color if they have all the same value?

Paolo

René gave you the solution … see his post.

Thank you all.
Now everything seems fine.

Paolo