ROOT Basics

Import Required Modules and Turn on Javascript

In [2]:
from ROOT import TFile, TCanvas, TH1F

%jsroot on
Welcome to JupyROOT 6.07/07

Open a Data File

In [3]:
file = TFile("opendata/data/Dimuons.root","READ")

Declare a Histogram

Histogram is a Graphical Way to Visualize Data

Divide Data into Equal Intervals (Bins) and Count How Many Values in Each Bin

Example Histogram of Distribution of Muon Charges

In [21]:
histogram = TH1F("Muon1_Charge","Muon1_Charge", 50, -2, 2)

declaration format: TH1F(name, title, number of bins, min value, max value)

ROOT Exercise 1:

Declare another histogram for x-component of muon momentum called Muon1_Px

In [36]:
histogram2 = TH1F("Muon1_Px","Muon1_Px", 100, -60, 60)

Loop Over Events in Data File

Fill the histogram with muon charge values (+1 or -1)

In [33]:
for dimuon in file.Dimuons:

Draw a Histogram on a Canvas

In [29]:
Canvas = TCanvas()



ROOT Exercise #2:

Plot another histogram (for example Muon1_Px)

Note: Same canvas can be used after clearing it with Canvas.Clear()

In [38]:
for dimuon in file.Dimuons:
In [39]:
In [ ]: