Saving canvas with fitted histogram to .gif file

Hi Rooters!

I have a canvas on which I have drawn a histogram. I have then fitted my histogram with a predefined function. I would now like to save the result to a .gif file. However, the fit is not shown.
Here’s a snippet of the code I used:

auto controlCanvas(new TCanvas("ControlCanvas", "Distributions", 20, 10, 600, 800));
  controlCanvas->cd();
  hist->Draw();
  hist->Fit("expo");
  controlCanvas->Update();
  hist->SetLineWidth(5);
  hist->GetXaxis()->SetTitle("Momentum (GeV/c)");
  controlCanvas->Print("Hists/controlHist0.gif");`

Am I doing anything wrong?

P.S. I’m using ROOT in compiled mode.

Hi,
try to use TCanvas::SaveAs() instead of print.

Cheers,
Stefano

I tried but no success.

I tried this macro and for me SaveAs works fine.

void macro(){
    
    TCanvas * controlCanvas=new TCanvas("ControlCanvas", "Distributions", 20, 10, 600, 800);
    controlCanvas->cd();
    TH1D *hist = new TH1D("","",100,-1,1);
    hist->FillRandom("gaus",10000);
    hist->Draw();
    hist->Fit("gaus");
    controlCanvas->Update(); hist->SetLineWidth(5);
    hist->GetXaxis()->SetTitle("Momentum (GeV/c)");
    controlCanvas->SaveAs("controlHist0.gif");
}

Can be that your parentheses at the first line are not right?

S

Everything seems right to me…
You used a TH1D while I used a TH1F, maybe the problem’s there.
But it would be quite strange if that were the case.
Also, I’m wrapping my histograms in STL smart pointers. Don’t know whether that can be harmful, though.

If you tried also with my macro and doesn’t work, you should wait for someone more expert than me.
I don’t know if the STL smart pointer can be the problem.
And I don’t think the TH1F is the problem I usually use TH1D just to avoid approximation problems.

Your macro works fine on my machine. I really have no idea.

Can you post a macro we can run reproducing the problem ?