'Need help to solve error in drawing histogram in root

this is my code I am checked it many times but it gives me an error when I run it.

TFile *f=new TFile("hist.root");
         TH1F *h = (TH1F*)f->Get("Phi_mu");
   auto c1= new TCanvas();             
     h->Draw();

this is the error message

///Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_113:1:
.C:21:3: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
         h->Draw();

can anyone tell me what is the wrong



Solution 1:[1]

You should check if your root file contains any TH1 object named Phi_mu.

In case you don't know how to check, just open your root file:

root -l  hist.root

then in the interactive mode, type:

_file0 -> ls()

here _file0 is the TFile object point to your root file. It will list all object in the root file, so you can check if the file contains the histogram you want to read.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rekkhan