Save fit parameters in a text file

I have to do gauss fitting of many TH1F plots. When I fit multiple plots using loop in my macro, I get the fit parameter showing up in the terminal, and its impractical to copy paste each value (I don’t want to show this plots, so putting the fit parameters in histograms is useless). I need only the mean value and corresponding errors. Is there any commands/codes to put in my macro so that I can save this fit parameter in an ascii / text file ?

Thanks
Gunn

hpx->Fit("gaus"); > fit.dat

I think he wants to do this from INSIDE of a C++ macro (possibly ACLiC pre-compiled), not from a ROOT command line.

See root.cern.ch/root/roottalk/roottalk03/0605.html

Why not simply do the following:

hpx->Fit("gaus");

FILE *fp = fopen("filename.dat","w");
if (fp!=NULL) {
   for (int i=0;i<fit->GetNpar();i++) {
      Float_t value = fit->GetParameter(i);
      fprintf(fp,"%d %f",i,value);
   }
}
fclose(fp);

Sorry I forgot to define the TF1 *fit. Corrected version below.

[code]
TF1 *fit = new TF1(“fit”,“gaus”);
hpx->Fit(fit);

FILE *fp = fopen(“filename.dat”,“w”);
if (fp!=NULL) {
for (int i=0;iGetNpar();i++) {
Float_t value = fit->GetParameter(i);
fprintf(fp,"%d %f",i,value);
}
}
fclose(fp);[/code]