Hands-on 7b

Nuclear Valley of stability

Start code: session7-start.tar.gz

In this exercise we will exploit what we have learned in the previous sessions:

  • reading in data of a given format
  • saving data in objects
  • using collections
  • using ROOT to create histograms

Start code

The start code is provided in the nuclei directory within session7-start.

We will use the CMake tool to build our application. CMake is a tool, independent from ROOT, that helps to simplify the build process for development projects across different platforms. It automates the generation of build systems such as Makefiles or Visual Studio project files.

To build a program with CMake:

  • Create a build directory, in the directory where you have nuclei. (In our instructions, we will suppose you kept it in session7-start.)
$ cd session7-start
$ mkdir nuclei_build
$ cd nuclei_build
$ cmake ../nuclei
$ make
  • If compilation went ok, we can now run the program readNuclei from the “build” directory:
$ ./readNuclei

Reading nuclei data

In this exercise we will adapt our program readIsotope.cxx and make it reading the new nuclei.txt file containing the data of known nuclei. You have to adapt the code to take into account the new data structure and the new class, Nucleus.

During code development you can use the nuclei_small.txt data file which contains a fraction of all data. When your program reads the data ok you can test with the big nuclei.txt file.

Note, that the input stream operator for the Nucleus class is not provided and so you need to read the data in local variables first and then use the class “set” functions to save them in the Nucleus objects.

If you have difficulties to complete this step you can follow the instructions step by step.

Adding an histogram (binding energy)

To draw a valley of stability we will display the nuclei binding energy per nucleus N (the number of neutrons) and Z (the number of protons). We will use a two-dimension histogram of double values (TH2D) which we will fill with the nucleus N, Z values weighted by the value of the binding energy. The created histogram will be written in a ROOT file, which will be then inspected in the ROOT session.

#include "TFile.h"
#include "TH2D.h"

// ...

  // Open Root file
  TFile rootFile("nuclei.root", "RECREATE");

  // create Root histogram
  TH2D h2("bindingEnergy", "bindingEnergy", 180, 0., 180., 120, 0., 120.);

  // Add a loop over the vector of nuclei 
  // Inside the loop get the values of N, Z and bindingEnergy
  // Fill the values in the histogram only if bindingEnergy>0.

  // After the loop save the histogram in the Root file and close the file

Hint: As the Nucleus class provides Z and A, you have to compute N = A - Z

When the program works, you can inspect the histogram in a ROOT session using a ROOT browser:

root[0] TBrowser b;

Find the nuclei.root in the left tab in the browser and use double-click to see the file content and then to draw an histogram.

To get a nice view, select the Histogram view options: "2D", "Col", "Palette". You can choose a "rainbow palette" with gStyle->SetPalette(55); setting, typed in the interpreter. To remove the box with statistics in the upper right corner, right-click on the histogram, select "SetStats" and fill 0 or kFALSE.

Adding histogram half-life

To display the nuclei half-life add another histogram with the same parameters as the previous one except for its name and title.

While the half-life values in the file are provided in seconds, the Nucleus class provides also a getter function that return the order (log10) of the half-life value expressed in years:

  double getLogHalflife();

Finally, as the 0 value has a special meaning in the context of histogram, we will shift all the filled values by a constant, for example 20:

h.Fill(n, z, logHalflife+20);