Session 1

Examen 2021-2022 - Session 1

Part A:test

Getting start code - Part B

Start code: examen_code.tar.gz

Download the start code, upack it and copy the top directory examen_code in a new directory, named examen_YourFamilyName. You should develop your solutions in this new directory.

cd 
tar xzvf examen_code.tar.gz
cp -r examen_code examen_YourFamilyName
cd examen_YourFamilyName

Task 1: isotopes

The given code in readIsotopes.cxx is buggy. Correct the compilation errors and then test the program.

Bonus: There is still a problem in the program running; find it and correct the program.

Task 2: morse

The task is to develop a program, that decode Morse code sentences stored in a text file. When the program is functional, translate the example text file encoded.txt, and copy the translation in another text file translated.txt.

We provide you with a skeleton morse.cxx source file as well a Makefile building the executable. This source file contains two vectors:

  • a vector of characters, v_decoding, collecting the characters with an encoding
  • a vector of strings, v_encoding, collecting the Morse encoding of the corresponding characters.

Example:

v_decoding[2] = 'C',  v_encoding[2] = "-.-."

Compile the skeleton file to check, then develop the program further.

Program development - Steps:

  1. Complete the function codeToChar to translate each word from Morse code to a letter
  2. Read the encoded text file word by word and decode it using the codeToChar function
  3. Print the translation to the screen

Task 3: histogram

The task is to develop a program, that creates a ROOT file with a histogram of randomnly generated numbers. When the program is functional, open the generated ROOT file in a ROOT interactive session and use the “File” menu in the browser to save the histogram image in a .png file.

In the provided program histogram.cxx, a random number generator defined in the Generator class is used to print 10 random values on the screen.

To compile our program with ROOT libraries, a CMake configuration file is provided.

First source ROOT environment:

$ source /nfsapp/physics/root.bash

Create build directory and generate Makefile

## cd to your examen_YourFamilyName directory
$ mkdir histogram_build
$ cd histogram_build
$ cmake ../histogram

After performing the steps above (just once), you can continue to compile the program in the histogram_build directory with a simple make command:

$ make

Program development - Steps:

  1. Add the code to create a ROOT file
  2. Add the code to create a 1-dimension ROOT histogram: TH1D, with 100 bins, (min,max) = (0., 1.)
  3. Add a loop to generate 10000 random numbers and fill them in the histogram
  4. Write the histogram and close the file

Bonus:

The provided Generator class can generate random numbers according to three distributions:

  • uniform
  • normal (gaussien) - default
  • exponentiel.

Let your program to create and save two more histograms for the other distributions.

Your Solution

Pack the code which you developed in a single tar file and send the tar file by e-mail to both teachers: ivana@ipno.in2p3.fr, lafage@ipno.in2p3.fr.

Before you leave the room, check with the teachers that they received your code.

cd 
tar czvf examen_YourFamilyName.tar.gz examen_YourFamilyName

Solution: