Re: How to get a polyline from a TGraph?

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Sat, 17 Feb 2007 09:54:30 +0100


Instead of building a TF1 from your TGraph and use TH1::Divide(TF1*), I suggest to create
a TH1 filled with the interpolated graph and then use TH1::Divide(TH1*). If your original histogram h1 has been created with nbins,xmin,xmax, do

    TH1F *h2 = new TH1F("h2","Interpolated points",nbins,xmin,xmax);     for (int bin=1;bin<=nbins;bin++)
h2->SetBinContent(bin,gr-Eval(h2->GetBinCenter()));

    h1->Divide(h2);

Rene Brun

Nico De Simone wrote:
> Hello Rene,
> the problem is that I need a TF1 to use a TH1::Divide(TF1*).
>
> Rene Brun wrote:
>
>> Hi Nico,
>>
>> I suggest TGraph::Eval to compute a linear interpolation between
>> points or a spline interpolation.
>> If you have a TGraph *g, you can make a spline with
>> TSpline3 *s = new TSpline3("s",g);
>> g-> Draw("alp");
>>
>
> This is what I want: a straight line between points. But I need a TF1
> for that TH1::Divide() and, possibly, usable as a class member.
>
>
>> s-> Draw("same");
>>
>
> But I see a curve. I'm just doing:
>
> {
> Double_t x[3] = {0., 1., 2.}
> Double_t y[3] = {0., .5, 5.}
>
> TGraph *gr = new TGraph(3, x, y);
> gr->Draw("alp");
>
> TSpline3 *sp = new TSpline3("sp",gr);
> sp->Draw("same");
> }
>
> Thanks.
> Nico
>
Received on Sat Feb 17 2007 - 09:54:37 CET

This archive was generated by hypermail 2.2.0 : Sat Feb 17 2007 - 23:50:01 CET