Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
JupyROOT

A software layer to integrate Jupyter notebooks and ROOT.

Installation

  1. Install ROOT6 (> 6.05)
  2. Install dependencies: pip install jupyter metakernel

Start using ROOTbooks

Set up the ROOT environment (. $ROOTSYS/bin/thisroot.[c]sh) and type in your shell:

root --notebook

This will start a ROOT-flavoured notebook server in your computer.

Alternatively, if you would like to use the Jupyter command directly, you can do:

jupyter kernelspec install $ROOTSYS/etc/root/notebook/kernels/root --user

Once the server is up, you can use ROOT with two kernels:

  1. ROOT C++: new kernel provided by ROOT
  2. Python: already provided by Jupyter

C++ ROOTbook

ROOT offers a C++ kernel that transforms the notebook in a ROOT prompt. Embedded graphics, syntax highlighting and tab completion are among the features provided by this kernel.

An example of how you would plot a histogram in a C++ ROOTbook is:

TH1F h("h","ROOT Histo;X;Y",64,-4,4);
h.FillRandom("gaus");
h.Draw();
c.Draw();
#define c(i)
Definition RSha256.hxx:101
#define h(i)
Definition RSha256.hxx:106
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878

Python ROOTbook

If you prefer to use Python, you can create a new Python kernel and import the ROOT libraries:

import ROOT

And then you could write something like:

c = ROOT.TCanvas("c")
h = ROOT.TH1F("h","ROOT Histo;X;Y",64,-4,4)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.

Additionally, you can mix Python and C++ in the same notebook by using the %cpp magic:

%%cpp
h->FillRandom("gaus");
h->Draw();
c->Draw();