How to save the multiple histogram in one pdf

Dear Experts,

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.

Here’s the macro and the root file: binned_D01_Kpipi0_RS_M_D0.C (3.9 KB) and D0_M_all_set_kpipi0_total_proc11_4loop.root (95.9 KB)

Would you please help??

Regards,
Chanchal Sharma


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


The following version of your macro create 81 pdf files.
We can also make the 81 plot in one single file if you need.
Let me know.

binned_D01_Kpipi0_RS_M_D0.C (3.7 KB)

Thanks for this and sorry for the late reply. I just see this msg.
yes, I want to save these 81 plots in one single pdf.
Please help me.

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.

2 Likes

Thanks a lot. Now its working.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.