Exercise 10: Writing histograms to a file (10 minutes)

In all the analysis macros we’ve worked with, we’ve drawn any plots in the Terminate method. Pick one of your analysis macros that creates histograms, and revise it so that it does not draw the histograms on the screen, but writes them to a file instead. Make sure that you don’t try to write the histograms to “experiment.root”; write them to a different file named “analysis.root”. When you’re done, open “analysis.root” in ROOT and check that your plots are what you expect.


In Saving your work, part 2, I described all the commands you’re likely to need.

Don’t forget to use the ROOT web site as a reference. Here’s a question that’s also a bit of a hint: What would be the difference between opening your new file with “UPDATE” access, “RECREATE” access, and “NEW” access? Why might it be a bad idea to open a file with “NEW” access? (A hint within a hint: what would happen if you ran your macro twice?)