Read a histogram

Hello all,

I was trying to open a histogram in a macro, I followed this solution

but in all the cases show me this error

and this is my histogram

how can I fix this problem?

TFile *f1 = new TFile("1cut.root");

 TH1F* h1 =(TH1F*)f1->Get("MVA_BDT");
 h1->Draw();

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi Manuel,

based on your screnshot, the MVA_BDT histogram is located in the TMVAppbdt1.root, but your code

TFile *f1 = new TFile("1cut.root");

tries to open a different file. Why?
It’s usually a very good idea to check if your file exists, can be opened, and does contain the wanted histogram. To do this you should modify your code to something like this:

TFile *f1 = TFile::Open("1cut.root");
if (!f1 || f1->IsZombie())
{
    printf("f1 can not be opened\n");
    return;
}
TH1F* h1 = static_cast<TH1F*>(f1->Get("MVA_BDT"));
if (!h1)
{
    printf("MVA_BDT can not be fetched from f1\n");
    return;
}

yes thanks, I was very distracted and tired , sorry for posting that noob question hahaha

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