The aim of the workshop is to familiarize students with the CERN ROOT framework. The focus of the activities will be on working with CERN ROOT files, which is a necessary basis for other activities of this summer school. The workshop also includes a small demonstration of visualization facilities in the framework. Then students will use the framework to finish the implementation of a reader required to read the EUSO-SPB1 data. Another task is to finish the implementation of a reader for ESAF ROOT files. Finally, data read from the files will be visualized.
The Air Shower Pattern Recognition summer school consists of the following five workshops:
- Introduction to the JEM-EUSO and running air shower event simulations
- Reading the detector data
- Implementation of a feature extraction method
- Classification of the data through the extracted features
- Classification of the data using a convolutional neural network
Slides
Practical activity
- Writing and reading and ROOT files
- Partial Implementation of a Acquisition format reader
- Partial implementation of ESAF ROOT file reader (simu2npy)
- Visualization of data from the files
#1 Writing and reading and ROOT files
- Login to the remote machine (school.spaceforum.sk) using the personal credentials provided to each student.
- If you also want to be able to visualize plots in GUI connect to the ssh server with X11 forwarding (Optional).
- You can use Visual Studio Code’s extension “Visual Studio Code Remote – SSH” (Developing on Remote Machines using SSH and Visual Studio Code)
- If you have CERN ROOT on your computer, you can do this task locally.
- Change your current working directory to writing_reading_data.
- Activate the ROOT environment using
thisroot.sh
script. Paths apply for the machineschool.spaceforum.sk
.source /opt/ROOT6/bin/thisroot.sh
- Create a CERN ROOT file filled by random histograms
- Based on official CERN ROOT tutorial https://root.cern/manual/storing_root_objects/
- Review the file named
example_writing.C
- Open ROOT by running command:
root
Now you are in the ROOT shell environment (Cling). - Execute macro:
.x example_writing.C
- List contents of your current working directory using:
.!ls
- Check your current directory in ROOT environment:
gDirectory->pwd()
- In the ROOT shell environment, open the created file for reading:
TFile fdemo("demo.root", “READ”)
- Check your current directory in ROOT environment:
gDirectory->pwd()
- List contents of the file
fdemo.ls()
- Create a pointer variable:
TH1F *h3;
- Retrieve the entry “h3” from the file:
fdemo.GetObject("h3",h3);
- Check if it was retrieved:
h3
- Save the histogram as a macro:
h3->SaveAs("h3.C")
- Create a canvas (if you have X11 forwarding, a new window should open):
TCanvas c1;
- Draw the histogram:
h3->Draw()
- Save the canvas as an image:
c.SaveAs("c1.png")
- Exit the ROOT shell:
.q
- Creating and writing a ROOT tree.
- Based on the official CERN ROOT tutorial
https://root.cern/manual/trees/#writing-a-tree - Copy a file from ROOT tutorials directory to your directory:
cp -v $ROOTSYS/tutorials/tree/cernbuild.C .
- Edit the file, by changing the output file name to the “demo.root” and change the call of the method
TFile::Open()
to UPDATE mode. - Run the macro
root -b -q cernbuild.C
- Open the demo file in ROOT.
root demo.root
- List the contents of the file:
_file0->ls()
- Print tree information (GetObject happens automatically)
T->Print()
- See more possible activities with the tree here: https://root.cern/manual/trees/#writing-a-tree
- If you have X11, open TBrowser, and browse the file through GUI.
new TBrowser
- Based on the official CERN ROOT tutorial
#2 Partial Implementation of the acquisition file format reader
The aim of the task is to enable running of the feature extraction procedure on an input file. The feature extraction procedure will be developed at the next lesson. In the framework used here, the feature extraction for a single file is executed by feature_extraction.py
script.
- TTree-related operations in acquisition data reader (
AcqL1EventReader
)event_reading.ttree_reader.TTreeReader
:- Add calls of appropriate ROOT function to retrieve branch and leaf of a TTree object.
event_reading.acq_l1_event_reader.AcqL1EventReader.__init__
:- Provide allocated memory block of sufficient size for the branch
photon_count_data
- Provide allocated memory block of sufficient size for the branch
event_reading.gtu_pdm_data.GtuPdmDataIterator.__next__
:- Retrieve an entry from the tree. The index of the entry is stored in the member variable
aer._current_tevent_entry
- Retrieve an entry from the tree. The index of the entry is stored in the member variable
- Run the
feature_extraction.py
to visualize the data.- The script can be executed in the following way:
python feature_extraction.py ~/data/workshop2/acq.root
- The script is preconfigured to run the skeleton feature extraction code designated for this workshop.
- Basic visualization is implemented as a part of the method for processing of a single frame sequence (
event_processing.workshop.EventProcessingWorkshop.process_event
). The visualization draws three projections of the frame sequence.
- The script can be executed in the following way:
- Visualize data in ETOS software and compare the results.
- Recommended approach is to open the ETOS in a new shell and follow steps from the previous workshop.
- Use NumPy to apply an appropriate transformation to match visualization in the ETOS software.
Make the changes inevent_reading.GtuPdmData.__init__
#3 Partial implementation of ESAF ROOT file reader (simu2npy)
- simu2npy: A converter from ESAF output files to numpy files
- Activities:
- Review the code, observe steps required for working with ESAF under python
- Locate method
load_etree(self, pathnames, use_tchain=True)
, observe the usage of ROOT’s TChain. - Locate method
create_hierarchy_dicts(self, ev=None)
- Locate method
- Review the following ESAF’s files:
packages/common/root/include/EEvent.hh
packages/common/root/src/EEvent.cc
packages/common/root/include/EDetector.hh
packages/common/root/src/EDetector.cc
packages/common/root/include/EFee.hh
- Finish the implementation of the method
create_hierarchy_dicts()
, call appropriateEFee
getter methods - Run the simu2npy program:
python simu2npy.py
#4 Visualization of data from the files
- Connect to the JupyterHub at http://school.spaceforum.sk
- Launch notebook “
Event visualization.ipynb
”
Further reading
The task of ROOT file reading could also be likely handled by using root_numpy package. It is developed within the Scikit-HEP project.
A potentially useful package is Uproot, which enables I/O with ROOT files without ROOT dependency.
Another related package is root_pandas. This allows reading a ROOT file into Pandas DataFrame.
CERN ROOT package provides wide range of functions. We encourage you to review the Getting Started page at the root.cern.