Re: Fitting multiple subranges with user defined functions

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Wed, 16 May 2007 16:56:47 +0200


Hi Gabriele,

Expressions like

  total = new TF1("fit","ruth(0)+moliere(2)+ruth(5)",mina,maxa);

are not supported by TF1 (see doc).

You should proceed like shown in our tutorial FittingDemo.C

Rene Brun

Gabriele Postorino wrote:
> Hi,
> how can I use User Defined functions to fit datas on multiple subranges as
> described in the User Guide 5.14 in the Chapter "Fitting Histograms"?
>
> I tried defining functions as described
>
> Double_t moliere(Double_t *x,Double_t *par)
> {
> Double_t arg = 0;
> if (par[2] != 0) arg = (x[0] - par[1])/par[2];
> Double_t val = par[0]*TMath::Exp(-0.5*arg*arg);
> return val;
> }
>
> Double_t ruth(Double_t *x, Double_t *par)
> {
> Double_t val = par[0]/pow(sin((x[0]*TMath::PiOver2/180)-par[1]),4);
> return val;
> }
>
> and in the main:
>
> ruthsx = new TF1("sx",ruth,mina,sx,2);
> ruthsx->SetParameters(1,0);
>
> centro = new TF1("centro",moliere,sx,dx,3);
> centro->SetParameters(maxc, 0, 1);
>
> ruthdx = new TF1("dx",ruth,dx,maxa,2);
> ruthdx->SetParameters(1,0);
>
> total = new TF1("fit","ruth(0)+moliere(2)+ruth(5)",mina,maxa);
>
> but when trying to launch it, it returns:
> Error in <TFormula::Compile>: Bad numerical expression : "ruth(0)"
> Error in <TF1::TF1>: function: fit/ruth(0)+moliere(2)+ruth(5) has 0 parameters
> instead of 1
>
> thanks in advance
> Gabriele
>
Received on Wed May 16 2007 - 16:56:53 CEST

This archive was generated by hypermail 2.2.0 : Wed May 16 2007 - 23:50:01 CEST