Is it possible to zoom TH2 x and y axes but not z?

Hi,

I am using a histogram drawn with colz to display the structure of my detector. This may be an unconventional choice but the results are very satisfactory in that the event can be overlaid as a tgraph, coordinates are shown, zooming is handled well, etc. A few pictures are included (note, they don’t show the problem I’m having). However, I do have one problem. The histogram has a few different colors (bin heights in z) and when I zoom in x and y the z axis also zooms, depending on the maximum bin content within the x and y regions. I want users to be able to zoom the display using the mouse but I don’t want the histogram z axis to autozoom. Is there a way to get the behaviour I want?

mike




Try to fixe the maximum and minimum of your histogram with SetMaximum and SetMinimum before drawing it.

This doesn’t work. Unzooming the y axis causes the maximum to reset. The same thing isn’t true of the xaxis. Try this:

TH2* h = new TH2F("h", "h", 100, -5,5, 100, -5,5);
for(int i=0; i<10000; i++){ h->Fill(gRandom->Gaus(),gRandom->Gaus());}
h->SetMaximum(h->GetMaximum()*2.0);
h->Draw("col");

Then zoom and unzoom the x and y axes. You’ll see what I mean (at least with 4.04.02f).

mike

Unless I have not understood what you want, seems to me the macro you sent works as you wish with ROOT 5. It plots an histogram with colors, the lowest bins are grey. If I zoom in that grey region, the bins remain grey. I think that’s what you wanted, isn’t it ?

Do you zoom it in the y direction and then unzoom it? It looks fine when zoomed but when you unzoom the histogram maximum apparently resets. This is only when zooming the y-axis. Also, I am using 4.04.02f. If you think the behaviour has changed in root 5, I will check it out. Unfortunately, it doesn’t help me much as our software framework is currently tied to root 4 and I cannot expect users to have root 5 installed yet. Is there perhaps some setting whereby I can instruct the z-axis not to zoom at all? If not, can you suggest some other ROOT facility for plotting a background as I am doing?

thanks for the help,

mike

You are right, on the Y axis when we unzoom the maximum is reset. I’ll check the reason why.

The following seems to be the relevant bit of code, taken from the html documenation of ROOT 5. Note that if the axis name is not “xaxis” and the histogram isn’t “hframe” then the histogram maximum and minimum are reset to the default -1111. I suppose this unzooms the histogram. I don’t think this bit of code has changed since 4.04.02

void TAxis::UnZoom()
{
   // Reset first & last bin to the full range

   TView *view = gPad->GetView();
   if (view) {
      delete view;
      gPad->SetView(0);
   }
   SetRange(0,0);
   if (!strstr(GetName(),"xaxis")) {
      TH1 *hobj = (TH1*)GetParent();
      if (hobj->GetDimension() == 2 && strstr(GetName(),"zaxis")) {
         hobj->SetMinimum();
         hobj->SetMaximum();
         hobj->ResetBit(TH1::kIsZoomed);
         return;
      }
      if (strcmp(hobj->GetName(),"hframe") == 0 ) {
         hobj->SetMinimum(fXmin);
         hobj->SetMaximum(fXmax);
      } else {
         hobj->SetMinimum();
         hobj->SetMaximum();
         hobj->ResetBit(TH1::kIsZoomed);
      }
   }
}

Hmmm… I suppose a work-around is now occuring to me. Rename the y-axis to “xaxis”.

mike

This is exactly the place I am looking at. I would like to understand all the possible side effects before making any change. I do not think your trick will work.

You are right. When I tried the trick I found that I could no longer zoom the y axis with the mouse. Drat.

mike

it is now fixed in the CVS head