Fitting and drawing histograms in a loop

Hi,

I have a ROOT macro which loops over an array of histograms and fits each
of them with the same function, from the same starting parameters. Unless
there are too few events in the histograms (which is common towards
the end of my loop), all the fits are successful and give reasonable results.

I want to divide a TCanvas into the applicable number of pads and draw all
the fits. If I update the canvas after each iteration of the loop, the
drawing of the fit function looks fine, but when I save it, the fit
function looks very different. It seems successive iterations of the loop
are doing something to the function.

How can I draw (and save) the successive fits?

I use, for example, code like this (on ROOT 4.00.08, but I see the same problem with 5.26):

dat_canv->Divide(4);
for(k=0; k<4; ++k){
sprintf(hname,“hist_%d”,k+1);
histo1[k] = (TH1F*) datafile->Get(hname);
Double_t fpar[] = {100.,0.};

  mf = new TF1("mf",myfunction1,x1,x2,2);
  mf->SetParameters(&fpar[0]);

  (dat_canv->GetPad(k+1))->cd();
  histo1[k]->Fit(mf,"RL");
  mf->GetParameters(&fpar[0]);

  dat_canv->Update();

}
dat_cav->Print(“file.eps”);

Thanks,
-BT

After the line

histo1[k]->Fit(mf,"RL"); add

histo1[k]->DrawCopy();
Rene