📚 What is that?
Setting up ROOT in Google Colab has traditionally been a time-consuming process that can take hours away from your valuable research time. This project eliminates these installation hurdles by providing ready-to-use, optimized ROOT binaries that work seamlessly with Colab's environment.
Instead of wrestling with build configurations or waiting for lengthy compilations, you can now have ROOT up and running in your Colab notebook within seconds. The project pre-built binaries are automatically maintained to stay compatible with Colab's Python versions and include all commonly used features while maintaining optimal performance.
🔧 Available Builds
ROOT 6.30.04
ROOT 6.32.04
🛠 Build Features
Included Components
- ✅ Python bindings (PyROOT)
- ✅ RooFit statistical analysis package
- ✅ MathMore libraries
- ✅ Multithreading support (IMT)
- ✅ SSL and XML support
- ✅ XRootD support (built-in)
- ✅ ROOT 7 features
- ✅ 3D Graphics (graf3d)
- ✅ PYTHIA8 integration
- ✅ Fortran support
- ✅ Thread support
Excluded
- ❌ OpenGL support
- ❌ Vector Detection Technology (VDT)
- ❌ SQLite support
- ❌ GDML support
- ❌ Davix
- ❌ FITS I/O
- ❌ Table support
- ❌ Testing modules
- ❌ Debug symbols
🚀 Detailed Usage Guide
1. Initial Setup
# Check Python version and install ROOT
!python --version
# Step 1: Download the pre-built ROOT tarball from GitHub Releases
!wget -q --show-progress https://github.com/MohamedElashri/ROOT/releases/download/ubuntu/root_v6.30.04_Ubuntu_Python3.11.zip
# Step 2: Extract the ROOT files
!unzip -q root_v6.30.04_Ubuntu_Python3.11.zip
# Step 3: Install missing system dependencies for ROOT
!sudo ldconfig & apt-get install -y git dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev libxft-dev libxext-dev tar gfortran subversion libpython3.11-dev
# Step 4: Remove the tarball to free up space
!rm -f root_v6.30.04_Ubuntu_Python3.11.zip
# Step 5: Install Compatible libssl
!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
!sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
!rm -f libssl1.1_1.1.1f-1ubuntu2_amd64.deb
# Step 6: Configure Python paths and load libraries
import sys
import ctypes
# Append ROOT paths to Python
sys.path.append("root_build/")
sys.path.append("root_build/bin/")
sys.path.append("root_build/include/")
sys.path.append("root_build/lib/")
# Load the required shared libraries (.so files)
ctypes.cdll.LoadLibrary("root_build/lib/libCore.so")
ctypes.cdll.LoadLibrary("root_build/lib/libThread.so")
ctypes.cdll.LoadLibrary("root_build/lib/libTreePlayer.so")
print("ROOT Libraries Loaded Successfully!")
2. Basic Data Analysis
# Create and fill a histogram
import ROOT
# Create a 1D histogram
h1 = ROOT.TH1F("h1", "Gaussian Distribution;X;Entries", 100, -5, 5)
# Fill with random numbers
for i in range(10000):
h1.Fill(ROOT.gRandom.Gaus(0, 1))
# Customize appearance
h1.SetLineColor(ROOT.kBlue)
h1.SetFillColor(ROOT.kBlue - 10)
# Draw and save
c1 = ROOT.TCanvas("c1", "Canvas", 800, 600)
h1.Draw("hist")
c1.Draw()
3. Data Fitting
# Create a more complex example with fitting
import ROOT
import numpy as np
# Create data with two peaks
h2 = ROOT.TH1F("h2", "Double Gaussian;X;Entries", 100, -10, 10)
# Fill with two Gaussians
for i in range(5000):
h2.Fill(ROOT.gRandom.Gaus(-2, 1.5))
for i in range(3000):
h2.Fill(ROOT.gRandom.Gaus(3, 0.8))
# Define fit function
fit_func = ROOT.TF1("fit_func", "gaus(0) + gaus(3)", -10, 10)
fit_func.SetParameters(2000, -2, 1.5, 1000, 3, 0.8)
# Perform fit
h2.Fit(fit_func, "R")
# Draw results
c2 = ROOT.TCanvas("c2", "Fit Canvas", 800, 600)
h2.Draw()
c2.Draw()
4. Advanced Visualization
# Create a 2D histogram
h3 = ROOT.TH2F("h3", "2D Gaussian;X;Y", 50, -5, 5, 50, -5, 5)
# Fill with correlated random numbers
for i in range(50000):
x = ROOT.gRandom.Gaus(0, 1)
y = ROOT.gRandom.Gaus(0.5 * x, 0.5)
h3.Fill(x, y)
# Create canvas and draw
c3 = ROOT.TCanvas("c3", "2D Canvas", 800, 800)
# Set color scheme and draw options
ROOT.gStyle.SetPalette(ROOT.kBird)
h3.Draw("colz")
# Add color scale
c3.SetRightMargin(0.15)
c3.Draw()
⚠️ Known Issues
SSL Certificate Issues
If you encounter SSL certificate validation errors when using ROOT in Google Colab, this typically occurs due to missing or outdated SSL libraries. You can resolve this by installing the required SSL package:
!wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
!sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
!rm libssl1.1_1.1.1f-1ubuntu2_amd64.deb
Other Common Issues
- If ROOT fails to import after installation, try restarting your Colab runtime
- If you need any of the excluded features, you will need to build ROOT with them
- Building ROOT in the same Colab runtime will take most of the runtime allocation time