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

In all the analysis scripts we’ve worked with, we’ve drawn any plots in the Wrap-up section. Pick one of your scripts 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 with the TBrowser in command-line ROOT and check that your plots are what you expect.

Hint

In Saving your work, part 2, I described all the commands you’ll 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’s 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 script twice?)