Skip to content

YanzhaoW/SupervisingUniKoeln

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CMake configuration

example:

# CMake versions (could be higher)
cmake_minimum_required(VERSION 3.24)

# include root package
find_package(ROOT REQUIRED COMPONENTS Hist RIO MathCore)

# project name
project(test)

# C++ standard. Options: 11, 14, 17, 20, 23
set(CMAKE_CXX_STANDARD 20)

set(CMAKE_EXPORT_COMPILE_COMMANDS on)

# Create excutable from main.cpp
add_executable(main main.cpp)

# link the external package to your main.cpp
target_link_libraries(main PUBLIC ROOT::Hist ROOT::RIO ROOT::MathCore)

For other ROOT library targets, please visit this ROOT website.

Python and jupyter lab

initial setup

To use python with ROOT in a jupyter lab, a proper python environment should be set up. Here conda is used. The following steps only need to be done once in the beginning.

step 1: find out the python version

The python version of the conda environment must be matched with the ROOT version. To find out which python version should be used, run following command:

root-config --python-version

It prints out the corresponding python version for the ROOT you are currently using.

step 2: create conda environment

Run the following command with an environment name and the python version

conda create --name [any_name] PYTHON=[version]

Activate the conda environment:

conda activate [any_name]

step 3: install jupyter lab

pip install jupyterlab

Open the jupyter lab in your browser

The jupyter lab is usually run in our IKP servers instead of our local personal laptops. But still we can open the jupyter lab from the local web browser using so called ssh tunneling.

step 1: launch the jupyter in the server

Inside the IKP server, run the following command to launch the jupyter server:

jupyter lab --no-browser --port [port number]

Here the port number can be any larger number ( > 10000)

step 2: connect a ssh tunnel

In your local computer, run the following command:

ssh -L [port number]:localhost:[port number] server_name -N -f

Here the port number must be the same as the port number during the jupyter launching. The server_name should be the server where you launch the jupyter lab.

step 3: open the url

Once the jupyter lab is launched in the server, you can find an url from the terminal output. Copy the url, paste in the web browser and hit enter.

Use python and jupyter lab to plot histograms

step 1: import libraries

Import necessary ROOT libraries. The library name should be same with the class name.

from ROOT import TFile, TCanvas, TH1

step 2: open a root file and create a canvas

The usage of the ROOT classes is the same as in C++, except that in python only objects are used instead of pointers.

input_file = TFile("any_root_file.root", "read")
canvas = TCanvas("canvas", "canvas", 0, 0, 800, 600)

step 3: plot the histogram

The name of the histogram can be obtained by using a member function input_file.ls() from the TFile object. After knowing the name of the histogram, it can obtained with:

histogram = input_file.get("histogram_name")
histogram.Draw()
canvas.Draw()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors