Error: attempt to access a null-pointer, while plotting histo

Dear ROOT experts,

I have a root file with several histograms in it. I am trying to access those histograms and plot them, but getting the error attempt to access a null pointer . I opened the file with TBrowser and all TH1F histograms can be displayed. Here is part of the code and below the error message.

	histo_file = ru.TFile(outfile, "READ")   
	
	# call each histo
        h0 = ru.TH1F()
        h0 = histo_file.Get("ZZ4Mu")
       
	final_histo = ru.TFile("final_histo.root", "RECREATE")
	
	# define canvas 
	cnv = ru.TCanvas("canv", "canv", 400, 400)

        final_histo.cd()
        cnv.cd()

        h0.Draw("HIST")

Error message:

  File "plotHisto.py", line 156, in <module>
    h0.Draw("HIST")
ReferenceError: attempt to access a null-pointer

Thanks in advance,
Aya

_ROOT Version: 6.18.04
_Platform: Ubuntu.18.04


After the line you better check that h0 is really set. It might be that Get did not work. For instance if ZZ4Mu does not exist in your file.

Thanks for answering, how could I be able to check it?

rootls -l final_histo.root

Just test if the returned pointer exits, ie: is not null.

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