Python Exercise 11: Stand-alone program (optional) (30 minutes)
Why would you want to write a stand-alone program instead of using ROOT interactively?
You can’t live in a notebook forever.1 Typical analysis scripts get so large that you may want to use a regular text editor to work with them, instead of the limited editing available in a notebook cell.
One method of speeding up a Python program is to use Cython, a Python optimizing compiler: http://cython.org/. You can use Cython within a notebook, but you’ll get better results if you create a stand-alone program.
Stand-alone programs are necessary if you want to submit your Python program to a batch system.
So far, you’ve used ROOT interactively to perform the exercises. Your task now is to write a stand-alone program that uses ROOT. Start with the script you created in Exercise 10: you have a notebook cell that reads an n-tuple, performs a calculation, and writes a plot to a file. Create a stand-alone program that does the same thing.
If you tried to do the C++ version of this Exercise, you may have found it difficult. The Python equivalent is much easier. Part of the reason is that all the clues you need are in the condor tutorial I frequently teach as part of the class:
Look at the instructions for the
.py files in that tutorial, then
look at the comments in the
.py files themselves.
Don’t forget to use
module load root (or the equivalent if you’re
not using a Nevis server) if you expect a stand-alone Python program to
be able to import the ROOT libraries!
Whether this is a programming tip or general life advice I leave up to you.