RE: Zooming two histograms in sync

From: Anton Fokin (fokin@tsl.uu.se)
Date: Sun Feb 27 2000 - 22:40:16 MET


Sorry for being not precise. Of course it is possible to distinguish between
different types of events in a pad. I meant that there is no way to catch
"zoom" event (there is no zoom event). Also, it would be nice to have
"unzoom" event, otherwise my second pad stays zoommed after I unzoom the
first one. (it gets unzoommed after I produce a mouse click in the first pad
though). Anyway it looks nice :)

/Anton

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Anton Fokin
Sent: Sunday, February 27, 2000 8:01 PM
To: Rene Brun
Cc: roottalk@pcroot.cern.ch
Subject: RE: Zooming two histograms in sync


Fantastic!!! :))

The only side effect is that it executes zoompad2() on any event in pad1. Is
there a mechanism to distinguish between events?

/Anton

-----Original Message-----
From: Rene Brun [mailto:brun@pcbrun.cern.ch]
Sent: Sunday, February 27, 2000 7:42 PM
To: Anton Fokin
Cc: roottalk@pcroot.cern.ch
Subject: RE: Zooming two histograms in sync


Anton,
I hope you will get some inspiration from the macro below.
To use it, do
 Root > .L zoom.C
 Root > zoom()

You can use the normal zoom on the x axis of the histogram
in the top pad. The histogram in the second pad will be automatically
redrawn in the second pad when you release the mouse.
You can implement a different logic to react to other values of event.
You can also look at $ROOTSYS/tutorials/exec2.C

Rene Brun

//--------------file zoom.C
TH1F *h1, *h2;
TPad *pad1, *pad2;
void zoom() {
   h1 = new TH1F("h1","h1",100, -4,4);
   h2 = new TH1F("h2","h2",1000,-4,4);
   for (Int_t i=0;i<10000;i++) {
      h1->Fill(gRandom->Gaus(0,1));
      h2->Fill(gRandom->Gaus(0,1));
   }
   TCanvas *c1 = new TCanvas("c1","test zoom2",700,900);
   c1->Divide(1,2);
   c1->cd(1);
   pad1 = gPad;
   h1->Draw();
   gPad->AddExec("ex","zoompad2()");
   c1->cd(2);
   pad2 = gPad;
   h2->Draw();
}
void zoompad2() {
   int event = gPad->GetEvent();
   if (event != 11) return;
   TObject *select = gPad->GetSelected();
   if (!select) return;
   TAxis *axis1 = h1->GetXaxis();
   Int_t binmin = axis1->GetFirst();
   Int_t binmax = axis1->GetLast();
   Float_t xmin = axis1->GetBinLowEdge(binmin);
   Float_t xmax = axis1->GetBinLowEdge(binmax);
   TAxis *axis2 = h2->GetXaxis();
   Int_t newmin = axis2->FindBin(xmin);
   Int_t newmax = axis2->FindBin(xmax);
   axis2->SetRange(newmin,newmax);
   pad2->Modified();
   pad2->Update();
}


On Sun, 27 Feb
2000, Anton Fokin
wrote:

> Rene,
>
> I meant two pads and mouse zoom. Of course it is trivial to do in the
solid
> code :) The problem is that I have checked zooming in root and do not see
a
> straightforward way to catch a mouse zoom event and use it to zoom the
> second histogram.
>
> -----Original Message-----
> From: Rene Brun [mailto:brun@pcbrun.cern.ch]
> Sent: Sunday, February 27, 2000 9:38 AM
> To: Anton Fokin
> Cc: Rene Brun; roottalk@pcroot.cern.ch
> Subject: Re: Zooming two histograms in sync
>
>
> Anton,
>
> Assume TH1 *h1 in TPad *pad1 and h2 in pad2, do
>    h1->GetXaxis()->SetRange(firstbin,lastbin); pad1->Modified();
>    h2->GetXaxis()->SetRange(firstbin,lastbin); pad2->Modified();
>    canvas->Update();
>
> Rene Brun
>
>
> On Sat, 26 Feb 2000, Anton Fokin wrote:
>
> > Hi rooters,
> >
> > I have two histograms in two pads in a canvas and I zoom histograms in
> sync,
> > i.e. if I zoom the upper one, the lower one should also zoom to the same
> > range. (Imagine how it is important for time series applications). What
is
> > the best way to implement it?
> >
> > Best regards,
> > Anton
> >
> >
>
>



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET