RE: Zooming two histograms in sync

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sun Feb 27 2000 - 19:41:49 MET


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