Introduction
This is a simple example of analysing some (simulated) LHC data using C++.
It is based on two samples: ZH production, with Z→μμ and H→bb (the signal), and Zbb production with Z→ee (the background).
The aim is to find similarities and differences between the signal and background events, by making histograms of various quantities.
I run this on a linux machine, it should also work on a mac or with windows. To run this, you will need: a C++ compiler, like g++; a text editor (I use emacs); Root. The first two are readily available on linux/mac.
Root & Fastjet
For better or worse, Root is by far the dominant data analysis/histogramming package used in particle physics. It is freely available from CERN, so download the "Pro" version then follow the installation instructions. Online searching will probably turn up the answers to any problems you encounter.
Fastjet is a package to cluster particles into jets. You can install this anywhere on your system, but I have a short script to download, build and install it in the current directory. Execute it:
. setup-fastjet.sh
Again, some additional packages may be required.
Finally, some variables must be set for each new terminal or session:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/PATH/TO/FASTJET
. /PATH/TO/ROOT/bin/thisroot.sh
these two lines could be copied into to your ~/.bashrc file, for example. The fastjet path should point to the directory containing libfastjet.so, for example ./fastjet-install/lib, otherwise you will see errors like error while loading shared libraries: libfastjet.so.0.
The Code
The analysis code consists of analysis.cpp,
analysis.h,
and a Makefile to compile them.
You will also need to download the plot.cpp file, more of which later.
Finally, two data files, VH_events.root and
Zbb_events.root.
Download all 5 files to the same directory, then open the Makefile and check the paths to libfastjet.so. Then compile & run the code using:
make
./analysis
By default, the code runs over VH_events.root, and writes to VH_histograms.root. To run over the other file:
./analysis Zbb_events.root Zbb_histograms.root
The result is a new root file containing histograms. These can be opened and viewed in root:
root VH_histograms.root
.ls
mass->Draw()
Or in root open the gui new TBrowser and click on the plots. To quit root, type: . q
The plot.cpp code will open two root files, overlay a plot and save the result as an eps file. To run this:
./plot
Changing the Code
The main file to edit will be analysis.cpp. This code loops over all the events in the file:
for (Long64_t jentry=0; jentry<nentries;jentry++){
Inside this loop, it loops over all the particles in each event:
for(int i=0; i<_pdgid.size();i++) {
and it looks for stable particles (if( _status[i]==1)) that are muons (if(_pdgid[i]==13)).
A full list of particle ID codes is available here.
Further down, the code makes the combined dimuon 4-vector (TLorentzVector sum = v1 + v2;) and fills the histogram with the invariant mass of this new 4-vector.
Here are some good exercises. After making changes to the code, you will need to recompile (make), fixing any compilation errors, before you can run the updated code.
- 1) Add some more histograms. The histogram is declared near the top of the code:
TH1 * h_mass = new TH1F("mass", "mass", 100,0,300);
which has 100 bins, between 0 and 300. Some interesting things to plot: the number of muons
per event; the muon transverse momentum (pT), muon rapidity (y), dimuon rapidity, dimuon pT.
- 2) Modify the code to find b quarks and b antiquarks (pdgid 5 and -5) - note that b-quarks will not have status 1!
Then make similar plots to the muons: number of b-quarks, b and anti-b combined mass, etc.
- 3) Look at the reconstructed jets in the event, stored in a vector _jets.
Try matching jets to b-quarks, based on ΔR (see here, for example.) Plot the ΔR distribution, then require a jet to be with, for example ΔR<0.4 of a b-quark.
After matching a jet to the b-quark and b-antiquark, plot the mass of the combined jets.
Fitting
Finally, it is quite often worth fitting a parametric curve to the data. This code is a basic fitting example provided by the root authors. You could try including this into the plot.cpp code
and fitting the dimuon mass distribution.