Saving fitted histogram and TF1s in rootfile

Hi all,

I’m trying to save in an unique rootfile a fitted histogram and 3 TF1, with optfit(1) and logy scale.

Here I fit the histo and draw all into my canvas:

[code] hist->Fit(FuncTot, “RV”);

            FuncTot->GetParameters(new_params);
                    FuncC14->SetParameters(new_params);
                    FuncPile1->SetParameters(new_params);
                    FuncPile2->SetParameters(new_params);
                            FuncC14->Draw("SAME");
                            FuncPile1->Draw("SAME");
                            FuncPile2->Draw("SAME");[/code]

I’d like to save all into a rootfile. How can I do it?

Thank you!

[code]TFile *f = new TFile(“out.root”);

hist->Fit(FuncTot, “RV”);

            FuncTot->GetParameters(new_params);
                    FuncC14->SetParameters(new_params);
                    FuncPile1->SetParameters(new_params);
                    FuncPile2->SetParameters(new_params);
                            FuncC14->Draw("SAME");
                            FuncPile1->Draw("SAME");
                            FuncPile2->Draw("SAME");


hist->Write();
FuncTot->Write();

f->Write();
f->Close();[/code]

Thank you for your reply, but I’d like to have all these things in the same histogram.

edit: and, I’d like to have a logy axis…

I think you cannot. As they are different object, you have to save them independently.
However, once you have all the objects in your ROOT file, you can redraw what you want with them.

Another solution is to save the TCanvas which contains the plot you have drawn.

[quote=“pamputt”]I think you cannot. As they are different object, you have to save them independently.
However, once you have all the objects in your ROOT file, you can redraw what you want with them.

Another solution is to save the TCanvas which contains the plot you have drawn.[/quote]

Ok, and after saving the canvas I can go back to the histogram and to the TF1s, right?

So, I’ll save everything :smiley:

[quote=“LucaCrippa”]Ok, and after saving the canvas I can go back to the histogram and to the TF1s, right?

So, I’ll save everything :smiley:[/quote]

Yes, you can. See for example [url=https://root-forum.cern.ch/t/import-histogram-from-root-file/17278/1 post[/url].

[quote=“pamputt”][quote=“LucaCrippa”]Ok, and after saving the canvas I can go back to the histogram and to the TF1s, right?

So, I’ll save everything :smiley:[/quote]

Yes, you can. See for example [url=https://root-forum.cern.ch/t/import-histogram-from-root-file/17278/1 post[/url].[/quote]

Ok, thank you! :slight_smile:
Last thing, how can I save my histogram and my canvas with OptFit(1)? I’d like to see all my fit parameters directly!