I have a problem plotting multiple TH2F histos with COLZ option if number of plotted histograms is big. First I am filling histograms from TTree, then I set style and finally I draw them with SetBatch(true) followed by SaveAs. I receive information that PNG was saved and at the end of loop over histograms my macro terminates. Then I find 35/50 plots filled properly, one plot half rendered and the rest empty (only style, titles, etc. remain).
I assume SaveAs is too slow and program terminates before rendering is done. Is there any way I can force SaveAs to wait until it is finished? Why I get info about file successfully saved if this is not true? Any other tips (maybe parallelization of SaveAs, speeding up SaveAs).
funny thing, when creating simplified macro for you I have excluded some styling (removed SetContour(nb) and TColor::CreateGradientColorTable) and noticed that all plots are rendered. Then I played with number of contours:
nb = 128 works in my original code
nb = 256 works in attached macro but not in original code (which is much more complex GUI)
nb = 512 will not work in both
Solution to take 128 colors is fine to me. But I still do not like that SaveAs will tell you that PNG was saved when rendering is not complete.
I attach quick macro, run as: root -l make_plots.cpp
Yes the number of contour is limited.
Some .png files are created but the plot in them was wrong because of a too high level of contours.
It wild have been the same if you would have displayed on screen.
SaveAs does not check how the plot looks like.
It saves what is rendered
However if you start plotting histograms from the middle of the list you will have them plotted correctly. It seems that rendering is slow (Draw step is slow?). Is there a way to wait until rendering is done and only then raise SaveAs function?
You render the histograms with the COLZ option. The rendering speed is directly proportional to the number of bins of your histogram. The pictures I saw showed histograms with only a few bins. It should not be that slow. The rendering is done in a TCanvas and then is saved in a .png file via the SaveAs command. If you want to save the canvases when all the rendering is done you will need to keep all the canvases in a list, loop on it at the end of your program and for each of them call SaveAs.