Re: Fitting function cannot be compiled

Rene Brun (Rene.Brun@cern.ch)
Fri, 26 Jun 1998 13:15:46 +0200


Wei Xie wrote:
>
> Dear ROOTer's
>
> My fitting process is like followed:
>
> (1). Generate a histogram with 1000 Monte Carlo entries and fit it with my
> function.
> (2). Generate a second histogram with another 1000 entries and do the
> same fitting.
> (3). repeat this process 200 times.
>
> Specifically, the code is more or less like followed. During the
> loop from 0 to 200, when i=0, everything is OK but when i>0, ROOT
> start to give messages:
>
> >>>> Function: myfunction cannot be compiled.
>
> please do some help for this problem !
>
> Sincerely, Xie
>

You should not delete the function inside the loop.
See modified code below

Rene Brun

> ----------
> The code |
> -------------------------
>
> Double_t myfunction(Double_t *x, Double_t *par) // Fitting function.
> { .........................................}
>
> void fit()
> {
> ...................
>
FitFunc = new TF1("myfunction",myfunction,-10,20,2);
> for(int i=0;i<=200;i++) //*****> repeat fitting 200 times
> { ...................
>
> fpx = new TH1F("fpx","",BinNum, Xmin,Xmax);
>
> for(int j=0;j<1000;j++)
> fpx->Fill(....); //****> 1000 Monte Carlo Events
>
> FitFunc->SetParameters(0.5,0.1);
> FitFunc->SetParNames("Normalize","Most Probable");
> fpx->Fit("myfunction","r");
>
> delete fpx;
> }
delete FitFunc;
> }