Unable to Draw Histogram from directory

HI all,

I am trying to read a histogram from a TDirectory but somehow its not drawing. I am trying to draw it like:

import ROOT as r

file = r.TFile.Open("Timing_Data_new.root")

dir = file.Get("asahi_0p0Prct_Th60mv_SF6_09p4kV")

hist = r.TH1F()

hist = dir.Get("Hist_09p4kV")

hist.Draw()

I am also attaching my input root file [1]. Please let me know what I am doing wrong?

Thanks,
Ram

[1] Timing_Data_new.root (43.1 KB)

Hi Ram,
I think we’ll need more information because as you described the situation I cannot reproduce your problem:

If I do, from a terminal:

$ python
>>> import ROOT
>>> file = ROOT.TFile.Open("Timing_Data_new.root")
>>> hist = file.Get("asahi_0p0Prct_Th60mv_SF6_09p4kV/Hist_09p4kV")
>>> hist.Draw()

I get a histogram correctly drawn in a canvas. The commands above should be completely equivalent to what you wrote above.

How are you executing your commands? As a script or in a python interpreter? Can you try my commands from an interpreter and see if they work? What version of ROOT are you using? What version of python?
If you can think of other info that might help narrow the problem down just write them.

Cheers,
Enrico

Hi Enrico,

Thanks for the response.

Yes, from interpreter it worked fine.

I noticed that the above script also worked but only after defining the TCanvas.

import ROOT as r

file = r.TFile.Open("Timing_Data_new.root")
dir = file.Get("asahi_0p0Prct_Th60mv_SF6_09p4kV")
hist = r.TH1F()

hist = dir.Get("Hist_09p4kV")

c = r.TCanvas("c")
hist.Draw()

My root version is ROOT 6.13/01 . This is not the stable version but I forgot to change the git branch and installed. Python version is Python 2.7.10

Thanks & regards,
Ram

So you are saying that when you execute the snippet above as python myscript.py nothing happens? or you get a blank canvas?

When i run my script like python -i myscript.py then I get a blank canvas if I don’t define the canvas.

ok I think that is expected behavior in pyROOT (you need to explicitly define the canvas), but @etejedor can comment with more authority on this

Hi,

It should not be necessary to create the canvas explicitly since a default one should be created for you. Also, it should make no difference when you run it with python -i myscript.py or when you run it from the shell step by step.

If I run this from lxplus (this uses ROOT 6.13):

[etejedor@lxplus026 ~]$ source /cvmfs/sft.cern.ch/lcg/views/dev3/latest/x86_64-slc6-gcc62-opt/setup.sh 
[etejedor@lxplus026 1]$ python -i myscript.py 
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
>>> 

Do you also see the message about the default canvas creation, but when you look at it is empty? Can you click on the canvas with the mouse, to check if it is a refreshing problem?

Enric

Dear Enric,

Yes, when I click on the canvas it appeared. So, it is a refreshing problem if I don’t define canvas explicitly.

with regards,
Ram

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