Graph: read point that would be drawn by option "c"

Hi ROOTers,

I have another question. Suppose I have a TGraph with some points, and I draw them with option “c”. Given (x0, y0) < (x1, y1) < (x2, y2) are 3 points shown on the graph, with (x1, y1) not in the list of points I feed to the ctor (and so it has to be computed by “c”), how can I get the point out to be stored in a variable etc?

It would be even better if I can somehow do it without actually drawing it, so if I can simply do like x1 = gr->GetSmoothCurve(y) or something along those lines that would be better. Staring at the TGraph class page, nothing stands out as being what I want.

Cheers,
Afiq

I am not sure I fully understand what you are trying to do, but it might be that you are looking for the Eval() method.

Looks like it, yeah, if the TSpline that Draw(“c”) uses is the same as one as Eval(“s”). Can you confirm if this is the case? If not, what kind of TSpline should I provide?

Also, is it possible to do it the other way around? Meaning, I give a specific value of y and have it return x.

No Eval with use a linear approximation. But I would not recommend to use what “C” does. The interpolation is not always good. See:

{
   Double_t fx1[3] = {
   -0.07425637,
   0.4414914,
   0.4856734};
   Double_t fy1[3] = {
   0.7358946,
   0.8311425,
   0.4547368};
   TGraph *graph = new TGraph(3,fx1,fy1);
   graph->Draw("ac*");
}

I’m aware that “c”-interpolation isn’t always ideal. But in my use case, I just want to find (from a set of parabolic points) the 2 values of x such that the y equals some values, in order to define the position of the bands.

The parabola can be inspected easily enough, but the current way I do it makes it depend entirely on the granularity of the points I give it. Deciding to inject more points and remaking the whole thing seems overkill to me, since by that part of the code I know already the shape is there.

So ma be the best for you is to use TSpline instead of TGraph. TSpline also has an Eval() method.

Hm I don’t find the documentation about drawing those, and I’m not familiar with the class.

I guess I’ll settle with granularity-dependent x-clamp-around-1 mechanism I have now…

May be this example can help:

{
   c1 = new TCanvas("c1","A Simple Spline",200,10,700,500);

   const Int_t n = 20;
   Double_t x[n], y[n];
   for (Int_t i=0;i<n;i++) {
     x[i] = i*0.1;
     y[i] = 10*sin(x[i]+0.2);
   }

   TGraph *gr = new TGraph(n,x,y);
   TSpline3 *s3 = new TSpline3("s3",gr);

   c1->DrawFrame(0.,0.,3.,12.);
   s3->Draw("C* SAME");
}

Interesting. Range setting seems only possible through DrawFrame though.

I guess there’s no easy way directly from TGraph (don’t really want to add another plotting type to think about). Oh well.

In any case, thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.