Re: [ROOT] How to calculate distance between pushed and released points.

From: Harufumi TSUCHIYA (harufumi@pc5.so-net.ne.jp)
Date: Sun Nov 10 2002 - 13:09:09 MET


Hello.

Thank you for you reply.

What I would like to do is the follwing.

I have the histogram which has time as x-axis and count as y-axis.
When I zoom in along xaxis, I would like to know the points
where I press and release to obtain time range of my zoom selection.

So, I made the attached macro and I used this macro in my compiled
code using c1->AddExec("ex1", ".x GetDist.C").
But, in this case, x1 always 0. 
So, Can I get both x1 and x2 in the follwing code ?

Harufumi Tsuchiya

ROOT v3.03.09
g++ 2.95.3
FreeBSD 4.6.2-RELEASE

------------------ GetDist.C ---------------------------
void GetDist() {
  Double_t x1, x2;
  Int_t event = gPad->GetEvent();
  if ( event != kButton1Up  && event != kButton1Down ) return;
  TObject *select = gPad->GetSelected();
  if ( strcmp(select->GetName(), "xaxis") != 0 )return;
  Int_t px = gPad->GetEventX(); 
  Double_t xp = gPad->AbsPixeltoX(px);
  if ( event == kButton1Down ) {
    // Get x1 // 
    x1  = gPad->PadtoX(xp); 
  }
  else if ( event == kButton1Up ) {
    // Get x2 //
    x2  = gPad->PadtoX(xp); 
    Double_t dist = x2 - x1;
    cout << "x1, x2, dist " << x1 << " " << x2 << " " << dist << endl;    
  }
}


> Hi Harufumi,
> Assuming that 
>   Int_t px1,py1 are the mouse pixel coordinates of the point
> where you press the button and px2,py2 where you release
> the button, you can compute the user coordinates with
>   Double_t x1 = gPad->AbsPixeltoX(px1);
>   Double_t y1 = gPad->AbsPixeltoX(py1);
> same for x2,y2
> 
> Rene Brun
> 
> 
> 
> On Sat, 9 Nov 2002, Harufumi TSUCHIYA wrote:
> 
> > 
> > Hello ROOTers
> > 
> > I am now trying to modify exec1.C in $ROOT/tutorials to
> > calculate distance two points along x-axis of my histogram.
> > The two points are pushed and released by mouse, respectively.
> > 
> > I succeeded in knowing pushed points and released points
> > using return values of gPad->GetEvent()(kButton1Down and kButton1Up).
> > 
> > But, the distance between two points could not be obtained.
> > 
> > So, is there the way to get the distance of the two points ?
> > 
> > Harufumi Tsuchiya
> > 
> > ROOT v3.03.09
> > g++ 2.95.3
> > FreeBSD 4.6.2
> > 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:17 MET