I am using a fitting script to fit all the histogram simultaneously with the binned fit as there is a total of 81 histograms that I want to fit. I am able to fit all the histogram simultaneously and saved it in another root file after the fit.
But now I want to save all the histograms in pdf after the fitting. For this, I am trying with h1->SaveAs(“hist1.pdf”). but after the run, this pdf (hist1.pdf) is coming empty.
Open a canvas. Use hist->Draw() to draw the histograms as pictures (you’re not wanting to save the objects to a ROOT file, right?).
For multiple page output, it’s a bit tricky, and uses magic characters.
TCanvas canvas("canvas");
canvas.Print("my_output.pdf["); // Opens output file for multipage
canvas.Clear();
hist1->Draw();
canvas.Print("my_output.pdf"); // First page with one histogram
canvas.Clear();
hist2->Draw();
canvas.Print("my_output.pdf"); // Second page with one histogram
. . .
canvas.Print("my_output.pdf]"); // Finished; close the multipage file
You can wrap the stuff between the “[” and “]” lines in a loop, or a function call, or whatever. You can divide the canvas into subpads if you want multiple histograms per page, and so on.