Re: Contours for 2-D histogram with variable bin width

Rene Brun (Rene.Brun@cern.ch)
Mon, 01 Mar 1999 10:18:00 +0000


Hi Mark,
The 2-d drawing routines do not draw the bin contents if the number
of entries is zero. In your macro, you use SetCellContent. This function
does not increment the number of entries. I will remove the return
statement from the drawing routines in case nentries=0.
The modified macro below works OK (in case of variable bin size, you
must
specified nbins+1 values in your arrays.

Rene Brun

{
Float_t binsx[6] = { 1e-5,1e-4,1e-3,1e-2,1e-1,1 };
Float_t binsy[6] = { 1e-5,1e-4,1e-3,1e-2,1e-1,1 };
TH2F *hist2 = new TH2F("hist2","Variable bin
histogram",4,binsx,4,binsy);
Int_t j,k;

for (j=1; j< 6; j++)
{
for(k=1; k < 6; k++)
{
hist2->SetCellContent(j,k,(Float_t)(j+k));
}
}
hist2->SetEntries(1);
hist2->Draw("box");
}

Mark Boulay wrote:
>
> Hello All,
> I'm trying to define a 2-D histogram with variable
> bin width, and then draw a contour map, using root 2.21/03.
> The following code illustrates how the histogram is created:
>
> {
> Float_t binsx[6] = { 1e-5,1e-4,1e-3,1e-2,1e-1,1 };
> Float_t binsy[6] = { 1e-5,1e-4,1e-3,1e-2,1e-1,1 };
> TH2F *hist2 = new TH2F("hist2","Variable bin histogram",5,bx,5,by);
> Int j,k;
>
> for (j=1; j< 6; j++)
> {
> for(k=1; k < 6; k++)
> {
> hist2->SetCellContent(j,k,(Float_t)(j+k));
> }
> }
> }
>
> If I then try to draw this histogram with Draw(), only the axies are
> drawn. Scanning the mouse over the pad (with Event Status on) shows
> that the cells have the proper contents. If I then use
> Draw("cont"), the same axies are again drawn (without contours). This
> time the Event Status shows that all points inside the axies are in
> cell (6,6).
>
> Thanks in advance for any help,
>
> Mark.
>
>
>
> =================================================================
> = =
> = Mark Boulay =
> = Department of Physics phone/voice mail: (613) 533-6861 =
> = Queen's University fax: (613) 533-6813 =
> = Kingston, Ontario email: mgb@sno.phy.queensu.ca =
> = Canada, K7L 3N6 Office 121 (c) =
> = =
> =================================================================