Import ROOT, .Draw not displaying image on Jupyter Notebook

Hi, I have the problem that I am using the import ROOT library, to use the ROOT CERN functions. But when I want to graph my histogram nothing appears, empty space appears for the histogram without canvas or anything, only space but nothing is seen, part of my code is as follows:

from root import TFile, TCanvas, TPad, TChain, TLegend, TLine, THStack, TArrow, TEfficiency
from root import kGreen, kBlue, kRed, kBlack, kOrange, kGreen, kCyan, kMagenta, kAzure
from root import TH1D
import numpy as np
% jsroot on

chalpa = TChain ("alpa")
chalpa.AddFile ("alpaprub.root")

def getHistogram (chain, leaf, name, title, bins, minHist, maxHist):
    hist = TH1D (name, title, bins, minHist, maxHist)
    for i in range (chain.GetEntries ()):
        chain.GetEntry (i)
        #some cuts
        if chain.alpa_3prong_chiProb <= 0:
        hist.Fill (chain.GetLeaf (leaf) .GetValue ())
    return hist

alpaThr = getHistogram (chalpa, "thrust", "alpaThr", "", 50,0.6,1.0)

alpaSC3 = getHistogram (chalpa "sumCos3prong", "alpaSC3", "", 50, -1,3.2)

alpaThr.SetStats (0)
alpaThr.SetLineColor (kBlue + 4)
alpaThr.SetFillColorAlpha (kBlue + 4, 0.25)

alpaSC3.SetStats (0)
alpaSC3.SetLineColor (kBlue + 4)
alpaSC3.SetFillColorAlpha (kBlue + 4, 0.5)

c1 = TCanvas ("c1", "Thrust", 900, 400) ()

alpaThr.Draw ("HIST")

label = TLegend (.2, .60, .45, .85);
label.AddEntry (alpaThr, "#tau +} #tau -", "f")
label.SetBorderSize (0)
label.Draw ()

alpaSC3.Draw ("HIST same")
label.Draw ()

c1.Draw ()

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

I don’t see anything obvious. Maybe @etejedor can take a look


I noticed that you do:

from root import

Whereas ROOT is imported via the ROOT module.

I tried your code by doing:

import ROOT

in the first cell. Then in the second cell

%jsroot on
# rest of your code, replacing root with ROOT

and I saw the canvas appearing. I don’t have your file so the histogram was empty, but the axis and the legend were there.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.