Software

C++ Stuff

C++ is the current lingua franca of computing in high energy physics. It's a high-level object-oriented language that still gives users low-level access to memory manipulation and other things you might want to optimize if you're writing a code library.

Unfortunately, this is a big pitfall for users, since there are many subtleties involved in designing good C++ code without bugs and memory leaks. These things can only be avoided with experience, which you can gain by reading about others' mistakes. Some books on the subject that can help you are:

Once you're relatively familiar with C++, I recommend you bookmark the website C/C++ Reference, which is quite handy for all the syntax questions that come up while you are coding.

ROOT Stuff

ROOT is a C++-based analysis program currently popular in high energy physics. It is maintained at CERN, the European Center for Nuclear Research; hence, the ROOT logo is a partially nude woman with roots for legs. Quite European, no?

ROOT is mainly used for plotting data, but it also supplies a full statistics package for histogramming, fitting, cutting, transforming, and otherwise torturing your favorite dataset. You can also build in support for GEANT, MySQL, Qt, Pythia, a ROOT-based file server (!), ruby, afs, ssl, and whatever else the maniacs at CERN have decided they want to put into the latest release. Actually, this stuff is enabled by default and you have to make sure to disable it when you build from source.

So, ROOT is quite bloated, and because of this its documentation is a bit poor (though its C++ classes are well-documented). Often the usage cases are only documented on some dude's private web page... like this one.

In that spirit, I am posting some advice that will help beginners get what they want out of the program.

  1. How to learn the basics of ROOT

    The ROOT source code comes with a folder of examples and tutorials, but while it's good to explore them, they are a bit hard to go through when you're a beginner. A great place to learn the basics is the ROOT Course at Fermilab.

  2. How to make ROOT plots that don't look like sh*t

    For some reason, the default plotting style in ROOT is insanely ugly. The plot background is a sickly gray; all labels and titles use a bold font; and don't even get me started on the color palette.

    ugly default pretty plot

    To get plots to look halfway decent (as in the second of the two shown here), it is best to use the ROOT graphics editor. In the canvas menu, go to View->Editor to open the editor panel. Then you can click on different elements in your canvas and change their properties in the editor.

    However, if you always use certain fonts and colors, it becomes a pain to change every plot using the editor. In this case, it's best to create a ROOT macro with your preferred settings. This mainly involves calls to the TStyle class. For an example, see the macro I use:

    SetStyles.C

    I find it convenient to have this macro automatically loaded when I start ROOT. It's easy to do. Suppose you put the macro in the directory /home/username/etc/SetStyles.C. Then in your home directory, create the file .rootrc with the following line:

    Rint.Logon: /home/username/etc/SetStyles.C

  3. How to plot unusual coordinate systems in ROOT

    It is very common, especially in astronomy, to make plots that don't use Cartesian coordinates: for example, a map projection. Can ROOT handle this? In fact, there is a built-in function for plotting latitude/longitude data using a Hammer-Aitoff projection, but you can't plot arbitrary projections like the one below.

    mollweide grid

    So, I wrote a macro that will plot coordinates and gridlines using arbitrary projections; you can download it here:

    PlotCoords.C

    Currently the program is set up to use the Mollweide projection, but it can be extended to any projection you like. I leave it up to users to alter the code for their own purposes.

HEALPix

HEALPix is a handy Fortran/C/C++ library for performing geometrical calculations on the sphere and for making fast Fourier decompositions of smoothed astronomical skymaps.

In the past I have used all three language interfaces, but now I stick to the C++ module (v2.01), which has a simple and well-documented API. However, the program (which you can download here) requires the FITS astronomical library v2.5.10, and this version of the FITS library is out of date and hard to come by. Moreover, the C++ module is buried inside the source tree and is a bit tricky to build.

To make builds and software configuration easier, I extracted the FITS and HEALPix C++ code from their respective sources and put them into a single source tree. I then wrote a CMake build script to build all of the relevant libraries and sample binaries for a nice, clean installation. Finally, I made a bash script (healpix-cxx-config) that can be used to easily setup the shell for building against these libraries. It can all be found here:

healpix-cxx-2.0.1-Source.tar.gz

Build instructions are contained in the source. Note that only the build scripts are new; the FITS and HEALPix code has not been altered.

HEALPix and ROOT

I also wrote a small set of routines that perform trivial operations useful in cosmic ray studies, such as generating a list of random directions on the sphere weighted by a HEALPix skymap. Some of these routines can be found in the archive

healpix_examples.tgz

Included is a program that will print HEALPix FITS files in a ROOT canvas with a nice color scheme and full coordinate axes. It can be used as a replacement for the map2tga program that comes with the HEALPix C++ module, and it generates images like the one below:

exposure map