Start code: session7-start.tar.gz
In this exercise we will exploit what we have learned in the previous sessions:
The start code is provided in the
nuclei directory within
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:
nuclei. (In our instructions, we will suppose you kept it in
$ cd session7-start $ mkdir nuclei_build $ cd nuclei_build $ cmake ../nuclei $ make
readNucleifrom the “build” directory:
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,
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
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.
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
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 h2.Write(); rootFile.Close();
Hint: As the
Nucleus class provides
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 TBrowser b;
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
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:
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
h.Fill(n, z, logHalflife+20);