Re: [ROOT] Zoom again

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Oct 03 2000 - 15:27:42 MEST


Hi Anton,
I could implement a set of functions in TGraph returning the x/y min/max
corresponding to an x/y range, eg:
  Double_t TGraph::GetYmin(Double_t xmin, Double_t xmax);
that will return the minimum y value of any point in the x range [xmin, xmax]
etc, same for all other combinations
  Double_t TGraph::GetYmax(Double_t xmin, Double_t xmax);
  Double_t TGraph::GetXmin(Double_t ymin, Double_t ymax);
  Double_t TGraph::GetXmax(Double_t ymin, Double_t ymax);

A possible implementation will look like the script below:

Double_t GetYmin(TGraph *gr, Double_t xmin, Double_t xmax)
{
   // return the minimum y of all points of gr in the range [xmin,xmax]
   Int_t np = gr->GetN();
   Double_t *x = gr->GetX();
   Double_t *y = gr->GetY();
   Double_t ymin = 0;
   Bool_t noPoints = kTRUE;
   for (Int_t i=0;i<np;i++) {
      if (x[i] < xmin || x[i] > xmax) continue;
      if (noPoints) { noPoints = kFALSE; ymin = y[i];}
      else ymin = TMath::Min(ymin,y[i]);
   }
   return ymin;
}


Comments/Suggestions are welcome on the proposed interface.

Rene Brun


KOSU_FOKIN@garbo.lucas.lu.se wrote:
> 
> Hello!
> Well, thanks for the suggestions but they both are not quite what
> I was asking for. Assume I have a picture like this:
> 
> 20 |
>    |
> 15 |     /\
>    |    /  \
> 10 |   /    \
>    |  /      \
>  5 | /        \
>    |/__________\____
>  0  5     10    15
> 
> As you see Ymin = 0 and YMax = 15. Then I zoom X axis,
> say from 7.5 to 12.5
> 
> 20 |
>    |
> 15 |    / \
>    |  /     \
> 10 |/         \
>    |
>  5 |
>    |_______________
>  0 7.5         12.5
> 
> Y axis range will stay the same but now Ymin = 10 and Ymax = 15 (min and
> max of the graph in the new X range, not min and max of the Y axis!).
> How can I get these numbers? If I use
> 
> h2->GetYaxis()->GetXmin();
> h2->GetYaxis()->GetXmax();
> 
> I will not get Ymin and Ymax of the points on the picture but min and
> max of the axis (0-15 in both cases).
> 
> Regards,
> Anton



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