Abnormal termination of minimization

I generated data according to the distribution that i will fit in the macro, but the macro give me the same error abnormal termination of minimization.

Please help me.
mortemuone.txt (20.7 KB)
random.c (1.24 KB)
mu.c (1.11 KB)

Looking at your data file, I see that you have a “,” instead of "."
If you fix this problem your macro should work. I also made some fixes to your macro such that it is valid C++.
see below

Rene

[code]#include <TROOT.h>
#include <TH1F.h>
#include <TF1.h>
#include <TFile.h>
#include <TTree.h>
#include <TMath.h>
#include <Riostream.h>

Double_t life(Double_t *x, Double_t par)
{
Float_t xx = x[0];
Double_t xx1 = -xx/par[1];
Double_t xx2 = -xx/par[2];
if (xx1 > 300 || xx2 > 300) return 1e10;
Double_t f = par[0]
(exp(xx1)+exp(xx2));
return f;
}

void mu()
{
TF1 *f1 = new TF1(“mu”,life,0,1000,3);
f1->SetParameters(70,100,2000);
f1->SetParNames(“ampiezza”,“meanlife1”,“meanlife2”);
f1->Draw();
}

void myfit()
{
TF1 f1=(TF1)gROOT->GetFunction(“mu”);
f1->SetParameters(35,100,2200);
ifstream in;
in.open(“dati.txt”);
Double_t mlife;
TFile *f = new TFile(“mlife.root”,“RECREATE”);
TH1F *h1 = new TH1F(“h1”,“mlife distribution”,100,30,800);
while (1) {
if (!in.good()) break;
in >> mlife;
cout << mlife << endl;
h1->Fill(mlife);
}
in.close();
h1->Fit(“mu”);
Double_t Chisquare = f1->GetChisquare();
Double_t NDF = (Double_t)f1->GetNDF();
printf(“Chisquare=%g, NDF=%f\n”,Chisquare,NDF);
cout<<“Chi quadro ridotto”<<" = "<<Chisquare/NDF<<endl;
f->Write();
//f->Close();
}
[/code]

I’m sorry i’ve attached old data in which i don’t replaced “,” with “.”. I made the changes you have suggested but it doesn’t work, give to me the same error.

macro finally works!It want in fit the range over which to apply the fit.