NTuple python drawing graph

Hi all,

I need to draw a function from ntuple
data.root is the name of root file
vdMScanData is ntuple directory
SCANDATA is ntuple subdirectory where are stored “NominalSeparation” and “ScanLB” branches(variables)

This is what I tried:

from ROOT import TCanvas, TPad, TFile, TPaveText
from ROOT import gBenchmark, gStyle, gROOT
c1 = TCanvas(‘c1’,‘The Ntuple canvas’,200,10,700,780)
f1 = TFile(‘data.root’)
pad1 = TPad(‘pad1’,‘This is pad1’,0.02,0.52,0.48,0.98,21)
pad1.cd()
ntuple = gROOT.FindObject(‘vdMScanData’)
ntuple.Draw(‘NominalSeparation:ScanLB’)

and it`s not working
Can you help me with this?

thanks in forward,
V

Hello

Can you do a: print ntuple and check whether or not is it returning a null ptr? Please, post the result here.

Shubham

This is the macro

from ROOT import TCanvas, TPad, TFile, TPaveText
from ROOT import gBenchmark, gStyle, gROOT

c1 = TCanvas(‘c1’,‘The Ntuple canvas’,200,10,700,780)

gBenchmark.Start(‘ntuple1’)

f1 = TFile(‘2018Oct14Scan1-3-v06.root’)

pad1 = TPad(‘pad1’,‘This is pad1’,0.02,0.52,0.48,0.98,21)

pad1.Draw()

pad1.cd()
pad1.SetGrid()
pad1.SetLogy()
pad1.GetFrame().SetFillColor(15)
ntuple = gROOT.FindObject(‘SCANDATA’)

ntuple.Draw(‘NominalSeparation:ScanLB’)

c1.Update()

And this is the traceback

File “ntuple1.py”, line 35, in
ntuple.Draw(‘NominalSeparation:ScanLB’)
ReferenceError: attempt to access a null-pointer

You probably meant:

ntuple = f1.Get(‘SCANDATA’)

Hello

You can see that the error says: attempt to access null-pointer which means the ntuple is not pointing to your SCANDATA branch.
The solution given by @pcanal should work.

Regards

This is what solved the problem
ntuple=f1.Get(“vdMScanData”)

Thank you guys

Regards

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