ROOT is well integrated with Jupyter Notebooks, both for what concerns its Python and C++ interface. This how-to explains some of the details. These instructions are relative to version 6.07.06 and later. For older versions please refer to this notebook. Here we list the relevant information about the integration:
In ROOT canvases, represented by the TCanvas class, are the entities which hold graphic primitives and more complex objects such as histograms or graphs. Canvases are updated automatically in several situations. Unfortunately this concept cannot be translated in a notebook.
Therefore, canvases must be drawn explicitly, for example a C++ cell could look like:
TCanvas c; myhistogram.Draw(); c.Draw();
It should be noted that without a canvas being explicitly defined by the user, ROOT provides a default one which can be accessed via the gPad variable (ROOT.gPad in PyROOT).
Note that the magics are available in Python notebooks after importing the ROOT module.
- %%cpp -d: code inside a cell is used to declare C++ functions.
- %%cpp -a: code inside a cell is used to build a C++ library with ACLiC.
- All integration is triggered by the import ROOT statement. Import statements like **from ROOT import *** are not supported at the moment.
We provide a ROOT Jupyter Kernel which allows to have C++ ROOTbooks.
- Functions and macros can be declared within cells marked with the %%cpp -d (or -a) magic.
- Include statements (#include "myheadeer.h") cannot coexist with other statements unless the cell is marked with the %%cpp -d (or -a) magic.
- The TTree::Scan method cannot be invoked and display many lines.