Copy histogram from a root file

_Hi, i have a issue when a try to copy a histogram from a root file with the line


i have this Error.

Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.

just to know what is going on, this macro worked before, and now it does not. maybe it’s just a pointer issue, or the version of root (“6.24/06”).

Please read tips for efficient and successful posting and posting code

_ROOT Version: 6.24/06
_Platform: Ubuntu
Compiler: Not Provided

Hi Sergio,

try running

if (!h)
    printf("No TProfile with such name exists in the file!\n");

If the error comes from this line, it’s because f == NULL.

Thanks to the replies
I will make a better description of the problem.
The code that i have now is:

void MakeHisto(){

    std::unique_ptr<TFile> file( TFile::Open("myrootfileroot") );
    if (!file || file->IsZombie()){
        std::cerr << "Error opening file" << endl;
    TH1 *h;
    h = static_cast<TH1*>(file->Get("Pt"));
    if (!h) printf("No TH1 with such name exists in the file!\n");


and the output is

5. Listing inside of subfolders. 
Declare the h hsito as TH1
Copy the histogram!
No TH1 with such name exists in the file!
 Generating stack trace...
 0x00007f568ef985b4 in <unknown function>
 0x00007f568ef98053 in <unknown function>
 0x00007f5689a59698 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f56899c2557 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f56899c2cc9 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f5689ad0ea5 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f5689adf4b5 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f5689ae08e6 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f5689ac9e39 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f56897d5fa9 in <unknown> from /snap/root-framework/412/usr/local/lib/
 0x00007f56897d6a3f in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x8e3 from /snap/root-framework/412/usr/local/lib/
 0x00007f56897da5ae in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0xa6 from /snap/root-framework/412/usr/local/lib/
 0x00007f568f2904a2 in TApplication::ExecuteFile(char const*, int*, bool) at TApplication.cxx:? from /snap/root-framework/412/usr/local/lib/
 0x00007f568f28fc00 in TApplication::ProcessFile(char const*, int*, bool) + 0x34 from /snap/root-framework/412/usr/local/lib/
 0x00007f568f28f9eb in TApplication::ProcessLine(char const*, bool, int*) + 0xda9 from /snap/root-framework/412/usr/local/lib/
 0x00007f568f64e8fb in TRint::ProcessLineNr(char const*, char const*, int*) + 0x24d from /snap/root-framework/412/usr/local/lib/
 0x00007f568f64d10a in TRint::Run(bool) + 0x6b2 from /snap/root-framework/412/usr/local/lib/
 0x00005618841db241 in main + 0x78 from /snap/root-framework/412/usr/local/bin/root.exe
 0x00007f568ebcb0b3 in __libc_start_main + 0xf3 from /lib/x86_64-linux-gnu/
 0x00005618841db10e in _start + 0x2e from /snap/root-framework/412/usr/local/bin/root.exe
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_8:1:
/home/sergio/Documents/QualificationTask/Programming/Macros/MakeHisto.cpp:97:5: warning: null passed to a callee that requires a non-null argument [-Wnonnull]

Screenshot from 2022-02-15 20-50-46

Is the Pt histogram listed by this? Also, cd() returns a boolean, so you can check if it was successful.

Instead of "file->ls try “gDirectory->ls” and instead of “file->Get” try “gDirectory->Get”.

BTW. You should have:

if (!h) printf(...);
else h->Draw();

you are right, thanks a lot to all. now it’s work.

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